I'm have a problem closing my child window, and would greatly appreciate some directions on how to solve my problem.
I use the following code to create the window, which succesfully creates and shows the child window.
hwndComboBoxLang = CreateWindow(WC_COMBOBOX, TEXT(""),
CBS_DROPDOWN | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE ,
xpos, ypos, nwidth, nheight, hwnd, NULL, hThisInstance,
NULL);
And this to destroy the window:
DestroyWindow(DW.hwndComboBoxLang);
The function is being reached, as I have tested it out by succesfully destroying the "child" window when the WS_CHILD parameter is removed, and succesfully used the function on the parent window. I am also unable to succesfully use the ShowWindow(DW.hwndComboBoxLang, SW_HIDE); function on the child window.
I have not registered the child window, as I assume its derived from the registered parent class therefore this is not nessecary, is this assumption wrong? Is the child window created but is the handle pointing towards nothing?
Can you point me in the right direction on how to correctly close a child window?
Thank you in advance,
Related
Hi I am writing a Win32 Windows program. I created a child window with the following command
case ID_VIEW_CARVIEW:
carViewHwnd = CreateWindowEx(WS_EX_TOPMOST, L"Edit", L"Edit",
WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_BORDER,
000, 00, 656, 519, hWnd, (HMENU)NULL, GetModuleHandle(NULL), NULL);
SetWindowLongPtr(carViewHwnd, GWLP_WNDPROC, (LONG_PTR)CarViewWndProc);
However, this child windows has two problems:
It does not have a "close" button on the top right.
It always stay on top of all windows on my desktop top.
How can I change it?
It does not have a "close" button on the top right.
You need set WS_SYSMENU flag for dwStyle parameter to have a window menu on its title bar.
It always stay on top of all windows on my desktop top.
Because you define WS_EX_TOPMOST style: "The window should be placed above all non-topmost windows and should stay above them, even when the window is deactivated."
I am creating a MFC frame based application for instrument monitoring/plotting/interaction, with several child windows hosted in a main frame. These child windows are all created by the main frame using:
MakeCommandsWindow("Child Window",
WS_VISIBLE | WS_CHILD ,
CommandsRect, this, NULL);
which calls this construtor:
BOOL Commands::MakeCommandsWindow(LPCSTR WindowTitle, DWORD dwStyle,
RECT& rect, CWnd* pParent, UINT nID){
CString CommandsWindowClass = AfxRegisterWndClass(
CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW ,
AfxGetApp()->LoadStandardCursor(IDC_ARROW));
CWnd::Create(CommandsWindowClass, WindowTitle, dwStyle,
rect, pParent, nID);
The application works well except in its handling on repaint events. When the application is covered by another window, and uncovered, it does not redraw properly. In addition, it does not maximize or resize properly. My understanding is that MFC automatically sends redraw messages during these events, and that I should not have to intercept these messages. I have implemented some manual redraw() instructions after modal dialogs close to handle some of these issues so far, but I do not know what is the proper way to handle this deeper problem, or what aspect of my application is incorrect.
Thank you, any advice appreciated.
Edit: the Redraw() mentioned:
After a dialog (which covers the centerwindow) closes, I tell the center window to repaint:
PlotSettings Dlg;
Dlg.DoModal();
MonitorWindow->RedrawWindow();
I have main MDI window and have custom CWnd derived window which I create dynamically run-time. I want to keep that window on the screen even when main MDI window is minimized but I dont want to have top-most window. I have tried use WS_EX_CONTROLPARENT | WS_EX_APPWINDOW styles, set parent to NULL and set owner to GetDesktopWindow() but nothing works.
Any ideas how I should do that?
When window is minimized, it takes down with it all of its child and owned windows.
This code creates a regular (not topmost) window which is not hidden when the main frame is minimized:
HWND hWnd = ::CreateWindow(L"button", L"test", WS_CAPTION|WS_VISIBLE,
100, 100, 200, 200, GetDesktopWindow(), 0, 0, 0);
I tried to create a child window using:
CreateWindowEx( NULL, NULL, "MyChild", WS_CHILD | WS_VISIBLE | WS_BORDER, 300, 300, 400, 200, hParentWnd, NULL, NULL );
where the parent HWND hParentWnd has many other child windows already. However, this created a child window hiding behind all the siblings. Windows Spy++ shows that it is on top (first) of the z-order among the child windows of hParentWnd. I have tried all different win32 commands including SetWindowPos(), BringWindowToTop(), SetForegroundWindow(), SetFocus(), SetActiveWindow(), SendMessage(WM_ACTIVATE, 0, 0), etc., but none brings it from behind the siblings. When I replaced WS_CHILD by WS_OVERLAPPEDWINDOW in the CreateWindowEx() command, the created non-child window has no problem showing as the topmost foreground active window. So what must I do to get the child window to the top from behind the siblings?
Thanks a million.
z/0
It is quite explicit in the MSDN article for CreateWindowEx():
If the created window is a child window, its default position is at the bottom of the Z-order. If the created window is a top-level window, its default position is at the top of the Z-order.
You'll need to move it to the top of the Z-order with SetWindowPos().
Environment: Visual Studio 2008, Visual Studio Feature Pack, MFC Dialog App, Windows XP, New Common Controls.
I'm having a problem with a list control that happens to be on a tab control.
To reproduce the problem simply create a dialog based app. Place a tab control on that dialog, then put a list control onto that tab control. You don't need to add any code to the project. Just build and run. Set the focus to the list view and then either minimize the dialog or bring another window in front of it.
Now bring the dialog back to the foreground, the list will not draw itself correctly.
One thing I have tried is handle the set focus event for the list control, but left it with an empty method body, ie...
void CMyListControl::OnSetFocus(CWnd* window)
{
// Default();
}
Then the redraw problem goes away, however now you can not select items within the list. Uncommenting the call to Default makes the problem come back.
If I move the list off of the tab the problem goes away. If I set the focus to another control on the tab or dialog, the problem goes away. This is a weird one.
In fact, if you watch closely you can see the list drawing itself and then being obscured by the tab control.
I know it's late but I had them same problem today. You need to set ListView's parent to Tab control.
hWndTab = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TABCONTROL, NULL,
WS_CHILD | WS_TABSTOP | WS_VISIBLE,
0, 0, 0, 0, hWnd, (HMENU) IDC_TAB, hInstance, NULL);
hWndList = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
WS_CHILD | WS_TABSTOP | WS_VISIBLE | LVS_REPORT,
0, 0, 0, 0, hWndTab, (HMENU) IDC_LIST, hInstance, NULL);
Note parent window handler for hWndList: hWndTab. Or you can use SetParent.