Thread: Dialog box not displaying

  1. #1
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115

    Dialog box not displaying

    Help.
    I have been looking at this code far too long. Would someone be able to tell me why this damn dialog box won't display. I get an invalid handle error and I can't see why. I typed this program in from Petzold's book and made sure the code is the same but my dialog box won't open..... very frustating. Any help is appreciated.
    all the code should be in the zip file.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    When you are creating the winclass you are setting the menu to the app name. It should be a resource ID like

    MAKEINTRESOURCE(ID_MYMENU);

    otherwise use GetLastError()
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    well from what petzold says.. you can use a string instead of a number

    The first argument to LoadIcon is the instance handle that indicates what file the resource comes from. Using hInstance means it comes from the program's own .EXE file. The second argument to LoadIcon is actually defined as a pointer to a character string. As we'll see shortly, you can identify resources by character strings instead of numeric identifiers. The macro MAKEINTRESOURCE ("make an integer into a resource string") makes a pointer out of the number like so:


    #define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))

    The LoadIcon function knows that if the high word of the second argument is 0, then the low word is a numeric identifier for the icon. The icon identifier must be a 16-bit value.

    Sample programs presented earlier in this book use predefined icons:


    LoadIcon (NULL, IDI_APPLICATION) ;

    Windows knows that this is a predefined icon because the hInstance parameter is set to NULL. And IDI_APPLICATION happens also to be defined in WINUSER.H in terms of MAKEINTRESOURCE:


    #define IDI_APPLICATION MAKEINTRESOURCE(32512)

    The second argument to LoadIcon raises an intriguing question: can the icon identifier be a character string? Yes, and here's how: In the Developer Studio list of files for the ICONDEMO project, select IDONDEMO.RC. You'll see a tree structure beginning at the top with IconDemo Resources, then the resource type Icon, and then the icon IDI_ICON. If you right-click the icon identifier and select Properties from the menu, you can change the ID. In fact, you can change it to a string by enclosing a name in quotation marks. This is the method I prefer for specifying the names of resources and that I will use in general for the rest of this book.

    I prefer using text names for icons (and some other resources) because the name can be the name of the program. For example, suppose the program is named MYPROG. If you use the Icon Properties dialog box to specify the ID of the icon as "MyProg" (with quotation marks).
    and for menus
    Most Windows applications have only one menu in the resource script. You can give the menu a text name that is the same as the name of the program. Programmers often use the name of the program as the name of the menu so that the same character string can be used for the window class, the name of the program's icon, and the name of the menu. The program then makes reference to this menu in the definition of the window class:
    besides the menu isnt causing me the issues.

    I used GetLastError and got invalid handle. The problem is in the AboutDlgProc() itself. When I hit the DialogBox() macro, I traced what was going on and the message sent to my AboutDlgProc()isn't WM_INITDIALOG. I don't know what message is being sent. All I know it that there in no case in my code to hadle it and it is giving me and error when it returns.

    thanks anyways.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    If you tell the compiler to use a menu that you have not created, coded or included, what will happen?


    Sorry though I misunderstood your problem.

    There is something wrong with your About dlg. You seem to have named it incorrectly and it will not work. Why? I don't know and don't have time to fix. This will get you past the problem.

    Add another dialog, use the default name IDD_DIALOG1 (not "IDD_DIALOG" ie not a string as it will be defined by the resource editor as an int)

    Use MAKEINTRESOURCE(IDD_DIALOG1) instead of teh text string and all will work correctly.
    Last edited by novacain; 05-01-2003 at 08:37 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    I will try that. I guess what is bugging me is that the program from the book works and mine doesn't and the code is almost identical. Thanks for the help though. I will get it to work yet if it kills me(and it just might). I hate it when a program has a bug in it I can't figure out
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> the program from the book works and mine doesn't

    ... hmmmm...

    >>> and the code is almost identical.

    ... hmmmm... almost.

    If you run the original, exactly as it is in the book, does it work? I don't have the original program, so can only see yours.

    When I run this, the menu invokes the correct option in the switch, so the menu is okay.

    You are not casting the last parameter in the DialogBox() call to (DLGPROC), that is probably why DialogBox() is complaining.

    Changing that, and tracing the program into the dialog box, (which is starting), the messages that arrive are not catered for in your dialog boxes switch, so fall through and returns FALSE.

    I don't have more time now.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    here is the actual code from the book if anyone wants to look at it.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  8. #8
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    Something stange is going here. I just inserted my .cpp file into petzold's project and removed his file from it(I created a new project using only his code to see if it actually worked). Changed the WM_COMMAND file message in my WndProc() so it was the same as his menu ID and changed the dialog name in my code to the one he is using and my code works!! What the hell is going on. I though maybe my code had a typo in the dialog name when I created my project but that isnt the case. My project just doesn't want to give me a vailid handle. I tried creating a whole new project but that still didn't work. Grrrrrrrr
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  9. #9
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    Victory!!!!!
    I figured out what was going on. Basically when I was creating the dialog box, I added a custom control and in the class name I entered in the right name but had it between quotation marks which it shouldn't have been. Now when DialogBox() tried to create the dialog based on my template, it tried to access this control but the handle was invalid because the wndclass I registered was named EllipPush and I had the custom control button using a class named "EllipPush".

    Stupid Stupid Stupid
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  2. Parent of a BrowseForFolder dialog box
    By @nthony in forum Windows Programming
    Replies: 4
    Last Post: 01-08-2007, 02:54 PM
  3. Display Dialog Box Then Execute
    By stickman in forum C++ Programming
    Replies: 17
    Last Post: 05-10-2006, 11:02 AM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM