![]() |
|
|
|
||||||
Home
Books
SimTel
C/C++
|
Home CodeBase! Snippets that will make you work faster
Creating buttons
#define BUTTON_QUIT 20
#define BUTTON_RESTART 21
// hwndMain = you main window handle
// hInstance = passed to you via WinMain
CreateWindow("BUTTON", "Press me to quit", BS_PUSHBUTTON | BS_TEXT, x, y,
width, height, hwndMain, (HMENU) BUTTON_QUIT, hInstance, NULL);
CreateWindow("BUTTON", "Press me to restart", BS_PUSHBUTTON | BS_TEXT, x, y,
width, height, hwndMain, (HMENU) BUTTON_RESTART, hInstance, NULL);
Directory Dialogs BROWSEINFO bi; char dirname[100]; bi.hwndOwner=NULL; bi.pidlRoot=NULL; //start from desktop bi.pszDisplayName =dirname; bi.lpszTitle="Select Directory"; bi.ulFlags=BIF_RETURNONLYFSDIRS; bi.lpfn=NULL; bi.lParam=NULL; bi.iImage=NULL; SHBrowseForFolder(&bi); m_TargetDir=dirname; UpdateData(FALSE); Load BMP's without GDI
BOOL LoadSplashBitMap(int *xSize, int *ySize) {
HANDLE hBitMapFile = INVALID_HANDLE_VALUE ;
BITMAPFILEHEADER bmfh ;
BITMAPINFOHEADER bmih ;
LPBITMAPINFO lpbmi ;
LPVOID lpvBits ;
DWORD dwRead ;
HDC hDC ;
/* Retrieve a handle identifying the file */
if ((hBitMapFile = CreateFile(SPLASHFILE, GENERIC_READ,
FILE_SHARE_READ,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_READONLY,
(HANDLE)>NULL)) == INVALID_HANDLE_VALUE)
return FALSE;
/* Retrieve the BITMAPFILEHEADER structure */
if (!ReadFile(hBitMapFile, &bmfh, sizeof(BITMAPFILEHEADER),
&dwRead, (LPOVERLAPPED)NULL) ||
dwRead != sizeof(BITMAPFILEHEADER)) goto Error ;
/* Retrieve the BITMAPINFOHEADER structure */
if (!ReadFile(hBitMapFile, &bmih, sizeof(BITMAPINFOHEADER),
&dwRead, (LPOVERLAPPED)NULL) ||
dwRead != sizeof(BITMAPINFOHEADER)) goto Error ;
/* Allocate memory for the BITMAPINFO structure */
if ((hMem1 = GlobalAlloc(GHND, >sizeof(BITMAPINFOHEADER)+((1
bmih.biBitCount)*sizeof(RGBQUAD))))
== NULL || (lpbmi = GlobalLock(hMem1)) == NULL) goto Error ;
/* Load BITMAPINFOHEADER into the BITMAPINFO structure */
lpbmi->bmiHeader.biSize = bmih.biSize ;
lpbmi->bmiHeader.biWidth = bmih.biWidth ;
lpbmi->bmiHeader.biHeight = bmih.biHeight ;
lpbmi->bmiHeader.biPlanes = bmih.biPlanes ;
lpbmi->bmiHeader.biBitCount = bmih.biBitCount ;
lpbmi->bmiHeader.biCompression = bmih.biCompression ;
lpbmi->bmiHeader.biSizeImage = bmih.biSizeImage ;
lpbmi->bmiHeader.biXPelsPerMeter = bmih.biXPelsPerMeter ;
lpbmi->bmiHeader.biYPelsPerMeter = bmih.biYPelsPerMeter ;
lpbmi->bmiHeader.biClrUsed = bmih.biClrUsed ;
lpbmi->bmiHeader.biClrImportant = bmih.biClrImportant ;
/* Retrieve the color table.
if (!ReadFile(hBitMapFile, lpbmi->bmiColors,
((1<< bmih.biBitCount)*sizeof(RGBQUAD)),
&dwRead, (LPOVERLAPPED) NULL) ||
dwRead != ((1<
Identifying 16 bit surfaces in DirectX (by Christoph Meyer)
Convert 256 color pixel to 16 bit (by Christoph Meyer)
USHORT _RGB16BIT (int r , int g, int b)
{
// the return value
USHORT retval = 0;
// max value has to be either 32 or 64,
// depending on the number of bits of the channel:
if (redbits == 6) r >>= 2; else r >>= 3;
if (greenbits == 6) g >>= 2; else g >>= 3;
if (bluebits == 6) b >>= 2; else b >>= 3;
// as I said, I don’t know how many modes there are. If you do, shorten
// the function by removing unnessessary lines above.
// And please tell me! ;-)
// now build a word of the three channels by shifting them by the
// _correct_ number of bits:
retval = (USHORT) (b + (g << bluebits) + (r << (bluebits + greenbits)));
// return the color:
return(retval);
}
|
||||||