from MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd145213%28v=vs.85%29.aspx
"An application returns zero if it processes this message."
see these code on my label control:

case WM_PAINT:
            {
                PAINTSTRUCT test;
                BeginPaint(inst->hwnd, &test);
                image imglabel(inst->imgtest.width(),inst->imgtest.height());
                brush brshbackcolor(inst->clrBackColor);
                imglabel.Backcolor=inst->clrBackColor;
                brush brshTransparent;
                FillRect(imglabel,&test.rcPaint,brshbackcolor);
                if(inst->imgtest.haveimage())
                    DrawHICONtoHDC(imglabel, inst->imgtest);
                imglabel.DrawText(inst->strCaption);
                pen penColor(1,2,RGB(0,255,0));
                penColor.ToDC(imglabel);
                imglabel.DrawRectangle(10,10,10,10);
                pen penColor2(1,2,RGB(255,0,0));
                penColor2.ToDC(imglabel);
                imglabel.DrawLine(0,0,20,20);
                pen penColor3(1,2,RGB(0,0,255));
                penColor3.ToDC(imglabel);
                //brshTransparent.ToDC(imglabel);
                imglabel.DrawEllipse(0,0,20,20);
                //imglabel.DrawLine(0,0,20,20);
                if(inst->blnBorder==true)
                    DrawEdge(imglabel, &test.rcPaint,BDR_SUNKENINNER | BDR_RAISEDOUTER,BF_RECT);
                if(inst->blnTransparent==true)
                {
                     //destroy the region
                    SetWindowRgn(inst->hwnd,NULL,FALSE);

                    //draw the image transparent
                    TransparentBlt(test.hdc,0,0,test.rcPaint.right,test.rcPaint.bottom,imglabel,0,0, test.rcPaint.right ,test.rcPaint.bottom, inst->clrBackColor);



                    //Create and set them region
                    inst->LabelRegion=RegionbyBitmap(imglabel, inst->clrBackColor);
                    SetWindowRgn(inst->hwnd,inst->LabelRegion,FALSE);
                }
                else
                {
                    SetWindowRgn(inst->hwnd,NULL,FALSE);
                    BitBlt(test.hdc,0,0,imglabel.width(),imglabel.height(),imglabel,0,0,SRCCOPY);
                }
                EndPaint(inst->hwnd, &test);
                return 0;
            }
            break;

some code can be confused, but like you see, i return 0.
but the ToolTip is blocked :(
if i put the label hidded, the ToolTip is showed. seems that i have here a problem. can anyone advice me?

if i take off the Region code, the ToolTip is showed:

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)
  {
    delete[] pPixels;
    return NULL;
  };

  // return the pixel array
    return pPixels;
}

HRGN RegionbyBitmap(HBITMAP pBitmap,COLORREF clrTransparent=-1 )
{
    BYTE jTranspR = GetRValue(clrTransparent), jTranspG=GetGValue(clrTransparent), jTranspB=GetBValue(clrTransparent);
  // 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 hRgn;
}

so these 2 functions have some memory leaks... can anyone help me find them?

Hi Everyone I would like to ask if anyone could help in my project of WinMain function to get my backgrouond and text colors to change.

Typically I know there are differences in types of mains that can be used in C++ WinMain WINAPI etc... But I'm a dummy to figuring if the WNDCLASS Function has other ways to get colors to the GUI Console In The Window to change. Or a parameter that is added in at the end (HBRUSH)COLOR_WINDOW. Thanks

I have my code attached for those that are interested in reviewing. Any suggestions are welcome, I love learning new things.

Attachments
#define _WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>

 

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
 
static char gszClassName[]  = "darkblue";
static HINSTANCE ghInstance = NULL;
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
        WNDCLASSEX WndClass;
        HWND hwnd;
        MSG Msg;
         
        ghInstance = hInstance;
 
        WndClass.cbSize        = sizeof(WNDCLASSEX);
        WndClass.style         = NULL;
        WndClass.lpfnWndProc   = WndProc;
        WndClass.cbClsExtra    = 0;
        WndClass.cbWndExtra    = 0;
        WndClass.hInstance     = ghInstance;
        WndClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
        WndClass.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);//Replaced COLOR_WINDOW+1
        WndClass.lpszMenuName  = NULL;
        WndClass.lpszClassName = gszClassName;
        WndClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
 
        if(!RegisterClassEx(&WndClass))
		{
                MessageBox(0, "Error Registering Window!", "Error!", MB_ICONSTOP | MB_OK);
                return 0;
        }
         hwnd = CreateWindowEx(
                WS_EX_STATICEDGE,
                gszClassName,
                "darkblue owNz!",
                WS_OVERLAPPEDWINDOW,
                CW_USEDEFAULT, CW_USEDEFAULT,
                640, 480,
                NULL, NULL,
                ghInstance,
                NULL);
 
        if(hwnd == NULL) 
		{
                MessageBox(0, "Window Creation Failed!", "Error!", MB_ICONSTOP | MB_OK);
                return 0;
        }
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
        while(GetMessage(&Msg, NULL, 0, 0))
		{
                TranslateMessage(&Msg);
                DispatchMessage(&Msg);
        }
        return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
        HDC hdc;
        PAINTSTRUCT ps;
        LPSTR szMessage = "darkblue 0wNz j00!";
		switch(Message) {
                case WM_PAINT:
                        hdc = BeginPaint(hwnd, &ps);
                        TextOut(hdc, 70, 50, szMessage, strlen(szMessage));
                        EndPaint(hwnd, &ps);
                        break;
                case WM_CLOSE:
                        DestroyWindow(hwnd);
                        break;
                case WM_DESTROY:
                        PostQuitMessage(0);
                        break;
                default:
                        return DefWindowProc(hwnd, Message, wParam, lParam);
        }
        return 0;
}
This article has been dead for over six months. Start a new discussion instead.