1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <tchar.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
const TCHAR szClassName [ ] = _T("ComputerInformationDisplayApp");
const TCHAR szWindowTitle[ ] = _T("Computer Information Display");
const SIZE sizeWindow = {544, 375};
int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument, int nCmdShow) {
// The Window structure
WNDCLASSEX wincl;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; // Catch double-clicks
wincl.lpfnWndProc = WindowProcedure; // This function is called by windows
wincl.cbClsExtra = 0; // No extra bytes after the window class
wincl.cbWndExtra = 0; // structure or the window instance
wincl.hInstance = hThisInstance;
// Use default icon and mouse-pointer
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
// Use Windows's default colour as the background of the window
wincl.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
wincl.lpszMenuName = NULL; // No menu
wincl.lpszClassName = szClassName;
// As for large icon
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
// Register the window class, and if it fails quit the program
if (!RegisterClassEx (&wincl)) {
return 0;
}
// The class is registered, let's create the program*/
HWND hwnd = CreateWindowEx (
0, // No extended style
szClassName, // Class name
szWindowTitle, // Title Text
WS_OVERLAPPEDWINDOW, // default window style
CW_USEDEFAULT, // Windows decides the position
CW_USEDEFAULT, // where the window ends up on the screen
sizeWindow.cx, // The programs main window width
sizeWindow.cy, // and height in pixels
HWND_DESKTOP, // The window is a child-window to desktop
NULL, // No menu
hThisInstance, // Program Instance handler
NULL // No Window Creation data
);
if (!hwnd) {
return 0;
}
// Make the window visible on the screen
ShowWindow (hwnd, nCmdShow);
// Run the message loop. It will run until GetMessage() returns 0
MSG msg = {0};
while (GetMessage (&msg, NULL, 0, 0)) {
// Translate virtual-key messages into character messages
TranslateMessage(&msg);
// Send message to WindowProcedure
DispatchMessage(&msg);
}
// The program return-value is 0 - The value that PostQuitMessage() gave
return msg.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_PAINT: {
PAINTSTRUCT ps = {0};
HDC hdc = BeginPaint (hwnd, &ps) ;
RECT rect = {0};
GetClientRect(hwnd, &rect);
const TCHAR szWindowText[] = _T("Testing this out today");
POINT pointText = {5, 5};
TextOut (hdc, pointText.x, pointText.y, szWindowText, _tcslen(szWindowText));
EndPaint (hwnd, &ps);
return 0 ;
}
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|