Created
June 6, 2013 00:27
-
-
Save gszauer/5718425 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define WIN32_LEAN_AND_MEAN | |
#define WIN32_EXTRA_LEAN | |
#include <windows.h> | |
#include <iostream> | |
using std::cout; | |
HWND hwnd; | |
HINSTANCE hinstance; | |
#pragma comment(linker,"/SUBSYSTEM:CONSOLE") | |
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam); | |
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow); | |
int main(int argc, char** argv) { | |
WinMain(GetModuleHandle(NULL), NULL, GetCommandLine(), SW_SHOWDEFAULT); | |
return 0; | |
} | |
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { | |
hinstance = hInstance; | |
WNDCLASS wndclass; | |
wndclass.style = CS_HREDRAW | CS_VREDRAW; | |
wndclass.lpfnWndProc = WndProc; | |
wndclass.cbClsExtra = 0; | |
wndclass.cbWndExtra = 0; | |
wndclass.hInstance = hInstance; | |
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); | |
wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); | |
wndclass.lpszMenuName = 0; | |
wndclass.lpszClassName = "ssrWin"; | |
RegisterClass(&wndclass); | |
RECT wndRect; SetRect(&wndRect, 0, 0, 600, 400); | |
AdjustWindowRect(&wndRect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, false); | |
int x = (GetSystemMetrics(SM_CXSCREEN) / 2) - ((wndRect.right - wndRect.left) / 2); | |
int y = (GetSystemMetrics(SM_CYSCREEN) / 2) - ((wndRect.right - wndRect.left) / 2); | |
int w = (wndRect.right - wndRect.left); int h = (wndRect.bottom - wndRect.top); | |
hwnd = CreateWindow("ssrWin", "ssr Software Renderer", WS_OVERLAPPEDWINDOW | WS_VISIBLE, x, y, w, h, NULL, NULL, hInstance, szCmdLine); | |
MSG msg; | |
while (GetMessage(&msg, NULL, 0, 0)) { | |
TranslateMessage(&msg); | |
DispatchMessage(&msg); | |
} | |
return (int)msg.wParam; | |
} | |
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { | |
switch (iMsg) { | |
case WM_CREATE : | |
break; | |
case WM_CLOSE : | |
DestroyWindow(hwnd); | |
break; | |
case WM_DESTROY : | |
PostQuitMessage(0); | |
break; | |
} | |
return DefWindowProc(hwnd, iMsg, wParam, lParam); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment