System Information Functions

#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 = {0};
MSG msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = TEXT("myWindowClass");
RegisterClassEx(&wc);
CreateWindowEx(WS_EX_CLIENTEDGE,TEXT("myWindowClass"),TEXT("System info"),WS_THICKFRAME|WS_OVERLAPPEDWINDOW| WS_VISIBLE | WS_OVERLAPPEDWINDOW ,CW_USEDEFAULT, CW_USEDEFAULT, 340, 320, 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://traps paint message
{
hdc = BeginPaint(hwnd, &Ps);
TCHAR OutputText[128]="Machine Name -- ";
TCHAR SystemInfo[MAX_PATH];
DWORD buf = 256;
int stringlength;
GetComputerName(SystemInfo, &buf);
_tcscat(OutputText,SystemInfo);
stringlength=_tcslen(OutputText);
TextOut(hdc, 0,0, OutputText,stringlength);

GetSystemDirectory(SystemInfo,MAX_PATH);
_tcscpy(OutputText,"Windows Directory -- ");
_tcscat(OutputText,SystemInfo);
stringlength=_tcslen(OutputText);
TextOut(hdc, 0,15,OutputText,stringlength);

_tcscpy(OutputText,"Current Directory -- ");
GetCurrentDirectory(MAX_PATH,SystemInfo);
_tcscat(OutputText,SystemInfo);
stringlength=_tcslen(OutputText);
TextOut(hdc, 0,30,OutputText,stringlength);

buf = 256;
GetEnvironmentVariable("ProgramFiles", SystemInfo, buf);
_tcscpy(OutputText,"Program Files directory -- ");
_tcscat(OutputText,SystemInfo);
stringlength=_tcslen(OutputText);
TextOut(hdc, 0,45,OutputText,stringlength);


GetEnvironmentVariable("OS", SystemInfo, buf);
_tcscpy(OutputText,"Current OS -- ");
_tcscat(OutputText,SystemInfo);
stringlength=_tcslen(OutputText);
TextOut(hdc, 0,60,OutputText,stringlength);


TCHAR datevalue[32];
TCHAR month[32];
TCHAR year[32];
SYSTEMTIME lpSystemTime;
GetLocalTime(&lpSystemTime);
_tcscpy(OutputText,"Current Date -- ");
wsprintf(SystemInfo,TEXT("%i"), lpSystemTime.wDay);
_tcscat(OutputText,SystemInfo);
_tcscat(OutputText,".");
wsprintf(SystemInfo,TEXT("%i"), lpSystemTime.wMonth);
_tcscat(OutputText,SystemInfo);
_tcscat(OutputText,".");
wsprintf(SystemInfo,TEXT("%i"), lpSystemTime.wYear);
_tcscat(OutputText,SystemInfo);
stringlength=_tcslen(OutputText);
TextOut(hdc, 0,75,OutputText,stringlength);
EndPaint(hwnd, &Ps);
DeleteDC(hdc);
}
break;

case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}