winMain是一個默認的主函數沒有別的。包含在其中的window.cpp包含在其中。爲什麼我的win32多邊形不工作?
沒有多邊形的代碼可以被編譯和一個簡單的窗口顯示。 但是當我想繪製多邊形我收到以下錯誤信息:
D:\...\window.cpp|| undefined reference to `[email protected]'|
試圖找到多邊形的實現,但我的IDE(代碼塊)無法找到它。
window.cpp
#include "window.h"
LRESULT CALLBACK window::windproc(HWND hMain, UINT msg, WPARAM wParam, LPARAM lParam)
// PROCEDURE OF THE MAIN WINDOW
{
HDC hdc;
PAINTSTRUCT ps;
POINT pt[3];
pt[0].x = 300;
pt[0].y = 200;
pt[1].x = 350;
pt[1].y = 100;
pt[2].x = 400;
pt[2].y = 200;
switch(msg)
{
case WM_PAINT:
hdc = BeginPaint(hMain,&ps);
Polygon(hdc,pt,3);
EndPaint(hMain,&ps);
break;
case WM_MBUTTONDOWN:
PostQuitMessage(0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc (hMain, msg, wParam, lParam);
}
return 0;
}
void center_window(HWND main)
{
RECT rc;
GetClientRect(main, &rc);
int xPos = (GetSystemMetrics(SM_CXSCREEN) - rc.right)/2;
int yPos = (GetSystemMetrics(SM_CYSCREEN) - rc.bottom)/2;
SetWindowPos(main, 0, xPos, yPos, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
void check_return(HWND main)
{
if(!main)
MessageBox(main, __FILE__, "ERROR", MB_OK | MB_ICONERROR);
}
在window.h
#include <windows.h>
class window
{
public:
class invalid{}; // to throw an exception
window(){}
~window(){}
LPCSTR label{"main"};
LPCSTR title{"Placeholder"};
static LRESULT CALLBACK windproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
};
// AUX FUNCTIONS
void center_window(HWND hwnd);
void check_return(HWND hwnd);
這是一個鏈接器錯誤,顯示你的代碼不能幫助我們幫助你。鏈接gdi32。 –