1

Windowsクラスのラッパーの作成が完了している間に、すべてが正常に機能していることを確認するために、いくつかのテキストを使用してテストを行いました。ただし、「これはテストです!!!!」というテキストを削除またはコメントアウトしても、プログラムの実行時に、実行可能ファイルの実行中はそのまま残ります。

LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        switch (uMsg)
        {
        case WM_PAINT:
            PAINTSTRUCT ps;
            HDC hdc;

            //hdc = BeginPaint(hwnd, &ps); 

            //TextOut(hdc, 0, 0, L"This is a TEST!!!", 17);

            //EndPaint(hwnd, &ps);
            break;
        case WM_DESTROY:
            bWindowClosed = TRUE;
            break;
        case WM_CREATE:
            MessageBox(NULL, L"Create", L"test", MB_OK);
            break;
        default:
            return CBaseWindow::WinMsgHandler(hwnd, uMsg, wParam, lParam);
        }

        return 0;
    };

編集:

これがwinmainソースファイルです。私はそれが私がすべてを括弧でくくった方法と関係があると感じています。CDerivedWindowは、ウィンドウ初期化プロセスのほとんどをカプセル化するためのラッパークラスです。

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{

    CDerivedWindow mainWnd(hInstance);

    WNDCLASSEX wcx; 

    // Fill in the window class structure with default parameters 
    wcx.cbSize = sizeof(WNDCLASSEX);                            // size of structure 
    wcx.style = CS_HREDRAW | CS_VREDRAW;                        // redraw if size changes 
    wcx.lpfnWndProc = CBaseWindow::stWinMsgHandler;             // points to window procedure 
    wcx.cbClsExtra = 0;                                         // no extra class memory 
    wcx.cbWndExtra = 0;                                         // no extra window memory 
    wcx.hInstance = hInstance;                                  // handle to instance 
    wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);                // predefined app. icon 
    wcx.hCursor = LoadCursor(NULL, IDC_ARROW);                  // predefined arrow 
    wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);    // white background brush 
    wcx.lpszMenuName = NULL;                                    // name of menu resource 
    wcx.lpszClassName = L"True Wild";                           // name of window class 
    wcx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);              // small class icon 

    initSprites();

    // register the window
    if (mainWnd.RegisterWindow(&wcx))
    {
        DWORD dwError = 0;
        DWORD dwStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
        RECT rc;

        rc.top = 100;
        rc.left = 100;
        rc.right = SCREEN_WIDTH;
        rc.bottom = SCREEN_HEIGHT;

        // create the window and start the message loop
        // we will get kicked out of the message loop when the window closes
        if (mainWnd.Create(dwStyle, &rc))
        {
            // message loop
            MSG msg;


            //game Loop
            while (TRUE)
            {
                while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
                { 
                    // Translate the message and dispatch it to WindowProc()
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);

                    if (mainWnd.IsWindowClosed())
                        return 0;

                }


                //Run game code
                render();
            }
            return 0;
        }
        else
            return -1;
    }
    else
        return -2;

    return 0;
}

回答1の編集:

// the message handler for this window
LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_DESTROY:
        bWindowClosed = TRUE;
        break;
    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }

    return DefWindowProc(hwnd, uMsg, wParam, lParam);
};
4

1 に答える 1

0

WM_PAINT を処理しない場合は、それを渡してDefWindowProc()クライアント領域を検証し、ウィンドウを再描画する必要があります。

スイッチ/ケースから抜け出し、0 を返しているようです。次のように置き換えます。

return 0;

return DefWindowProc(hwnd, uMsg, wParam, lParam);
于 2012-11-24T02:55:56.913 に答える