Re: Swap handles of attached windows ... assert in wincore.cpp .... please explain
On 7 Okt., 02:30, Joseph M. Newcomer <newco...@flounder.com> wrote:
You are doing this the hard way. Again, I have no idea what you're trying to do, but
swapping handles as you have done is not going to work. Doing complex attach operations
like this is going to result in problems, because now you have potential multiple
mappings.
On Fri, 05 Oct 2007 11:51:17 -0700, ".rhavin grobert" <cl...@yahoo.de> wrote:
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();
****
Code this complex is dangerous. You are playing with fire here. What are you really
trying to do here?
CQObject is the baseclass of CQListBox, CQComboBox, CQYouNameIt, ...
those classes all have two baseclasses: their window-control-class
(eg. CListBox, CCombobox, ...) and CQObject.
I get a pointer to the CWnd-baseclass [QGetCWnd()] and get the
settings for the following creation-command to
create a similar window.
****> 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);
****
Why do you think 32 is going to make sense?
'twas enough for testing. later i wanted to see if i find some
MAX_CLASSNAME_LENGHT anywher.
****
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);
****
I can't begin to understand the purpose of the above code. You are asking detailed
questions of how to do something without explaining your purpose in doing it.
QCreateNew() creates a new window-control of the derived class. After
that, i get its CWnd
[QGetCWnd()] and modify it's settings according to the original
control.
Now i have two similar controls, one with the style-flags originally
set by the resources, one
with the flags i want. I thought i can now somehow swap the windows of
the two CWnd and
destroy the newly created object, that way destroying the old window.
I didnt know that a
CWnd needs more than a hwnd to point to a window. Seems like it really
doesn't _need_ more,
the rest seems to be moe like some error-management to me, because the
actual communication
is still handled via hwnd. please correct me if im wrong.
****
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;
}
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm