-3

谁能告诉我我的窗口创建有什么问题?这个函数是从主函数中调用的,它全部编译并运行良好。然而,渲染出来的窗口根本就不是一个窗口,而只是一个白色的大方块。这是我的窗口创建功能:

/**
 *  handles everything for initialising a window
 *
 *  @param  hInst               unique handle of window instance
 *  @param  hPrevInst           legacy parameter for copying memory from other instance into this one
 *  @param  cmdLine             commands application is started with
 *  @param  cmdShow             specifies how program should be displayed (maximised, minimized, or hidden)
 */
int Window::Init (HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmdLine, int cmdShow)
{
    //  name of application
    static TCHAR    appName[]       = TEXT ("App");

    //  contains window class information
    WNDCLASSEX      wndC;

    //  window handle
    HWND            hWnd;

    //  define the windows class information
    wndC.cbSize                 = sizeof (WNDCLASSEX);          //  specifies the size of the structure (in bytes)
    wndC.style                  = CS_HREDRAW | CS_VREDRAW;      //  employs window class style to redraw if any resizing occurs
    wndC.lpfnWndProc            = WndProc;                      //  pointer to the window procedure function
    wndC.cbClsExtra             = 0;                            //  number of extra bytres to allocate for window class
    wndC.cbWndExtra             = 0;                            //  number of extra bytes to allocate per window instance
    wndC.hInstance              = hInst;                        //  handle to instnace conatining window procedure for this class
    wndC.hIcon                  = NULL;                         //  handle to large 32x32 (shown when alt + tab)
    wndC.hCursor                = LoadCursor (NULL, IDC_ARROW); //  handle to class cursor resource
    wndC.hbrBackground          = (HBRUSH) (COLOR_WINDOW + 1);  //  handle to class background brush (for painting background)
    wndC.lpszMenuName           = NULL;                         //  pointer to string with name of class menu (no default menu)
    wndC.lpszClassName          = appName;                      //  specifies windows class name
    wndC.hIconSm                = NULL;                         //  handle to small 16x16 icon (top left corner of window)

    //  registers window class with system, will terminate is parameter is invalid
    if (!RegisterClassEx (&wndC))   return 0;

    //  rect used for defining window
    RECT            wndRc;

    //  calculate size of window based on entire client window size
    wndRc.left                  = 0;
    wndRc.top                   = 0;
    wndRc.right                 = 800;
    wndRc.bottom                = 600;

    long            tStyle      = 0;

    //  style chosen based on whether this window is fullscreen
    if (mFullScreen)
        tStyle                  = WS_POPUP;
    else
    {
        tStyle                  = WS_OVERLAPPEDWINDOW;
        //  calculates required size of window rectangle, based on desired client-rectangle size
        AdjustWindowRect (&wndRc, tStyle, FALSE); 
    }

    //  now class is registered, we create a window with it
    hWnd                        = CreateWindowEx (0, appName, appName, WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, 
                                    wndRc.right - wndRc.left, wndRc.bottom - wndRc.top, NULL, NULL, hInst, NULL);
    //  check we have a valid handle
    if (hWnd == NULL)               return 0;

    //  show window and update it (cmdShow allows user to specify whether they want window to start maximised, minimised, etc.)
    ShowWindow (hWnd, cmdShow);
    UpdateWindow (hWnd);

    //  if we fail to create the direct x device send an error message and terminate
    if (DirectDraw::GetInstance()->CreateDevice (hWnd, 800, 600, mFullScreen) != 1)
    {
        MessageBox (hWnd, "Failed to create surfaces", "Error", MB_OK);
        return 0;
    }

    //  adds rectangle to the specified window's update region (portion of window to be redrawn)
    InvalidateRect (hWnd, NULL, TRUE);

    return 1;
}
4

1 回答 1

0

感谢 Arx 和 Tenfour 在我的帖子的评论中,问题只是我将窗口类的样式设置为“WS_POPUP”,这显然不适合在全屏窗口之外。

于 2012-07-20T22:36:17.890 回答