一个简单的MFC程序,只要求按鼠标左键显示文本出现了如下的错误提示,使用的是vs2017
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 LNK1120 1 个无法解析的外部命令 Project1 C:\Users\dell-pc\source\repos\Project1\Debug\Project1.exe 1
错误 LNK2019 无法解析的外部符号 _main,该符号在函数 "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 中被引用 Project1 C:\Users\dell-pc\source\repos\Project1\Project1\MSVCRTD.lib(exe_main.obj)
#include <Windows.h>
HINSTANCE hInst; HWND hWnd; MSG msg; char lpszClassName[] = "窗口"; char *ShowText; char c[] = "hello!";
ATOM MyRegisterClass(HINSTANCE hInstance); BOOL Create(HINSTANCE, int); int Run();
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void onlbuttondown(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
void onpaint(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
void ondestroy(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPresvInstance, LPSTR lpCmdLine, int nCmdShow) {
MyRegisterClass(hInstance); Create(hInstance, nCmdShow); ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd); return Run();
}
ATOM MyRegisterClass(HINSTANCE hInstacne) {
WNDCLASS wc;
wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstacne;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL;
wc.lpszClassName = lpszClassName; return RegisterClass(&wc);
}
BOOL Create(HINSTANCE hInstance, int nCmdShow) {
hWnd = CreateWindow(lpszClassName, "windows", WS_OVERLAPPEDWINDOW, 400, 300, 180, 160, NULL, NULL, hInstance, NULL);
return TRUE;
}
int Run() {
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_LBUTTONDOWN:onlbuttondown(hWnd, message, wParam, lParam); break;
case WM_PAINT:onpaint(hWnd, message, wParam, lParam); break;
case WM_DESTROY:ondestroy(hWnd, message, wParam, lParam); break;
default:return DefWindowProc(hWnd, message, wParam, lParam);
}return 0;
}
void onlbuttondown(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
ShowText = c; InvalidateRect(hWnd, NULL, 1);
}
void onpaint(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps; HDC hdc; hdc = BeginPaint(hWnd, &ps); TextOut(hdc, 50, 50, ShowText, 6);
EndPaint(hWnd, &ps);
}
void ondestroy(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
PostQuitMessage(0);
}
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 LNK1120 1 个无法解析的外部命令 Project1 C:\Users\dell-pc\source\repos\Project1\Debug\Project1.exe 1
错误 LNK2019 无法解析的外部符号 _main,该符号在函数 "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 中被引用 Project1 C:\Users\dell-pc\source\repos\Project1\Project1\MSVCRTD.lib(exe_main.obj) 1