Click here to Skip to main content
16,008,469 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CS_SAVEBITS Pin
John R. Shaw26-May-03 13:34
John R. Shaw26-May-03 13:34 
GeneralRe: CS_SAVEBITS Pin
Neville Franks26-May-03 14:49
Neville Franks26-May-03 14:49 
GeneralRe: CS_SAVEBITS Pin
John R. Shaw26-May-03 17:04
John R. Shaw26-May-03 17:04 
GeneralRe: CS_SAVEBITS Pin
Neville Franks27-May-03 11:57
Neville Franks27-May-03 11:57 
QuestionTextOut with leaning attributes ? Pin
dlhson226-May-03 7:46
dlhson226-May-03 7:46 
AnswerRe: TextOut with leaning attributes ? Pin
John R. Shaw26-May-03 8:33
John R. Shaw26-May-03 8:33 
GeneralHosting Calender Pin
bsanoop1726-May-03 7:32
bsanoop1726-May-03 7:32 
GeneralSkins look good, but not always... Pin
georgiek5026-May-03 7:25
georgiek5026-May-03 7:25 
Hi,

After fully skinning my app using regions I have found out that it works perfect on Windows XP and not so perfect on Windows 98 SE.

Here are two screenshots to see what I am talking about:

Windows XP
Windows 98 SE

If you can see on the second screenshot the four buttons on the left show the mask color meaning that region wasn't applied correctly yet the top three buttons (Menu, minimize, and close) have their region set correctly. Here are some code samples used to skin the window and apply the region:


These two functions scan a bitmap, exclude the mask color and create a region.

HRGN cMainSkin::ScanRegion(HBITMAP pBitmap, BYTE jTranspR, BYTE jTranspG, BYTE jTranspB)
{
    // bitmap width and height
    WORD wBmpWidth, wBmpHeight;

    // the final region and a temporary region
    HRGN hRgn, hTmpRgn;

    // 24bit pixels from the bitmap
    BYTE *pPixels = Get24BitPixels(pBitmap, &wBmpWidth, &wBmpHeight);
    
     if (!pPixels) 
          return NULL;

    // create our working region
    hRgn = CreateRectRgn(0, 0, wBmpWidth, wBmpHeight);
    
     if (!hRgn) 
     { 
          delete pPixels;
         
         return NULL;
    }

    // ---------------------------------------------------------
    // scan the bitmap
    // ---------------------------------------------------------
    DWORD p = 0;

    for (WORD y = 0; y < wBmpHeight; y++)
    {
         for (WORD x = 0; x < wBmpWidth; x++)
         {
              BYTE jRed   = pPixels[p+2];
              BYTE jGreen = pPixels[p+1];
              BYTE jBlue  = pPixels[p+0];

              if (jRed == jTranspR && jGreen == jTranspG && jBlue == jTranspB)
              {
                   // remove transparent color from region
                   hTmpRgn = CreateRectRgn(x,y,x+1,y+1);
                   CombineRgn(hRgn, hRgn, hTmpRgn, RGN_XOR);
                   DeleteObject(hTmpRgn);
              }

              // next pixel
              p += 3;
         }
    }

    // release pixels
    delete pPixels;

    // return the region
    return hRgn;
}

BYTE* Get24BitPixels(HBITMAP pBitmap, WORD *pwWidth, WORD *pwHeight)
{
    // a bitmap object just to get bitmap width and height
    BITMAP bmpBmp;

    // pointer to original bitmap info
    LPBITMAPINFO pbmiInfo;

    // bitmap info will hold the new 24bit bitmap info
    BITMAPINFO bmiInfo;

    // width and height of the bitmap
    WORD wBmpWidth, wBmpHeight;

    // ---------------------------------------------------------
    // get some info from the bitmap
    // ---------------------------------------------------------
    GetObject(pBitmap, sizeof(bmpBmp), &bmpBmp);
    pbmiInfo   = (LPBITMAPINFO) &bmpBmp;

    // get width and height
    wBmpWidth  = (WORD)pbmiInfo->bmiHeader.biWidth;
    wBmpWidth -= (wBmpWidth%4);                       // width is 4 byte boundary aligned.
    wBmpHeight = (WORD)pbmiInfo->bmiHeader.biHeight;

    // copy to caller width and height parms
    *pwWidth  = wBmpWidth;
    *pwHeight = wBmpHeight;
    // ---------------------------------------------------------

    // allocate width * height * 24bits pixels
    BYTE *pPixels = new BYTE[wBmpWidth*wBmpHeight*3];
    
     if (!pPixels) 
          return NULL;

    // get user desktop device context to get pixels from
    HDC hDC = GetWindowDC(NULL);

    // fill desired structure
    bmiInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmiInfo.bmiHeader.biWidth = wBmpWidth;
    bmiInfo.bmiHeader.biHeight = -wBmpHeight;
    bmiInfo.bmiHeader.biPlanes = 1;
    bmiInfo.bmiHeader.biBitCount = 24;
    bmiInfo.bmiHeader.biCompression = BI_RGB;
    bmiInfo.bmiHeader.biSizeImage = wBmpWidth * wBmpHeight * 3;
    bmiInfo.bmiHeader.biXPelsPerMeter = 0;
    bmiInfo.bmiHeader.biYPelsPerMeter = 0;
    bmiInfo.bmiHeader.biClrUsed = 0;
    bmiInfo.bmiHeader.biClrImportant = 0;

    // get pixels from the original bitmap converted to 24bits
    int iRes = GetDIBits(hDC, pBitmap, 0, wBmpHeight, (LPVOID)pPixels, &bmiInfo, DIB_RGB_COLORS);

    // release the device context
    ReleaseDC(NULL, hDC);

    // if failed, cancel the operation.
    if (!iRes)                                                              // The error is here, GetLastError gives me #87 INVALID_PARAM
    {
         delete pPixels;     
          
          return NULL;
    };

    // return the pixel array
    return pPixels;
}


To continue the story it seems that it creates the first region handle fine (top left button for menu) and applies it to the first three buttons ok. I tested it by changing the minimize button somewhat resulting in a good menu button and a good close button but a regionless minimize button. For some reason the first region is created and applied OK yet anything after that does not work in Windows 98 (the four big buttons plus the main window)

Here is the code that applies the regions:

void cMainSkin::SetButtonRegion(void)
{
    for (int i = 0; i < 7; i++)
         hButtonRgn[i] = ScanRegion(hButtonPartialBitmap[i], iMaskColor[0], 
                                           iMaskColor[1], iMaskColor[2]);

    
     SetWindowRgn(hwndMenu,     hButtonRgn[0], TRUE);
    SetWindowRgn(hwndMinimize, hButtonRgn[1], TRUE);
    SetWindowRgn(hwndClose,    hButtonRgn[2], TRUE);
    SetWindowRgn(hwndView,     hButtonRgn[3], TRUE);
    SetWindowRgn(hwndAdd,      hButtonRgn[4], TRUE);
    SetWindowRgn(hwndFind,     hButtonRgn[5], TRUE);
    SetWindowRgn(hwndExternal, hButtonRgn[6], TRUE);

    for (i = 0; i < 7; i++)
         DeleteObject(hButtonRgn[i]);
}


I have tried getting rid of DeleteObject and also applying the region for each child window as soon as it is retrieved but with no results. Does anyone have any insight into this problem? Let me know if you need more code posted.
GeneralRe: Skins look good, but not always... Pin
John R. Shaw26-May-03 8:55
John R. Shaw26-May-03 8:55 
GeneralRe: Skins look good, but not always... Pin
georgiek5026-May-03 10:12
georgiek5026-May-03 10:12 
GeneralRe: Skins look good, but not always... Pin
John R. Shaw26-May-03 10:35
John R. Shaw26-May-03 10:35 
GeneralUrgent For Interview Pin
bsanoop1726-May-03 7:23
bsanoop1726-May-03 7:23 
GeneralWin32dll Pin
bsanoop1726-May-03 7:19
bsanoop1726-May-03 7:19 
GeneralAlgorithm Pin
Anonymous26-May-03 7:08
Anonymous26-May-03 7:08 
GeneralRe: Algorithm Pin
John R. Shaw26-May-03 9:19
John R. Shaw26-May-03 9:19 
GeneralRe: Algorithm Pin
John R. Shaw26-May-03 9:22
John R. Shaw26-May-03 9:22 
Generalsmall application Pin
centrum26-May-03 5:02
centrum26-May-03 5:02 
GeneralRe: small application Pin
Renjith Ramachandran26-May-03 6:33
Renjith Ramachandran26-May-03 6:33 
GeneralCan't debug if including 'vector' Pin
ScorpioMidget26-May-03 4:45
ScorpioMidget26-May-03 4:45 
GeneralRe: Can't debug if including 'vector' Pin
Rage26-May-03 4:50
professionalRage26-May-03 4:50 
GeneralRe: Can't debug if including 'vector' Pin
ScorpioMidget26-May-03 4:52
ScorpioMidget26-May-03 4:52 
GeneralRe: Can't debug if including 'vector' Pin
Andrew Walker26-May-03 4:53
Andrew Walker26-May-03 4:53 
GeneralOS awareness Pin
Themis26-May-03 4:28
Themis26-May-03 4:28 
GeneralRe: OS awareness Pin
Rage26-May-03 4:40
professionalRage26-May-03 4:40 
GeneralRe: OS awareness Pin
markkuk26-May-03 4:51
markkuk26-May-03 4:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.