Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 24th, 2006, 12:06 PM   #1
apcx
Newbie
 
Join Date: Apr 2005
Posts: 6
Rep Power: 0 apcx is on a distinguished road
Question WIN32 GUI application - problem getting dialog box to pop up

Hi all

I have been following a tutorial on creating win32 GUI applications. I'm having a problem getting a dialog box to pop up on top of my main window ...the CreateDialog() method returns a NULL for some reason.

Would really appreciate some help with this.

The source code -- http://www.apcx.3rror.com/main.cpp

(the program runs, but the test condition for CreateDialog()'s return value shows a NULL value is returned)


The resource file:
Quote:
#include "windows.h"
IDD_TOOLBAR DIALOGEX 0, 0, 98, 52
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "My Dialog Toolbar"
FONT 8, "MS Sans Serif"
BEGIN
PUSHBUTTON "&Press This Button",IDC_PRESS,7,7,84,14
PUSHBUTTON "&Or This One",IDC_OTHER,7,31,84,14
END


Window Procedure of the main window...
Quote:
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  
   {
                  
        case WM_CREATE:
        {
            hDialog = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_TOOLBAR),hwnd, ToolDlgProc);
            if(hDialog != NULL)
            {
              ShowWindow(hDialog, SW_SHOW);
            }
            else
            {
                        MessageBox(hwnd, "CreateDialog returned NULL", "Warning!", MB_OK | MB_ICONINFORMATION);
            }
        }
        break;
        //handle other messages...
}
...where the (HWND) hDialog is declared as global variable.


Message Handling function of the dialog box...
Quote:
BOOL CALLBACK ToolDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
        case WM_INITDIALOG:
             return TRUE;
        case WM_COMMAND:
        switch(LOWORD(wParam))
        {
            case IDC_PRESS:
             MessageBox(hwnd, "Hi!", "This is a message", MB_OK | MB_ICONEXCLAMATION);
            break;
            case IDC_OTHER:
                  MessageBox(hwnd, "Bye!", "This is also a message", MB_OK | MB_ICONEXCLAMATION);
            break;
         }
         break;
         default:
            return FALSE;
    }
    return TRUE;
}

Last edited by apcx; Feb 24th, 2006 at 12:30 PM.
apcx is offline   Reply With Quote
Old Feb 24th, 2006, 4:28 PM   #2
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 261
Rep Power: 4 Cache is on a distinguished road
Well for a start: I doubt that 'IDD_TOOLBAR' is defined in 'windows.h'.
Cache is offline   Reply With Quote
Old Feb 24th, 2006, 10:10 PM   #3
apcx
Newbie
 
Join Date: Apr 2005
Posts: 6
Rep Power: 0 apcx is on a distinguished road
I've defined it in main.cpp:

#define IDD_TOOLBAR 9004

Now I've tried defining it in the resource file as well, but CreateDialogBox() still returns a NULL ...
apcx is offline   Reply With Quote
Old Feb 24th, 2006, 11:01 PM   #4
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 261
Rep Power: 4 Cache is on a distinguished road
Place all your resource ID definitions in a single header file, and include that as needed. Also, try cast the parameter 'lpDialogFunc' of 'CreateDialog' to 'DLGPROC' like so:

hDialog = CreateDialog( GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_TOOLBAR), hwnd, reinterpret_cast<DLGPROC>(ToolDlgProc) );
Cache is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:47 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC