[WinAPI]Nietworzące się okno
Ostatnio zmodyfikowano 2015-05-17 21:43
TheReclif Temat założony przez niniejszego użytkownika |
[WinAPI]Nietworzące się okno » 2015-05-12 23:06:13 Witam! Jak w temacie. Okno w ogóle się nie tworzy. Do jego tworzenia mam dwie metody: rejestrującą klasę okna i tworzącą je. Ich kod: void windowClass::create( LPCSTR winName, UINT width, UINT height, bool fullscreen, bool hideCursor ) { this->fullscreen = fullscreen; this->winName = const_cast < LPSTR >( winName ); DEVMODE dmScreenSettings; UINT screenW, screenH, posX, posY; screenW = GetSystemMetrics( SM_CXSCREEN ); screenH = GetSystemMetrics( SM_CYSCREEN ); if( fullscreen ) { memset( & dmScreenSettings, 0, sizeof( dmScreenSettings ) ); dmScreenSettings.dmSize = sizeof( dmScreenSettings ); dmScreenSettings.dmPelsWidth =( unsigned long ) screenW; dmScreenSettings.dmPelsHeight =( unsigned long ) screenH; dmScreenSettings.dmBitsPerPel = 32; dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; this->width = screenW; this->height = screenH; ChangeDisplaySettings( & dmScreenSettings, CDS_FULLSCREEN ); posX = posY = 0; } else { posX =( GetSystemMetrics( SM_CXSCREEN ) - screenW ) / 2; posY =( GetSystemMetrics( SM_CYSCREEN ) - screenH ) / 2; } * win = CreateWindowEx( WS_EX_APPWINDOW, winClassName, this->winName, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP, posX, posY, width, height, NULL, NULL, GetModuleHandle( NULL ), NULL ); ShowWindow( * win, SW_SHOW ); SetForegroundWindow( * win ); SetFocus( * win ); ShowCursor( hideCursor ); }
void windowClass::init( HICON icon, HCURSOR cursor ) { wndclass wc; int posX, posY; wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = stdDefProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GetModuleHandle( NULL ); wc.hIcon = icon; wc.hIconSm = wc.hIcon; wc.hCursor = cursor; wc.hbrBackground =( HBRUSH ) GetStockObject( BLACK_BRUSH ); wc.lpszMenuName = NULL; wc.lpszClassName = winClassName; wc.cbSize = sizeof( WNDCLASSEX ); if( !RegisterClassEx( & wc ) ) { throw WNDCLASS_RECORDER_ERROR; } }
Gdyby trzeba było podać kod innych funkcji, proszę pisać. Z góry dziękuję za pomoc. |
|
pekfos |
» 2015-05-12 23:17:46 Gdzie te metody wywołujesz? |
|
TheReclif Temat założony przez niniejszego użytkownika |
» 2015-05-12 23:27:43 void handlingClass::init( HICON icon, HCURSOR cursor ) { win.init( icon, cursor ); return; }
void handlingClass::create( systemSettings setts, LPCSTR winName ) { win.create( winName, setts.width, setts.height, setts.fullscreen, setts.showCursor ); return; }
Klasa systemSettings: class systemSettings { public: systemSettings() { closeWhenX = false; }; ~systemSettings() { }; int width; int height; int showCmd; lpcstr winName, winClassName; bool fullscreen; bool showCursor; bool closeWhenX; };
Wykorzystanie w int WINAPI WinMain: handlingClass * hc = new handlingClass; const int resW = 800; const int resH = 600; systemSettings sysSetts; sysSetts.fullscreen = false; sysSetts.showCmd = nShowCmd; sysSetts.showCursor = true; sysSetts.winClassName = "Model Viewer WinClass"; sysSetts.winName = "Model Viewer"; sysSetts.closeWhenX = false; sysSetts.width = resW; sysSetts.height = resH; HCURSOR cursor = loadDefaultCursor(); HICON icon = loadDefaultIcon();
hc->init( icon, cursor ); hc->create( sysSetts, sysSetts.winName );
Tak to wygląda(po okrojeniu paru zbędnych namespaców) |
|
TheReclif Temat założony przez niniejszego użytkownika |
» 2015-05-17 21:43:14 Naprawione. Problem był z pętlą główną programu. Temat zamykam. |
|
« 1 » |