Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
//-----------------------------------------------------------------------------
#define APPNAME "GetKey2"
#define APPTITLE "GetKey2"
#include <windows.h>
#include <stdio.h>
#include <time.h>
HWND hWnd;
/* Print the virtual Key Code */
void PrintKey(WPARAM wParam)
{
HDC pDc;
RECT rct;
char msg[10];
sprintf(msg, "%d\n", wParam );
pDc = GetDC( hWnd );
GetClientRect( hWnd, &rct );
FillRect(pDc, &rct, (HBRUSH)GetStockObject(BLACK_BRUSH));
DrawText( pDc, msg, strlen(msg), &rct, DT_LEFT | DT_TOP);
ReleaseDC(hWnd,pDc);
}
LRESULT CALLBACK WindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_KEYDOWN:
PrintKey( wParam );
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
};
return DefWindowProc(hWnd, message, wParam, lParam);
};
bool WindowInit (HINSTANCE hThisInst, int nCmdShow)
{
WNDCLASSEX wcl;
/* define the class of your main window */
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.lpszClassName = APPNAME;
wcl.lpfnWndProc = WindowProc;
wcl.style = 0;
wcl.hIcon = LoadIcon (hThisInst, IDC_ICON);
wcl.hIconSm = LoadIcon (hThisInst, IDC_ICON);
wcl.hCursor = LoadCursor (hThisInst, IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
/* Register class in Windows system */
RegisterClassEx (&wcl);
/* Create the window in memory */
hWnd = CreateWindowEx( WS_EX_TOPMOST, APPNAME, APPTITLE, WS_OVERLAPPEDWINDOW, 75, 75, 320, 240, NULL, NULL, hThisInst, NULL);
if(!hWnd) return false;
return true;
};
bool AppInit (HINSTANCE hThisInst, int nCmdShow)
{
if(!WindowInit (hThisInst, nCmdShow)) return false;
ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
return true;
};
int APIENTRY WinMain (HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
if(!AppInit (hThisInst, nCmdShow)) return false;
while (1)
{
// Look if there are messages
if(PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
{
// Get the first message in the stack
if(!GetMessage (&msg, NULL, 0, 0)) break;
// Convert the message for WNDPROC functions
TranslateMessage (&msg);
// Give the message to all applications
DispatchMessage (&msg);
}
else
{
// Do what you want when no message happens
}
};
return 0;
};