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
|
// Main.cpp
// cl Main.cpp /O1 /Os /GS- /FeAllocConsole.exe /link TCLib.lib kernel32.lib user32.lib gdi32.lib
// Compiles/links to 4608 byte executable in x64
#include <windows.h>
#include "stdio.h"
#include "AllocateConsole.h"
LRESULT fnWndProc_OnCreate(WndEventArgs& Wea)
{
HWND hButton;
Wea.hIns=((LPCREATESTRUCT)Wea.lParam)->hInstance;
hButton=CreateWindow("button","Execute",WS_CHILD|WS_VISIBLE,70,35,141,30,Wea.hWnd,(HMENU)IDC_BUTTON,Wea.hIns,0);
return 0;
}
LRESULT fnWndProc_OnCommand(WndEventArgs& Wea)
{
HMENU hSysMenu;
unsigned int i;
if(LOWORD(Wea.wParam)==IDC_BUTTON)
{
AllocConsole();
hSysMenu=GetSystemMenu(GetConsoleWindow(),0);
DeleteMenu(hSysMenu,6,MF_BYPOSITION);
for(i=0;i<10;i++)
printf("%u\t%s\n",i,"Some Of The More Wicked Code I've Ever Written!");
}
return 0;
}
LRESULT fnWndProc_OnClose(WndEventArgs& Wea) //This function handles the WM_CLOSE message
{ //sent when the 'x' button is clicked.
if(MessageBox(Wea.hWnd,"Do You Wish To Exit This App?","Exit Check?",MB_YESNO)==IDYES)
{
DestroyWindow(Wea.hWnd);
PostQuitMessage(WM_QUIT);
}
return 0;
}
LRESULT __stdcall fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
WndEventArgs Wea;
for(size_t i=0; i<dim(EventHandler); i++)
{
if(EventHandler[i].iMsg==msg)
{
Wea.hWnd=hwnd, Wea.lParam=lParam, Wea.wParam=wParam;
return (EventHandler[i].fnPtr)(Wea);
}
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
int __stdcall WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
char szClassName[]="AllocateConsole";
WNDCLASS wc;
MSG messages;
HWND hWnd;
wc.lpszClassName=szClassName; wc.lpfnWndProc=fnWndProc;
wc.style=0, wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=hIns, wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW, wc.cbWndExtra=0;
wc.lpszMenuName=NULL, wc.cbClsExtra=0;
RegisterClass(&wc);
hWnd=CreateWindow(szClassName,"Allocate Console",WS_OVERLAPPEDWINDOW,900,700,300,150,HWND_DESKTOP,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return (int)messages.wParam;
}
|