【发布时间】:2011-02-25 11:31:04
【问题描述】:
我正在尝试学习如何在 C++ 中创建窗口,我看过一篇关于创建包装类的文章,但我并不真正理解它。到目前为止,我知道你不能有一个类方法 WndProc(我不知道为什么),但老实说,仅此而已。有人可以给出解释,同时解释 reinterpret_cast 吗? Here是文章。
LRESULT CALLBACK Window::MsgRouter(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
Window *wnd = 0;
if(message == WM_NCCREATE)
{
// retrieve Window instance from window creation data and associate
wnd = reinterpret_cast<Window *>((LPCREATESTRUCT)lparam)->lpCreateParams;
::SetWindowLong(hwnd, GWL_USERDATA, reinterpret_cast<long>(wnd));
// save window handle
wnd->SetHWND(hwnd);
}
else
// retrieve associated Window instance
wnd = reinterpret_cast<Window *>(::GetWindowLong(hwnd, GWL_USERDATA));
// call the windows message handler
wnd->WndProc(message, wparam, lparam);
}
先谢谢了,嗯。
【问题讨论】:
标签: c++ class window wrapper casting