🔒 Locked
Dialog Boxes
Advertisement
Original Post
Hi I am creating a terrain editor using visual studio, c++, Windows, and DirectX. To do this I require dialog boxes containing text boxes, buttons, and slider controls. I have tried using MFC (Visual Studio, project, add resource, dialog box) to do this. However this requires MFC with the includes and defines: #define _AFXDLL #include #include "Resource.h" I get the error "Windows.h already included" apparantly MFC apps cannont include I have tried replacing the windows include with the required MFC includes, but that gives other errors, e.g. cannot use timeGetTime as it is an undeclared identifier. What do people use for their dalog boxes? If people use MFC is there anything that they can tell me about integrating it into their project that I might be overlooking? Any help/advice would be much appreciated. Thanks.
I'd steer clear from MFC. It's pretty outdated, and has all sorts of problems like what you're seeing. For simple dialogs, there's nothing to stop you using Win32 rather than MFC.
I figured as much, Guess I just like the click and drag interface too much as I am familiar with it from Java and C#. Thanks for the reply. I'll start going through the joy ow windows messages again lol.
If anyone has any ideas of where to look for any good tutorials on this it would help a lot.
Thanks.
If anyone has any ideas of where to look for any good tutorials on this it would help a lot.
Thanks.
I Agree with Evil Steve, stay away from MFC. As for an alternative, using pure win32 might be a bit difficult if you have no prior experience with it, so it might be better to start with a thin wrapper library for win32. Win32++ and DWinLib are good for that, although I prefer Win32++ over DWinLib. There is also a small such library in the AngelCode toolbox, although I don't think it's mature enough to be used for anything serious.
Both wxWidgets and qt has application where you can click/drag your interfaces. Since the layoutengines are different the drawing experience differ, but at least the wxWidget editor is acceptable when coming from an C# background. I haven't tried qt as I didn't like it's license.
Pretty good for an outdated api, wouldn't you say ;)
Quote:The latest version(9.0) came out in april(2008). DirectX 10 is actually older as it came out in february. This blog describes the new mfc features. As far as I know there isn't any other microsoft api that has these features..
I'd steer clear from MFC. It's pretty outdated
Pretty good for an outdated api, wouldn't you say ;)
Maybe I'm just naive, but why hasn't anyone suggested using C++/CLI and winforms if he's used to C#? Is there some reason this is bad?
Cheers
-Scott
Cheers
-Scott
Thanks a lot for the replies.
I have looked into all of the information provided.
The only problem I find with MFC is that your application has to be an MFC application, and I really don't want to rewrite my existing code for my window wrapper to cater for MFC (which to be fair looks a lot better than it did last time I used it). Still looking into Win32++.
My application is up and running, all I am looking to do is to allow the creation of a window that can have sdit boxes, slider controls, buttons etc...
Everything I have looked at so far seems a bit hardcore for what I want.
At the moment it seems like just doing it myself with Win32 seems the best option.
I just seem to be having trouble trying to figure out if it is possible to create a window from a resource file. If it is then it seems like all I have to do is to deal with the window proc (probably just returning DefWindProc) and checking for an OnCommand(WPARAM wParam).
By looking into win32++ I know that you can switch through the ID's of the controls by switching through the LOWORD of the WPARAM, but not sure where you would call this from (guessing the WndProc).
My dialog boxes need no parent windows, and when active, it is the only thing active (modal mode is this called?)
In short, anyone know if you can create a window from a resource file, or if it is possible to call say CreateTextEditBox(blah) CreateStaticText(blah) to create these boxes in a window?
I have looked into all of the information provided.
The only problem I find with MFC is that your application has to be an MFC application, and I really don't want to rewrite my existing code for my window wrapper to cater for MFC (which to be fair looks a lot better than it did last time I used it). Still looking into Win32++.
My application is up and running, all I am looking to do is to allow the creation of a window that can have sdit boxes, slider controls, buttons etc...
Everything I have looked at so far seems a bit hardcore for what I want.
At the moment it seems like just doing it myself with Win32 seems the best option.
I just seem to be having trouble trying to figure out if it is possible to create a window from a resource file. If it is then it seems like all I have to do is to deal with the window proc (probably just returning DefWindProc) and checking for an OnCommand(WPARAM wParam).
By looking into win32++ I know that you can switch through the ID's of the controls by switching through the LOWORD of the WPARAM, but not sure where you would call this from (guessing the WndProc).
My dialog boxes need no parent windows, and when active, it is the only thing active (modal mode is this called?)
In short, anyone know if you can create a window from a resource file, or if it is possible to call say CreateTextEditBox(blah) CreateStaticText(blah) to create these boxes in a window?
I've spent far too much time with MFC: you're making the right decision to stay away from it.
In Win32:
- CreateWindow and CreateWindowEx allow you to create windows and common controls. In short CreateWindow is also CreateEditControl, and CreateStatic and so on...
- CreateDialog will allow you to create dialog boxes from a resource file.
- Edit: Just noticed that you are looking for Modal Dialogs. For that, use the DialogBox(..) macro.
In Win32:
- CreateWindow and CreateWindowEx allow you to create windows and common controls. In short CreateWindow is also CreateEditControl, and CreateStatic and so on...
- CreateDialog will allow you to create dialog boxes from a resource file.
- Edit: Just noticed that you are looking for Modal Dialogs. For that, use the DialogBox(..) macro.
Win32 is definitely the best GUI library for windows, it just requires some time to get used to using it, which is why I suggested a wrapper library for it. The reason people stay away from MFC is not because it's outdated, but because it's bloated and not exactly "clean", and it costs money, and for someone who knows his way around win32, it provides nothing.
If you want to visually design your dialogs (which is a special type of window where controls are commonly put (which I think what you mean when you say "window")), then look at ResEdit. It's a very powerful free resource editor - its quality surprised me the first time I used it, given it's free.
Basically you create a new resource file in resedit, which creates a .rc file and an .h file. The .rc file contains the resources (dialogs, menus, bitmaps... etc), and the .h file contains the IDs for those resources. All you have to do is add the .rc file to your project (MSVC will know how to compile it into the exe, even the express versions) and include the .h file (typically called resource.h) in your source code. After that, having your application display a dialog from the resource is easy:
Hope this helps.
If you want to visually design your dialogs (which is a special type of window where controls are commonly put (which I think what you mean when you say "window")), then look at ResEdit. It's a very powerful free resource editor - its quality surprised me the first time I used it, given it's free.
Basically you create a new resource file in resedit, which creates a .rc file and an .h file. The .rc file contains the resources (dialogs, menus, bitmaps... etc), and the .h file contains the IDs for those resources. All you have to do is add the .rc file to your project (MSVC will know how to compile it into the exe, even the express versions) and include the .h file (typically called resource.h) in your source code. After that, having your application display a dialog from the resource is easy:
# include "resource.h"INT_PTR CALLBACK MyDialogProc( HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam ){ switch( Msg ) { case WM_INITDIALOG: // Initialize control contents here... break; case WM_COMMAND() // ... blah blah. return TRUE; } return FALSE; // Return false to let the dialog manager take default actions.}// In WinMain() or something:DialogBox( hInstance /*Or GetModuleHandle(NULL)*/, MAKEINTRESOURCE(IDD_MY_DIALOG_WHICH_I_DESIGNED_IN_RESEDIT), hMainWnd, MyDlgProc );Hope this helps.
Thanks a lot guys.
I now have my app displaying the dialog box.
My love for blackboxing and making functions generic always seem to slow me down, especially when I deal with windows stuff.
I have 4 functions :
1. Create the dialog box using the macro
2. Set the text of an item (SetDlgItemText)
3. Get the text from an item (GetDlgItemText)
4. The Proc for the dialog box
At the moment this class is completely generic (will work with any resource).
However as the class does not know what the resource file contains, it is hard to put much in the DialogProc. Currently all that is there is:
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwndDlg, wParam);
return true;
}
}
The problem I have is that as the box is modal the application cannot get or set any values in the dialog box until the box is closed.
I'm guessing that I could have all of the values to be set stored before creating the box and set them at the command WM_INITDIALOG.
And retrieve them all before I close the dialog, here I could also check that the items are valid.
I'm not exactly sure what this would entail, i'm thinking along the lines of storing it all in 2 vectors, one for setting and one for retrieving. This could be done as the functions only take text and an ID for the control.
However I'm not sure this would be the best way, seems like it could get a lot more complicated if list/combo boxes, radio buttons etc... were added.
Any feedback/input on this would be nice.
hikikomori-san - Thanks for pointing me to ResEdit, being able to view the source code for a dialog will really help me understand things quicker.
I now have my app displaying the dialog box.
My love for blackboxing and making functions generic always seem to slow me down, especially when I deal with windows stuff.
I have 4 functions :
1. Create the dialog box using the macro
2. Set the text of an item (SetDlgItemText)
3. Get the text from an item (GetDlgItemText)
4. The Proc for the dialog box
At the moment this class is completely generic (will work with any resource).
However as the class does not know what the resource file contains, it is hard to put much in the DialogProc. Currently all that is there is:
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwndDlg, wParam);
return true;
}
}
The problem I have is that as the box is modal the application cannot get or set any values in the dialog box until the box is closed.
I'm guessing that I could have all of the values to be set stored before creating the box and set them at the command WM_INITDIALOG.
And retrieve them all before I close the dialog, here I could also check that the items are valid.
I'm not exactly sure what this would entail, i'm thinking along the lines of storing it all in 2 vectors, one for setting and one for retrieving. This could be done as the functions only take text and an ID for the control.
However I'm not sure this would be the best way, seems like it could get a lot more complicated if list/combo boxes, radio buttons etc... were added.
Any feedback/input on this would be nice.
hikikomori-san - Thanks for pointing me to ResEdit, being able to view the source code for a dialog will really help me understand things quicker.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement