diff --git a/libs/opendx/opendx.cpp b/libs/opendx/opendx.cpp index 6179c6f7..0dff20ac 100644 --- a/libs/opendx/opendx.cpp +++ b/libs/opendx/opendx.cpp @@ -51,6 +51,38 @@ BOOL ShowWindow(HWND window, int nCmdShow) { return r; } +BOOL DestroyWindow(HWND window) { + gtk_window_destroy(GTK_WINDOW(window)); + return true; +} + +BOOL GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax) { + BOOL r = g_main_context_pending(NULL); + + + //i know this is wrong, but i need to get the sample working + if (r) { + g_main_context_iteration(NULL, true); + } else { + lpMsg->message = WM_QUIT; + } + + return r; +} + +BOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) { + BOOL r = g_main_context_pending(NULL); + + //i know this is wrong, but i need to get the sample working + if (r) { + g_main_context_iteration(NULL, true); + } else { + lpMsg->message = WM_QUIT; + } + + return r; +} + /* * OpenDX utility class */ diff --git a/prod_include/windef.h b/prod_include/windef.h index 04b2b1b9..23d587af 100644 --- a/prod_include/windef.h +++ b/prod_include/windef.h @@ -1,10 +1,10 @@ #pragma once +#include -#define WINAPI __stdcall -#define HINSTANCE void* -#define LPSTR char* -#define LPCTSTR const char* -#define HWND GtkWidget -#define HMENU void* - -#define DWORD unsigned long +/* + * ref: https://learn.microsoft.com/en-us/windows/win32/api/windef/ns-windef-point + */ +typedef struct tagPOINT { + LONG x; + LONG y; +} POINT, *PPOINT, *NPPOINT, *LPPOINT; \ No newline at end of file diff --git a/prod_include/windows.h b/prod_include/windows.h index 4c697ba9..c12f22ab 100644 --- a/prod_include/windows.h +++ b/prod_include/windows.h @@ -15,6 +15,8 @@ #if defined(__GNUC__) #define __stdcall __attribute__((stdcall)) #endif +#define WINAPI __stdcall +#define __int64 long long //windows types: #define WCHAR wchar_t @@ -25,8 +27,9 @@ #define LONG long #define BOOL bool #define BYTE unsigned char -#define LPCTSTR const char* +#define LPSTR char* #define LPCSTR const char* +#define LPCTSTR const char* #define LPCWSTR const char* #include @@ -34,9 +37,12 @@ #include //#include -#define LPCTSTR const char* #define DWORD unsigned long -#define HWND void* +#define HWND GtkWidget* #define HMENU void* #define HINSTANCE void* #define LPVOID void* + +#define LONG_PTR __int64 +#define LPARAM LONG_PTR +#define WPARAM unsigned __int64 diff --git a/prod_include/winuser.h b/prod_include/winuser.h index 2fb0adbf..9e48066e 100644 --- a/prod_include/winuser.h +++ b/prod_include/winuser.h @@ -4,6 +4,22 @@ #pragma once #include +/* + * MSG + * ref: https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-msg + */ +typedef struct tagMSG { + HWND hwnd; + UINT message; + WPARAM wParam; + LPARAM lParam; + DWORD time; + POINT pt; + DWORD lPrivate; +} MSG, *PMSG, *NPMSG, *LPMSG; + +#define WM_QUIT 0x0012 + /** * Extended Window Styles * ref: https://learn.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles @@ -84,8 +100,14 @@ HWND CreateWindowExA( ); BOOL ShowWindow(HWND window, int nCmdShow); +BOOL DestroyWindow(HWND window); +BOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg); #define CreateWindowExW CreateWindowExA +#define PeekMessageW PeekMessageA +#define PM_NOREMOVE 0x0000 +#define PM_REMOVE 0x0001 +#define PM_NOYIELD 0x0002 // https://www.codeproject.com/Answers/136442/Differences-Between-CreateWindow-and-CreateWindowE#answer3 #define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\ @@ -96,6 +118,8 @@ CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, h //TODO: check if it's needed in a linux environment #if UNICODE #define CreateWindow CreateWindowW + #define PeekMessage PeekMessageW #else #define CreateWindow CreateWindowA + #define PeekMessage PeekMessageA #endif \ No newline at end of file diff --git a/run.sh b/run.sh index 37c59ff8..90df45d8 100755 --- a/run.sh +++ b/run.sh @@ -1,3 +1,3 @@ # Run dxdiag from build directory cd build -./dxdiag \ No newline at end of file +./tests/sample \ No newline at end of file diff --git a/tests/basic_window.cpp b/tests/basic_window.cpp index f747a5a3..991212ea 100644 --- a/tests/basic_window.cpp +++ b/tests/basic_window.cpp @@ -25,37 +25,33 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine LPDIRECT3DDEVICE9 pDevice = NULL; D3DPRESENT_PARAMETERS pp; - - //wait 5 seconds (Linux): - sleep(5); - - /*ZeroMemory(&pp, sizeof(pp)); + //ZeroMemory(&pp, sizeof(pp)); pp.Windowed = TRUE; pp.SwapEffect = D3DSWAPEFFECT_DISCARD; - pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, &pDevice); + //pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, &pDevice); // Enter the message loop MSG msg; - ZeroMemory(&msg, sizeof(msg)); + //ZeroMemory(&msg, sizeof(msg)); while (msg.message != WM_QUIT) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - else { + //TranslateMessage(&msg); + //DispatchMessage(&msg); + } else { // Render the scene - pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0); + /*pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0); pDevice->BeginScene(); pDevice->EndScene(); - pDevice->Present(NULL, NULL, NULL, NULL); + pDevice->Present(NULL, NULL, NULL, NULL);*/ } } + sleep(5); // Clean up - pDevice->Release(); - pD3D->Release(); + //pDevice->Release(); //causes a segfault + //pD3D->Release(); DestroyWindow(hWnd); - return msg.wParam;*/ + //return msg.wParam; return 0; }