Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #define local_function static
- #define local_persist static
- #define global_variable static
- global_variable bool running = true;
- global_variable BITMAPINFO BitmapInfo;
- global_variable void *BitmapMemory;
- global_variable HBITMAP BitmapHandle;
- global_variable HDC BitmapDeviceContext;
- local_function void ResizeDIBSection(int width, int height) {
- if (BitmapHandle) {
- DeleteObject(BitmapHandle);
- }
- if (!BitmapDeviceContext) {
- BitmapDeviceContext = CreateCompatibleDC(0);
- }
- BitmapInfo.bmiHeader.biSize = sizeof(BitmapInfo.bmiHeader);
- BitmapInfo.bmiHeader.biWidth = width;
- BitmapInfo.bmiHeader.biHeight = height;
- BitmapInfo.bmiHeader.biPlanes = 1;
- BitmapInfo.bmiHeader.biBitCount = 32;
- BitmapInfo.bmiHeader.biCompression = BI_RGB;
- BitmapHandle = CreateDIBSection(
- BitmapDeviceContext,
- &BitmapInfo,
- DIB_RGB_COLORS,
- &BitmapMemory,
- 0, 0);
- };
- local_function void UpdateMyWindow(HDC DeviceContext, int X, int Y, int Width, int Height) {
- StretchDIBits(
- DeviceContext,
- X, Y, Width, Height,
- X, Y, Width, Height,
- &BitmapMemory,
- &BitmapInfo,
- DIB_RGB_COLORS,
- SRCCOPY
- );
- }
- LRESULT Wndproc(
- HWND Window,
- UINT Message,
- WPARAM unnamedParam3,
- LPARAM unnamedParam4
- )
- {
- switch (Message) {
- case WM_DESTROY:
- running = false;
- break;
- case WM_CLOSE:
- running = false;
- break;
- case WM_SIZE: {
- RECT clientRect;
- GetClientRect(Window, &clientRect);
- int Width = clientRect.right - clientRect.left;
- int Height = clientRect.bottom - clientRect.top;
- ResizeDIBSection(Width, Height);
- }
- break;
- case WM_PAINT:
- {
- PAINTSTRUCT Paint;
- HDC DeviceContext = BeginPaint(Window, &Paint);
- int X = Paint.rcPaint.left;
- int Y = Paint.rcPaint.top;
- int Width = Paint.rcPaint.right - Paint.rcPaint.left;
- int Height = Paint.rcPaint.bottom - Paint.rcPaint.top;
- UpdateMyWindow(DeviceContext, X, Y, Width, Height);
- EndPaint(Window, &Paint);
- };
- break;
- default:
- return DefWindowProcA(Window, Message, unnamedParam3, unnamedParam4);
- break;
- }
- }
- int WINAPI WinMain(
- HINSTANCE Instance,
- HINSTANCE PrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow
- ) {
- WNDCLASSEXA windowClass = {};
- windowClass.cbSize = sizeof(WNDCLASSEXA);
- windowClass.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
- windowClass.lpfnWndProc = Wndproc;
- windowClass.hInstance = Instance;
- windowClass.lpszClassName = "Game";
- if (RegisterClassExA(&windowClass)) {
- HWND windowHandle = CreateWindowExA(
- 0,
- windowClass.lpszClassName,
- "My Window",
- WS_OVERLAPPEDWINDOW|WS_VISIBLE,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 0,
- 0,
- Instance,
- 0
- );
- if (windowHandle) {
- MSG Message;
- while (running) {
- BOOL messageResult = GetMessage(&Message, 0, 0, 0);
- if (messageResult > 0) {
- TranslateMessage(&Message);
- DispatchMessageA(&Message);
- }
- else {
- //In here the Data saving and everything else is handled.
- break;
- }
- }
- }
- else {
- MessageBoxA(0, "windowHandle failure", "Bruh", 0);
- //Add error handling;
- }
- }
- else {
- //Error Handling
- MessageBoxA(0, "RegisterClass failure", "Bruh", 0);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment