|
-
Aug 13th, 2001, 07:36 PM
#1
Thread Starter
Addicted Member
GUI stuff
I'm trying to create a GUI for a simple program I'm working on. I figured out how to use resource dialogs (in VC++ 5). And making a GUI in that is sooo easy. Is it possible to use just this dialog for my program?
I can't seem to word this correctly. I guess what I want is a dialog with no parent.
Any help would be great. Thanks.
Cbomb
Techie 
-
Aug 13th, 2001, 08:38 PM
#2
PowerPoster
If you just want that dialog to show up when your program starts, then it's possible!
(I actually did not fully understand your question )
-
Aug 13th, 2001, 08:40 PM
#3
Thread Starter
Addicted Member
lol i know...
Basically. The visible application would be just that dialog. I just dont want to do a bunch of "CreateWindows" to make everything.
Better?
Cbomb
Techie 
-
Aug 13th, 2001, 09:16 PM
#4
PowerPoster
You just need to call "CreateDialog" or "ShowDialog" to make the dialog visible.
Here is a simple dialog based app that just shows a dialogbox (stored in a resource file) when the program starts:
Code:
#include <windows.h>
#include "resource.h"
static HINSTANCE hinst = NULL;
BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
HWND dlghwnd;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndClass;
MSG Msg;
hinst = hInstance;
dlghwnd = CreateDialog(hinst, MAKEINTRESOURCE(MYDLG), NULL, DlgProc);
ShowWindow(dlghwnd, nCmdShow);
UpdateWindow(dlghwnd);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wparam, LPARAM lparam)
{
switch(Message)
{
case WM_INITDIALOG:
return TRUE;
case WM_CLOSE:
EndDialog(hwnd, 0);
PostQuitMessage(0);
return TRUE;
}
return FALSE;
}
-
Aug 13th, 2001, 10:06 PM
#5
Thread Starter
Addicted Member
cool
Ok it compiles 0 errs 0 warns but when I run it there is no window. I check running processes and it IS there, so I kill it.
Heres my code:
Code:
#include <windows.h>
#include "resource.h"
HWND dlghwnd;
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
HINSTANCE hinst;
hinst = hInstance;
dlghwnd = CreateDialog(hinst, MAKEINTRESOURCE(ID_dialog_compviewer), NULL, (WNDENUMPROC)DlgProc);
ShowWindow(dlghwnd, nCmdShow);
UpdateWindow(dlghwnd);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
What am I not doing? Thanks.
Cbomb
Techie 
-
Aug 13th, 2001, 11:02 PM
#6
PowerPoster
Re: cool
I just made a little changes to the code. See if that helps
Code:
#include <windows.h>
#include "resource.h"
HWND dlghwnd;
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG: //You need to handle this messages and return
//TRUE for that
return TRUE;
case WM_CLOSE: //If you want close the dialog box and exit the
//program then you also need to handle this message
DestroyWindow(hwnd); //Closes the dialog box
PostQuitMessage(0); //Exit the program
return TRUE;
}
return FALSE; // Return FALSE for any other message that we dont
//care of
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
HINSTANCE hinst;
hinst = hInstance;
dlghwnd = CreateDialog(hinst, MAKEINTRESOURCE(ID_dialog_compviewer), NULL, DlgProc); //You dont need "WNDENUMPROC" here
ShowWindow(dlghwnd, nCmdShow);
UpdateWindow(dlghwnd);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
-
Aug 14th, 2001, 03:20 PM
#7
Thread Starter
Addicted Member
(WNDENUMPROC)
if I dont put the (WNDENUMPROC) in there I get this error:
error C2664: 'CreateDialogParamA' : cannot convert parameter 4 from 'int (void *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(void)'
??
Cbomb
Techie 
-
Aug 14th, 2001, 03:26 PM
#8
PowerPoster
I get an error message when I use WNDENUMPROC in VC++. Just leave it where it is and then try to run your code
-
Aug 14th, 2001, 04:17 PM
#9
Frenzied Member
-
Aug 14th, 2001, 10:12 PM
#10
Thread Starter
Addicted Member
WOOHO!
That example project works great! Thank you.
Cbomb
Techie 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|