System Information Example

#include <windows.h> #include <tchar.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; MSG msg; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszClassName = TEXT("myWindowClass"); RegisterClassEx(&wc); CreateWindowEx( WS_EX_CLIENTEDGE, TEXT("myWindowClass"), TEXT("System Information"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 420, 220, NULL, NULL, hInstance, NULL); while(GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT Ps; HDC hdc; switch(msg) { case WM_PAINT: { hdc = BeginPaint(hwnd, &Ps); TCHAR OutputText[256] = TEXT(""); TCHAR SystemInfo[MAX_PATH]; DWORD buf = MAX_PATH; int stringlength; // Computer name _tcscpy(OutputText, TEXT("Machine Name -- ")); GetComputerName(SystemInfo, &buf); _tcscat(OutputText, SystemInfo); stringlength = _tcslen(OutputText); TextOut(hdc, 0, 0, OutputText, stringlength); // Windows system directory GetSystemDirectory(SystemInfo, MAX_PATH); _tcscpy(OutputText, TEXT("Windows Directory -- ")); _tcscat(OutputText, SystemInfo); stringlength = _tcslen(OutputText); TextOut(hdc, 0, 20, OutputText, stringlength); // Current directory _tcscpy(OutputText, TEXT("Current Directory -- ")); GetCurrentDirectory(MAX_PATH, SystemInfo); _tcscat(OutputText, SystemInfo); stringlength = _tcslen(OutputText); TextOut(hdc, 0, 40, OutputText, stringlength); // Program Files folder GetEnvironmentVariable(TEXT("ProgramFiles"), SystemInfo, MAX_PATH); _tcscpy(OutputText, TEXT("Program Files Directory -- ")); _tcscat(OutputText, SystemInfo); stringlength = _tcslen(OutputText); TextOut(hdc, 0, 60, OutputText, stringlength); // Operating system GetEnvironmentVariable(TEXT("OS"), SystemInfo, MAX_PATH); _tcscpy(OutputText, TEXT("Current OS -- ")); _tcscat(OutputText, SystemInfo); stringlength = _tcslen(OutputText); TextOut(hdc, 0, 80, OutputText, stringlength); // Current date SYSTEMTIME SystemTime; GetLocalTime(&SystemTime); _tcscpy(OutputText, TEXT("Current Date -- ")); wsprintf(SystemInfo, TEXT("%d"), SystemTime.wDay); _tcscat(OutputText, SystemInfo); _tcscat(OutputText, TEXT(".")); wsprintf(SystemInfo, TEXT("%d"), SystemTime.wMonth); _tcscat(OutputText, SystemInfo); _tcscat(OutputText, TEXT(".")); wsprintf(SystemInfo, TEXT("%d"), SystemTime.wYear); _tcscat(OutputText, SystemInfo); stringlength = _tcslen(OutputText); TextOut(hdc, 0, 100, OutputText, stringlength); EndPaint(hwnd, &Ps); } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }