14

Is it usual to use a Dialog as main Windows? So without registering any user class via RegisterClassEx? Can I do everything I do via CreateWindow()? Why should I create controls such as buttons,editboxes etc via CreateWindow() instead of just making a Dialog and use it as main Window?

I'd also like to know main difference between a dialog and a windows and why use one the first instead of the second.

Thanks

Puppy
  • 144,682
  • 38
  • 256
  • 465
user1365914
  • 858
  • 2
  • 18
  • 32
  • You look a little bit confused...these 5 questions may need very long answers. Start to read http://msdn.microsoft.com/en-us/library/windows/desktop/ms632597(v=vs.85).aspx for an overview about windows and the remarks of this http://msdn.microsoft.com/en-us/library/windows/desktop/ms645452(v=vs.85).aspx to understand what a dialog is. – Adriano Repetti Jun 19 '12 at 21:28
  • Short answers (I'm sure someone will provide a more extensive answer): 1) yes, a lot; 2) no you need to register windows you'll use; 3) no (if with everything you mean that you won't need any other code), yes if you mean you do not really need to create a dialog resource; 4) usually you do not have to do it and if it happens _usually_ it's because you do not know the real content of a window at compile time; 5) a dialog (more or less) IS a window, just modal. – Adriano Repetti Jun 19 '12 at 21:34
  • My 2 cents: If you use Visual Basic, Delphi, or .NET you wouldn't need to worry about low level stuff like that and you would be much, much more productive. A window is abstracted to be a rectangular visual container with properties. – Steve Wellens Jun 19 '12 at 21:35
  • @SteveWellens you're right but don't you feel happy if someone starts from the basic to understand these stuffs? Even if he'll write just one application using Windows API only. – Adriano Repetti Jun 19 '12 at 21:37
  • Thanks, I'm not using VB,Delphi or .NET, just C/C++ – user1365914 Jun 19 '12 at 21:44
  • possible duplicate of [Create Window without Registering a WNDCLASS?](http://stackoverflow.com/questions/10232221/create-window-without-registering-a-wndclass) – Hans Passant Jun 19 '12 at 21:45
  • @Adriano - It's too far back to start...it is almost like learning assembly language first. Theoretically maybe but in reality there isn't enough time. – Steve Wellens Jun 20 '12 at 01:11
  • @AdrianoRepetti You say `a dialog (more or less) IS a window, just modal` - nah. A dialog IS a window. Period. They have a window handle, they accept window messages, they have a message queue. They ARE windows. And no, they are not always "modal". You make a modal dialog with `DialogBox` and a modeless dialog with `CreateDialog` (in which case you must implement the message loop). Users should read: https://docs.microsoft.com/en-us/windows/win32/dlgbox/using-dialog-boxes#creating-a-modeless-dialog-box and https://docs.microsoft.com/en-us/windows/win32/winmsg/using-messages-and-message-queues – Mitch McMabers Aug 01 '19 at 02:16
  • Furthermore: Dialogs are GREAT as main window. They have very good layout/design tools in Visual Studio. And in Windows 10, if your app has PerMonitorV2 dpi scaling mode, the dialog AUTOMATICALLY supports high-DPI and live, dynamic rescaling whenever DPI or the active display changes. It's awesome. People should definitely use (modeless) dialogs, with their own message pump. It's powerful, and the modern Windows 10 OS takes care of all the high-DPI support work for you. As for older OS, I just mark the app as DPI-aware and let it be unscaled on those since old computers mostly 96 DPI screens! – Mitch McMabers Aug 01 '19 at 02:19
  • @MitchMcMabers strictly speaking everything is a _window_ in Windows then it should be obviously read as a _different type of window_. In that sense a dialogbox is REALLY different from (let's say) the standard main window. Obviously if you're using some high level framework you won't probably notice any difference but in the other cases you will. Dialog as the only app window? Why not, for some kind of applications it's a perfectly fine choice! – Adriano Repetti Aug 01 '19 at 08:27
  • @AdrianoRepetti Well I'm writing in unmanaged C++ with pure Win32 API. And any Windows API function which takes a HWND (window handle) will take a HWND from a dialog as well. The only difference is: 1) Dialogs use "points" instead of pixels, which makes them high-DPI scaled automatically. Especially great in `PerMonitorV2` mode on Windows 10 (it gets LIVE re-scaling too). 2) Dialogs pump messages via `IsDialogMessage`, which triggers your message callback. See MSDN for how to have both in the msg loop. 3) Its default handler uses IDCANCEL to close but is fixable by catching WM_CLOSE yourself! – Mitch McMabers Aug 01 '19 at 20:31
  • Plus a bunch of different messages, keyboard handling, defaults and logic. More than enough to be _"more or less"_. IMHO – Adriano Repetti Aug 01 '19 at 22:02

3 Answers3

7

Is it usual to use a Dialog as main Windows?

Yes, it is quite common.

So without registering any user class via RegisterClassEx?

A dialog is usually a predefined window class, so there usually no need for registering.

I'd also like to know main difference between a dialog and a windows and why use one the first instead of the second.

Well, two big differences would be that you cannot resize a dialog box and it has no minimize or maximize buttons (by default, but there are workarounds for this). Keep in mind the name, dialog box. In other words they are used for having a dialog with the user (receive input and displays messages to user). In a sense they are just like any other window, underneath CreateWindowxx, etc. is called, etc. However, they are somewhat predefined windows which can be made quickly and there are limitations to what you can do with them.

Also, a dialog uses a dialog procedure rather than a window procedure, which does some default processing for you, such as initializing some controls, etc.

Jesse Good
  • 50,901
  • 14
  • 124
  • 166
  • The wizard automatically generates the code to minimize a dialog box, and it's not hard to add resizing and maximize - see http://stackoverflow.com/a/5739620/5987 – Mark Ransom Jun 19 '12 at 22:12
  • @MarkRansom: That's true. I was thinking more about the "default settings", but there probably are workarounds for almost anything since dialogs are "just windows". – Jesse Good Jun 19 '12 at 22:39
2

Yes, an application can be dialog-based. There's even a Wizard for that if your'e using VisualStudio and MFC.

In VS2010, Create New Project > MFC Application. In "Application Type" select Dialog Based. Click through the rest of the Wizard, and you're off to the races.

Dialog-based applications are much simpler, architectually, than other designs such as Document/View. As such, simple things are much easier to "bang out" quickly, but the limitations of the design become apparent when you try to do more complex things. You could end up replicating much of the Doc/View architecture in your dialog-based app in order to build a production-quality Dialog-based application. In that case, did you really save yourself anything?

John Dibling
  • 99,718
  • 31
  • 186
  • 324
2

A dialog is a kind of window just as all of the various controls like buttons are really just windows. You can think of a dialog as being a kind of window with a lot of extra functionality to support the kinds of things that dialogs are used for.

There are two types of dialogs, modal which display and expect you to use them and then dismiss them, and non-modal which display but which do not capture and keep the input focus until they are dismissed. You can see these two types used in applications where a modal dialog is used to display an error or require the user to make some setting and a non-modal acts as a kind of tool box that stays displayed and when you need it, you click on it to do something and other times you are using some other window in the application.

Normally a dialog would not have a menu bar but would instead have all of its controls visible or easily accessible via tabs or some other type of presentation. Visual Studio and other IDEs have dialog designers to allow the placement of various controls along with wizards to allow the controls to be tied to classes and class members.

Which brings up a major difference between a dialog and a window. A window is kind of an empty page and to do things with the page requires more work. A dialog has tools that make the design easy however you are also constrained in large part by the toolbox.

If you have an application that is focused on basically allowing a user to specify certain settings and then do some task, a dialog works fairly well. If you have something that requires more complicated user interaction, an application window as the base from which all of your other dialogs and controls will be managed and manipulated will be more necessary.

Richard Chambers
  • 16,643
  • 4
  • 81
  • 106