Advertisement
Guest User

pluh

a guest
Jan 4th, 2025
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.76 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>
  3.  
  4. CALLBACK LRESULT handlePaint(HWND handle, WPARAM wParam, LPARAM lParam) {
  5.     if (!wParam) {
  6.         return DefWindowProcW(handle, WM_PAINT, 0, lParam);
  7.     }
  8.     const unsigned int *epic = (unsigned int *)((long long unsigned int)wParam | ((long long unsigned int)lParam << 32));
  9.     printf("Recieved int from 0x%16X; ", epic);
  10.     printf("recieved int *%u\r\n", *epic);
  11.     return 0;
  12. }
  13.  
  14. CALLBACK LRESULT wcMainLpfnWndProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam) {
  15.     switch (message) {
  16.         default:
  17.             return DefWindowProcW(handle, message, wParam, lParam);
  18.         case WM_DESTROY:
  19.             PostQuitMessage(0);
  20.             return 0;
  21.         case WM_PAINT:
  22.             return handlePaint(handle, wParam, lParam);
  23.     }
  24.     return -418;
  25. }
  26.  
  27. __stdcall DWORD MainThread(PVOID data) {
  28.     const HWND handle = (HWND)data;
  29.     const unsigned int epic = 42069;
  30.     printf("About to post int %u at address 0x%16X\r\n", epic, &epic);
  31.     PostMessageW(handle, WM_PAINT, (WPARAM)&epic, (long long unsigned int)&epic >> 32);
  32.     return 0;
  33. }
  34.  
  35. WINAPI int wWinMain(HINSTANCE h_inst, HINSTANCE h_prev_inst, LPWSTR p_cmd_line, int n_cmd_show) {
  36.     WNDCLASSW wc_main = {
  37.         .lpfnWndProc = wcMainLpfnWndProc,
  38.         .hInstance = h_inst,
  39.         .hCursor = LoadCursorW(NULL, IDC_ARROW),
  40.         .lpszClassName = L"mainwindow"
  41.     };
  42.  
  43.     // Register the class.
  44.     ATOM wc_main_id = RegisterClassW(&wc_main);
  45.     // Cannot continue if class is not registered.
  46.     if (!wc_main_id) {
  47.         return -1;
  48.     }
  49.     // Create the window.
  50.     HWND hwnd_main = CreateWindowExW(
  51.         0,
  52.         // functional parameters
  53.         MAKEINTRESOURCEW(wc_main_id), // class atom
  54.         L"Epic Window Title",         // name
  55.  
  56.         // window style
  57.         WS_OVERLAPPEDWINDOW + WS_VISIBLE,
  58.         //    x              y
  59.         CW_USEDEFAULT, CW_USEDEFAULT,
  60.         //    w              h
  61.         CW_USEDEFAULT, CW_USEDEFAULT,
  62.  
  63.         // additional parameters
  64.         NULL,   // parent
  65.         NULL,   // menu
  66.         h_inst, // h_inst
  67.         NULL    // additional handle
  68.     );
  69.     // Cannot continue without a window handle.
  70.     if (!hwnd_main) {
  71.         return GetLastError();
  72.     }
  73.  
  74.     // Instantiate the main execution thread.
  75.     DWORD main_thread_id;
  76.     HANDLE main_thread_handle = NULL;
  77.     main_thread_handle = CreateThread(
  78.         NULL,           // Security attributes
  79.         5000000,        // Allocated stack size
  80.         MainThread,     // Thread function
  81.         hwnd_main,      // Parameters passed
  82.         0,              // Creation flags
  83.         &main_thread_id // Thread ID
  84.     );
  85.     // Cannot continue without main execution thread.
  86.     if (!main_thread_handle) {
  87.         return GetLastError();
  88.     }
  89.  
  90.     MSG msgCurrent = {0};
  91.     while (GetMessageW(&msgCurrent, hwnd_main, 0, 0) > 0) {
  92.         TranslateMessage(&msgCurrent);
  93.         LRESULT result = DispatchMessageW(&msgCurrent);
  94.         if (FAILED(result)) {
  95.             return result;
  96.         }
  97.     }
  98.  
  99.     DestroyWindow(hwnd_main);
  100.     return msgCurrent.wParam;
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement