cc13092941489
2017-11-23 10:10
采纳率: 100%
浏览 1.4k

有没有大神看一下这个C++程序为什么没有运行窗口

#include
#include
#include
#include"resource.h"
#define BLOCK 100

LRESULT CALLBACK WindowProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM LParam
);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR IpCmdLine, int nCmdShow){
wchar_t szAppClassName[20] = L"TZGuiFoundation";
WNDCLASS wndClass;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
wndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = WindowProc;
wndClass.lpszClassName = szAppClassName;
wndClass.lpszMenuName = NULL;
wndClass.style = CS_HREDRAW | CS_VREDRAW;

//
RegisterClass(&wndClass);
//
HWND hWnd = CreateWindow(szAppClassName,
    L"黑白块游戏",
    WS_OVERLAPPEDWINDOW,
    500,
    100,
    BLOCK * 4 + 20,
    BLOCK * 4 + 40,
    NULL,
    NULL,
    hInstance,
    NULL
    );

ShowWindow(hWnd,
    SW_SHOW
    );
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}
return TRUE;

}

LRESULT CALLBACK WindowProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
PAINTSTRUCT ps;
HDC hDC;
static int bw[4];
switch (uMsg)
{
case WM_CREATE:

{
                  srand((UINT)time(NULL));
                  for (int i = 0; i < 4; i++)
                  {
                      bw[i] = rand() % 4;

                  }
                  SetTimer(hWnd, 1, 10, NULL);

}
case WM_CLOSE:
    DestroyWindow(hWnd);
    break;
case WM_DESTROY:
    PostQuitMessage(0);
    break;
case WM_PAINT:
hDC=    BeginPaint(hWnd, &ps);
    for (int i = 0; i < 4; i++)
    {
        MoveToEx(hDC, 0, i*BLOCK, NULL);
        LineTo(hDC, 4 * BLOCK, i*BLOCK);

        MoveToEx(hDC, i*BLOCK, 0, NULL);
        LineTo(hDC, 4 * BLOCK, i*BLOCK);




        EndPaint(hWnd, &ps);
        return TRUE;

    }

    return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

}

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 逆水行舟天涯路 2017-11-24 08:25
    已采纳

    case WM_CREATE:
    {
    srand((UINT)time(NULL));
    for (int i = 0; i < 4; i++)
    {
    bw[i] = rand() % 4;

                  }
                  SetTimer(hWnd, 1, 10, NULL);
    

    }
    break;
    case WM_CLOSE:
    创建的时候没有break,直接跑到WM_CLOSEl了,肯定直接关闭窗口

    已采纳该答案
    打赏 评论
  • littlebai07 2017-11-23 14:21

    程序不全吧,这是MFC的一部分啊

    打赏 评论

相关推荐 更多相似问题