I made an MFC application based on a dialog. Into this, I added a CStatusBar into bottom of the dialog addin this code into CMyDialog::InitDIalog() :
//Create status bar
BOOL bReturn = m_wndStatusBar.Create(this);
m_wndStatusBar.SetIndicators(indicators,1);
// Find the Size of Dialog box
CRect rect;
GetClientRect(&rect);
// Size the two panes
m_wndStatusBar.SetPaneInfo(0,IDD_INDICATOR_STATUS, SBPS_NORMAL, rect.Width());
// This is where we actually draw it
RepositionBars( AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, IDD_INDICATOR_STATUS ) ;
Note in the dialog editor, I had to keep some space at the bottom for the status bar. Work fine so far, status bar is correctly displayed :
BUT problem occurs when I resize the dialog. I put this code into CMyDialog::OnSize() :
RepositionBars( AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, IDD_INDICATOR_STATUS) ;
m_wndStatusBar.SetForegroundWindow();
The position of the CStatusBar window is correctly adapted... but status bar is displayed behind other controls.
Any idea how to solve this ? Why the call to SetForegroungWindow() is not working in this case ?
Related
I have a MFC CDateTimeCtrl object in my MFC based Dialog.
My question is, how can I change the background color and the text color of the edit box ?
After an extensive search I tried the following code for a subclassed CDateTimeCtrl but this shows my background color only if I click in the DateTimeCtrl box.
BOOL CCHDateTimeCtrl::OnEraseBkgnd(CDC *pDC)
{
CRect rect;
pDC->GetClipBox(&rect);
pDC->FillSolidRect(&rect, getBackgroundColor());
return TRUE;
}
Hopefully someone has a suggestion.
I am creating some dialog-based MFC application (C++) and need to use tab control. Here is the code where I try to adjust child dialog to a tab control display area (Visual Studio 2015):
/* main dialog */
BOOL CResourceBrowserDlg::OnInitDialog()
{
....
/*
* `m_Page` is my child dialog instance:
* CDlgFilterPage::CDialogEx *m_Page
*/
m_Page = new CDlgFilterPage();
m_Page->Create(IDD_FILTERPAGE, m_FilterTab.GetWindow(IDD_FILTERPAGE));
RECT rect;
/*
* `m_FilterTab` is a tab control element:
* CTabCtrl m_FilterTab
*/
m_FilterTab.GetWindowRect(&rect);
m_FilterTab.AdjustRect(FALSE, &rect);
m_Page->MoveWindow(&rect);
m_Page->ShowWindow(SW_SHOW);
m_FilterTab.InsertItem(0, L"Page1");
...
}
Running this i got the following:
So how should I act to get child window fit nicely within tab control?
First of all, you probably want to first add a page and then position the other dialog within the client area of the tab. Otherwise, your tab window will not have the tab buttons and the size of the dialog will be larger than what you expect.
Second, you need to position the new dialog inside the client area. You have to retrieve that and then translate it based on the window area.
Here is how you do all that:
m_Page = new CDlgFilterPage();
m_Page->Create(IDD_FILTERPAGE, m_FilterTab.GetWindow(IDD_FILTERPAGE));
m_FilterTab.InsertItem(0, L"Page1");
CRect rcClient, rcWindow;
m_FilterTab.GetClientRect(&rcClient);
m_FilterTab.AdjustRect(FALSE, &rcClient);
m_FilterTab.GetWindowRect(&rcWindow);
ScreenToClient(rcWindow);
rcClient.OffsetRect(rcWindow.left, rcWindow.top);
m_Page->MoveWindow(&rcClient);
m_Page->ShowWindow(SW_SHOW);
The result is this:
Do not try to get the Window position in OninitDialog() function. It will show 0,0 location instead of actual position of dialog.
I have an MFC dialog with a button and a Picture control. When I click the button, I draw line inside the picture control.
The problem is that the CDC I get is the whole dialog client area. So the line is drawn outside the picture control. I need to get the CDC of only the Picture control, because the line coordinates should be relative to picture control rectangle.
Here is the code:
void SimulatorDlg::OnBnClicked()
{
CDC *pDC = GetDlgItem(IDC_VIDEO_PREVIEW)->GetDC();
pDC->MoveTo(0,0);
pDC->LineTo(100,100);
ReleaseDC(pDC);
}
IDC_VIDEO_PREVIEW is the id of the Picture Control, which is inside the dialog.
When using the CreateSimpleReBar in WTL the main menu bar has this blue color on mouse hover and not the native vista/7 round and transparent shape. Also for some reason the menu bar seems taller then the usual native one.
Does CreateSimpleReBar draw the menu itself or am I missing something?
http://imageshack.us/photo/my-images/259/wtlmainmenu.png/
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);
// Set m_hWndToolBar member
CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
// Add a band to the rebar represented by m_hWndToolBar
AddSimpleReBarBand(hWndCmdBar);
CreateSimpleReBar creates a rebar control, and the menu is one of the rebar bands, created by m_CmdBar.Create - WTL's CCommandBarCtrl class. The latter custom-draws the menu to mimic OS behavior, including blue highlighting with COLOR_MENUHILIGHT (atlctrlw.h).
Ok so I am using this code to hide the taskbar icon of a dialog based MFC application(VC++). The taskbar icon and the dialog box hide whenever I click on the cross or the close buttons. But I can’t get this one thing right. Whenever I hit the close or the cross button from title bar, the dialog box first flickers and shows a sort of intermediate dialog box and then hides. This is very annoying. I am posting my code here after two days of vain effort. So guys please help me. Thanks in advance.
void CMyAppDlg::OnBnClickedCancel()
{
// TODO: Add your control notification handler code here
CWnd* pWnd;
pWnd = AfxGetMainWnd();
RemoveTaskbarIcon(pWnd);
pWnd->ModifyStyle(WS_VISIBLE, 0);
mVisible = FALSE;
}
BOOL CMyAppDlg::RemoveTaskbarIcon(CWnd* pWnd)
{
LPCTSTR pstrOwnerClass = AfxRegisterWndClass(0);
// Create static invisible window
if (!::IsWindow(mWndInvisible.m_hWnd))
{
if (!mWndInvisible.CreateEx(0, pstrOwnerClass, _T(""),
WS_POPUP,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL, 0))
return FALSE;
}
pWnd->SetParent(&mWndInvisible);
return TRUE;
}
Here are the screen shots of dialog box. When I press the close or cross button, the dialog box which looks like this in the first place turns into this for like less than half a second and then disappears (hides).
If you show your dialog using CDialog::DoModal() the framework will make sure your dialog is shown. There is only one way to prevent a modal dialog from being shown:
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
ON_WM_WINDOWPOSCHANGING()
END_MESSAGE_MAP()
BOOL CHiddenDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_visible = FALSE;
return TRUE;
}
void CHiddenDialog::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
if (!m_visible)
lpwndpos->flags &= ~SWP_SHOWWINDOW;
CDialog::OnWindowPosChanging(lpwndpos);
}
I think Paul DiLascia recommended the following. This is for modal dialogs only.
The following code can be put in OnInitDialog to move the dialog off-screen. You will need to implement a method for moving it back on-screen when appropriate.
CRect DialogRect;
GetWindowRect(&DialogRect);
int DialogWidth = DialogRect.Width();
int DialogHeight = DialogRect.Height();
MoveWindow(0-DialogWidth, 0-DialogHeight, DialogWidth, DialogHeight);
The answer from l33t looks good and is probably better but this is an alternative.
Maybe an obvious thing, but what happens when you do the hide before you reparent the dialog? Also what if you don't directly modify the window style but use ShowWindow(SW_HIDE)?
Finally, have you tried switching the dialog's window style to WS_CHILD before calling SetParent() and/or maybe moving it out of the client area so that the window isn't shown any more (MoveWindow(-1000, -1000) or something like that).