Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[WinAPI]Nietworzące się okno

Ostatnio zmodyfikowano 2015-05-17 21:43
Autor Wiadomość
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:
C/C++
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;
    // Determine the resolution of the clients desktop screen
    screenW = GetSystemMetrics( SM_CXSCREEN );
    screenH = GetSystemMetrics( SM_CYSCREEN );
   
    // Setup the screen settings depending on whether it is running in full screen or in windowed mode
    if( fullscreen )
    {
        // If full screen set the screen to maximum size of the users desktop and 32bit
        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;
       
        // Change the display settings to full screen
        ChangeDisplaySettings( & dmScreenSettings, CDS_FULLSCREEN );
       
        // Set the position of the window to the top left corner
        posX = posY = 0;
    }
    else
    {
        // Place the window in the middle of the screen
        posX =( GetSystemMetrics( SM_CXSCREEN ) - screenW ) / 2;
        posY =( GetSystemMetrics( SM_CYSCREEN ) - screenH ) / 2;
    }
   
    // Create the window with the screen settings and get the handle to it
    * win = CreateWindowEx( WS_EX_APPWINDOW, winClassName, this->winName,
    WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
    posX, posY, width, height, NULL, NULL, GetModuleHandle( NULL ), NULL ); //win jest HWND*
   
    // Bring the window up on the screen and set it as main focus
    ShowWindow( * win, SW_SHOW );
    SetForegroundWindow( * win );
    SetFocus( * win );
   
    // Hide the mouse cursor.
    ShowCursor( hideCursor );
}

void windowClass::init( HICON icon, HCURSOR cursor )
{
    wndclass wc;
    int posX, posY;
   
    // Setup the windows class with default settings
    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 );
   
    // Register the window class
    if( !RegisterClassEx( & wc ) )
    {
        throw WNDCLASS_RECORDER_ERROR;
    }
   
}

Gdyby trzeba było podać kod innych funkcji, proszę pisać. Z góry dziękuję za pomoc.
P-132165
pekfos
» 2015-05-12 23:17:46
Gdzie te metody wywołujesz?
P-132167
TheReclif
Temat założony przez niniejszego użytkownika
» 2015-05-12 23:27:43
C/C++
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:
C/C++
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:
C/C++
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)
P-132169
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.
P-132436
« 1 »
  Strona 1 z 1