[摘要]cwMessage->message == WM_ERASEBKGND ) //重画用户窗口DrawBitmap(hClientHandle, hFaceBitmap, iClientHeight,... cwMessage->message == WM_ERASEBKGND ) { //重画用户窗口 DrawBitmap(hClientHandle, hFaceBitmap, iClientHeight, iClientWidth); } } if ( hMsgHook != NULL) //将消息继续下传 lReturn = CallNextHookEx(hMsgHook, nCode, wParam, lParam ); return lReturn; } //卸载钩子函数 void __fastcall TMainForm::FormClose(TObject Sender, TCloseAction &&Action) { if ( hMsgHook != NULL) UnhookWindowsHookEx( hMsgHook ); if ( Face != NULL ) delete Face; } //在指定的窗口中,画位图,填充整个用户窗口 //Ture为绘制成功,false为绘制失败 BOOL DrawBitmap(HWND Handle, HBITMAP hBitmap, int iClientHeight, int iClientWidth) { if ( hBitmap == NULL ) return false; BITMAP b; int iBitmapH, iBitmapW; GetObject( hBitmap, sizeof( BITMAP), &&b); iBitmapH = b.bmHeight; iBitmapW = b.bmWidth; int x, y; HDC hClientDC, hMemDC; hClientDC = GetDC(Handle); if ( hClientDC == NULL ) return false; hMemDC = CreateCompatibleDC( hClientDC ); if ( hMemDC == NULL ) { DeleteDC( hClientDC ); return false; } SelectObject( hMemDC, hBitmap ); x = 0; while ( x < iClientWidth ) { y = 0; while ( y < iClientHeight ) {ClientCanvas->Draw(x, y, Face); BitBlt( hClientDC, x, y,iBitmapW, iBitmapH, hMemDC, 0, 0,SRCCOPY ); y = y + iBitmapH; } x = x + iBitmapW; } DeleteDC( hMemDC ); DeleteDC( hClientDC ); return true; }
将上述C++ Builder代码片段加入用户的MDI软件中即可实现任意的MDI程序背景图 |