我的win32应用程序中有不同的屏幕用于不同的目的,每个屏幕具有不同的背景。主窗口有自己的静态背景。 我正在使用以下代码在自定义窗口上绘制屏幕背景。
panelBackground = LoadBitmap ( hInstance, MAKEINTRESOURCE ( bitmap ) );
WNDCLASSEX wincl;
wincl.hInstance = hInstance;
wincl.lpszClassName = "jPanel";
wincl.lpfnWndProc = WndProc;
wincl.style = CS_BYTEALIGNWINDOW;// | CS_HREDRAW | CS_VREDRAW;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = 0;
wincl.hIconSm = 0;
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 4;
wincl.hbrBackground = ( HBRUSH ) GetStockObject( BLACK_BRUSH );
RegisterClassEx (&wincl);
hwnd = CreateWindowEx ( 0, "jPanel", txt.c_str(), WS_CLIPSIBLINGS | WS_CHILD, x, y, width, height, parent, 0, hInstance, 0) ;
SetWindowLong( hwnd , 0 , ( LONG ) this ) ;
SetWindowPos ( hwnd , HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE ) ;
然后在WndProc:
view::jPanel* panel = ( view::jPanel* ) GetWindowLong( hwnd , 0 ) ;
case WM_PAINT:
{
if ( ! panel )
return 0 ;
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
GetClientRect( hwnd , &rect ) ;
hdc = BeginPaint( hwnd , &ps ) ;
HDC dcSkin = CreateCompatibleDC ( hdc ); // memory dc for skin
HDC hMemDc = CreateCompatibleDC ( hdc ); // memory dc for painting
HBITMAP hmemBmp = CreateCompatibleBitmap ( hdc, rect.right - rect.left, rect.bottom - rect.top ); // Create bitmap to draw on
HBITMAP hOldMemBmp = (HBITMAP)SelectObject ( hMemDc, hmemBmp ); // select memory bitmap in memory dc
HBITMAP hOldSkinBmp = (HBITMAP)SelectObject ( dcSkin, panel->panelBackground ); //select skin bitmap in skin memory dc
BitBlt ( hMemDc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, dcSkin, 0, 0, SRCCOPY ); // Paint Skin on Memory DC
BitBlt ( hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, hMemDc, 0, 0, SRCCOPY ); // Paint Skin on Window DC
//<<<... DeleteDC will leak memory if it holds a resource, so lets select the old bitmap back in the memory DCs
SelectObject ( hMemDc, hOldMemBmp ); // select old bitmaps back to their respective DCs before deleting
SelectObject ( dcSkin, hOldSkinBmp ); // select old bitmaps back to their respective DCs before deleting
DeleteObject ( hOldSkinBmp );
DeleteObject ( hOldMemBmp );
DeleteObject( hmemBmp );
DeleteDC ( hMemDc );
DeleteDC ( dcSkin );
EndPaint( hwnd , &ps ) ;
}
break ;
问题:属于该屏幕的子窗口(按钮,编辑控件)不显示,我猜 它们位于屏幕背景窗口下方。使用WS_EX_TOPMOST样式将控件向上移动z顺序既不能使用SetWindowPos移动z-order底部的屏幕背景窗口(hwnd,HWND_BOTTOM,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);的工作原理。
是的按钮是BS_BITMAP样式。
答案 0 :(得分:0)
在创建父窗口时添加WS_CLIPCHILDREN
样式。