Friday, April 06, 2007

How to make a transparent check box?

Wrong Method 1:
in the case WM_CTLCOLORSTATIC:
Set the backbround mode to transparent to both checkbox and picture control can't work. SetBkMode(GetDC(hWnd), TRANSPARENT);

Wrong Method 2:
in the case WM_CTLCOLORSTATIC:
Select a null brush to the CheckBox can't work.
SelectObject ((HDC)wParam, GetStockObject (NULL_BRUSH));

Wrong Method 3:
in the case WM_CTLCOLORSTATIC:
Both ExtTextOut and DrawText to the Picture control's DC can't work

Wrong Method 4:
in the case WM_CTLCOLORSTATIC:
BitBlt(HDC(wParam),10,0,60,30,GetDC(hWnd),50,150,SRCCOPY);
SetBkMode (HDC(wParam), TRANSPARENT);
ExtTextOut(HDC(wParam),0,0,0,NULL,TEXT ("TIMXX"),5,NULL);

Wrong Method 5:
Override the Picture control's window proc and in the WM_PAINT:
SetBkMode ((HDC) wParam, TRANSPARENT);
ExtTextOut((HDC) wParam,rectCli.left,rectCli.top,0,NULL,TEXT ("TIMXX"),5,NULL);

Wrong Method 6:
Override the Picture control's window proc and in the WM_PAINT:
SetBkMode (GetDC(hWnd), TRANSPARENT);
ExtTextOut(GetDC(hWnd),rectCli.left,rectCli.top,0,NULL,TEXT ("TIMXX"),5,NULL);

Wrong Method 7:
Override the Picture control's window proc and in the WM_PAINT:
HDC hdcT=GetDC(hWnd);
SetBkMode (hdcT, TRANSPARENT);
ExtTextOut(hdcT,rectCli.left,rectCli.top,0,NULL,TEXT ("TIMXX"),5,NULL);
ReleaseDC(hWnd,hdcT);

Final Method:
Override the Picture control's window proc Process the default window proc first
CallWindowProc((WNDPROC)l_winProc,hWnd, wMsg, wParam, lParam);
and in the WM_PAINT:
HDC hdcT=GetDC(hWnd);
SetBkMode (hdcT, TRANSPARENT);
ExtTextOut(hdcT,rectCli.left,rectCli.top,0,NULL,TEXT ("TIMXX"),5,NULL);
ReleaseDC(hWnd,hdcT);

Remark:
HDC GetDC(HWND hWnd); //This function retrieves a handle to a display device context (DC)ReleaseDC(); //must call ReleaseDC when you get the HDC by calling GetDC()


WM_PAINT hdc = (HDC) wParam;
//Parametershdc Handle to the device context to draw in. If this parameter is NULL, use the default device context.

No comments: