Skip to content

Instantly share code, notes, and snippets.

Created July 8, 2012 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3069862 to your computer and use it in GitHub Desktop.
Save anonymous/3069862 to your computer and use it in GitHub Desktop.
// Win32 Libraries
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
// Global Variables:
const TCHAR* szClassName = L"GameWindow"; //You can do that, too.
/* all the functions here were... useless o.0 */
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
switch (message)
{
//case WM_COMMAND:
// handle menu selections etc.
//break;
//case WM_PAINT:
// draw our window - note: you must paint something here or not trap it!
//break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
// We do not want to handle this message so pass back to Windows
// to handle it in a default way
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
char * cmdParam, int cmdShow) {
// Window Class
WNDCLASSEX GameWindow; // Populate the WNDCLASSEX structure
/* memset(...) is used to zero our every member of GameWindow. Since WNDCLASSEX is no class but a good old C-style struct
it's member variables won't automatically default to 0 (or anything else). Just to be on the safe side it's good to
set them all to 0 first. */
memset(&GameWindow, 0, sizeof(WNDCLASSEX));
GameWindow.cbSize = sizeof(WNDCLASSEX); // always set to size of WNDCLASSEX or WNDCLASS depending which you use
GameWindow.style = CS_HREDRAW | CS_VREDRAW; // designates when that the window is resized horizontally and vertically
GameWindow.lpfnWndProc = WndProcedure; // pointer to the start of the windows message handler
GameWindow.cbClsExtra = 0;
GameWindow.cbWndExtra = 0;
GameWindow.hIcon = LoadIcon(NULL, IDI_APPLICATION); // Window icon
GameWindow.hCursor = LoadCursor(NULL, IDC_ARROW); // Window cursor
GameWindow.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // Color of the background
GameWindow.lpszMenuName = NULL;
GameWindow.lpszClassName = szClassName; // unique name to the window class. Used when we call CreateWindow(Ex) to tell the function which window class we want an object instance of
GameWindow.hInstance = hInstance;// the handle to the instance of your app. This is given to your WinMain function and is passed there
GameWindow.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// Register the class
RegisterClassEx(&GameWindow);
// HWND is a handle to a window object
// We have a opportunity to chose window style and to add a menu.
HWND hWnd = CreateWindowEx(0, szClassName, L"Window Title Goes Here", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768, NULL,
NULL, hInstance, NULL);
// Show the Window
ShowWindow(hWnd, SW_SHOWNORMAL); // Second parameter is a style to show the window
UpdateWindow(hWnd);
Sleep(1000); //Sleeps for 1 second so you actually see the window.
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment