can not create a button inside a child view of a frame
"Florin" <florinl_ro-/[email protected]>
| Newsgroups | gmane.comp.windows.wtl |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I need your help in order to figure out why I am not able to create a button control at runetime within a client view area.
The main classes are listed below (the code that does not work resides in method OnCreate of the class CTest_wtlView):
// the client view
class CTest_wtlView :
public CScrollWindowImpl<CTest_wtlView, CWindow, CWinTraits<WS_OVERLAPPEDWINDOW | WS_VISIBLE> >
{
public:
DECLARE_WND_CLASS_EX(GetWndClassName(),
CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, COLOR_3DFACE)
static LPCTSTR GetWndClassName() { return _T("CTest_wtlView"); }
BOOL PreTranslateMessage(MSG* /*pMsg*/)
{
return FALSE;
}
BEGIN_MSG_MAP(CTest_wtlView)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
END_MSG_MAP()
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
RECT btnRc = {10, 10, 100, 35};
m_btn.Create(m_hWnd, &btnRc, _T("Hello"), WS_CHILD | WS_VISIBLE);
ATLASSERT(m_btn.IsWindow());
return 0;
}
void DoPaint(CDCHandle)
{
}
private:
WTL::CButton m_btn;
};
// the frame (only the important code is listed)
class CMainFrame :
public CFrameWindowImpl<CMainFrame>,
public CUpdateUI<CMainFrame>,
public CMessageFilter, public CIdleHandler
{
public:
DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)
CTest_wtlView m_view;
CCommandBarCtrl m_CmdBar;
virtual BOOL PreTranslateMessage(MSG* pMsg)
{
if(CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
return TRUE;
return m_view.PreTranslateMessage(pMsg);
}
// ... skiping messages map
// CFrameWindowImplBase::UpdateLayout override for CCS_TOP status bar
void UpdateLayout(BOOL bResizeBars = TRUE)
{
if (m_view.IsWindow()) {
RECT wndRc;
GetClientRect(&wndRc);
m_view.SetWindowPos(NULL, &wndRc, SWP_NOZORDER | SWP_NOACTIVATE);
}
}
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// create command bar window
HWND hWndCmdBar = m_CmdBar.Create(m_hWnd, rcDefault, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE);
// attach menu
m_CmdBar.AttachMenu(GetMenu());
// load command bar images
m_CmdBar.LoadImages(IDR_MAINFRAME);
// remove old menu
SetMenu(NULL);
HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_MAINFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
AddSimpleReBarBand(hWndCmdBar);
AddSimpleReBarBand(hWndToolBar, NULL, TRUE);
CreateSimpleStatusBar();
m_hWndClient = m_view.Create(m_hWnd, rcDefault, 0, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
UIAddToolBar(hWndToolBar);
UISetCheck(ID_VIEW_TOOLBAR, 1);
UISetCheck(ID_VIEW_STATUS_BAR, 1);
// register object for message filtering and idle updates
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->AddMessageFilter(this);
pLoop->AddIdleHandler(this);
return 0;
}
// ...
}
Thanks for your support,
Florin
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/wtl/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/wtl/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[email protected]
mailto:[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/