alan_cmlee
August 5th, 2005, 09:25 AM
Dear gurus,
I need to display a transparent listbox(that is the background bitmap is shown, only listbox text is shown). There is a background bitmap under the listbox. Can anybody tell me how to do that? I have stuck for two days.
The project use win32 without MFC.
Should I use implement WM_ERASEBKGND? WM_CTLCOLORLISTBOX? WM_CTLCOLORDLG?
Can anybody help please?
I have tried the following, but didn't work.
case WM_CTLCOLORLISTBOX:
{
hBrushe = CreateSolidBrush(NULL_BRUSH);
SetBkMode((HDC)wParam, TRANSPARENT);
}
return (LRESULT)hBrushe;
mistersulu
August 5th, 2005, 10:29 AM
I believe you would need to handle all drawing yourself by handling WM_PAINT (change the listbox's WndProc). I would advise looking for a third-party control. There are a lot of fancy custom controls out there.
sulu
Runt888
August 5th, 2005, 11:16 AM
Here's the paint I use to double buffer a list. You can use it to draw the list text to a memory buffer, then use TransparentBlt or AlphaBlend to put it wherever you need to.
switch( message )
case WM_PAINT:
{
//Double buffer the window to avoid flickering.
PAINTSTRUCT ps;
HDC dc = BeginPaint( hwnd, &ps );
RECT rectClient;
GetClientRect( hwnd, &rectClient );
HDC memoryDC = CreateCompatibleDC( dc );
HBITMAP bitmap = CreateCompatibleBitmap( dc, rectClient.right - rectClient.left, rectClient.bottom - rectClient.top );
HBRUSH brush = CreateSolidBrush( GetBkColor( dc ) );
HBITMAP oldBitmap = (HBITMAP)SelectObject( memoryDC, bitmap );
//Fill Background color.
RECT fillRect = { rectClient.left, rectClient.top, rectClient.right - rectClient.left, rectClient.bottom - rectClient.top };
FillRect( memoryDC, &fillRect, brush );
//Draw the list view. - CALL THE DEFAULT WINDOW PROC HERE.
LRESULT retVal = cCHSNativeComponent::WIN32WindowProcedure( hwnd, message, (WPARAM)memoryDC, lParam );
BitBlt( dc, rectClient.left, rectClient.top, rectClient.right - rectClient.left, rectClient.bottom - rectClient.top, memoryDC, 0, 0, SRCCOPY );
SelectObject( memoryDC, oldBitmap );
DeleteObject( brush );
DeleteObject( bitmap );
DeleteDC( memoryDC );
EndPaint( hwnd, &ps );
return retVal;
}
break;
Kelly
alan_cmlee
August 5th, 2005, 11:51 AM
Thank you for your help.
But, what is
cCHSNativeComponent::WIN32WindowProcedure ?
I can't find it from msdn.
What can it be replaced if I haven't got such library?
Runt888
August 5th, 2005, 12:00 PM
That's part of my code. Replace that call with the call to the default window procedure.
Kelly