Created
January 24, 2017 19:57
-
-
Save TheServer201/49e2191a9e5fa4f783c465f5a076ecde 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
// gcc -Os -s -nostartfiles -nostdlib -e __main -Wl,-gc-sections win.c -o win -luser32 -lkernel32 | |
#define UNICODE | |
#include <windows.h> | |
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); | |
void _main(){ | |
MSG msg = {0}; | |
WNDCLASS wc = {0}; | |
wc.lpfnWndProc = WndProc; | |
wc.lpszClassName = L"\x01"; | |
RegisterClass(&wc); | |
CreateWindow(wc.lpszClassName, NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 640, 480, 0, 0, NULL, NULL); | |
while(GetMessage(&msg, NULL, 0, 0 ) > 0) | |
DispatchMessage(&msg); | |
ExitProcess(0); | |
} | |
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ | |
switch(message){ | |
case WM_KEYDOWN: | |
{ | |
BYTE KeyState[256]; | |
GetKeyboardState(KeyState); | |
WORD lpChar = 0; | |
if(ToAscii(wParam, lParam, KeyState, &lpChar, 0) > 0){ | |
DWORD lpNumberOfCharsWritten; | |
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), &lpChar, 1, &lpNumberOfCharsWritten, NULL); | |
} | |
break; | |
} | |
case WM_CLOSE: | |
PostQuitMessage(0); | |
break; | |
default: | |
return DefWindowProc(hWnd, message, wParam, lParam); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment