Halcyon > Win32 Dialog wo/resource

Sample Code:

#include <windows.h>

/* Functions */
///////////////
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
const char ClassName[ ] = “Dialog”;
///////////////

/* Variables */
///////////////
HWND hWnd;
HWND button_hWnd[2];
HINSTANCE hInstance;
const int button_ok = 1;
const int button_cancel = 0;
static int xpos, ypos;
///////////////

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow ) {
HWND hWnd;
MSG messages;
WNDCLASSEX wincl;
hInstance = hInstance;
wincl.hInstance = hInstance;
wincl.lpszClassName = ClassName;
wincl.lpfnWndProc = WndProc;
wincl.style = CS_VREDRAW | CS_HREDRAW;
wincl.cbSize = sizeof( WNDCLASSEX );
wincl.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wincl.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
wincl.hCursor = LoadCursor( NULL, IDC_ARROW );
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;

wincl.hbrBackground = ( HBRUSH ) COLOR_BACKGROUND;

if( !RegisterClassEx( &wincl ) ) {
MessageBox( NULL, “Could not register”, “ERROR”, MB_OK | MB_ICONERROR );
return 0;
}

xpos = GetSystemMetrics( SM_CXSCREEN );
ypos = GetSystemMetrics( SM_CYSCREEN );

hWnd = CreateWindowEx(
0,
ClassName,
“Dialog”,
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU,
( ( xpos / 2 ) - 143 ),
( ( ypos / 2 ) - 102 ),
286,
177,
HWND_DESKTOP,
NULL,
hInstance,
NULL );

ShowWindow(hWnd,nCmdShow);

while( GetMessage( &messages, NULL, 0, 0 ) ) {
TranslateMessage( &messages );
DispatchMessage( &messages );
}
return messages.wParam;
}

LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) {
switch(message) {
case WM_CREATE: {
button_hWnd[1] = CreateWindow( “Button”,“OK”,WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,180,20,80,22,hWnd,(HMENU) button_ok,hInstance,NULL );
button_hWnd[2] = CreateWindow( “Button”,“Cancel”,WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,180,50,80,22,hWnd,(HMENU) button_cancel,hInstance,NULL );
break;
}

case WM_COMMAND: {
if( HIWORD( wParam ) == BN_CLICKED ) {
switch( LOWORD( wParam) ) {
case button_cancel:
DestroyWindow( hWnd );
break;
}
}
break;
}

case WM_DESTROY: {
PostQuitMessage(0);
break;
}
default:
return DefWindowProc( hWnd,message,wParam,lParam );
break;
}
return 0;
}

  • VC6-OGL

OOOOH…so what you are saying is that make the window you first create a dialog box. That makes sense. But what about if you have a main window already and you want to create a dialog box? Would have to make and MDI application then?

Most Likely.

  • VC6-OGL

Thanks! Heh…have you ever tried doing MDI in MFC? It’s probably just me but that is ONE CONFUSING thing to do. I can sit here reading aobut Convolution filters or vertex and pixel shaders and a lot of it makes sense. But MDI in MFC…that’s a WHOLE other story . Lucky me that i use Win32 . Well Happy Holidays!

  • Halcyon

I have NEVER tried doing MDI in MFC, and it is confusing.

Happy Holidays to you to!!!

  • VC6-OGL