error LNK2019: 無法解析的外部符號 _main,該符號在函式 ___tmainCRTStartup 中被引用
阿新 • • 發佈:2019-02-02
錯誤提示:#include <Windows.h> HINSTANCE hinst;//例項控制代碼太重要了,要用一個全域性變數將其儲存起來 HWND hwnd; LRESULT CALLBACK MainWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam); int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { //定義視窗類 WNDCLASSEX wcx; MSG msg; BOOL fGotMessage; hinst=hinstance; wcx.lpszClassName = "MainWClass"; wcx.cbSize = sizeof(wcx); wcx.style = CS_HREDRAW | CS_VREDRAW; wcx.lpfnWndProc = MainWndProc; wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; wcx.hInstance = hinstance; wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcx.hCursor = LoadCursor(NULL, IDC_ARROW); wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wcx.lpszMenuName = NULL; wcx.hIconSm = (HICON)LoadImage(hinstance, MAKEINTRESOURCE(5), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); if(!RegisterClassEx(&wcx)) { return 1; } //使用視窗類建立視窗 hwnd = CreateWindow("MainWClass", "Hello!", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, (HWND)NULL, (HMENU)NULL, hinstance, (LPVOID)NULL); if(!hwnd) { return 1; } ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd);//ShowWindow之後要馬上UpdateWindow一下,否則視窗顯示不出來 while((fGotMessage = GetMessage(&msg,(HWND)NULL,0,0)) != 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } //視窗過程函式,處理訊息 LRESULT CALLBACK MainWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch(uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_LBUTTONDOWN: MessageBox(hwnd,"Hello 視窗!","你好",MB_OK); return 0; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); } }