PDA

View Full Version : Halcyon > Win32 Dialog wo/resource



Stack Overflow
12-24-2002, 10:53 AM
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

Halcyon
12-24-2002, 11:09 AM
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?

Stack Overflow
12-24-2002, 11:12 AM
Most Likely.

- VC6-OGL

Halcyon
12-24-2002, 11:43 AM
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 http://www.opengl.org/discussion_boards/ubb/biggrin.gif. Lucky me that i use Win32 http://www.opengl.org/discussion_boards/ubb/smile.gif. Well Happy Holidays!


- Halcyon

Stack Overflow
12-24-2002, 11:47 AM
I have NEVER tried doing MDI in MFC, and it is confusing.

Happy Holidays to you to!!! http://www.opengl.org/discussion_boards/ubb/smile.gif

- VC6-OGL