Skip to content

Commit 555849a

Browse files
committed
merged contents
1 parent 6380022 commit 555849a

File tree

6 files changed

+86
-28
lines changed

6 files changed

+86
-28
lines changed

libs/opendx/opendx.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,38 @@ BOOL ShowWindow(HWND window, int nCmdShow) {
5151
return r;
5252
}
5353

54+
BOOL DestroyWindow(HWND window) {
55+
gtk_window_destroy(GTK_WINDOW(window));
56+
return true;
57+
}
58+
59+
BOOL GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax) {
60+
BOOL r = g_main_context_pending(NULL);
61+
62+
63+
//i know this is wrong, but i need to get the sample working
64+
if (r) {
65+
g_main_context_iteration(NULL, true);
66+
} else {
67+
lpMsg->message = WM_QUIT;
68+
}
69+
70+
return r;
71+
}
72+
73+
BOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) {
74+
BOOL r = g_main_context_pending(NULL);
75+
76+
//i know this is wrong, but i need to get the sample working
77+
if (r) {
78+
g_main_context_iteration(NULL, true);
79+
} else {
80+
lpMsg->message = WM_QUIT;
81+
}
82+
83+
return r;
84+
}
85+
5486
/*
5587
* OpenDX utility class
5688
*/

prod_include/windef.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#pragma once
2+
#include <windows.h>
23

3-
#define WINAPI __stdcall
4-
#define HINSTANCE void*
5-
#define LPSTR char*
6-
#define LPCTSTR const char*
7-
#define HWND GtkWidget
8-
#define HMENU void*
9-
10-
#define DWORD unsigned long
4+
/*
5+
* ref: https://learn.microsoft.com/en-us/windows/win32/api/windef/ns-windef-point
6+
*/
7+
typedef struct tagPOINT {
8+
LONG x;
9+
LONG y;
10+
} POINT, *PPOINT, *NPPOINT, *LPPOINT;

prod_include/windows.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#if defined(__GNUC__)
1616
#define __stdcall __attribute__((stdcall))
1717
#endif
18+
#define WINAPI __stdcall
19+
#define __int64 long long
1820

1921
//windows types:
2022
#define WCHAR wchar_t
@@ -25,18 +27,22 @@
2527
#define LONG long
2628
#define BOOL bool
2729
#define BYTE unsigned char
28-
#define LPCTSTR const char*
30+
#define LPSTR char*
2931
#define LPCSTR const char*
32+
#define LPCTSTR const char*
3033
#define LPCWSTR const char*
3134

3235
#include <stdarg.h>
3336
#include <windef.h>
3437
#include <winnt.h>
3538
//#include <gtk/gtk.h>
3639

37-
#define LPCTSTR const char*
3840
#define DWORD unsigned long
39-
#define HWND void*
41+
#define HWND GtkWidget*
4042
#define HMENU void*
4143
#define HINSTANCE void*
4244
#define LPVOID void*
45+
46+
#define LONG_PTR __int64
47+
#define LPARAM LONG_PTR
48+
#define WPARAM unsigned __int64

prod_include/winuser.h

+24
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
#pragma once
55
#include <windows.h>
66

7+
/*
8+
* MSG
9+
* ref: https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-msg
10+
*/
11+
typedef struct tagMSG {
12+
HWND hwnd;
13+
UINT message;
14+
WPARAM wParam;
15+
LPARAM lParam;
16+
DWORD time;
17+
POINT pt;
18+
DWORD lPrivate;
19+
} MSG, *PMSG, *NPMSG, *LPMSG;
20+
21+
#define WM_QUIT 0x0012
22+
723
/**
824
* Extended Window Styles
925
* ref: https://learn.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles
@@ -84,8 +100,14 @@ HWND CreateWindowExA(
84100
);
85101

86102
BOOL ShowWindow(HWND window, int nCmdShow);
103+
BOOL DestroyWindow(HWND window);
87104

105+
BOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg);
88106
#define CreateWindowExW CreateWindowExA
107+
#define PeekMessageW PeekMessageA
108+
#define PM_NOREMOVE 0x0000
109+
#define PM_REMOVE 0x0001
110+
#define PM_NOYIELD 0x0002
89111

90112
// https://www.codeproject.com/Answers/136442/Differences-Between-CreateWindow-and-CreateWindowE#answer3
91113
#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
96118
//TODO: check if it's needed in a linux environment
97119
#if UNICODE
98120
#define CreateWindow CreateWindowW
121+
#define PeekMessage PeekMessageW
99122
#else
100123
#define CreateWindow CreateWindowA
124+
#define PeekMessage PeekMessageA
101125
#endif

run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Run dxdiag from build directory
22
cd build
3-
./dxdiag
3+
./tests/sample

tests/basic_window.cpp

+12-16
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,33 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
2525
LPDIRECT3DDEVICE9 pDevice = NULL;
2626
D3DPRESENT_PARAMETERS pp;
2727

28-
29-
//wait 5 seconds (Linux):
30-
sleep(5);
31-
32-
/*ZeroMemory(&pp, sizeof(pp));
28+
//ZeroMemory(&pp, sizeof(pp));
3329
pp.Windowed = TRUE;
3430
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
35-
pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, &pDevice);
31+
//pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, &pDevice);
3632

3733
// Enter the message loop
3834
MSG msg;
39-
ZeroMemory(&msg, sizeof(msg));
35+
//ZeroMemory(&msg, sizeof(msg));
4036
while (msg.message != WM_QUIT) {
4137
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
42-
TranslateMessage(&msg);
43-
DispatchMessage(&msg);
44-
}
45-
else {
38+
//TranslateMessage(&msg);
39+
//DispatchMessage(&msg);
40+
} else {
4641
// Render the scene
47-
pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
42+
/*pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
4843
pDevice->BeginScene();
4944
pDevice->EndScene();
50-
pDevice->Present(NULL, NULL, NULL, NULL);
45+
pDevice->Present(NULL, NULL, NULL, NULL);*/
5146
}
5247
}
5348

49+
sleep(5);
5450
// Clean up
55-
pDevice->Release();
56-
pD3D->Release();
51+
//pDevice->Release(); //causes a segfault
52+
//pD3D->Release();
5753
DestroyWindow(hWnd);
58-
return msg.wParam;*/
54+
//return msg.wParam;
5955

6056
return 0;
6157
}

0 commit comments

Comments
 (0)