yoogi Temat założony przez niniejszego użytkownika |
[WinAPI] Wiele okienek » 2011-12-16 19:33:00 Witam, chciał bym zrobić drugie okno do mojej aplikacji. Po kliknięciu na przycisk "Opcję" ma się wyświetlić normalne okienko, z różnymi kontrolkami. Chciał bym żeby nie dało isę przejść do głównej aplikacji z otwartym okienkiem "opcję". Nie chcę używać plików *.rc, chcę aby wszystko było w jednym kodzie źródłowym. znalazłem przykładowy kod, po czym lekko go zmodyfikowałem: #include <windows.h> #include <commctrl.h>
HWND hButton, hWnd, hWndChild;
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ); LRESULT CALLBACK WNDchild( HWND, UINT, WPARAM, LPARAM );
INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lStart, INT nShow ) { WNDCLASSEX wc; wc.hInstance = hInstance; wc.lpszClassName = "Parent"; wc.lpfnWndProc = WndProc; wc.style = 0; wc.cbSize = sizeof( WNDCLASSEX ); wc.hIcon = LoadIcon( 0, IDI_APPLICATION ); wc.hIconSm = LoadIcon( 0, IDI_APPLICATION ); wc.hCursor = LoadCursor( 0, IDC_ARROW ); wc.lpszMenuName = 0; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground =( HBRUSH ) GetStockObject( WHITE_BRUSH ); if( !RegisterClassEx( & wc ) ) return 0; WNDCLASSEX wcp; wcp.hInstance = hInstance; wcp.lpszClassName = "Child"; wcp.lpfnWndProc = WNDchild; wcp.style = 0; wcp.cbSize = sizeof( WNDCLASSEX ); wcp.hIcon = LoadIcon( 0, IDI_APPLICATION ); wcp.hIconSm = LoadIcon( 0, IDI_APPLICATION ); wcp.hCursor = LoadCursor( 0, IDC_ARROW ); wcp.lpszMenuName = 0; wcp.cbClsExtra = 0; wcp.cbWndExtra = 0; wcp.hbrBackground =( HBRUSH ) GetStockObject( WHITE_BRUSH ); if( !RegisterClassEx( & wcp ) ) return 0; hWnd = CreateWindowEx( 0, "Parent", "rodzic", WS_SYSMENU, 20, 20, 600, 300, 0, 0, hInstance, 0 ); hButton = CreateWindowEx( 0, WC_BUTTON, "Przycisk1", WS_CHILD | WS_VISIBLE, 480, 90, 100, 30, hWnd,( HMENU ) 1, hInstance, 0 ); hWndChild = CreateWindowEx( 0, "Child", "Okno potomne", WS_SYSMENU, 20, 20, 600, 300, hWnd, 0, hInstance, 0 ); UpdateWindow( hWnd ); UpdateWindow( hWndChild ); UpdateWindow( hButton ); ShowWindow( hWnd, nShow ); ShowWindow( hButton, SW_SHOW ); MSG msgs; while( GetMessage( & msgs, 0, 0, 0 ) ) { TranslateMessage( & msgs ); DispatchMessage( & msgs ); } return msgs.wParam; }
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wPar, LPARAM lPar ) { if( msg == WM_COMMAND ) { if( wPar == 1 ) { ShowWindow( hWndChild, SW_SHOW ); } } if( msg == WM_CLOSE ) { if( hwnd == hWndChild ) { ShowWindow( hWndChild, SW_HIDE ); } if( hwnd == hWnd ) { DestroyWindow( hButton ); PostQuitMessage( 0 ); } } else { return DefWindowProc( hwnd, msg, wPar, lPar ); } return 0; }
LRESULT CALLBACK WNDchild( HWND hwnd, UINT msg, WPARAM wPar, LPARAM lPar ) { switch( msg ) { case WM_PAINT: break; case WM_CLOSE: ShowWindow( hwnd, SW_HIDE ); break; default: return DefWindowProc( hwnd, msg, wPar, lPar ); } return 0; }
Z góry dzięki za każdą odpowiedź |