Re: Swap handles of attached windows ... assert in wincore.cpp .... please explain
I'd realy like it if someone could please answer something;)
If i get rid of all the...
AFX_MANAGE_STATE(AfxGetStaticModuleState());
....i can create the new control and use it, but i get an assert when i
try to destroy the old one after swapping hWnds.
If i keep them, i can correctly (?) create the new window, destroy the
old one, attach the new hwnd to the old controls CWnd but then all
SendMessages to my control seem to vanish into void. Perhaps someone
finds something i didnt find in the whole lot of code that comes here?
_______________________________________________________
// class CQListBox is base public CListbox, public CQObject....
// QGetCWnd(), QCreateNew(), QDelete() and QGetAllocation()
// are CQObject's virtual functions overloaded by CQListBox.
bool CQObject::QRecreateWindow(DWORD dwStyle, DWORD dwStyleEx) {
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd* pWnd = QGetCWnd();
if (pWnd == NULL) return false;
if (pWnd->GetSafeHwnd() == 0) return false;
CWnd* pParent = pWnd->GetParent();
HWND hParent = 0;
UINT nID = pWnd->GetDlgCtrlID();
CFont* pFont = pWnd->GetFont();
CWnd* pWndAfter = pWnd->GetNextWindow(GW_HWNDPREV);
LPVOID lParam = (LPVOID) GetWindowLong(pWnd->GetSafeHwnd(),
GWL_USERDATA);
LONG lWndProc = GetWindowLong(pWnd->GetSafeHwnd(), GWL_WNDPROC);
if (pWndAfter == NULL ) pWndAfter = (CWnd*) &CWnd::wndBottom;
if (pWnd->GetParent()) hParent = pWnd->GetParent()->GetSafeHwnd();
CRect rc;
pWnd->GetWindowRect(&rc);
rc.bottom += 150; // this is just to see both windows
rc.top += 150;
pParent->ScreenToClient(&rc);
CString scCaption;
pWnd->GetWindowText(scCaption);
char szClass[32];
GetClassName(pWnd->GetSafeHwnd(), szClass, 32);
CQObject* pObjNew = QCreateNew(dwStyleEx, szClass, scCaption,
dwStyle, rc, pParent, nID, lParam);
CWnd* pNew = pObjNew->QGetCWnd();
pWnd->DestroyWindow();
HWND hWnd = pNew->Detach();
pWnd->Attach(hWnd);
pWnd->SetWindowPos(pWndAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
pWnd->SetFont(pFont);
QDelete(pObjNew->QGetAllocation());
return true;
}
// ________________________________
CQObject* CQListBox::QCreateNew(
DWORD dwExStyle, LPCTSTR szClassName,
LPCTSTR szWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd,
UINT nID, LPVOID lpParam)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CQListBox* pObj = new CQListBox;
pObj->CreateEx(dwExStyle, szClassName, szWindowName,
dwStyle, rect, pParentWnd, nID, lpParam);
return pObj;
}
// ________________________________
void CQListBox::QDelete(void* pAlloc) {
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CQListBox* p_C = (CQListBox*) pAlloc;
p_C->DestroyWindow();
delete p_C;
}
// ________________________________
CWnd* CQListBox::QGetCWnd() {
return this;
}
// ________________________________
void* CQListBox::QGetAllocation() {
return this;
}