locked
ShowWindow() FAIL (return FALSE) RRS feed

  • Question

  • I don't understand why ShowWindow() return a false value. I'm new of Win32, some1 can help me? My code bottom (main.cpp)

    #include "Game.h"

    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT nCmdShow )

    {

    Game game;

    HRESULT hResult;

    hResult = game.InitWindow(hInst,nCmdShow,TEXT("Tutorial 01: Init Window"),800,600,false);

    if ( FAILED(hResult) ) {

    DXTrace(__FILE__,__LINE__,hResult,DXGetErrorDescription(hResult),TRUE);

    return 1;

    }

    if ( FAILED(game.Run()) )

    return 1;

    return 0;

    }

     

    Application (Game.cpp)

    #include "Game.h"

    LRESULT CALLBACK MsgProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )

    {

    PAINTSTRUCT ps;

    HDC hdc;

    switch (message)

    {

    case WM_PAINT:

    hdc = BeginPaint(hWnd, &ps);

    EndPaint(hWnd, &ps);

    break;

    case WM_DESTROY:

    PostQuitMessage(0);

    break;

    default:

    return DefWindowProc(hWnd, message, wParam, lParam);

    }

    return 0;

    }

    HRESULT Game::InitWindow(HINSTANCE hInst, INT nCmdShow, LPCTSTR title, int nWidth, int nHeight, BOOL full)

    {

     

    wc.cbSize = sizeof(WNDCLASSEX); // Window Class Size

    wc.style = CS_HREDRAW | CS_VREDRAW; // Redraw On Move, And Own DC For Window

    wc.lpfnWndProc = (WNDPROC) MsgProc; // WndProc Handles Messages

    wc.cbClsExtra = 0L; // No Extra Window Data

    wc.cbWndExtra = 0L; // No Extra Window Data

    wc.hInstance = hInst; // Set The Instance

    wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer

    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW); // Background Color

    wc.lpszClassName = TEXT("D3D Tutorial"); // Set The Class Name

    wc.hIcon = NULL; // Load The Default Icon

    wc.hIconSm = NULL; // No IconSm

    wc.lpszMenuName = NULL; // We Don't Want A Menu

     

    if ( !RegisterClassEx( &wc ) )

    return E_FAIL;

     

    wWidth = nWidth;

    wHeight = nHeight;

     

    dd = GetPrimaryDevice();

    dm.dmSize = sizeof(DEVMODE);

    if ( !EnumDisplaySettings(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm) )

    return E_FAIL;

    // Create window

    if ( !(hWnd = CreateWindow(

    wc.lpszClassName,

    title,

    WS_OVERLAPPEDWINDOW,

    ((dm.dmPelsWidth-wWidth)/2), ((dm.dmPelsHeight-wHeight)/2),

    wWidth, wHeight,

    NULL, NULL, wc.hInstance, NULL )) )

    return E_FAIL;

    // Show and update the window

    if ( !ShowWindow( hWnd, nCmdShow ) )

    return E_FAIL;

    UpdateWindow( hWnd );

    return S_OK;

    }

     

    HRESULT Game::Run(void)

    {

    ZeroMemory( &msg, sizeof(msg) );

    while ( msg.message!=WM_QUIT ) {

    if ( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) {

    TranslateMessage( &msg );

    DispatchMessage( &msg );

    }

    }

    UnregisterClass( wc.lpszClassName, wc.hInstance );

    return S_OK;

    }

     

    Thursday, November 23, 2006 3:47 PM

Answers

All replies