Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- CALLBACK LRESULT handlePaint(HWND handle, WPARAM wParam, LPARAM lParam) {
- if (!wParam) {
- return DefWindowProcW(handle, WM_PAINT, 0, lParam);
- }
- const unsigned int *epic = (unsigned int *)((long long unsigned int)wParam | ((long long unsigned int)lParam << 32));
- printf("Recieved int from 0x%16X; ", epic);
- printf("recieved int *%u\r\n", *epic);
- return 0;
- }
- CALLBACK LRESULT wcMainLpfnWndProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam) {
- switch (message) {
- default:
- return DefWindowProcW(handle, message, wParam, lParam);
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- case WM_PAINT:
- return handlePaint(handle, wParam, lParam);
- }
- return -418;
- }
- __stdcall DWORD MainThread(PVOID data) {
- const HWND handle = (HWND)data;
- const unsigned int epic = 42069;
- printf("About to post int %u at address 0x%16X\r\n", epic, &epic);
- PostMessageW(handle, WM_PAINT, (WPARAM)&epic, (long long unsigned int)&epic >> 32);
- return 0;
- }
- WINAPI int wWinMain(HINSTANCE h_inst, HINSTANCE h_prev_inst, LPWSTR p_cmd_line, int n_cmd_show) {
- WNDCLASSW wc_main = {
- .lpfnWndProc = wcMainLpfnWndProc,
- .hInstance = h_inst,
- .hCursor = LoadCursorW(NULL, IDC_ARROW),
- .lpszClassName = L"mainwindow"
- };
- // Register the class.
- ATOM wc_main_id = RegisterClassW(&wc_main);
- // Cannot continue if class is not registered.
- if (!wc_main_id) {
- return -1;
- }
- // Create the window.
- HWND hwnd_main = CreateWindowExW(
- 0,
- // functional parameters
- MAKEINTRESOURCEW(wc_main_id), // class atom
- L"Epic Window Title", // name
- // window style
- WS_OVERLAPPEDWINDOW + WS_VISIBLE,
- // x y
- CW_USEDEFAULT, CW_USEDEFAULT,
- // w h
- CW_USEDEFAULT, CW_USEDEFAULT,
- // additional parameters
- NULL, // parent
- NULL, // menu
- h_inst, // h_inst
- NULL // additional handle
- );
- // Cannot continue without a window handle.
- if (!hwnd_main) {
- return GetLastError();
- }
- // Instantiate the main execution thread.
- DWORD main_thread_id;
- HANDLE main_thread_handle = NULL;
- main_thread_handle = CreateThread(
- NULL, // Security attributes
- 5000000, // Allocated stack size
- MainThread, // Thread function
- hwnd_main, // Parameters passed
- 0, // Creation flags
- &main_thread_id // Thread ID
- );
- // Cannot continue without main execution thread.
- if (!main_thread_handle) {
- return GetLastError();
- }
- MSG msgCurrent = {0};
- while (GetMessageW(&msgCurrent, hwnd_main, 0, 0) > 0) {
- TranslateMessage(&msgCurrent);
- LRESULT result = DispatchMessageW(&msgCurrent);
- if (FAILED(result)) {
- return result;
- }
- }
- DestroyWindow(hwnd_main);
- return msgCurrent.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement