Dialog Boxes

This is a discussion on Dialog Boxes within the Windows Programming forums, part of the Platform Specific Boards category; I'm fairly new to Win Programming. For the DialogBox function ( http://msdn2.microsoft.com/en-us/library/ms645452.aspx ) what is the 2nd parameter, exactly? I ...

  1. #1
    Me
    Join Date
    Jul 2006
    Posts
    71

    Dialog Boxes

    I'm fairly new to Win Programming.

    For the DialogBox function (http://msdn2.microsoft.com/en-us/library/ms645452.aspx) what is the 2nd parameter, exactly? I see that it says you can use 'MAKEINTRESOURCE'. So does that mean the template is a image?

    Thanks,

    Relyt_123

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    You use that macro if you have an ID number for the Dialog Box. You could designate this ID number in the resource file of your program.

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    The template for your dialog box is usually a DIALOGEX resource, defined in your resource file. All dialog resources must have a nameID which can either be a string or 16-bit unsigned integer number. Since the latter is commonly the case when naming resources, you will usually need to use the MAKEINTRESOURCE macro which creates the necessary identifier from your integer resource id to supply to the DialogBox function. I.E. if you defined a DialogEx resource as such:
    Code:
    #define IDD_MYDIALOGBOX 24
    ...
    ...
    IDD_MYDIALOGBOX DIALOGEX DISCARDABLE 0, 0, 0, 0
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "MyDialog"
    {
    }
    Then you would call DialogBox as so:
    Code:
    DialogBox(hInst, MAKEINTRESOURCE(IDD_MYDIALOGBOX), hwnd, myDialogProc);

  4. #4
    Me
    Join Date
    Jul 2006
    Posts
    71
    This doesn't work. I put it in the .rc file and it wouldn't compile. Said the error was 'Syntax Error'.

    When I transferred the code into the .cpp it had two errors:

    error: expected unqualified-id before numeric constant

    error: expected ',' or ';' before numeric constant

    They were both on the line "IDD_MYDIALOGBOX DIALOGEX DISCARDABLE 0, 0, 0, 0"

    Any suggestions?

  5. #5
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    where is the resource.h?
    Typically you use a resource.h to declare the constants used in resource.rc
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  6. #6
    Me
    Join Date
    Jul 2006
    Posts
    71
    I have three files:

    -main.cpp:
    Code:
    #include <windows.h>
    ...
    ...
    -resource.h:
    Code:
    #define ID_FILE_EXIT 9001
    #define ID_HELP_ABOUT 9002
    #define IDD_MYDIALOGBOX 9003
    -resources.rc:
    Code:
    #include "resource.h"
    IDD_MYDIALOGBOX DIALOGEX DISCARDABLE 0, 0, 0, 0
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "MyDialog"
    {
    }
    Edit: Turns out it's a problem with the line, "STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU"

    Doesn't say what it is though. It just says it's a "Syntax Error". No specifics. If I comment out that line, the program will compile and run and the dialogbox will be created but it is just a small rectangle box.
    Last edited by relyt_123; 06-23-2007 at 09:01 PM.

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Are you including Windows.h?

  8. #8
    Me
    Join Date
    Jul 2006
    Posts
    71
    I am into 'main.cpp'.

    Edit: Should I include "resources.rc" into main.cpp?
    Last edited by relyt_123; 06-23-2007 at 09:07 PM.

  9. #9
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    No that's totally wrong, and silly.

    Include Windows.h from inside resources.rc.

  10. #10
    Me
    Join Date
    Jul 2006
    Posts
    71
    Like that, it compiles, but the dialog box is still strange in size. It is merely a small box ~10px wide and the heigh of the title bar of the window.

  11. #11
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    How about not giving it a width and height of 0? lol....

  12. #12
    Me
    Join Date
    Jul 2006
    Posts
    71
    No one ever told me what those arguments were... I would have looked them up if I had known that was the issue.

    Thanks for the help.

  13. #13
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Isn't that the point? If you know the solution for every problem you have, then what's the reason for debugging? This is why being a good programmer requires more than simply just being able to write code that compiles.

    OK, ok.... I'll stop lecturing.

  14. #14
    Me
    Join Date
    Jul 2006
    Posts
    71
    I realize that. It's just that I had no way to debug it if I didn't know the arguments in the first place, eh?

  15. #15
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Quote Originally Posted by relyt_123 View Post
    No one ever told me what those arguments were... I would have looked them up if I had known that was the issue.

    Thanks for the help.
    Did you not see my BIG GLARING RED CAPSLOCK TEXT LINK to the DialogBoxEX resource in my previous post that I selflessly found and provided for you EVEN though it is more than readily available via MSDN search? Didn't you think a link to the MSDN DIALOGEX resource might just have something to do with.. oh, i dunno, a DialogBox resource??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Common Dialog boxes GetOpenFileName()
    By A10 in forum Windows Programming
    Replies: 3
    Last Post: 09-02-2008, 09:56 PM
  2. Dialog Boxes
    By Thantos in forum Windows Programming
    Replies: 7
    Last Post: 08-26-2003, 01:49 PM
  3. Dialog Boxes and Sliders
    By AtomRiot in forum Windows Programming
    Replies: 4
    Last Post: 01-29-2003, 08:36 AM
  4. Dialog Boxes
    By cerion in forum Windows Programming
    Replies: 4
    Last Post: 06-10-2002, 07:54 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21