Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

Image Loading... Image Loading...
Click Here to Visit Our Sponsor

Home
News
Cartoon

Books
Reviews

SimTel
Compress
Database
Delphi
Desktop
Diskutl
Fileutl
Graphics
Inet
Mmedia
Prog
Scrsave
Util

C/C++
CodeBase!
Libraries
Tutorials
WebLinks

Pascal
Libraries
WebLinks



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<

  if (!ReadFile(hBitMapFile, lpvBits, (bmfh.bfSize - 
      bmfh.bfOffBits), &dwRead, (LPOVERLAPPED) NULL) ||
      dwRead != (bmfh.bfSize - bmfh.bfOffBits)) goto Error ;


  /* Create a bitmap from the data stored in the .BMP file */

  hDC = GetDC(hMainWnd) ;

  hBitMap = CreateDIBitmap(hDC, &bmih, CBM_INIT, lpvBits,
    lpbmi, DIB_RGB_COLORS) ;

  ReleaseDC(hMainWnd, hDC) ;
  if (hBitMap == NULL) goto Error;


  /* Unlock the global memory objects and close the .BMP file */

  GlobalUnlock(hMem1) ;> GlobalUnlock(hMem2) ;
  CloseHandle(hBitMapFile) ;


  /* Return size of bitmap */

  *xSize = bmih.biWidth ;
  *ySize = bmih.biHeight ;
  return TRUE ;

  /* An error occured: clean up mess before leaving */
Error:
  if (hMem1) GlobalFree(hMem1) ;
  if (hMem2) GlobalFree(hMem2) ;
  if (hBitMapFile != INVALID_HANDLE_VALUE) CloseHandle(hBitMapFile);
  return FALSE ;
}

Identifying 16 bit surfaces in DirectX (by Christoph Meyer)

DWORD redbits, greenbits, bluebits, rgbbits;

bool MyGetPixelFormat() { // init the vars: redbits = greenbits = bluebits = rgbbits = 0; // the PixelFormat structure: DDPIXELFORMAT DDPixelFormat; DDPixelFormat.dwSize = sizeof(DDPIXELFORMAT); // don’t forget this! // fill the pixel-format structure: if (lpddsprimary->GetPixelFormat(&DDPixelFormat)!=DD_OK) return false; // * error * // // fill the global vars with values from the struct: redbits = DDPixelFormat.dwRBitMask; greenbits = DDPixelFormat.dwGBitMask; bluebits = DDPixelFormat.dwBBitMask; rgbbits = DDPixelFormat.dwRGBBitCount; // now let us see, how much bits each color-channel has got (5 or 6): int bit = 0; bool done = false; DWORD count = 1; // look for # of blue bits: while (!done) { if (bluebits & count) { bit++; count <<= 1; } else done = true; } bluebits = bit; bit = 0; done = false; // look for # of green bits: while (!done) { if (greenbits & count) { bit++; count <<= 1; } else done = true; } greenbits = bit; bit = 0; done = false; // look for # of red bits: while (!done) { if (redbits & count) { bit++; count <<= 1; } else done = true; } redbits = bit; // Now the red-, green- and bluebits are filled return true; }

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);
}

Image Loading...