【发布时间】:2015-11-13 16:40:37
【问题描述】:
winMain 是一个默认的 main 函数,仅此而已。 window.cpp 包含在其中。
没有多边形,可以编译代码并显示一个简单的窗口。 但是当我想绘制一个多边形时,我收到以下错误消息:
D:\...\window.cpp|| undefined reference to `Polygon@12'|
试图找到多边形的实现,但我的 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。