Cwnd returnd Undefined Value
I want to use Setwindowpos() in global function to change the postiion of one dialog. So i coded like below
CWnd *pWnd = (CWnd*)pMain->GetDlgItem(IDD_TOOLBAR_DIALOG);//GetActiveFrame ();
pWnd->SetWindowPos(&CWnd::wndBottom,0,80,45,900,SWP_SHOWWINDOW);
pWnd returns as undefined value. So i follow this method
CToolTab * tab;
tab = new CToolTab();
if(tab->GetSafeHwnd() == 0)
{
tab = new CToolTab();
if( tab->m_hWnd != NULL )
{
tab->SetWindowPos(&CWnd::wndBottom,0,80,45,900,SWP_SHOWWINDOW); }
}
But m_hWnd returns开发者_C百科 0x0000.So in both cases SetWindowPos shows assertion error. How can i get the handle of dialog in Global function?
Ok so i was thinking this through - and then it occurred to me that IDD_TOOLBAR_DIALOG is almost certainly the resource id for the dialog itself not a control on the dialog. You can't call GetDlgItem referencing the Dialog resource ID and expect to find the window that contains it (It simply won't work and you'll get back a null CWnd* pointer).
What is it that pMain points to? The main application window? Is that the parent to the Dialog?
Where in the code do you create the Dialog that want to move? At that point you must have a valid CWnd derived object for it? One solution would be to hold on to that as member variable to allow you call SetWindowPos on it later when necessary.
精彩评论