Untitled
unknown
c_cpp
a year ago
2.3 kB
4
Indexable
#include <Windows.h> #define Assert(cond) do {if(!(cond)) *(int*)0 = 5;} while(0); int Run = 0; LRESULT CALLBACK WindowProcedure(HWND WindowHandle, UINT Message, WPARAM WParam ,LPARAM LParam) { LRESULT Result = 0; switch (Message) { case WM_CREATE: { OutputDebugString("Window Created\n"); Run = 1; } break; case WM_CLOSE: { OutputDebugString("Window Was closed\n"); Run = 0; } break; default: { Result = DefWindowProc(WindowHandle, Message, WParam, LParam); } } return (Result); } void Win32ReportError(char* ErrorMessage) { char Buffer[1024]; DWORD Error = GetLastError(); char const* Msg = "With Error Code = "; int Index = 0; while(*ErrorMessage) { Buffer[Index++] = *ErrorMessage++; } Buffer[Index++] = ' '; Buffer[Index++] = '|'; Buffer[Index++] = ' '; while(*Msg) { Buffer[Index++] = *Msg; } int ErrorCodeSize = 1; int Copy = Error; while(Copy /= 10) { ErrorCodeSize++; } for(int I = 0; I < ErrorCodeSize; ++I) { Buffer[Index + ErrorCodeSize - I - 1] = Error % 10; Error /= 10; } Buffer[Index + ErrorCodeSize] = 0; OutputDebugString(Buffer); MessageBox(0, Buffer, "Error Happened", MB_OK); Assert(0); } int WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CommandLine, int Shown) { WNDCLASS WindowClass = {}; WindowClass.style = CS_HREDRAW | CS_VREDRAW; WindowClass.lpfnWndProc = WindowProcedure; WindowClass.hInstance = Instance; WindowClass.lpszClassName = "AClass"; if(!RegisterClass(&WindowClass)) { Win32ReportError("Failed to register a Window Class"); } HWND WindowHandle = CreateWindow("AClass", "Bilinear", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 480, 480, 0, 0, Instance, 0); if(!WindowHandle) { Win32ReportError("Could not create Window"); } while(Run) { MSG Message; while(PeekMessage(&Message, WindowHandle, 0, 0, PM_REMOVE)) { DispatchMessage(&Message); } } }
Editor is loading...
Leave a Comment