How do I display a CFormView in a mainframe? - c++

I created an SDI MFC app without the doc/view support. The MFC template gives me an app with a blank window (And a menu, etc)
I want to show my CFormView object on that main window. (Based on a dlg made in the gui editor)
How do I do that? CreateWindow and showwindow don't seem to be all that is needed. All the web pages I find seem to talk about MDI and other stuff that is not in my app.
This view is never going to change. It will have one list box control on it and that is all. How do I get a new form view to appear?
Additionally, how do I get a floating window with one control on it to appear as well? (DLG boxes and DoModal() will not work for me here.)

Give your CFormView the WS_CHILD style
Create it as a MODELESS dialog with the app window as the parent window
resize it to fit the parent's client area, or resize the parent to fit it.
The WS_CHILD style is not a default style for a dialog template, but you can add it.
this will cause the dialog to show up inside the client area of the main frame window you when create it.
You may also want to add a call to IsDialogMessage() to your message pump. This is needed get the TAB key to behave the way you expect it do in a dialog.
Edit ----
I'm not an MFC programmer, so I can only guess how you would go about this in MFC.
Presumably you still have dialog templates, so you would go into your .RC file
and remove the WS_POPUP and add the WS_CHILD style to your template declaration. like this:
IDD_WHATEVER DIALOG DISCARDABLE 0, 0, 275, 217
STYLE DS_MODALFRAME | DS_3DLOOK | WS_CHILD | WS_VISIBLE
CAPTION "General"
FONT 8, "MS Sans Serif"
BEGIN
// etc
END
Modeless dialogs are created in Win32 by using CreateDialog rather than DialogBox, in
MFC by using Create() rather than DoModal().

Related

Win32: Is it possible to show the window but to hide it from taskbar?

If I have an win32 application with several windows, is it possible to show a window but hide the window icon in the taskbar?
I have tried creating the window with WS_EX_TOOLWINDOW and WS_EX_APPWINDOW.
You have a few options:
Tool windows do not have taskbar buttons. Create a tool window by including the WS_EX_TOOLWINDOW extended window style.
Owned windows without the WS_EX_APPWINDOW extended style do not have taskbar buttons.
Hidden windows do not have taskbar buttons.
Option 1 is simple enough. If you don't want to use a tool window, use a combination of 2 and 3. Create a hidden unowned window that is the owner of your main window.

Constraining draggable child windows within parent window?

Please take a look at this screenshot:
As you can see, the "Executable modules" and "Threads" child windows are free to roam about in the sandbox-like "Themida" parent window, and if they get dragged past the edge the overflow simply gets hidden. How can I create this effect?
That is a Multiple Document Interface (MDI) application. The containing window, with the dark grey background is the MDI client window, and the windows inside are the MDI child windows.
The use of MDI has been discouraged by Microsoft for many years so you may wish to think twice about using it in a new application.
Simply set the window style to WS_CHILD, and the window will be confined in the parent client rectangle.
You can do this during window creation, or after using SetWindowLongPtr() and GetWindowLongPtr():
SetWindowLongPtr(hwnd, GWL_STYLE, WS_CHILD | GetWindowLongPtr(hwnd, GWL_STYLE));
P.S. You don't need to create an MDI application to have this behavior.

Is there a way to make an editbox in an overlaped childwindow editable?

The last two days I worked on my little GUI. I'm new in the C++ and WINAPI world and want to learn some basic things about the WINAPI.
Currently I created a childWindow with the WS_OVERLAPPEDWINDOW and WS_CHILD style in my parent Window and added a button and an editbox. I subclassed the CALLBACK function for my buttons and editbox so that they have an own callback function. The Buttons works currently fine but the editbox not. I can't click inside the editbox and edit the text.
This is the way I created my Windows:
Create a normal parent/main Window
Create a childwindow with WS_CHILD and WS_OVERLAPPEDWINDOW style
Add an editbox and a button with WS_CHILD style to the childwindow
Here a screenshot:
If I remove the WS_OVERLAPPEDWINDOW or the WS_CHILD style from the childwindow the editbox works. But then the childwindow has no "windowborder" or is not inside the parentwindow anymore.
After searching in the internet I found out that MDI Windows could solve this problem.
Now my final question is if it's absolutely not possible to create an childwindow with the WS_OVERLAPPEDWINDOW style and add there editboxes and other control elements? Is the MDI Window the only way or are there maybe some styles/settings I could use to get the editbox working?

Hide main MFC window while modal dialog is active?

I have a native C++ MFC app. It has a main window based on CWnd, and user action can create a modal dialog. While the dialog is active, I want the main window to disappear, the dialog to be visible, and the main window's icon to remain in the task bar.
How can I accomplish this?
If I hide the main window (ShowWindow(SW_HIDE)), the task bar icon disappears. If I minimize the main window (SW_MINIMIZE), the icon remains. However, since the dialog is owned by the main window, this also hides the dialog.
After the dialog is created, clicking on the task bar icon makes the dialog visible. Naturally, I do not want to require the user to do this.
Even if I insert ShowWindow(SW_SHOW) in the dialog's OnInit handler, the dialog remains not visible. Spy++ shows that its visible bit is set, though. Same is true if I add SetWindowActive to OnInit.
I am not interested in changing the UI design. While the dialog is active, the user interacts only with it, and is not interested in anything in the main window. Therefore, the main window should disappear.
Using Windows VS2005 under WinXP32.
Well, in the block of code where you create the dialog and show it modal, you can do whatever you want to the main window of your app (show/hide) as long as you make the desktop window the parent of your dialog. Usually, the constructor for CDialog and derivatives takes a default argument of NULL for the parent window in which the framework ends up substituting AfxGetMainWnd(). Instead pass CWnd::GetDesktopWindow() as the parent of your dialog and then you should probably be able to hide your main window. However, you still might have a problem with the taskbar--but I'll let someone else give hints since I know nothing offhand about it.
In OnInitDialog, add following codes
//Set windows size zero, the windows disappear.
MoveWindow(0,0,0,0);
//If you want it invisible on taskbar. add following codes.
DWORD dwStyle = GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);
dwStyle &=~WS_EX_APPWINDOW;
dwStyle |= WS_EX_TOOLWINDOW;
SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, dwStyle);
You're fighting the OS. A modal dialog, by definition, disables but does not hide the "main" (parent) window. If you wanted another window, make a second one, but don't tell the OS to treat it as a modal dialog over the first window.
Perhaps you can resize the main window to a really small size and always keep it behind the modal dialog.

How do you have a window that has no icon in the tasktray?

I found the windows style WS_EX_TOOLWINDOW but this changes the title bar. Is there a way to not have the tasktray icon but keep the normal window titlebar?
You usually do want to do this if you have added an alternate means to restore the window - for example placing an icon in the notification tray.
The usual way of ensuring the taskbar does not display your window is to create it with a hidden parent window. Whenever a window has a parent, the parent window is used to create the button - hidden windows are not shown on the taskbar.
Also, WS_EX_APPWINDOW should be removed as that performs the opposite hint to the shell and forces the window onto the taskbar even if it would otherwise not have been shown.