Skip to content

Instantly share code, notes, and snippets.

@mmmunk
Last active February 10, 2020 08:26
Show Gist options
  • Save mmmunk/510369def82ba83582e184d34da853df to your computer and use it in GitHub Desktop.
Save mmmunk/510369def82ba83582e184d34da853df to your computer and use it in GitHub Desktop.
Template for a basic Windows application to be compiled with MS command line compiler
// Compile with MS cmd-line: cl basic_windows_application.c user32.lib
// Compile with Embarcadero cmd-line: bcc32c -tW -tU basic_windows_application.c
// Compile from Ubuntu: x86_64-w64-mingw32-gcc -mwindows -municode -Os -o basic.exe basic_windows_application.c
// Compile with Digital Mars C: dmc basic_windows_application.c
// + strip basic.exe
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow)
{
WNDCLASSW wc = {0};
wc.lpszClassName = L"MyAppClassName";
wc.hInstance = hInstance;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc;
wc.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClassW(&wc);
HWND hwnd = CreateWindowW(wc.lpszClassName, L"Basic Windows Application", WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, 0, 0, hInstance, 0);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment