mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
Implemented "CreateWindow"
This commit is contained in:
parent
e9ce3f02d8
commit
9daf7764ef
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -2,5 +2,9 @@
|
|||||||
"mesonbuild.configureOnOpen": true,
|
"mesonbuild.configureOnOpen": true,
|
||||||
"C_Cpp.codeAnalysis.clangTidy.checks.disabled": [
|
"C_Cpp.codeAnalysis.clangTidy.checks.disabled": [
|
||||||
"clang-diagnostic-pragma-once-outside-header"
|
"clang-diagnostic-pragma-once-outside-header"
|
||||||
]
|
],
|
||||||
|
"files.associations": {
|
||||||
|
"phtml": "php",
|
||||||
|
"new": "cpp"
|
||||||
|
}
|
||||||
}
|
}
|
@ -43,9 +43,17 @@ include_directories(./prod_include)
|
|||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
#libdsetup.so:
|
#dependency
|
||||||
|
include_directories(${GTK4_INCLUDE_DIRS})
|
||||||
|
link_directories(${GTK4_LIBRARY_DIRS})
|
||||||
|
|
||||||
#resolve wildcards and add "dsetup.cpp" as the first of the list
|
#libopendx.so:
|
||||||
|
set(OPENDX_CPP libs/opendx/opendx.cpp)
|
||||||
|
#file(GLOB_RECURSE OPENDX_CPP libs/opendx/fun/*.cpp)
|
||||||
|
add_library(opendx SHARED ${OPENDX_CPP})
|
||||||
|
target_link_libraries(opendx ${GTK4_LIBRARIES})
|
||||||
|
|
||||||
|
#libdsetup.so:
|
||||||
set(DSETUP_CPP libs/dsetup/dsetup.cpp)
|
set(DSETUP_CPP libs/dsetup/dsetup.cpp)
|
||||||
file(GLOB_RECURSE DSETUP_CPP libs/dsetup/fun/*.cpp)
|
file(GLOB_RECURSE DSETUP_CPP libs/dsetup/fun/*.cpp)
|
||||||
|
|
||||||
@ -57,10 +65,6 @@ add_library(d3d9 SHARED libs/d3d9/d3d9.cpp)
|
|||||||
#dxdiag:
|
#dxdiag:
|
||||||
pkg_check_modules(GTK4 REQUIRED gtk4)
|
pkg_check_modules(GTK4 REQUIRED gtk4)
|
||||||
|
|
||||||
|
|
||||||
include_directories(${GTK4_INCLUDE_DIRS})
|
|
||||||
link_directories(${GTK4_LIBRARY_DIRS})
|
|
||||||
|
|
||||||
add_executable(dxdiag tools/dxdiag/main.cpp)
|
add_executable(dxdiag tools/dxdiag/main.cpp)
|
||||||
target_link_libraries(dxdiag ${GTK4_LIBRARIES})
|
target_link_libraries(dxdiag ${GTK4_LIBRARIES})
|
||||||
target_link_libraries(dxdiag dsetup)
|
target_link_libraries(dxdiag dsetup)
|
||||||
|
@ -1 +1,2 @@
|
|||||||
|
#pragma onnce
|
||||||
#include "fun/DirectXSetupGetVersion.hpp"
|
#include "fun/DirectXSetupGetVersion.hpp"
|
@ -1,3 +1,4 @@
|
|||||||
|
#pragma onnce
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1 +1,86 @@
|
|||||||
|
#include <windows.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <winuser.h>
|
||||||
|
#include <opendx.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a Window
|
||||||
|
*
|
||||||
|
* @return HWND
|
||||||
|
*/
|
||||||
|
HWND CreateWindowExA(
|
||||||
|
DWORD extStyle,
|
||||||
|
LPCSTR className, //optional
|
||||||
|
LPCSTR title, //optional
|
||||||
|
DWORD style,
|
||||||
|
int x, //ignored. It's the user responsability to set the window position. (GTK4)
|
||||||
|
int y, //ignored. It's the user responsability to set the window position. (GTK4)
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
HWND parent, //optional
|
||||||
|
HMENU menu, //optional
|
||||||
|
HINSTANCE instance, //optional (Windows ignores it)
|
||||||
|
LPVOID param //optional
|
||||||
|
) {
|
||||||
|
GtkWidget* window = gtk_window_new();
|
||||||
|
|
||||||
|
if (title != nullptr) {
|
||||||
|
gtk_window_set_title(GTK_WINDOW(window), title);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
|
||||||
|
|
||||||
|
//style:
|
||||||
|
// TODO: Complete the list
|
||||||
|
if (!(style & WS_CAPTION)) {
|
||||||
|
gtk_window_set_title(GTK_WINDOW(window), "");
|
||||||
|
}
|
||||||
|
if (!(style & WS_SYSMENU)) {
|
||||||
|
gtk_window_set_deletable(GTK_WINDOW(window), false);
|
||||||
|
}
|
||||||
|
if (style & WS_VISIBLE) {
|
||||||
|
gtk_widget_show(GTK_WIDGET(window));
|
||||||
|
}
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL ShowWindow(HWND window, int nCmdShow) {
|
||||||
|
BOOL r = gtk_widget_get_visible(GTK_WIDGET(window));
|
||||||
|
gtk_widget_show(GTK_WIDGET(window));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* OpenDX utility class
|
||||||
|
*/
|
||||||
|
OpenDX::OpenDX(int argc, char* argv[], int (*WinMain)(HINSTANCE, HINSTANCE, LPSTR, int)) {
|
||||||
|
//Converts argc and argv to WinMain params
|
||||||
|
char* cmdline = (char*) malloc(sizeof(char));
|
||||||
|
cmdline[0] = '\0';
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; i++) {
|
||||||
|
cmdline = (char*) realloc(cmdline, strlen(cmdline) + strlen(argv[i]) + 2);
|
||||||
|
strcat(cmdline, argv[i]);
|
||||||
|
if (i < argc - 1) {
|
||||||
|
strcat(cmdline, " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_init();
|
||||||
|
if (WinMain != nullptr) {
|
||||||
|
winMain_r = (*WinMain)(nullptr,nullptr,cmdline,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenDX::OpenDX(int (*WinMain)(HINSTANCE, HINSTANCE, LPSTR, int)) {
|
||||||
|
gtk_init();
|
||||||
|
|
||||||
|
if (WinMain != nullptr) {
|
||||||
|
winMain_r = (*WinMain)(nullptr,nullptr,"",0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int OpenDX::getReturnCode() {
|
||||||
|
return winMain_r;
|
||||||
|
}
|
@ -1 +1,2 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
15
prod_include/opendx.h
Normal file
15
prod_include/opendx.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief OpenDX utility class
|
||||||
|
*/
|
||||||
|
class OpenDX {
|
||||||
|
public:
|
||||||
|
OpenDX(int argc, char* argv[],int (*WinMain)(HINSTANCE, HINSTANCE, LPSTR, int) = nullptr);
|
||||||
|
OpenDX(int (*WinMain)(HINSTANCE, HINSTANCE, LPSTR, int) = nullptr);
|
||||||
|
int getReturnCode();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int winMain_r = 0;
|
||||||
|
};
|
@ -21,10 +21,13 @@
|
|||||||
#define TCHAR char
|
#define TCHAR char
|
||||||
#define UINT unsigned int
|
#define UINT unsigned int
|
||||||
#define ULONG unsigned long
|
#define ULONG unsigned long
|
||||||
#define UlONG_PTR unsigned long
|
#define ULONG_PTR unsigned long
|
||||||
#define LONG long
|
#define LONG long
|
||||||
#define BOOL bool
|
#define BOOL bool
|
||||||
#define BYTE unsigned char
|
#define BYTE unsigned char
|
||||||
|
#define LPCTSTR const char*
|
||||||
|
#define LPCSTR const char*
|
||||||
|
#define LPCWSTR const char*
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <windef.h>
|
#include <windef.h>
|
||||||
|
101
prod_include/winuser.h
Normal file
101
prod_include/winuser.h
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/**
|
||||||
|
* From "libopendx.so"
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extended Window Styles
|
||||||
|
* ref: https://learn.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles
|
||||||
|
*/
|
||||||
|
#define WS_EX_ACCEPTFILES 0x00000010L
|
||||||
|
#define WS_EX_APPWINDOW 0x00040000L
|
||||||
|
#define WS_EX_CLIENTEDGE 0x00000200L
|
||||||
|
#define WS_EX_COMPOSITED 0x02000000L
|
||||||
|
#define WS_EX_CONTEXTHELP 0x00000400L
|
||||||
|
#define WS_EX_CONTROLPARENT 0x00010000L
|
||||||
|
#define WS_EX_DLGMODALFRAME 0x00000001L
|
||||||
|
#define WS_EX_LAYERED 0x00080000
|
||||||
|
#define WS_EX_LAYOUTRTL 0x00400000L
|
||||||
|
#define WS_EX_LEFT 0x00000000L
|
||||||
|
#define WS_EX_LEFTSCROLLBAR 0x00004000L
|
||||||
|
#define WS_EX_LTRREADING 0x00000000L
|
||||||
|
#define WS_EX_MDICHILD 0x00000040L
|
||||||
|
#define WS_EX_NOACTIVATE 0x08000000L
|
||||||
|
#define WS_EX_NOINHERITLAYOUT 0x00100000L
|
||||||
|
#define WS_EX_NOPARENTNOTIFY 0x00000004L
|
||||||
|
#define WS_EX_NOREDIRECTIONBITMAP 0x00200000L
|
||||||
|
#define WS_EX_RIGHT 0x00001000L
|
||||||
|
#define WS_EX_RIGHTSCROLLBAR 0x00000000L
|
||||||
|
#define WS_EX_RTLREADING 0x00002000L
|
||||||
|
#define WS_EX_STATICEDGE 0x00020000L
|
||||||
|
#define WS_EX_TOOLWINDOW 0x00000080L
|
||||||
|
#define WS_EX_TOPMOST 0x00000008L
|
||||||
|
#define WS_EX_TRANSPARENT 0x00000020L
|
||||||
|
#define WS_EX_WINDOWEDGE 0x00000100L
|
||||||
|
#define WS_EX_OVERLAPPEDWINDOW (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE)
|
||||||
|
#define WS_EX_PALETTEWINDOW (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Window Styles
|
||||||
|
* ref: https://learn.microsoft.com/en-us/windows/win32/winmsg/window-styles
|
||||||
|
*/
|
||||||
|
#define WS_BORDER 0x00800000L
|
||||||
|
#define WS_CAPTION 0x00C00000L
|
||||||
|
#define WS_CHILD 0x40000000L
|
||||||
|
#define WS_CHILDWINDOW 0x40000000L
|
||||||
|
#define WS_CLIPCHILDREN 0x02000000L
|
||||||
|
#define WS_CLIPSIBLINGS 0x04000000L
|
||||||
|
#define WS_DISABLED 0x08000000L
|
||||||
|
#define WS_DLGFRAME 0x00400000L
|
||||||
|
#define WS_GROUP 0x00020000L
|
||||||
|
#define WS_HSCROLL 0x00100000L
|
||||||
|
#define WS_ICONIC 0x20000000L
|
||||||
|
#define WS_MAXIMIZE 0x01000000L
|
||||||
|
#define WS_MAXIMIZEBOX 0x00010000L
|
||||||
|
#define WS_MINIMIZE 0x20000000L
|
||||||
|
#define WS_MINIMIZEBOX 0x00020000L
|
||||||
|
#define WS_OVERLAPPED 0x00000000L
|
||||||
|
#define WS_POPUP 0x80000000L
|
||||||
|
#define WS_SIZEBOX 0x00040000L
|
||||||
|
#define WS_SYSMENU 0x00080000L
|
||||||
|
#define WS_TABSTOP 0x00010000L
|
||||||
|
#define WS_THICKFRAME 0x00040000L
|
||||||
|
#define WS_TILED 0x00000000L
|
||||||
|
#define WS_VISIBLE 0x10000000L
|
||||||
|
#define WS_VSCROLL 0x00200000L
|
||||||
|
#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
|
||||||
|
#define WS_POPUPWINDOW (WS_POPUP | WS_BORDER | WS_SYSMENU)
|
||||||
|
#define WS_TILEDWINDOW (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
|
||||||
|
|
||||||
|
HWND CreateWindowExA(
|
||||||
|
DWORD extStyle,
|
||||||
|
LPCSTR className, //optional
|
||||||
|
LPCSTR title, //optional
|
||||||
|
DWORD style,
|
||||||
|
int x, //ignored. It's the user responsability to set the window position. (GTK4)
|
||||||
|
int y, //ignored. It's the user responsability to set the window position. (GTK4)
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
HWND parent, //optional
|
||||||
|
HMENU menu, //optional
|
||||||
|
HINSTANCE instance, //optional (Windows ignores it)
|
||||||
|
LPVOID param //optional
|
||||||
|
);
|
||||||
|
|
||||||
|
BOOL ShowWindow(HWND window, int nCmdShow);
|
||||||
|
|
||||||
|
#define CreateWindowExW CreateWindowExA
|
||||||
|
|
||||||
|
// 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)\
|
||||||
|
CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
|
||||||
|
#define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
|
||||||
|
CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
|
||||||
|
|
||||||
|
//TODO: check if it's needed in a linux environment
|
||||||
|
#if UNICODE
|
||||||
|
#define CreateWindow CreateWindowW
|
||||||
|
#else
|
||||||
|
#define CreateWindow CreateWindowA
|
||||||
|
#endif
|
@ -8,5 +8,5 @@ include_directories(${GTK4_INCLUDE_DIRS})
|
|||||||
link_directories(${GTK4_LIBRARY_DIRS})
|
link_directories(${GTK4_LIBRARY_DIRS})
|
||||||
|
|
||||||
add_executable(sample basic_window.cpp)
|
add_executable(sample basic_window.cpp)
|
||||||
target_link_libraries(sample ${GTK4_LIBRARIES})
|
target_link_libraries(sample opendx)
|
||||||
target_link_libraries(sample d3d9)
|
target_link_libraries(sample d3d9)
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
*
|
*
|
||||||
* Code that doesn't work is also commented.
|
* Code that doesn't work is also commented.
|
||||||
*/
|
*/
|
||||||
|
#include <opendx.h>
|
||||||
|
#include <winuser.h>
|
||||||
#include <d3d9.h>
|
#include <d3d9.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -12,12 +14,21 @@
|
|||||||
|
|
||||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
|
||||||
// Create the window
|
// Create the window
|
||||||
//HWND hWnd = CreateWindow("DX9 Window", "DX9 Window", 0, 0, 0, 640, 480, NULL, NULL, hInstance, NULL);
|
HWND hWnd = CreateWindow(
|
||||||
|
"DX9 Window", "DX9 Window",
|
||||||
|
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||||
|
0, 0, 640, 480, NULL, NULL, hInstance, NULL
|
||||||
|
);
|
||||||
|
|
||||||
// Create the Direct3D device
|
// Create the Direct3D device
|
||||||
LPDIRECT3D9 pD3D = Direct3DCreate9(D3D_SDK_VERSION);
|
LPDIRECT3D9 pD3D = Direct3DCreate9(D3D_SDK_VERSION);
|
||||||
LPDIRECT3DDEVICE9 pDevice = NULL;
|
LPDIRECT3DDEVICE9 pDevice = NULL;
|
||||||
D3DPRESENT_PARAMETERS pp;
|
D3DPRESENT_PARAMETERS pp;
|
||||||
|
|
||||||
|
|
||||||
|
//wait 5 seconds (Linux):
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
/*ZeroMemory(&pp, sizeof(pp));
|
/*ZeroMemory(&pp, sizeof(pp));
|
||||||
pp.Windowed = TRUE;
|
pp.Windowed = TRUE;
|
||||||
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||||
@ -49,18 +60,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Linux's main
|
//Linux's main or MinGW's main:
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
char* cmdline = (char*) malloc(sizeof(char));
|
//OpenDX transforms argc and argv to WinMain params
|
||||||
cmdline[0] = '\0';
|
//then calls WinMain. You can also initialize OpenDX
|
||||||
|
//without params and insert your code right here if
|
||||||
|
//you are using MinGW.
|
||||||
|
OpenDX odx(argc, argv,WinMain); //or OpenDX odx();
|
||||||
|
|
||||||
for (int i = 0; i < argc; i++) {
|
return odx.getReturnCode(); // 0 if WinMain is not passed.
|
||||||
cmdline = (char*) realloc(cmdline, strlen(cmdline) + strlen(argv[i]) + 2);
|
|
||||||
strcat(cmdline, argv[i]);
|
|
||||||
if (i < argc - 1) {
|
|
||||||
strcat(cmdline, " ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return WinMain(nullptr, nullptr, cmdline, 0);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user