VS10: MCBS: Hi, In the light of this discussion, there was a problem trying to implement Raymond Chen's Hello World method in How can I make WNDPROC or DLGPROC a member of my C ++ class? using Pudeyev code for "Hello World" :
error LNK2001: unresolved external symbol "private: long __thiscall
BaseWnd::WndProc(struct HWND__ *,unsigned int,unsigned int,long)"
(?WndProc@BaseWnd@@AAEJPAUHWND__@@IIJ@Z)
The code is as follows:
#include <windows.h>
HINSTANCE appHinst;
class BaseWnd
{
public:
BaseWnd();
static LRESULT CALLBACK s_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT BaseWnd::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};
BaseWnd::BaseWnd(void)
{
WNDCLASSW wc = {
CS_HREDRAW|CS_VREDRAW,
BaseWnd::s_WndProc,
0,
0,
appHinst,
LoadIcon(0, IDI_APPLICATION),
LoadCursor(0, IDC_ARROW),
HBRUSH(COLOR_BACKGROUND),
0,
L"BaseWnd"
};
RegisterClassW(&wc);
HWND hwnd = CreateWindowW(L"BaseWnd", L"Hello, World!", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, appHinst, this);
ShowWindow(hwnd, SW_SHOW);
}
LRESULT BaseWnd::WndProc(HWND hwnd, UINT Umsg, WPARAM wParam, LPARAM lParam)
{
switch (Umsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
RECT r;
GetClientRect(hwnd, &r);
SetBkMode(ps.hdc, TRANSPARENT);
DrawTextW(ps.hdc, L"Hello, World!", -1, &r, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
EndPaint(hwnd, &ps);
break;
default:
return DefWindowProc(hwnd, Umsg, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK BaseWnd::s_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
BaseWnd *pThis;
if (uMsg == WM_NCCREATE) {
LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam);
pThis = static_cast<BaseWnd*>(lpcs->lpCreateParams);
SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pThis));
} else {
pThis = reinterpret_cast<BaseWnd*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
}
if (pThis) {
return pThis->WndProc(hwnd, uMsg, wParam, lParam);
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPTSTR cmdline, int showcmd)
{
appHinst = hinst;
BaseWnd p;
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
Is there something wrong with how the BaseWnd constructor is called or the class setting - or maybe from a date in Raymond's article, a C ++ 11 revision that can't handle it?
: WndProc BaseWnd:: WndProc . , , .
Edit2: CS_HREDRAW|CS_VREDRAW WNDCLASS.