Recreate a Window ... how to stop asserts...?
the following func was meant to recreate a window with given styles.
unfortunaltely, it asserts in WinCtrl1.cpp if a listbox is recreated
with the ownerdrawn-style set because MeasureItem() is not overloaded.
how do i stop this assert?
bool RecreateWindow(CWnd* pWnd, DWORD dwStyle, DWORD dwStyleEx) {
if (pWnd == NULL) return false;
if (pWnd->GetSafeHwnd() == 0) return false;
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);
pWnd->ScreenToClient(&rc);
CString scCaption;
pWnd->GetWindowText(scCaption);
char szClass[32];
GetClassName(pWnd->GetSafeHwnd(), szClass, 32);
HWND hwnd = CreateWindowEx(dwStyleEx, szClass, scCaption, dwStyle,
rc.left, rc.top, rc.Width(), rc.Height(), hParent, (HMENU) nID,
AfxGetInstanceHandle(), lParam);
SetWindowLong(hwnd, GWL_WNDPROC, lWndProc);
// .... //
return true;
}