I would like to have thin child frame borders in my MFC/MDI application. Microsoft suggests changing window styles in PreCreateWindow function and it seems like proper window style is WS_BORDER. However something like this doesn't work;
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_BORDER;
return CMDIChildWnd::PreCreateWindow(cs);
}
What am I missing here?
Thanks
You can try something like this:
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style = WS_CHILD | WS_VISIBLE | WS_BORDER;
if(! CMDIChildWnd::PreCreateWindow(cs))
return FALSE;
return TRUE;
}
Related
I'm developing an application in MFC C++ and I have derived a CDockablePane object that I can view on the main window. I need the dockable pane's background to be transparent so you can see the main window through the dockable pane.
How would I accomplish this? Thanks.
this how i create the CDockable Pane object:
if (!FeaturePane.Create("Features", this, CSize (400,500), TRUE, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{
TRACE0("Failed to create Program window\n");
//return false; // failed to create
return FALSE;
}
i Know you can clear the background of a CDroDialog using the following code:
BOOL CDroDialog::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd,GWL_EXSTYLE) ^ WS_EX_LAYERED);
SetLayeredWindowAttributes(RGB(255,0,255),0, LWA_COLORKEY);
}
BOOL CDroDialog::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect clientRect ;
GetClientRect(&clientRect) ;
pDC->FillSolidRect(clientRect, RGB(255,0,255)) ; // paint background in magenta
//return CDialog::OnEraseBkgnd(pDC);
return FALSE;
}
I am writing a SDI application on Visual Studio 2012. The MFC Wizard generated two CDockablePane-derived objects. The right-side CPropertiesWnd (CDockablePane-derived) object is named m_wndProperties. I embed in m_wndProperties a CPropertySheet object with a CPageNone (CPropertyPage-derived) object captioned "HELP" like this (I use the CPropertySheet class directly). However, the real size of the CPropertySheet object is bigger.
I have tried to adjust the size of the dialog related to the CPageNone object (named m_pageNone) in the Dialog Editor. This has no effect. In the MainFrm.cpp, the only lines relating to m_wndProperties I can find are:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
.....
m_wndProperties.EnableDocking(CBRS_ALIGN_RIGHT);
DockPane(&m_wndProperties);
.....
}
.....
BOOL CMainFrame::CreateDockingWindows()
{
.....
CString strPropertiesWnd;
bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);
ASSERT(bNameValid);
if (!m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
{
TRACE0("無法建立 [屬性] 視窗\n");
return FALSE; // 無法建立
}
.....
}
.....
void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons)
{
.....
HICON hPropertiesBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_PROPERTIES_WND_HC : IDI_PROPERTIES_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
m_wndProperties.SetIcon(hPropertiesBarIcon, FALSE);
}
And here is the AdjustLayout() in my PropertiesWnd.cpp:
void CPropertiesWnd::AdjustLayout()
{
if (GetSafeHwnd () == NULL || (AfxGetMainWnd() != NULL && AfxGetMainWnd()->IsIconic()))
{
return;
}
CRect rectClient;
GetClientRect(rectClient);
m_PropertySheet.SetWindowPos (NULL, rectClient.left, rectClient.top, rectClient.Width (), rectClient.Height (), SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
}
And in my PageNone.cpp, I only have three functions: the default constructor, the default destructor and DoDataExchange.
My question is how can I adjust the size of m_wndProperties or m_pageNone to fit each other? Thank you very much.
I have got this working in a different way (the code is too large to give in this answer, but the main points are:
a) don't do anything in CMainFrame::OnCreate()
b) in CMainFrame::CreateDockingWindows(), after m_wndProperties.Create(), add the following code
m_PropertySheet.Create(...);
CRect rc;
m_PropertySheet.GetRect(&rc);
m_wndProperties.SetMinSize(rc.Width(), rc,Height());
m_wndProperties.EnableDocking(CBRS_ALIGN_RIGHT);
DockPane(&m_wndProperties);
ShowPane(&m_wndProperties, TRUE, FALSE, TRUE);
Your code in AdjustLayout() is plausible right, but I think during startup it will be called too early. Because the default size will be read from CWinAppEx::LoadState(), which always read the previous size from the Registry. It can probably disabled with CWinAppEx::EnableLoadWindowPlacement(FALSE). not tested.
Post a User-Defined Message at the end of InitInstance(). Or just try with a timer in CMainFrame::Create() .. SetTimer(123,2000,NULL);
void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == 123)
{
m_wndProperties.SetWindowPos(this, 0, 0, 400, 200, SWP_NOZORDER | SWP_FRAMECHANGED);
RecalcLayout();
KillTimer(123);
}
CFrameWndEx::OnTimer(nIDEvent);
}
I have a Dialog that has an progress bar.
I wan't to add a Method to that dialog that sets the progressbar to marquee.
I try following:
void CDownloader::SetIntermediate(wstring info)
{
SetDlgItemText(IDC_DOWNLOADER_LABEL, info.c_str());
auto style = GetWindowLong(GWL_STYLE);
style &= ~( PBS_SMOOTH | PBS_SMOOTHREVERSE | PBS_VERTICAL);
style |= PBS_MARQUEE;
SetWindowLong(GWL_STYLE, style);
RECT windowRect;
GetWindowRect(&windowRect);
SetWindowPos(HWND_TOP, &windowRect,SWP_FRAMECHANGED);
HWND progress = GetDlgItem(IDC_DOWNLOADER_PROGRESS);
::SendMessage(progress, PBM_SETMARQUEE, TRUE, 100);
}
However this does not work :(
I set the Window Style to MARQUEE removing styles that may conflict with it, using setWindowPos to update the style and the set the Progress to MARQUEE.
I can set the progress bar in the designer to marquee, but can't switch bac to normal.
For all that whant the correct code:
void CDownloader::SetPending(bool value)
{
if(value)
{
HWND progress = GetDlgItem(IDC_DOWNLOADER_PROGRESS);
auto style = ::GetWindowLong(progress, GWL_STYLE);
style |= PBS_MARQUEE;
::SetWindowLong(progress, GWL_STYLE, style);
::SendMessage(progress, PBM_SETMARQUEE, TRUE,0);
}
else
{
HWND progress = GetDlgItem(IDC_DOWNLOADER_PROGRESS);
auto style = ::GetWindowLong(progress, GWL_STYLE);
style &= ~PBS_MARQUEE;
::SetWindowLong(progress, GWL_STYLE, style);
::SendMessage(progress, PBM_SETMARQUEE, FALSE,0);
}
}
I'd be very grateful if anyone could help me with this? I'm trying to create a dialog box with a text box in it for receiving error messages. I've added ON_WM_CREATE to the message map, and written this function which the debug goes through, but the object doesn't display.
int CImportDatatoAPMDlg::OnCreate(LPCREATESTRUCT LpCreateStruct)
{
if(CWnd::OnCreate(LpCreateStruct) == -1)
{
return -1;
}
CEdit *MessageBox = new CEdit;
MessageBox->Create(WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL,CRect(100, 200, 450, 150), this, 0x1552);
return 0;
}
Do I have to make a dummy box when I'm designing the dialog box. I've already done this for the rest of the controls? I'm also wondering where I give this object a number ID combination?
Thanks,
James
You normally should use VisualStudio resource editor to add controls to your dialog. If you want to do it manually then create and add controls in your overriden OnInitDialog method:
BOOL CImportDatatoAPMDlg::OnInitDialog() {
BOOL bRes = CDialog::OnInitDialog();
CEdit *MessageBox; // !!! put it into class definition
MessageBox = new CEdit
MessageBox->Create(WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL,CRect(100, 200, 450, 150), this, 0x1552);
return bRes;
}
I'm using these window styles when calling CreateWindow
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
This disables the maximize box, but is there any way I can completely remove it?
No easy way, but if you are going to draw the title bar yourself - in this case you can do it.
To give you an idea, this article Adding a 'Minimize to tray'-button to a Form's caption bar explains how to add a button. Removing standard button is about the same - customization of non-client area.
This will remove the close, minimize and maximize buttons from a Windows 7 panel I realize this is very (very) late in coming, but posted it here as it may help someone else with same problem.
void ClearButtons(void)
{
int index = WS_BORDER;
unsigned int a = (unsigned int)((WS_BORDER | WS_CAPTION) & (~WS_ICONIC));
LONG_PTR lPtr;
HWND hWnd = GetActiveWindow();
lPtr = GetWindowLongPtr(hWnd, index);
SetWindowLongPtr(hWnd, GWL_STYLE, a);
}