-
Dialogs
Well after a couple of years doing dialog box, buttons, listviews, etc the hard way (ie CreateWindowEX), I have decieded to move on.
I guess the first question is I still want to use as much pure Win32/API as possible (no MFC) so is using the resource editor and Dialog or CreateDialog the best way to do this?
My second question is how do I do it? I make a quick dialog using an IDD_PROPAGE_MEDIUM. Now I am trying to get it to just come up. I have tried CreateDialog() and Dialog() with out any luck. Someone want to help me out?
Doing this I get a NULL g_hWnd
Code:
/*---------------------------------*/
//Include
#include "Main.h"
/*---------------------------------*/
//Global VARs
HWND g_hWnd; //Holds The Window Handle
HINSTANCE g_hInst; //Holds The Window Instance
TCHAR g_szClass[] = "Test Window";//Class Title
HANDLE g_hMutex = NULL; //Handle For The Mutex
/*---------------------------------*/
//Modual VARs
int m_iWidth = 500; //Main Window Width
int m_iHeight = 500; //Main Window Height
int m_iX = CENTERX(m_iWidth); //Main Window's X Position
int m_iY = CENTERY(m_iHeight); //Main Window's Y Position
/*---------------------------------*/
//Modual Functions
BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
/*---------------------------------*/
/*###########################################################################################*/
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
MSG _msg; //VAR To Hold Our Main Messages
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
if(!Startup(g_szClass)) //Run My Custom Start Function
return -1;
g_hWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, DialogProc);
ShowWindow(g_hWnd, SW_SHOW);
int i;
while(i = GetMessage(&_msg, NULL, 0, 0)) //Window Message Loop
{
if (i == -1)
break;
TranslateMessage(&_msg);
DispatchMessage(&_msg);
}
return ((int)_msg.wParam); //Exit The Program
}
/*###########################################################################################*/
BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_CLOSE:
DestroyWindow(hWnd); //Closes the dialog box
PostQuitMessage(0); //Exit the program
return TRUE;
}
return FALSE;
}
If I use Dialog instead I can get the window to come up, but if I even try to click on it I cant. Its like its not being drawn/redrawn. So I am stuck.
Any help would be great thanks.
-
Dialog? Do you mean DialogBox?
The code actually looks ok to me, I don't see why it shouldn't be working.
-
1 Attachment(s)
Yeah DialogBox, sorry.
I don't get it either, from what I can tell it SHOULD work too, which is why this is starting to get frustrating. All I wanted to do was make Windows faster instead of having to code everything by hand :mad:
Ok so if I use GetDesktopWindow() instead of NULL:
CreateDialog(g_hInst,MAKEINTRESOURCE(IDD_MAIN),GetDesktopWindow(),Main_DlgProc);
I get a window like DialogBox gives me, but I can't click on it or anything (See attached)
-
Ok I got it stupid POS. I had to change:
Code:
int i;
while(i = GetMessage(&_msg, NULL, 0, 0)) //Window Message Loop
{
if (i == -1)
break;
if(!IsDialogMessage(g_hWnd,&_msg))
{
TranslateMessage(&_msg);
DispatchMessage(&_msg);
}
}
Also for some REASON .NET 2003 has the dialog disabled by default. Oh well it looks like it is working now.
-
Oh yeah, the special message loop...
Never actually used it (I used dialogs only in MFC), but I read of it in the Petzold. Probably would have never thought of it.