file:///c:/2.jpgfile:///c:/3.jpg
//window_eg.cpp - a complete window program
//includes///////////////////////////////////////////////////////////////////////////////////////////////////////
# include <windows.h> //all window include
# include <windowsx.h> //useful macros
# include <stdio.h>
# include <math.h>
# include "resource.h"
//define////////////////////////////////////////////////////////////////////////////////////////////////////////
//define for window
# define WINDOW_CLASS_NAME "WINCLASS1"
//functions////////////////////////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg, WPARAM wparam,
LPARAM lparam)
{
//this is main message handler of the system
PAINTSTRUCT ps; //used in WM_PAINT
HDC hdc; //handle to a device context
HINSTANCE hinstance;
//char load_string[80];
switch(msg)
{
case WM_CREATE:
{
//do initialization stuff here
//LoadString(hinstance, IDS_STRING_LOAD_GAME, load_string, 80);
//return success
return 0;
}
break;
case WM_PAINT:
{
//simply validate the window
hdc = BeginPaint(hwnd, &ps);
//you would do all your painting here
EndPaint(hwnd, &ps);
//return success
return 0;
}
break;
case WM_DESTROY:
{
//kill the application this send a WM_QUIT message
PostQuitMessage(0);
//return success
return 0;
}
break;
default:
break;
}//end switch
return(DefWindowProc(hwnd, msg, wparam, lparam));
}//end winproc
//winmain////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASSEX winclass;//this will hold the class we create
HWND hwnd; //generic window handle
MSG msg; //generic messgae
//first fill int the window class structure
winclass.cbSize = sizeof(WNDCLASSEX); //size of this structure
winclass.style = CS_DBLCLKS | CS_OWNDC | //style flage
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc; //function pointer to handler
winclass.cbClsExtra = 0; //extra class info
winclass.cbWndExtra = 0; //extra window info
winclass.hInstance = hinstance; //the instance of the application winclass.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1)); //the main icon
winclass.hCursor = LoadCursor(hinstance, MAKEINTRESOURCE(IDC_CURSOR1)); //the cursor for the window
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); //the cursor for the window
winclass.lpszMenuName = NULL; //the background brush to paint the window
winclass.lpszClassName = WINDOW_CLASS_NAME; //the name of the menu to attach
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //the handle of the small icon
//register the window class
if(!RegisterClassEx(&winclass))
return 0;
//create the window
if(!(hwnd = CreateWindowEx(NULL,
WINDOW_CLASS_NAME,
"My basic window",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0,
400,400,
NULL,
NULL,
hinstance,
NULL)))
return 0;
//enter main event loop
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);