walek_xxx Temat założony przez niniejszego użytkownika |
[WinAPI] Modyfikowanie tła okna dialogowego » 2012-01-23 20:47:17 Witam,
Próbuję zmodyfikować wygląd okna wyboru pliku wg wskazówek z kursu.
Wszystko jest ok, oprócz tła wywołanego zmodyfikowanego okna wyboru.
Tłem jest wycinek z tego co jest pod spodem.
W żaden sposób nie mogę tego poprawić. Co robię źle?
Poniżej kody procedur obsługi komunikatów. Całość pracuje w prostym filtrze directshow.
UINT_PTR CALLBACK OFNHookProc( HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
bool g_Preview; char buffer[ MAX_PATH ]; BYTE bmi; HBITMAP g_hBitmap;
void FreeBitmap() { if( g_hBitmap ) DeleteObject( g_hBitmap ); g_hBitmap = NULL; }
UINT_PTR CALLBACK OFNHookProc( HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { HDC hDC = GetDC( hdlg ); HDC g_hDCMem = CreateCompatibleDC( hDC ); ASSERT( g_hDCMem ); ReleaseDC( hdlg, hDC ); switch( uMsg ) { case WM_NOTIFY: { NMHDR * pnmhdr =( NMHDR * ) lParam; OFNOTIFY * ofnot =( OFNOTIFY * ) lParam; if( pnmhdr->code == CDN_INITDONE ) { SendMessage( GetParent( hdlg ), DM_REPOSITION, 0, 0 ); } if( pnmhdr->code == CDN_SELCHANGE ) { SendMessage( GetParent( hdlg ), CDM_GETFILEPATH, sizeof( buffer ),( LPARAM ) & buffer ); LPSTR filename = buffer; FreeBitmap(); g_hBitmap =( HBITMAP ) LoadImage( 0, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION ); InvalidateRect( hdlg, NULL, true ); } else if( pnmhdr->code == CDN_FILEOK ) { FreeBitmap(); } return TRUE; } break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint( hdlg, & ps ); if( g_Preview && g_hBitmap && g_hDCMem ) { HWND hFrame = GetDlgItem( hdlg, IDC_RAMKA ); RECT rcFrame; GetWindowRect( hFrame, & rcFrame ); int w = rcFrame.right - rcFrame.left; int h = rcFrame.bottom - rcFrame.top; BITMAP bm; GetObject( g_hBitmap, sizeof( BITMAP ), & bm ); ScreenToClient( hdlg,( LPPOINT ) & rcFrame ); ScreenToClient( hdlg,( LPPOINT ) & rcFrame.right ); HBITMAP hbmDefault = SelectBitmap( g_hDCMem, g_hBitmap ); StretchBlt( hdc, rcFrame.left, rcFrame.top, w, h, g_hDCMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY ); SelectBitmap( g_hDCMem, hbmDefault ); } else { } EndPaint( hdlg, & ps ); return TRUE; } break; case WM_DESTROY: { FreeBitmap(); return TRUE; } break; case WM_INITDIALOG: { g_Preview = FALSE; RECT r1, r2; POINT pt; HWND hWnd = GetParent( hdlg ); GetWindowRect( GetDesktopWindow(), & r1 ); GetWindowRect( hWnd, & r2 ); pt.x =( r1.right - r1.left ) / 2 -( r2.right - r2.left ) / 2; pt.y =( r1.bottom - r1.top ) / 2 -( r2.bottom - r2.top ) / 2; MoveWindow( hWnd, pt.x, pt.y, r2.right - r2.left, r2.bottom - r2.top, true ); return TRUE; } break; case WM_COMMAND: g_Preview =( IsDlgButtonChecked( hdlg, IDC_PREVIEW ) == BST_CHECKED ); InvalidateRect( hdlg, NULL, true ); if( LOWORD( wParam ) == IDOK || LOWORD( wParam ) == IDCANCEL ) { EndDialog( hdlg, LOWORD( wParam ) ); return TRUE; } break; } return TRUE; }
BOOL CATestyProperties::OnReceiveMessage( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch( uMsg ) { case WM_COMMAND: { if( LOWORD( wParam ) == IDC_BUTTON1 ) { OPENFILENAME ofn; char sNazwaPliku[ MAX_PATH ] = ""; ZeroMemory( & ofn, sizeof( ofn ) ); ofn.lStructSize = sizeof( ofn ); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Pliki graficzne (*.bmp)\0*.bmp\0Wszystkie pliki\0*.*\0"; ofn.nMaxFile = MAX_PATH; ofn.lpstrFile = sNazwaPliku; ofn.lpstrDefExt = "bmp"; ofn.lpfnHook = OFNHookProc; ofn.hInstance =( HINSTANCE ) GetWindowLong( hwnd, GWL_HINSTANCE ); ofn.lpTemplateName = MAKEINTRESOURCE( IDD_DODATEK ); ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLETEMPLATE; if( GetOpenFileName( & ofn ) ) { } return( INT_PTR ) TRUE; } if( m_bIsInitialized ) { SetDirty(); return( LRESULT ) 1; } } break; } return CBasePropertyPage::OnReceiveMessage( hwnd, uMsg, wParam, lParam ); } |
DejaVu |
» 2012-01-23 21:23:46 MFC: CWnd::OnEraseBkgnd
WinAPI: WM_ERASEBKGND
Więcej informacji:
http://www.mombu.com/microsoft/windows-programmer-win32/t-wm-paint-wm-erasebkgnd-1275533.html
Czyli:
LRESULT CALLBACK WiadomoCoToJest( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch( uMsg ) { case WM_ERASEBKGND: return SmarujTlo( hWnd ); break; default: return DefWindowProc( hWnd, uMsg, wParam, lParam ); } return 0; }
int SmarujTlo( HWND hWnd ) { HDC hdc; HBRUSH hbrBkgnd; PAINTSTRUCT ps; RECT r; GetClientRect( hWnd, & r ); hdc = BeginPaint( hWnd, & ps ); hbrBkgnd = CreateSolidBrush( RGB( 255, 255, 255 ) ); FillRect( hdc, & r, hbrBkgnd ); EndPaint( hWnd, & ps ); return 1; }
|