Code:
// Include files
#include <windows.h>
#include <gl/gl.h>
#include "menu.h"
//end include files
//defs
#define SCREEN_DEPTH 32
#define IDBTN01 10
//end defs
HWND edit_box = NULL; //edit window handle
// Function Declarations
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
VOID EnableOpenGL( HWND edit_box, HDC * hDC, HGLRC * hRC );
VOID DisableOpenGL( HWND edit_box, HDC hDC, HGLRC hRC );
// WinMain
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow )
{
WNDCLASS wc; //main window class
WNDCLASS ed; //edit window class
WNDCLASS mp; //model preview class
HWND hwnd; //main window handle
HDC hdc; //windows device context
HGLRC gl_hrc;//OGL device context
MSG msg; //message handle
BOOL bQuit = FALSE;
float theta = 0.0f;
// register window class
wc.style = NULL;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( GRAY_BRUSH );
wc.lpszMenuName = "MAINMENU";
wc.lpszClassName = "PsychoEngine";
RegisterClass( &wc );
//regester edit class
ed.style = CS_OWNDC;
ed.lpfnWndProc = WndProc;
ed.cbClsExtra = 0;
ed.cbWndExtra = 0;
ed.hInstance = hInstance;
ed.hIcon = LoadIcon( NULL, IDI_APPLICATION );
ed.hCursor = LoadCursor( NULL, IDC_ARROW );
ed.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
ed.lpszMenuName = NULL;
ed.lpszClassName = "EDIT";
RegisterClass( &ed );
//regester model preview class
mp.style = CS_OWNDC;
mp.lpfnWndProc = WndProc;
mp.cbClsExtra = 0;
mp.cbWndExtra = 0;
mp.hInstance = hInstance;
mp.hIcon = LoadIcon( NULL, IDI_APPLICATION );
mp.hCursor = LoadCursor( NULL, IDC_ARROW );
mp.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
mp.lpszMenuName = NULL;
mp.lpszClassName = "MODEL";
RegisterClass( &mp );
// create main window
hwnd = CreateWindow(
"PsychoEngine", "PsychoEngine | PsychopathProductions",
WS_TILEDWINDOW | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 800, 570,
NULL, NULL, hInstance, NULL );
HWND edit_box = NULL;
HWND model_box = NULL;
LPARAM lParam;
RECT rect;
GetClientRect(hwnd,&rect);
//set up and create editbox
edit_box = CreateWindow("EDIT", "Edit Window",WS_CHILD | WS_CAPTION | WS_VISIBLE,
0, 0, 600, 516, hwnd, NULL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
//setup and create model preview box
model_box = CreateWindow("MODEL", "Model Preview",WS_CHILD | WS_CAPTION | WS_VISIBLE,
600, 338, 192, 178, hwnd, NULL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
//draw buttons
HWND button;
button = CreateWindow("BUTTON", "NPC's", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 616, 30, 64, 24, hwnd,(HMENU) 10, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "Player", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 708, 30, 64, 24, hwnd, NULL, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "World Options", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 646, 58, 98, 24, hwnd, NULL, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "Lighting", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 616, 86, 64, 24, hwnd, NULL, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
button = CreateWindow("BUTTON", "", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 708, 86, 64, 24, hwnd, NULL, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
// enable OpenGL for the edit window
EnableOpenGL( edit_box, &hdc, &gl_hrc );
// program main loop
while ( !bQuit ) {
// check for messages
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
// handle or dispatch messages
if ( msg.message == WM_QUIT ) {
bQuit = TRUE;
} else {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
} else {
// OpenGL animation code
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
glPushMatrix();
glBegin( GL_TRIANGLES );
glColor3f( 1.0f, 0.0f, 0.0f ); glVertex3f( 0.0f, 0.87f, 0.0f );
glColor3f( 0.0f, 1.0f, 0.0f ); glVertex3f( 0.87f, -0.5f, 0.0f );
glColor3f( 0.0f, 0.0f, 1.0f ); glVertex3f( -0.87f, -0.5f, 0.0f );
glEnd();
glPopMatrix();
SwapBuffers( hdc );
theta += 1.0f;
}
}
// shutdown OpenGL
DisableOpenGL( hwnd, hdc, gl_hrc );
// destroy the window explicitly
DestroyWindow( hwnd );
return msg.wParam;
}
// Window Procedure
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
HWND edit_box = NULL;
HWND model_box = NULL;
switch ( message )
{
case WM_CREATE:
break;
case WM_CLOSE:
MessageBox (NULL, "Are you sure you want to close the program?\nAll un-saved data will be lost." , "Exiting...", 0 + MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION);
PostQuitMessage( 0 );
break;
return 0;
case WM_DESTROY:
break;
return 0;
case WM_KEYDOWN:
switch ( wparam ) {
case VK_ESCAPE:
PostQuitMessage( 0 );
break;
return 0;
case WM_COMMAND:
{
WORD wID,wNotify;
wID=LOWORD(wparam);
wNotify=HIWORD(wparam);
if (lparam)
{
/* it's a control notification message */
if (wNotify==BN_CLICKED)
{
/* a button control has been clicked */
if (wID==10) /* replace with actual value */
{
MessageBox (NULL, "it works" , ":)", 0);
}
}
}
}
}
return 0;
default:
return DefWindowProc( hwnd, message, wparam, lparam );
}
}
// Enable OpenGL
VOID EnableOpenGL( HWND edit_box, HDC * hdc, HGLRC * gl_hrc )
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
// get the device context (DC)
*hdc = GetDC( edit_box );
// set the pixel format for the DC
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = SCREEN_DEPTH;
pfd.cDepthBits = SCREEN_DEPTH;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat( *hdc, &pfd );
SetPixelFormat( *hdc, iFormat, &pfd );
// create and enable the render context (RC)
*gl_hrc = wglCreateContext( *hdc );
wglMakeCurrent( *hdc, *gl_hrc );
}
// Disable OpenGL
VOID DisableOpenGL( HWND edit_box, HDC hdc, HGLRC gl_hrc )
{
wglMakeCurrent( NULL, NULL );
wglDeleteContext( gl_hrc );
ReleaseDC( edit_box, hdc );
}
thats the code for the whole program....there arn't any error messages...but i kno it dosn't work, other wise it would display the message box when i click the button