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;
}
还有我为什么把这段源代码复制到另一个里错误变更多了 展开
#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;
}
还有我为什么把这段源代码复制到另一个里错误变更多了 展开
1个回答
展开全部
字符串错误,和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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询