为什么会这样?
1>----- 构建开始:项目:客户端,配置:调试 Win32 ------
1> WindowManager.cpp
1> 生成代码...
1> 编译...
1> Main.cpp
1>生成代码...
1>WindowManager.obj : 错误 LNK2001: 无法解析的外部符号
“private: static int WindowManager::win_stat” (?win_stat@WindowManager@@0HA) 1>C:\Users\user\documents\visual studio 2012 \Projects\TalkToMe\Debug\Client.exe : 致命错误 LNK1120: 1 未解决
的外部 ========== 构建:0 成功,1 失败,0 最新,0 跳过 ===== =====
窗口管理器.cpp
#include "WindowManager.h"
void WindowManager::PekMessage()
{
if(PeekMessage(&msg, window, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
bool WindowManager::isWindowOpen()
{
return win_stat != -1;
}
HWND WindowManager::textbox(int width, int height, int xPos, int yPos, LPCSTR content, bool edit_able)
{
int type = (edit_able) ? (WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL) : (WS_CHILD|WS_VISIBLE|WS_HSCROLL|ES_AUTOHSCROLL);
return CreateWindowEx(
WS_EX_CLIENTEDGE,
"EDIT",
content,
type,
xPos,
yPos,
width,
height,
window,
(HMENU)50,
GetModuleHandle(NULL),
NULL
);
}
HWND WindowManager::textbox(Vector size, Vector position, LPCSTR content, bool edit_able)
{
return textbox(size.getX(), size.getY(), position.getX(), position.getY(), content, edit_able);
}
LRESULT CALLBACK WindowManager::WindowProcedure(HWND winhan,UINT uint_Message,WPARAM parameter1,LPARAM parameter2)
{
switch(uint_Message)
{
case 16: // exit button
win_stat = -1;
break;
}
return DefWindowProc(winhan,uint_Message,parameter1,parameter2);
}
WindowManager::WindowManager(LPCTSTR title,int x, int y, int width, int height)
{
WNDCLASSEX wnd;
wnd.cbSize = sizeof(wnd);
wnd.style = CS_HREDRAW | CS_VREDRAW;
wnd.lpfnWndProc = WindowProcedure;
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hInstance = GetModuleHandle(NULL);
wnd.hIcon = NULL;
wnd.hCursor = LoadCursor(NULL,IDC_ARROW);
wnd.hbrBackground = GetSysColorBrush(NULL);
wnd.lpszClassName = "TalkToMe";
wnd.lpszMenuName = NULL;
wnd.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wnd);
window = CreateWindowEx(WS_EX_CONTROLPARENT, wnd.lpszClassName, title,
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, x, y, width, height,NULL, NULL,
GetModuleHandle(NULL), NULL);
}
WindowManager::~WindowManager()
{
DestroyWindow(window);
}
窗口管理器.h
#pragma once
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#include <Windows.h>
#include "Vector.h"
class WindowManager
{
private:
MSG msg;
HWND window;
static int win_stat;
public:
WindowManager(LPCTSTR title,int x, int y, int width, int height);
~WindowManager();
static LRESULT CALLBACK WindowProcedure(HWND winhan,UINT uint_Message,WPARAM parameter1,LPARAM parameter2);
HWND textbox(int width, int height, int xPos, int yPos, LPCSTR content, bool edit_able=true);
HWND textbox(Vector size, Vector position, LPCSTR content, bool edit_able=true);
bool isWindowOpen();
void PekMessage();
};