Advertisement

Dialog Boxes

Started by August 23, 2000 03:40 PM
2 comments, last by jharkey 24 years, 4 months ago
Hello, does anyone know how to make dialogs in windows, without using mfc? I know i am doing it right because when i call the DialogBox function, my code switches over to the DialogProc function, but the dialog box itself doesn''t show up on the screen! I can''t figure it out, i have looked at lots of tutorials, but i can''t see what i am doing wrong. please help. #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #include #include #include"resource.h" #include"bhemain.h" HINSTANCE hinst=NULL; BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM lParam) { switch(uMsg){ case WM_INITDIALOG:{ Sleep(2000); EndDialog(hwndDlg,0); return true;}} return false; } //window processor LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; // used in WM_PAINT HDC hdc; // handle to a device context switch(msg){ case WM_CREATE:{ DialogBox(hinst,MAKEINTRESOURCE(IDD_DIALOG1), hwnd,DialogProc); InitDraw(); return 0;} break; case WM_PAINT:{ DrawGrid(hwnd); hdc=BeginPaint(hwnd,&ps); // end painting EndPaint(hwnd,&ps); return 0;} break; case WM_DESTROY:{ DestroyDraw(); PostQuitMessage(0); return 0;} break; default:break;} // process any messages that we didn''t take care of return(DefWindowProc(hwnd, msg, wparam, lparam)); } int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; HWND hwnd; MSG msg; // generic message // first fill in the window class stucture winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL,"IDI_ICON1"); winclass.hCursor = LoadCursor(NULL,IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); winclass.lpszClassName = "WINCLASS"; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // register the window class if(!RegisterClassEx(&winclass)) return 0; // create the window, note the use of WS_POPUP if(!(hwnd = CreateWindowEx(NULL, "WINCLASS", // class "Body-Hats Level Editor",// title WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, // x,y 600, // width 500, // height NULL, // handle to parent NULL, // handle to menu hinstance,// instance NULL))) // creation parms return 0; hinst=hinstance; // enter main event loop while(GetMessage(&msg,NULL,0,0)){ // test if this is a quit TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg);} // return to Windows like this return(msg.wParam); }
It doesn''t work because you call EndDialog() right after you INITiated it.
You could try this:

    //---------------------------------------------------------------------------BOOL CALLBACK DlgProcAbout(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam){	switch(uMsg)	{	case WM_INITDIALOG:		{				return TRUE;		}		case WM_COMMAND:			switch(LOWORD(wParam))	//HIWORD(wParam)==BN_CLICKED			{	case IDOK:				case IDCANCEL:					EndDialog(hDlg, 0);					return TRUE;			}			break;	}	return FALSE;}//---------------------------------------------------------------------------				case ID_HELP_ABOUT:					DialogBox((HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE), MAKEINTRESOURCE(IDD_ABOUT),	hWnd, (DLGPROC)DlgProcAbout);					return 0;    


Advertisement
thanks a lot
i thought if i made it sleep for a little bit, it would at least show me the dialog box for a couple of seconds, but i guess not. thanks again
Yes, at first you would think that, but after you return from the WM_INITDIALOG, windows calls some other functions like WM_SHOWWINDOW to make it visisble...

Good to be of any help,
- Bas

This topic is closed to new replies.

Advertisement