Last active
May 17, 2019 22:24
-
-
Save theahmadzai/a237419b3bca29078f0ffd91347ffda8 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
#include <stdlib.h> | |
#include <windows.h> | |
static TCHAR szClassName[] = L"Application"; | |
static TCHAR szWindowName[] = L"Title of the application"; | |
HINSTANCE hInst; | |
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); | |
int CALLBACK WinMain(HINSTANCE hInstance, | |
HINSTANCE hPrevInstance, | |
LPSTR lpCmdLine, | |
int nCmdShow) | |
{ | |
WNDCLASS wc = {NULL}; | |
wc.hInstance = hInstance; | |
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); | |
wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
wc.lpfnWndProc = WndProc; | |
wc.lpszClassName = szClassName; | |
if (!RegisterClass(&wc)) | |
{ | |
MessageBox(NULL, | |
L"Call to RegisterClass Failed!", | |
szWindowName, | |
NULL); | |
return 1; | |
} | |
hInst = hInstance; | |
HWND hWnd = CreateWindow( | |
szClassName, | |
szWindowName, | |
WS_OVERLAPPEDWINDOW, | |
CW_USEDEFAULT, CW_USEDEFAULT, | |
500, 100, | |
NULL, | |
NULL, | |
hInstance, | |
NULL | |
); | |
if (!hWnd) | |
{ | |
MessageBox(NULL, | |
L"Call to CreateWindow Failed!", | |
szWindowName, | |
NULL); | |
return 1; | |
} | |
ShowWindow(hWnd, nCmdShow); | |
UpdateWindow(hWnd); | |
MSG msg; | |
while (GetMessage(&msg, NULL, 0, 0)) | |
{ | |
TranslateMessage(&msg); | |
DispatchMessage(&msg); | |
} | |
return (int)msg.wParam; | |
} | |
LRESULT CALLBACK WndProc(HWND hWnd, | |
UINT uMsg, | |
WPARAM wParam, | |
LPARAM lParam) | |
{ | |
PAINTSTRUCT ps; | |
HDC hdc; | |
TCHAR greeting[] = L"Hello, Welcome to Application"; | |
switch (uMsg) | |
{ | |
case WM_PAINT: | |
hdc = BeginPaint(hWnd, &ps); | |
TextOut(hdc, 5, 5, greeting, wcslen(greeting)); | |
EndPaint(hWnd, &ps); | |
break; | |
case WM_DESTROY: | |
PostQuitMessage(0); | |
break; | |
default: | |
return DefWindowProc(hWnd, uMsg, wParam, lParam); | |
break; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment