0
我很困惑为什么第二个静态指针pthis不会初始化?我所做的是我通过静态函数子类化窗口过程。第一个静态指针lpProcess在主程序中初始化。然而,第二个甚至不会调用它自己的构造函数(我使用调试器来确定这个问题)。不知何故,它简单地跳过了建筑。起初,我怀疑我是误解了静态变量的一些观点。但是,看到第一个工作,为什么不是第二个?也许,我想这与深层递归或调用静态函数有关?静态指针不会在子类窗口过程中初始化?
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static QProcessor* lpProcess = new QProcessor(hwnd); //Initialized without any error
switch(msg)
{
case WM_CREATE:
{
lpProcess->SetFixed(322,200); //Set window size through the container
lpProcess->Update(); //Update members
if(!lpProcess->CreateChild()) //Create all controls
{
Error(); //print error
::DestroyWindow(hwnd); //terminate the window
}
QMonitor::Attach(hwnd); //Attach Monitor Window to current window
}
....
void QMonitor::Attach(HWND hwnd)
{
QMonitor::classdata = (LPVOID)::SetWindowLong(hwnd,GWL_WNDPROC,(LONG)QMainProc); //subclass procedure
}
LRESULT CALLBACK QMainProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static QMonitor* pthis = new QMonitor(hwnd); //Won't initialize??
switch(msg)
{
case WM_MOVE:
{
pthis->OnMove();
}
break;
case WM_SIZE:
{
pthis->OnSize();
}
break;
case WM_COMMAND:
break;
case WM_DESTROY:
delete pthis;
break;
}
return ::CallWindowProc(pthis->GetAttachWndProc(),hwnd,msg,wParam,lParam);
}