170 lines
7.4 KiB
C
170 lines
7.4 KiB
C
#if !defined(DN_Os_W32_H)
|
|
#define DN_Os_W32_H
|
|
|
|
#if defined(_CLANGD)
|
|
#define DN_H_WITH_OS 1
|
|
#include "../dn.h"
|
|
#include "dn_os_windows.h"
|
|
#endif
|
|
|
|
typedef enum DN_OsW32DllLoadFunctionsResult
|
|
{
|
|
DN_OsW32DllLoadFunctionsResult_Ok,
|
|
DN_OsW32DllLoadFunctionsResult_LoadLibraryFailed,
|
|
DN_OsW32DllLoadFunctionsResult_FunctionMissing,
|
|
}
|
|
DN_OsW32DllLoadFunctionsResult;
|
|
|
|
typedef struct DN_OsW32DllFunction DN_OsW32DllFunction;
|
|
struct DN_OsW32DllFunction
|
|
{
|
|
DN_Str8 name;
|
|
void *func_ptr;
|
|
};
|
|
|
|
typedef struct DN_OsW32DllCore DN_OsW32DllCore;
|
|
struct DN_OsW32DllCore
|
|
{
|
|
void* handle;
|
|
DN_OsW32DllFunction* functions;
|
|
DN_USize functions_count;
|
|
};
|
|
|
|
typedef struct DN_OsW32Error DN_OsW32Error;
|
|
struct DN_OsW32Error
|
|
{
|
|
unsigned long code;
|
|
DN_Str8 msg;
|
|
};
|
|
|
|
typedef struct DN_OsW32FolderIteratorW DN_OsW32FolderIteratorW;
|
|
struct DN_OsW32FolderIteratorW
|
|
{
|
|
void *handle;
|
|
DN_Str16 file_name;
|
|
wchar_t file_name_buf[512];
|
|
};
|
|
|
|
typedef struct DN_OsW32Window DN_OsW32Window;
|
|
struct DN_OsW32Window
|
|
{
|
|
HWND hwnd;
|
|
// NOTE: For windows with custom title bars, this should be the rect in framebuffer units that
|
|
// when the mouse is down will move the window, or if the mouse is double-clicked then toggle the
|
|
// maximisation of the window. This rect should not include any custom drawn menu buttons so that
|
|
// those buttons can be handled by your application.
|
|
DN_Rect custom_title_bar_rect_that_is_draggable;
|
|
bool custom_title_bar;
|
|
DN_OsW32Window *next;
|
|
};
|
|
|
|
typedef struct DN_OsW32TrayIcon DN_OsW32TrayIcon;
|
|
struct DN_OsW32TrayIcon
|
|
{
|
|
HWND hwnd;
|
|
UINT id;
|
|
UINT callback_message_id;
|
|
UINT taskbar_created_message_id;
|
|
DN_OsTrayIconCallback *callback;
|
|
void *user_data;
|
|
WCHAR tooltip[128];
|
|
bool init;
|
|
};
|
|
|
|
typedef enum DN_OsW32SyncPrimitiveType
|
|
{
|
|
DN_OsW32SyncPrimitiveType_Semaphore,
|
|
DN_OsW32SyncPrimitiveType_Mutex,
|
|
DN_OsW32SyncPrimitiveType_ConditionVariable,
|
|
DN_OsW32SyncPrimitiveType_Barrier,
|
|
}
|
|
DN_OsW32SyncPrimitiveType;
|
|
|
|
typedef struct DN_OsW32SyncPrimitive DN_OsW32SyncPrimitive;
|
|
struct DN_OsW32SyncPrimitive
|
|
{
|
|
union
|
|
{
|
|
void *sem;
|
|
CRITICAL_SECTION mutex;
|
|
CONDITION_VARIABLE cv;
|
|
SYNCHRONIZATION_BARRIER barrier;
|
|
};
|
|
|
|
DN_OsW32SyncPrimitive *next;
|
|
};
|
|
|
|
typedef HRESULT DN_OsW32SetThreadDescriptionFunc (HANDLE hThread, PWSTR const lpThreadDescription);
|
|
typedef BOOL DN_OsW32SetProcessDpiAwarenessContextFunc(void* value);
|
|
typedef UINT DN_OsW32GetDpiForWindowFunc (HWND hwnd);
|
|
typedef HRESULT DN_OsW32GetDpiForMonitorFunc (HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT *dpiX, UINT *dpiY);
|
|
typedef int DN_OsW32GetSystemMetricsForDpiFunc (int nIndex, UINT dpi);
|
|
|
|
#define DN_OsW32DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((void*)-4)
|
|
typedef struct DN_OsW32Core DN_OsW32Core;
|
|
struct DN_OsW32Core
|
|
{
|
|
// NOTE: These functions are dynamically loaded because they might not be present on the user's
|
|
// machine. For example the GetDpiForWindow is Windows 10+ only.
|
|
DN_OsW32SetThreadDescriptionFunc *set_thread_description;
|
|
DN_OsW32GetDpiForWindowFunc *get_dpi_for_window;
|
|
DN_OsW32GetDpiForMonitorFunc *get_dpi_for_monitor;
|
|
DN_OsW32GetSystemMetricsForDpiFunc *get_system_metrics_for_dpi;
|
|
|
|
LARGE_INTEGER qpc_frequency;
|
|
void* bcrypt_rng_handle;
|
|
bool bcrypt_init_success;
|
|
bool sym_initialised;
|
|
CRITICAL_SECTION sync_primitive_free_list_mutex;
|
|
DN_OsW32SyncPrimitive* sync_primitive_free_list;
|
|
|
|
DN_OsW32Window* windows;
|
|
WNDPROC fallback_wnd_proc;
|
|
DN_OsW32TrayIcon tray_icon;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// NOTE: DN Win32 book-keeping
|
|
DN_API void DN_Os_W32Init (DN_OsW32Core *w32);
|
|
DN_API DN_OsW32Core* DN_Os_W32GetCore ();
|
|
DN_API DN_OsW32Window* DN_Os_W32WindowFromHwndMaybeAlloc(DN_OsW32Core *w32, HWND hwnd, DN_Arena *arena);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// NOTE: Process management
|
|
DN_API void DN_Os_W32ThreadSetName (DN_Str8 name);
|
|
DN_API LRESULT __stdcall DN_Os_W32WindowProcCustomTitlebarAndTrayIcon(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param);
|
|
DN_API void DN_Os_W32MakeProcessDPIAware ();
|
|
DN_API bool DN_Os_W32TrayIconInit (DN_OsWindow *window, DN_U32 icon_id, DN_U32 callback_message, DN_Str8 tooltip, DN_OsTrayIconCallback *callback, void *user_data);
|
|
DN_API void DN_Os_W32TrayIconDeinit ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// NOTE: DLL
|
|
DN_API void DN_Os_W32DllUnload (DN_OsW32DllCore *dll);
|
|
DN_API DN_OsW32DllLoadFunctionsResult DN_Os_W32DllLoadFunctions (DN_OsW32DllCore *dll, DN_Str8 dll_path);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// NOTE: Errors
|
|
DN_API DN_Str16 DN_Os_W32Str16FromErrorCodeToMessageAlloc(DN_U32 error_code);
|
|
DN_API DN_OsW32Error DN_Os_W32ErrorFromErrorCodeAllocator (DN_Allocator allocator, DN_U32 error_code);
|
|
DN_API DN_OsW32Error DN_Os_W32ErrorFromLastErrorAllocator (DN_Allocator allocator);
|
|
DN_API DN_OsW32Error DN_Os_W32ErrorFromLastErrorArena (DN_Arena *arena);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// NOTE: Windows Str8 <-> Str16
|
|
DN_API int DN_Os_W32Str16FromStr8Buffer (DN_Str8 src, wchar_t *dest, int dest_size);
|
|
DN_API DN_Str16 DN_Os_W32Str16FromStr8Allocator (DN_Allocator allocator, DN_Str8 src);
|
|
DN_API DN_Str16 DN_Os_W32Str16FromStr8Arena (DN_Arena *arena, DN_Str8 src);
|
|
DN_API int DN_Os_W32Str8FromStr16Buffer (DN_Str16 src, char *dest, int dest_size);
|
|
DN_API DN_Str8 DN_Os_W32Str8FromStr16Heap (DN_Str16 src);
|
|
DN_API DN_Str8 DN_Os_W32Str8FromStr16Allocator (DN_Allocator allocator, DN_Str16 src);
|
|
DN_API DN_Str8 DN_Os_W32Str8FromStr16Arena (DN_Arena *arena, DN_Str16 src);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// NOTE: Path navigation
|
|
DN_API DN_Str16 DN_Os_W32ExePathW (DN_Arena *arena);
|
|
DN_API DN_Str16 DN_Os_W32ExeDirW (DN_Arena *arena);
|
|
DN_API DN_Str8 DN_Os_W32WorkingDir (DN_Arena *arena, DN_Str8 suffix);
|
|
DN_API DN_Str16 DN_Os_W32WorkingDirW (DN_Arena *arena, DN_Str16 suffix);
|
|
DN_API bool DN_Os_W32DirWIterate (DN_Str16 path, DN_OsW32FolderIteratorW *it);
|
|
#endif // !defined(DN_Os_W32_H)
|