how to make title bar less window in mfc by code? - mfc

how to make title bar less window in mfc by code?

Use:
ModifyStyle (WS_CAPTION, 0); // to hide
ModifyStyle (0, WS_CAPTION); // to show
To remove it earlier Override PreCreateWindow() and remove WS_SYSMENU

Just to add, calling:
SetWindowPos(nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
after ModifyStyle() applies the settings (at least for dialog-based applications).

Related

How to Hide a Title Bar in a CDockablePane?

I want to hide a title bar in CDockablePane. I tried calling ModifyStyle(), but it doesn't work.
ModifyStyle(WS_SYSMENU, 0, SWP_FRAMECHANGED);
Don't use the style WS_CAPTION when you create the pane!
you need to call dockablepane's EnableGripper(FALSE) to hide the pane's caption in docking state. Remember to call it when creating tabbedpane as well.
The function CDockablePane::Create() has a parameter called BOOL bHasGripper which is usually set to TRUE while in your case you can set it to FALSE, like below.
class COutputWnd : public CDockablePane {};
COutputWnd m_wndOutput;
if (!m_wndOutput.Create(strOutputWnd, this, CRect(0, 0, 100, 100), FALSE, ID_VIEW_OUTPUTWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{
return FALSE; // failed to create
}

How to make WS_THICKFRAME invisible, but still functional in MFC?

So, I created a dialog that has a style: WS_THICKFRAME.
This WS_THICKFRAME gives the dialog box the functionality to resize the window, but my problems is that I don't won't a border around my window to be visible. How would I make the border invisible, but still have the re-size capability?
An example would be most helpful! Thanks!
Below, are the styles of the template for the dialog box I created:
IDD_GADGETTRANSLUCENTDIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_ABSALIGN | DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | WS_SYSMENU | WS_THICKFRAME
Remove WS_THICKFRAME
Handle WM_NCHITTEST roughly as follows:
UINT CMyClass::OnNcHitTest(CPoint point)
{
CRect rWindow;
GetWindowRect(rWindow);
CRect rInner(rWindow);
rInner.DeflateRect(GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
if (rWindow.PtInRect(point) && !rInner.PtInRect(point))
{
// figure out which of the following codes to return: //
// HTBOTTOM, HTTOP, HTLEFT, HTRIGHT //
// HTBOTTOMLEFT, HTBOTTOMRIGHT, HTTOPLEFT, HTTOPRIGHT //
}
else
{
return CMyBaseClass::OnNcHitTest(point);
}
}

Set a window to be topmost

I am trying to keep my window on top of the all others. I am new to C++ Win32 programming. This is my initialization of my window in WinMain:
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
I previously worked with dialogs, so the topmost property was really easy to use. But here, on a window I don't know how to set it. I also want to be able to trigger it. Can anybody help me?
SetWindowPos(hwnd01, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
Note: SWP_NOMOVE | SWP_NOSIZE are for ignoring 3rd, 4th, 5th, 6th parameters of the SetWindowPos function.
The second parameter can be:
HWND_BOTTOM
HWND_NOTOPMOST (set window to be a normal window)
HWND_TOP
HWND_TOPMOST (set window to be always on top)
Use CreateWindowEx with (extended) window style WS_EX_TOPMOST.
Disclaimer: it's about 15 years or so since I touched that stuff.
see SetWindowPos, hWndInsertAfter parameter. passing HWND_TOPMOST should do what you want.
additionally, you may want to pass SWP_NOMOVE | SWP_NOSIZE to uFlags parameter if you want to keep position and size unchanged.
SWP_NOMOVE Retains the current position (ignores X and Y parameters).
SWP_NOSIZE Retains the current size (ignores the cx and cy parameters).
If you don't set these flags you should specify position and size instead of passing 0, 0, 0, 0

How to correctly create a CMFCListCtrl inside another window?

I'm having problems with the follow code
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
{
return -1;
}
DWORD dwStyle = LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP | WS_CLIPSIBLINGS | WS_CHILD;
CMFCListCtrl TempCtrl;
TempCtrl.Create(dwStyle, CRect(0, 0, 0, 0), this, IDC_FILTERLIST);
CMFCHeaderCtrl& HeaderCtrl = TempCtrl.GetHeaderCtrl();
if (!::IsWindow(HeaderCtrl.GetSafeHwnd()))
{
AfxMessageBox("Failed to create CMFCListCtrl properly!");
}
....
The header control part of the CMFCListCtrl is not getting created/initialized correctly. Does anyone have an idea what I'm doing wrong? Any help would be appreciated.
I noticed that you are creating a control inside a CView-derived class. Please note that the id must start from the value AFX_IDW_PANE_FIRST. Otherwise it will fail. Just google AFX_IDW_PANE_FIRST and you'll find the explanation why.
So, just replace your line with:
TempCtrl.Create(dwStyle, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST);
I solved the above problem by using the WS_VISIBLE style at creation, but I still don't understand why this is so.

WinApi - change Window Style

I want to change my windo style during runtime. I use this code
if (this->fullscreen)
{
this->style = WS_POPUP|WS_VISIBLE;
}
else
{
this->style = WS_OVERLAPPED|WS_SYSMENU|WS_VISIBLE;
}
SetWindowLongPtr(this->mainWindowHandle, GWL_STYLE, this->style);
SetWindowPos(this->mainWindowHandle,
HWND_TOP,
0,
0,
0, //New Width
0, //New Height,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
But it has no effect... and window is still without border (WS_POPUP)...
According to MSDN, you can't modify those particular styles after the window is created. If you're going to try to anyway, it also says that WS_SYSMENU requires WS_CAPTION.
Try calling SetWindowPos with the flag SWP_DRAWFRAME and see if it helps.
You might need to use CWnd::ModifyStyle. Have a look at example here
You might save the current pos and size from the actual window. Then destroy it an create an new window with the new style, previous pos and size.