Please support our C++ advertiser: Programming Forums
![]() |
•
•
Join Date: Sep 2004
Location: Durban, South Africa
Posts: 55
Reputation:
Rep Power: 5
Solved Threads: 0
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. Here is a zip file containing the main CPP and as well as the resource file.
http://www.apcx.3rror.com/test.zip
(the program runs, but the test condition for CreateDialog()'s return value shows a NULL value is returned)
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. Here is a zip file containing the main CPP and as well as the resource file.
http://www.apcx.3rror.com/test.zip
(the program runs, but the test condition for CreateDialog()'s return value shows a NULL value is returned)
•
•
Join Date: Sep 2004
Location: Durban, South Africa
Posts: 55
Reputation:
Rep Power: 5
Solved Threads: 0
http://www.apcx.3rror.com/main.cpp
The resource file:
Window Procedure of the main window...
...where the (HWND) hDialog is declared as global variable.
Message Handling function of the dialog box...
The resource file:
•
•
•
•
#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...
•
•
•
•
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...
•
•
•
•
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; }
•
•
Join Date: Jun 2005
Location: Tokyo, Japan
Posts: 1,481
Reputation:
Rep Power: 8
Solved Threads: 102
Try putting all the definitions,
to a
What is the compiler you are using. Is it a IDE or command line compiler?
#include <windows.h> #define ID_FILE_EXIT 9001 #define ID_STUFF_GO 9002 #define ID_STUFF_ABOUT 9003 #define IDD_TOOLBAR 9004 #define IDC_PRESS 9005 #define IDC_OTHER 9006 #define ID_DIALOG_SHOW 9007 #define ID_DIALOG_HIDE 9008 #define ID_HELP_ABOUT 9009 #define IDD_ABOUT 9010
resource.h file and including the resource.h file to both your .rc file and main.cpp file. I dont know if the compiler allows the present rc file name. It hasn't got a file name. Only an extention. Correct that also.What is the compiler you are using. Is it a IDE or command line compiler?
•
•
Join Date: Sep 2004
Location: Durban, South Africa
Posts: 55
Reputation:
Rep Power: 5
Solved Threads: 0
•
•
Join Date: Jun 2005
Location: Tokyo, Japan
Posts: 1,481
Reputation:
Rep Power: 8
Solved Threads: 102
There was nothing wrong with your rc file. I am using the Visual Studio IDE, and here is what I did to make the project compile.
1. Rename
2. Create a new file
3. Put the of your
4. Added to your
5. Added the above 3 files to a Visual Studio Solution and built it..
After that the program ran okay. I dont know the procedure for dev-Cpp. But I think you will have to do the above 4 steps for any compiler. Try it and tell the result. Only the way you compile; step 5, will change for Dev-Cpp. Here are the modified files.
1. Rename
.rc to main.rc2. Create a new file
resource.h3. Put the
#include <windows.h> #define ID_FILE_EXIT 9001 #define ID_STUFF_GO 9002 #define ID_STUFF_ABOUT 9003 #define IDD_TOOLBAR 9004 #define IDC_PRESS 9005 #define IDC_OTHER 9006 #define ID_DIALOG_SHOW 9007 #define ID_DIALOG_HIDE 9008 #define ID_HELP_ABOUT 9009 #define IDD_ABOUT 9010
main.cpp file to the resource.h file.4. Added
#include "resource.h"
main.cpp file and main.rc file.5. Added the above 3 files to a Visual Studio Solution and built it..
After that the program ran okay. I dont know the procedure for dev-Cpp. But I think you will have to do the above 4 steps for any compiler. Try it and tell the result. Only the way you compile; step 5, will change for Dev-Cpp. Here are the modified files.
Last edited by WolfPack : Feb 25th, 2006 at 4:20 am. Reason: Added new files
•
•
Join Date: Sep 2004
Location: Durban, South Africa
Posts: 55
Reputation:
Rep Power: 5
Solved Threads: 0
ah ... it runs fine in Dev-cpp. Thank you SO much, Wolfpack.
Just one more question. I'm creating this program to do some bitmap displaying/manipulation ... so I'd like to have another window (a blank one with no windows style/border and NO menu) pop up over this window.
So right after this bit of code ...
... I tried the following:
1.
wincl.lpfnWndProc = ImageWindowProc();
registered wincl
created a new HWND imageHwnd using CreateWindowEx()
then used the ShowWindow method to display this new window as well.
2.
created a new WNDCLASSEX -- wincl2.
After the creation of the main window:
initialized wincl2
registered wincl2
created a new HWND imageHwnd using CreateWindowEx()
used ShowWindow method to display this new window as well.
The problem is that in both of the above cases, the new window (whether it is the child is created as the child window of the main window or not) ... appears with the same menu that was added to the main window. The new window appears to share the main window's WindowProcedure method, even though I have tried to set it otherwise.
(My ImageWindowProc does NOT yet respond to any messages, e.g. display menu, dialogbox etc.)
Just one more question. I'm creating this program to do some bitmap displaying/manipulation ... so I'd like to have another window (a blank one with no windows style/border and NO menu) pop up over this window.
So right after this bit of code ...
•
•
•
•
WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ "Windows App", /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 544, /* The programs width */ 375, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ );
... I tried the following:
1.
wincl.lpfnWndProc = ImageWindowProc();
registered wincl
created a new HWND imageHwnd using CreateWindowEx()
then used the ShowWindow method to display this new window as well.
2.
created a new WNDCLASSEX -- wincl2.
After the creation of the main window:
initialized wincl2
registered wincl2
created a new HWND imageHwnd using CreateWindowEx()
used ShowWindow method to display this new window as well.
The problem is that in both of the above cases, the new window (whether it is the child is created as the child window of the main window or not) ... appears with the same menu that was added to the main window. The new window appears to share the main window's WindowProcedure method, even though I have tried to set it otherwise.
(My ImageWindowProc does NOT yet respond to any messages, e.g. display menu, dialogbox etc.)
•
•
Join Date: Jun 2005
Location: Tokyo, Japan
Posts: 1,481
Reputation:
Rep Power: 8
Solved Threads: 102
•
•
Join Date: Sep 2004
Location: Durban, South Africa
Posts: 55
Reputation:
Rep Power: 5
Solved Threads: 0
Hey guys... thanks for the replies
Yesterday, I used the main.cpp that Wolfpack included in GUI.zip ... everything worked fine, and the dialog box popped up.
Today I had to reinstall dev-cpp ... I tried compiling and running the same main.cpp but the dialogbox won't show up (a NULL value is returned again).
Everything is the same, except that I had to create a new resource file, with the same information, but this resource file did compile successfully.
I used GetLastError() ... it printed the value 1813.
Yesterday, I used the main.cpp that Wolfpack included in GUI.zip ... everything worked fine, and the dialog box popped up.
Today I had to reinstall dev-cpp ... I tried compiling and running the same main.cpp but the dialogbox won't show up (a NULL value is returned again).
Everything is the same, except that I had to create a new resource file, with the same information, but this resource file did compile successfully.
I used GetLastError() ... it printed the value 1813.
![]() |
Other Threads in the C++ Forum
- Previous Thread: get a random word
- Next Thread: First time posting...syntax error...
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode