0

on this website, under the "Edit Control" title, there are a couple of lines of code like this..

case WM_CREATE:
    hwndEdit = CreateWindow(TEXT("Edit"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,
                50, 50, 150, 20, hwnd, (HMENU) ID_EDIT,
                NULL, NULL);

    hwndButton = CreateWindow(
        TEXT("button"), TEXT("Set Title"),       
        WS_VISIBLE | WS_CHILD,  
        50, 100, 80, 25,        
        hwnd, (HMENU) ID_BUTTON, NULL, NULL);      

    break;

I know that this method of creating buttons and such are done on the fly, But I was wondering how you would do it without doing it like this, instead using a resource file?. In the Forgers Win32 tutorial it shows how to make a menu using a resource file, and how to describe a dialog box etc, But I cant seem to put any controls on the main(parent) window using a resource file??.

for example I have the following .rc file

#include "resource.h"
ID_MENU MENU
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "E&xit", ID_FILE_EXIT
    END
    POPUP "&About"
    BEGIN
        MENUITEM "&Information", ID_ABOUT_INFO
    END
END

ID_ABOUT_INFO DIALOG DISCARDABLE  0,0,250,250 
CAPTION "Information"
BEGIN
    CTEXT "some text",ID_BLA,15,15,144,33
END

//this is all fine but how do I decribe the main window?, instead of the menu and dialog boxes?.

How do I describe the main window instead of creating things on the fly?. Is there some kind of keyword?

silent
  • 2,836
  • 10
  • 47
  • 73

5 Answers5

3

You can create a dialog as your main window.

  1. If you are using MFC in Visual Studio, use the project wizard to create a Dialog-Based app.

    (File -> New Project -> Visual C++ / MFC -> MFC Application -> OK -> Application Type -> Dialog based.)

    The generated application will then create your main dialog for you, and exit when it closes.

    A simple example of such a beast, including source, is here:

    http://www.pretentiousname.com/ICFRanger/index.html

  2. If you are using straight Win32, you'd create the dialog using CreateDialogParam (or similar) and then show it like any other window, and run a message loop. (Or you could use DoModal, which runs its own message loop, but beware that modal dialogs need to behave slightly differently, especially when it comes to closing.)

    A simple example of that, including source, is here:

    http://www.pretentiousname.com/setpoint_aon/index.html

(Those are both programs I wrote, but very simple ones, so there's not much to get in the way of understanding what they do.)

Leo Davidson
  • 6,093
  • 1
  • 27
  • 29
  • File -> New Project -> Visual C++ / MFC -> MFC Application -> OK -> Application Type -> Dialog based. – Leo Davidson Nov 30 '10 at 10:20
  • Right, so this is if sil3nt uses Microsoft Visual Studio. Are you sure he is? Because I cannot find anything from him which implies that he does. – default Nov 30 '10 at 10:22
  • 1
    Can you use MFC with anything else these days? I figured the "If you are using MFC" part qualified the first suggestion well enough, and the second suggestion applied if he wasn't using MFC. Edited to mention VS explicitly anyway, just in case. – Leo Davidson Nov 30 '10 at 10:23
  • you may be right. I thought of MFC and Visual Studio as well, but I do not know if sil3nt uses it. @sil3nt, can you enlighten me/us? Since I got stuck on that, I didn't read part two which deserves an upvote. :) I guess resource files cannot include windows except for dialogs. – default Nov 30 '10 at 10:34
  • @Leo Davidson, That was very helpful thank you. Quick question, my push buttons and the overall style of the window looks really win98ish, I only saw the difference when I ran your program. Does this have anything to do with the styles?. (eg, instead of this http://confluence.atlassian.com/download/attachments/92504215/Windows_XP_System_Properties.png?version=1&modificationDate=1199944722762 , it kind of looks like this – silent Nov 30 '10 at 10:43
  • http://developer.vrjuggler.org/docs/vrjuggler/2.0/getting.started.guide/figures/Window.SystemProperties.winxp.png but worse lol. sorry bad place to post such a question. And its not the difference in the theme – silent Nov 30 '10 at 10:43
  • @Default, Nah I'm staying clear of Visual Studio right now, but it looks like you cant use resource files for windows?. The example Leo showed was much less code and simpler, Lol I don't see the point in WINDCLASSEX now really? (might of said that a bit too early, will revise once I understand more of this :) – silent Nov 30 '10 at 10:53
  • @sil3nt: For your style issue, if your window border looks normal but the controls are Win95 style, then you need to enable visual styles in your app. Several ways to do it (the manifest method is common): http://msdn.microsoft.com/en-us/library/bb773175%28VS.85%29.aspx -- On the other hand, if your window borders are also Win95 style, see here: http://stackoverflow.com/questions/4285201/how-to-change-the-border-style-of-applications-main-window-in-visual-c-win32-ap/4286101#4286101 – Leo Davidson Nov 30 '10 at 11:02
2

TheForger has added all his example code in a zip file, you can download them and check it out.

You still need to create the window, TheForger does this as well, but then he includes the icons and menus in the WNDCLASSEX struct which is passed to the window that is to be created. This is then collected from the resource file (.rc file) via the resouce.h file.

MSDN has a section about resource files as well, and as you can see

Resources can be composed of a wide range of elements, including interface elements that provide information to the user (for example a bitmap, icon, or cursor); custom resources that contain data an application needs; version resources that are used by setup APIs; and menu and dialog box resources.

The main window(s) are not mentioned.

default
  • 11,485
  • 9
  • 66
  • 102
2

At the API-level, consider functions like CreateDialog.

It's not more complicated than that.

Although a dialog as main window has some problems, especially in MFC (which treats it specially).

Cheers & hth.,

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • +1, Although this will limit it to a Dialog. Aren't they handled differently than windows created by `CreateWindow[Ex]`? – default Nov 30 '10 at 10:20
  • 1
    @Default: if you're going to do this at the API level, then get hold of a copy of Petzold's "Programming Windows". Re different handling that depends what you mean. At the API level dialogs are simply a kind of window (class) that *you* could have implemented, and you can override whatever you want of the default functionality. – Cheers and hth. - Alf Nov 30 '10 at 12:29
  • cool. thanks for the tip. What is the latest edition? (books.google.com gave me something from 1999) – default Nov 30 '10 at 12:39
  • The difference I thought of was, I thought they needed the GetMessage() loop to be written in a special way (that includes [isdialogmessage](http://msdn.microsoft.com/en-us/library/ms645498.aspx "IsDialogMessage function")) – default Nov 30 '10 at 12:41
1

You can design a window like it was a dialog and put it in your resourcefile .Then use the FindResource and LoadResource functions to get a pointer to a DLGTEMPLATE ,which contains all the dialogs layout which you can use to size you own window and place controls at the positions you defined in the dialog (It's not easy though to interpret the DLGTEMPLATE). Don't forget to free the pointer to the DLGTEMPLATE.

engf-010
  • 3,980
  • 1
  • 14
  • 25
1

Use CreateWindow and the various predefined classes. If you were to create a button you would use the class "BUTTON" set the style WS_CHILD|WS_VISIBLE and set the window procedure to NULL.

Jay Estux
  • 21
  • 1