Skip to main content
gamedev.net
🔒 Locked

Win32

Started by grahamhinchly Jan 21, 2001 at 2:02 PM 3 replies 350+ views
Original Post
grahamhinchly
grahamhinchly
Am I just being stupid, because I don''t know how to program WIndows? I have read the Programming genesis Part 1, but do not know how to actually put it all together as i does not have a full working example. If someone could post a well commented template that just displays a window with some text in it, I would be very grateful. Comments on it would help too, but i don''t want to be too nitpicky because any help would be greatly appreciated. Thank you The Stupid Beginner who can''t even begin to begin.
We were all beginners once, don't forget that...
gavco98
gavco98
heres the basic win32 template i use.

  
//---------------------------------------------------------------------------

//--------------------------------INCLUDES-----------------------------------

//---------------------------------------------------------------------------



#define WIN32_LEAN_AND_MEAN // Disable MFC


#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <math.h>


//---------------------------------------------------------------------------

//---------------------------------DEFINES-----------------------------------

//---------------------------------------------------------------------------


#define WINDOW_CLASS_NAME "INTROWINDOW"


//---------------------------------------------------------------------------

//---------------------------------GLOBALS-----------------------------------

//---------------------------------------------------------------------------

int Game_Main();


//---------------------------------------------------------------------------

//--------------------------------WINDOWPROC---------------------------------

//---------------------------------------------------------------------------

//-----------------------MESSAGE HANDLER FOR APPLICATION---------------------

//---------------------------------------------------------------------------


LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
PAINTSTRUCT ps; // used in WM_PAINT

HDC hdc; // handle to device context


// find out what the message is

switch(msg)
{
case WM_CREATE:
{
// initialise application


return(0); // Tell windows we handled it

} break;

case WM_PAINT:
{
hdc = BeginPaint(hwnd, &ps); // Simply validate the window

EndPaint(hwnd, &ps);

return(0); // Tell windows we handled it

}break;

case WM_DESTROY:
{
PostQuitMessage(0); // send WM_QUIT message to exit


return(0); // Tell windows we handled it

}break;


default:break; // Exit if message is not handled

}

return (DefWindowProc(hwnd,msg, wparam, lparam));
// Pass unhandled messages to windows


}

//---------------------------------------------------------------------------

//---------------------------------WINMAIN-----------------------------------

//---------------------------------------------------------------------------

//------------STARTING POINT FOR EXECUTION OF THE APPLICATION----------------

//---------------------------------------------------------------------------


int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpCmdline,
int ncmdshow)
{
WNDCLASSEX winclass; // create a window class

HWND hwnd; // window handle

MSG msg; // Generic message


// Fill in the values of the window class structure

winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0; // Extra storage space not required

winclass.cbWndExtra = 0; // Not required

winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL; // We do not require a menu

winclass.lpszClassName = WINDOW_CLASS_NAME;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);



if (!RegisterClassEx(&winclass)) // Register the window class

MessageBox(NULL, " Failed to create window class",
"Initialisation Failed", MB_OK | MB_ICONSTOP);



if (!(hwnd = CreateWindowEx(NULL, //Extended style not needed

WINDOW_CLASS_NAME, // Class

"Project GENESIS", // Window Title

WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0, // Initial X, Y coordinates

400, 400, // Initial Width and Height

NULL, // Handle to parent

NULL, // Handle to menu

hinstance, // Instance of application

NULL ))) // Extra creation paramaters

MessageBox(NULL, "Failed to display window", "Initilisation Failure",
MB_OK | MB_ICONSTOP);



// Main event loop

while(TRUE)
{

if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Check if message waiting

{ // If there is retrieve it

if(msg.message == WM_QUIT)
break;

TranslateMessage(&msg);
DispatchMessage(&msg); // Send message to message handler

}


Game_Main(); // Main game processing



}





return(msg.wParam);
}



//---------------------------------------------------------------------------

//---------------------------------GAME MAIN---------------------------------

//---------------------------------------------------------------------------

//-----------------------DO ALL GAME RELATED THINGS HERE---------------------

//---------------------------------------------------------------------------


int Game_Main()
{
// todo: make the game!

return(0);
}



Please feel free to flame it, as i know it aint great, and would like to know how it could be improved (comment wise mainly)

G Coates
-------------------------------------------

Green ribbon campain, for freedom of innovation
Windows: The only virus with a GUI!
Gavin Coates
[size="1"]IT Engineer / Web Developer / Aviation Consultant
[size="1"][ Taxiway Alpha ] [ Personal Home Page ]
gavco98
gavco98
Oh well, it kinda stuffed up my formatting

Gavin Coates
[size="1"]IT Engineer / Web Developer / Aviation Consultant
[size="1"][ Taxiway Alpha ] [ Personal Home Page ]
Crazy_Vasey
Crazy_Vasey
check out http://www.winprog.org there is no better tutorial on win32

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.