c++扫雷编程求助

#include<Windows.h>#include<string>usingnamespacestd;LRESULTCALLBACKmainWndProc(HWNDh... #include<Windows.h>
#include<string>
using namespace std;

LRESULT CALLBACK mainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint(hWnd, &ps);
string text = "hello windows programming!";
RECT rect;
GetClientRect(hWnd, &rect);
rect.left = 0;
rect.top = 0;
rect.right = 200;
rect.bottom = 200;
DrawText(hDC, text.c_str(), text.length(), &rect,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
EndPaint(hWnd, &ps);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hWnd, message, wParam, lParam);

}
int APIENTRY winmain(HINSTANCE hInst,
HINSTANCE hPrevInst,
LPTSTR lpCmdline,
int nCmdshow)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = mainWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
wcex.lpszMenuName = NULL;
string className = "MineSweeperMainWindow";
wcex.lpszClassName = className.c_str();
wcex.hIconSm = NULL;
RegisterClassEx(&wcex);
HWND mainWnd = CreateWindowA(className.c_str(), "shit", WS_OVERLAPPEDWINDOW,
128, 128, 640, 480, NULL, NULL, hInst, NULL);
ShowWindow(mainWnd, nCmdshow);
UpdateWindow(mainWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
还有我为什么把这段源代码复制到另一个里错误变更多了
展开
 我来答
凌云小紫冥
推荐于2016-08-11 · TA获得超过310个赞
知道小有建树答主
回答量:291
采纳率:0%
帮助的人:268万
展开全部

字符串错误,和Main函数错误,修改后的代码:

#include<Windows.h>
#include<string>
using namespace std;

LRESULT CALLBACK mainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_CREATE:
        return 0;
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hDC = BeginPaint(hWnd, &ps);
        wstring text = L"hello windows programming!";
        RECT rect;
        GetClientRect(hWnd, &rect);
        rect.left = 0;
        rect.top = 0;
        rect.right = 200;
        rect.bottom = 200;
        DrawText(hDC, text.c_str(), text.length(), &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
        EndPaint(hWnd, &ps);
        return 0;
    }
    case WM_DESTROY:
    {
        PostQuitMessage(0);
        return 0;
    }
    }
    return DefWindowProc(hWnd, message, wParam, lParam);

}
int WINAPI  WinMain(
    HINSTANCE hInst,
    HINSTANCE hPrevInst,
    LPSTR  lpCmdline,
    int nCmdshow
    )
{
    WNDCLASSEX wcex;
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = mainWndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInst;
    wcex.hIcon = NULL;
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
    wcex.lpszMenuName = NULL;
    wstring className = L"MineSweeperMainWindow";
    wcex.lpszClassName = className.c_str();
    wcex.hIconSm = NULL;
    RegisterClassEx(&wcex);
    HWND mainWnd = CreateWindow(className.c_str(), L"shit", WS_OVERLAPPEDWINDOW,
        128, 128, 640, 480, NULL, NULL, hInst, NULL);
    ShowWindow(mainWnd, nCmdshow);
    UpdateWindow(mainWnd);
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式