I am using Visual C++ 6.0 on Windows XP.
Using AppWizard I have a window for the view class and would like to
create a sibling window (that moves around in the same client area of
the main window) from that class.
I try the following
void CMyWinView::OnSiblingCreate()
{
CWnd* pMain=AfxGetApp()->m_pMainWnd;
CRMAWinDoc* pDoc = GetDocument();
char csTitleBarText[128];
DWORD dwStyle=GetStyle();
DWORD dwExStyle=GetExStyle();
RECT rClientRect={0, 0, dwColumns, dwRows};
CSiblingWin* pWnd = new CSiblingWin;
CString clsname = AfxRegisterWndClass(0);
HWND hNewWindow;
CWnd* cwNewWindow;
int iOffset=0;
sprintf(csTitleBarText, "%s: New Image", csImageFileName);
hNewWindow=CreateWindow(clsname, (LPCTSTR)csTitleBarText,
WS_OVERLAPPEDWINDOW | WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE |
WS_CLIPSIBLINGS,
iOffset, iOffset, rClientRect.right, rClientRect.bottom,
pMain->m_hWnd, GetMenu( )->m_hMenu, NULL, NULL );
cwNewWindow=FromHandle( hNewWindow );
cwNewWindow->ShowWindow(TRUE);
SetWindowPos( NULL, 100, 100, rClientRect.right, rClientRect.bottom,
SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
}
and I don't see anything until I resize the main window. Then its
frame is smeared. This also happens when I replace
WS_OVERLAPPEDWINDOW | WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE |
WS_CLIPSIBLINGS with GetStyle()
As an alternative, I tried this.
void CMyWinView::OnSiblingCreate()
{
CWnd* pMain=AfxGetApp()->m_pMainWnd;
CRMAWinDoc* pDoc = GetDocument();
char csTitleBarText[128];
DWORD dwStyle=GetStyle();
DWORD dwExStyle=GetExStyle();
RECT rClientRect={0, 0, dwColumns, dwRows};
CSiblingWin* pWnd = new CSiblingWin;
CString clsname = AfxRegisterWndClass(0);
HWND hNewWindow;
CWnd* cwNewWindow;
int iOffset=0;
sprintf(csTitleBarText, "%s: New Image", csImageFileName);
{
sprintf(csMessage, "Error code %d", GetLastError());
MessageBox( csMessage, "Error creating child window", MB_OK );
return ;
}
if (!(pWnd->CreateEx( dwExStyle, clsname, (LPCTSTR)csTitleBarText,
dwStyle, rClientRect, pMain, 0)))
{
sprintf(csMessage, "Error code %d", GetLastError());
MessageBox( csMessage, "Error creating child window", MB_OK );
return ;
}
SetWindowPos( NULL, 100, 100, rClientRect.right, rClientRect.bottom,
SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
}
Now I get a frame that is the right size but has no banner and is
stuck to the main frame rather like an outgrowth.
I would be grateful if someone could tell me how I can get a sibling
window with the same properties as the view window.
Many thanks in advance,
Peter.