Code:
// Include files
#include <windows.h>
#include <gl/gl.h>
//end include files
HWND edit_box = NULL;
// Function Declarations
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
VOID EnableOpenGL( HWND hWnd, HDC * hDC, HGLRC * hRC );
VOID DisableOpenGL( HWND hWnd, HDC hDC, HGLRC hRC );
// WinMain
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow )
{
WNDCLASS wc;
WNDCLASS ed;
HWND hwnd;
HDC hdc;
HGLRC gl_hrc;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;
// register window class
wc.style = CS_OWNDC;
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 = NULL;
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 );
// create main window
hwnd = CreateWindow(
"PsychoEngine", "PsychoEngine | PsychopathProductions",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 800, 570,
NULL, NULL, hInstance, NULL );
// enable OpenGL for the 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 goes here
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 ); glVertex2f( 0.0f, 1.0f );
glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f );
glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f );
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;
switch ( message )
{
case WM_CREATE:
RECT rect;
GetClientRect(hwnd,&rect);
edit_box = CreateWindow("EDIT", "Edit Window",WS_CHILD | WS_BORDER | WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 30, 600, 538, hwnd, NULL,
((LPCREATESTRUCT)lparam)->hInstance, NULL);
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;
}
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 = 24;
pfd.cDepthBits = 16;
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 );
}
...sorry...codes a little lengthy...anyway any help will be appreciated...