Get latest tely changes, w/ new OS primitives from internal project

This commit is contained in:
2026-09-29 22:28:31 +10:00
parent e9c25bae9c
commit d85b66d1da
9 changed files with 4631 additions and 2045 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+184
View File
@@ -1057,6 +1057,36 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
return result; return result;
} }
DN_API void DN_OS_W32Init(DN_OSW32Core *w32)
{
InitializeCriticalSection(&w32->sync_primitive_free_list_mutex);
QueryPerformanceFrequency(&w32->qpc_frequency);
// NOTE: DPI
HMODULE user32 = LoadLibraryA("user32.dll");
if (user32) {
w32->get_dpi_for_window = (DN_OSW32GetDpiForWindowFunc* )GetProcAddress(user32, "GetDpiForWindow");
w32->get_dpi_for_monitor = (DN_OSW32GetDpiForMonitorFunc * )GetProcAddress(user32, "GetDpiForMonitor");
w32->get_system_metrics_for_dpi = (DN_OSW32GetSystemMetricsForDpiFunc *)GetProcAddress(user32, "GetSystemMetricsForDpi");
FreeLibrary(user32);
}
// NOTE: SetThreadDesc
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
if (kernel32) {
w32->set_thread_description = DN_Cast(DN_OSW32SetThreadDescriptionFunc *) GetProcAddress(kernel32, "SetThreadDescription");
FreeLibrary(kernel32);
}
// NOTE: win32 bcrypt
wchar_t const BCRYPT_ALGORITHM[] = L"RNG";
long /*NTSTATUS*/ init_status = BCryptOpenAlgorithmProvider(&w32->bcrypt_rng_handle, BCRYPT_ALGORITHM, nullptr /*implementation*/, 0 /*flags*/);
if (w32->bcrypt_rng_handle && init_status == 0)
w32->bcrypt_init_success = true;
else
DN_LogErrorF("Failed to initialise Windows secure random number generator, error: %d", init_status);
}
DN_API DN_OSW32Core *DN_OS_W32GetCore() DN_API DN_OSW32Core *DN_OS_W32GetCore()
{ {
DN_Core *dn = DN_Get(); DN_Core *dn = DN_Get();
@@ -1456,6 +1486,160 @@ DN_API void DN_OS_W32ThreadSetName(DN_Str8 name)
DN_TcScratchEnd(&scratch); DN_TcScratchEnd(&scratch);
} }
DN_API DN_OSW32Window* DN_OS_W32WindowFromHwndMaybeAlloc(DN_OSW32Core *w32, HWND hwnd, DN_Arena *arena)
{
DN_OSW32Window *result = nullptr;
for (DN_OSW32Window *check = w32->windows; !result && check; check = check->next) {
if (check->hwnd == hwnd)
result = check;
}
if (!result && arena) {
result = DN_ArenaNewZ(arena, DN_OSW32Window);
if (result) {
result->hwnd = hwnd;
if (w32->windows)
w32->windows->next = result;
result->next = w32->windows;
w32->windows = result;
}
}
return result;
}
DN_API LRESULT __stdcall DN_OS_W32WindowProcCustomTitlebar(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param)
{
DN_OSW32Core *w32 = DN_OS_W32GetCore();
DN_AssertF(w32, "Using this window proc requires that DN's OS layer has been initialised");
LRESULT result = 0;
bool handled = true;
switch (msg) {
// NOTE: Sent when the size and position of a window's client area must be calculated. By
// processing this message, an application can control the content of the window's client area
// when the size or position of the window changes.
case WM_NCCALCSIZE: {
DN_OSW32Window *w32_window = DN_OS_W32WindowFromHwndMaybeAlloc(w32, hwnd, nullptr);
if (w32_window && w32_window->custom_title_bar) {
// NOTE: Code adapted from raddebugger
// https://github.com/EpicGames/raddebugger/blob/7a5a649b89f6a06abdbaee61540468fca9db58f9/src/win32/window_manager/win32_window_manager.c#L668
//
// The goal here is to subtract away the title bar from the window and restore the pixel
// border that native Windows renders windows with. Note that on Windows 11 a non-maximised
// window has rounded corners which eats into the available client space that is normally
// otherwise eaten into from the native titlebar.
DWORD window_style = GetWindowLongW(hwnd, GWL_STYLE);
bool is_fullscreen = !(window_style & WS_OVERLAPPEDWINDOW);
if (is_fullscreen) {
handled = false;
} else {
DN_UInt dpi = w32->get_dpi_for_window ? w32->get_dpi_for_window(hwnd) : 96;
int frame_x = w32->get_system_metrics_for_dpi ? w32->get_system_metrics_for_dpi(SM_CXFRAME, dpi) : GetSystemMetrics(SM_CXFRAME);
int frame_y = w32->get_system_metrics_for_dpi ? w32->get_system_metrics_for_dpi(SM_CYFRAME, dpi) : GetSystemMetrics(SM_CYFRAME);
int padding = w32->get_system_metrics_for_dpi ? w32->get_system_metrics_for_dpi(SM_CXPADDEDBORDER, dpi) : GetSystemMetrics(SM_CXPADDEDBORDER);
RECT *rect = w_param == 0 ? DN_Cast(RECT *)l_param : (DN_Cast(NCCALCSIZE_PARAMS *)l_param)->rgrc;
rect->right -= frame_x + padding;
rect->left += frame_x + padding;
rect->bottom -= frame_y + padding;
bool is_maximised = IsZoomed(hwnd) != 0;
if (is_maximised) {
rect->top += frame_y + padding;
// If we do not do this hidden taskbar can not be unhidden on mouse hover
// Unfortunately it can create an ugly bottom border when maximized...
rect->bottom -= 1;
} else {
int edge_height = w32->get_system_metrics_for_dpi ? w32->get_system_metrics_for_dpi(SM_CYEDGE, dpi) : GetSystemMetrics(SM_CYEDGE);
rect->top += edge_height;
}
}
} else {
handled = false;
}
} break;
// NOTE: Sent to a window in order to determine what part of the window corresponds to a
// particular screen coordinate. This can happen, for example, when the cursor moves, when a
// mouse button is pressed or released, or in response to a call to a function such as
// WindowFromPoint. If the mouse is not captured, the message is sent to the window beneath
// the cursor. Otherwise, the message is sent to the window that has captured the mouse.
case WM_NCHITTEST: {
DN_OSW32Window *w32_window = DN_OS_W32WindowFromHwndMaybeAlloc(w32, hwnd, nullptr);
if (w32_window && w32_window->custom_title_bar) {
// NOTE: Code adapted from raddebugger
// https://github.com/EpicGames/raddebugger/blob/7a5a649b89f6a06abdbaee61540468fca9db58f9/src/win32/window_manager/win32_window_manager.c#L668
//
// Since we removed the titlebar from the window, the resize handlers/grabbers at the top of
// the window are no longer functional. We have to reimplement it ourselves.
DWORD window_style = GetWindowLongW(hwnd, GWL_STYLE);
bool is_fullscreen = !(window_style & WS_OVERLAPPEDWINDOW);
handled = false;
if (!is_fullscreen) {
// Let the default procedure handle resizing areas
if (w32->fallback_wnd_proc)
result = CallWindowProcW(w32->fallback_wnd_proc, hwnd, msg, w_param, l_param);
else
result = DefWindowProcW(hwnd, msg, w_param, l_param);
switch (result) {
case HTNOWHERE:
case HTRIGHT:
case HTLEFT:
case HTTOPLEFT:
case HTTOPRIGHT:
case HTBOTTOMRIGHT:
case HTBOTTOM:
case HTBOTTOMLEFT: {
handled = true;
} break;
}
if (!handled) {
POINT pos_monitor = {};
pos_monitor.x = GET_X_LPARAM(l_param);
pos_monitor.y = GET_Y_LPARAM(l_param);
handled = true;
POINT pos_client = pos_monitor;
ScreenToClient(hwnd, &pos_client);
DN_V2F32 title_bar_min = w32_window->custom_title_bar_rect_that_is_draggable.pos;
DN_V2F32 title_bar_max = title_bar_min + w32_window->custom_title_bar_rect_that_is_draggable.size;
DN_UInt dpi = w32->get_dpi_for_window ? w32->get_dpi_for_window(hwnd) : 96;
int frame_y = w32->get_system_metrics_for_dpi ? w32->get_system_metrics_for_dpi(SM_CYFRAME, dpi) : GetSystemMetrics(SM_CYFRAME);
int padding = w32->get_system_metrics_for_dpi ? w32->get_system_metrics_for_dpi(SM_CXPADDEDBORDER, dpi) : GetSystemMetrics(SM_CXPADDEDBORDER);
bool is_over_top_resize = pos_client.y >= 0 && pos_client.y < (frame_y + padding);
bool is_over_title_bar = pos_client.x >= title_bar_min.x && pos_client.x < title_bar_max.x &&
pos_client.y >= title_bar_min.y && pos_client.y < title_bar_max.y;
bool is_maximised = IsZoomed(hwnd) != 0;
if (!is_maximised && is_over_top_resize)
result = HTTOP;
else if (is_over_title_bar)
result = HTCAPTION;
else
result = HTCLIENT;
}
}
} else {
handled = false;
}
} break;
default: {
handled = false;
} break;
}
if (!handled) {
if (w32->fallback_wnd_proc) {
result = CallWindowProcW(w32->fallback_wnd_proc, hwnd, msg, w_param, l_param);
} else {
result = DefWindowProcW(hwnd, msg, w_param, l_param);
}
}
return result;
}
DN_API DN_Str16 DN_OS_W32ErrorCodeToMsg16Alloc(DN_U32 error_code) DN_API DN_Str16 DN_OS_W32ErrorCodeToMsg16Alloc(DN_U32 error_code)
{ {
DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
+55 -26
View File
@@ -20,6 +20,18 @@ struct DN_OSW32FolderIteratorW
wchar_t file_name_buf[512]; wchar_t file_name_buf[512];
}; };
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;
};
enum DN_OSW32SyncPrimitiveType enum DN_OSW32SyncPrimitiveType
{ {
DN_OSW32SyncPrimitiveType_Semaphore, DN_OSW32SyncPrimitiveType_Semaphore,
@@ -41,40 +53,57 @@ struct DN_OSW32SyncPrimitive
DN_OSW32SyncPrimitive *next; DN_OSW32SyncPrimitive *next;
}; };
typedef HRESULT DN_OSW32SetThreadDescriptionFunc(HANDLE hThread, PWSTR const lpThreadDescription); 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)
struct DN_OSW32Core struct DN_OSW32Core
{ {
DN_OSW32SetThreadDescriptionFunc *set_thread_description; // NOTE: These functions are dynamically loaded because they might not be present on the user's
LARGE_INTEGER qpc_frequency; // machine. For example the GetDpiForWindow is Windows 10+ only.
void *bcrypt_rng_handle; DN_OSW32SetThreadDescriptionFunc *set_thread_description;
bool bcrypt_init_success; DN_OSW32GetDpiForWindowFunc *get_dpi_for_window;
bool sym_initialised; DN_OSW32GetDpiForMonitorFunc *get_dpi_for_monitor;
DN_OSW32GetSystemMetricsForDpiFunc *get_system_metrics_for_dpi;
CRITICAL_SECTION sync_primitive_free_list_mutex; LARGE_INTEGER qpc_frequency;
DN_OSW32SyncPrimitive *sync_primitive_free_list; 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_API DN_OSW32Core* DN_OS_W32GetCore (); DN_API void DN_OS_W32Init (DN_OSW32Core *w32);
DN_API void DN_OS_W32ThreadSetName (DN_Str8 name); DN_API DN_OSW32Core* DN_OS_W32GetCore ();
DN_API void DN_OS_W32ThreadSetName (DN_Str8 name);
DN_API DN_OSW32Window* DN_OS_W32WindowFromHwndMaybeAlloc(DN_OSW32Core *w32, HWND hwnd, DN_Arena *arena);
DN_API LRESULT __stdcall DN_OS_W32WindowProcCustomTitlebar(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param);
DN_API DN_Str16 DN_OS_W32ErrorCodeToMsg16Alloc(DN_U32 error_code); DN_API DN_Str16 DN_OS_W32ErrorCodeToMsg16Alloc(DN_U32 error_code);
DN_API DN_OSW32Error DN_OS_W32ErrorCodeToMsg (DN_Arena *arena, DN_U32 error_code); DN_API DN_OSW32Error DN_OS_W32ErrorCodeToMsg (DN_Arena *arena, DN_U32 error_code);
DN_API DN_OSW32Error DN_OS_W32ErrorCodeToMsgAlloc (DN_U32 error_code); DN_API DN_OSW32Error DN_OS_W32ErrorCodeToMsgAlloc (DN_U32 error_code);
DN_API DN_OSW32Error DN_OS_W32LastError (DN_Arena *arena); DN_API DN_OSW32Error DN_OS_W32LastError (DN_Arena *arena);
DN_API DN_OSW32Error DN_OS_W32LastErrorAlloc (); DN_API DN_OSW32Error DN_OS_W32LastErrorAlloc ();
DN_API void DN_OS_W32MakeProcessDPIAware (); DN_API void DN_OS_W32MakeProcessDPIAware ();
// NOTE: Windows Str8 <-> Str16 // NOTE: Windows Str8 <-> Str16
DN_API DN_Str16 DN_OS_W32Str8ToStr16 (DN_Arena *arena, DN_Str8 src); DN_API DN_Str16 DN_OS_W32Str8ToStr16 (DN_Arena *arena, DN_Str8 src);
DN_API int DN_OS_W32Str8ToStr16Buffer (DN_Str16 src, char *dest, int dest_size); DN_API int DN_OS_W32Str8ToStr16Buffer (DN_Str16 src, char *dest, int dest_size);
DN_API DN_Str8 DN_OS_W32Str16ToStr8 (DN_Arena *arena, DN_Str16 src); DN_API DN_Str8 DN_OS_W32Str16ToStr8 (DN_Arena *arena, DN_Str16 src);
DN_API int DN_OS_W32Str16ToStr8Buffer (DN_Str16 src, char *dest, int dest_size); DN_API int DN_OS_W32Str16ToStr8Buffer (DN_Str16 src, char *dest, int dest_size);
DN_API DN_Str8 DN_OS_W32Str16ToStr8FromHeap (DN_Str16 src); DN_API DN_Str8 DN_OS_W32Str16ToStr8FromHeap (DN_Str16 src);
// NOTE: Path navigation // NOTE: Path navigation
DN_API DN_Str16 DN_OS_W32EXEPathW (DN_Arena *arena); DN_API DN_Str16 DN_OS_W32EXEPathW (DN_Arena *arena);
DN_API DN_Str16 DN_OS_W32EXEDirW (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_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 DN_Str16 DN_OS_W32WorkingDirW (DN_Arena *arena, DN_Str16 suffix);
DN_API bool DN_OS_W32DirWIterate (DN_Str16 path, DN_OSW32FolderIteratorW *it); DN_API bool DN_OS_W32DirWIterate (DN_Str16 path, DN_OSW32FolderIteratorW *it);
#endif // !defined(DN_OS_W32_H) #endif // !defined(DN_OS_W32_H)
+187 -22
View File
@@ -13,19 +13,27 @@
#pragma comment(lib, "pathcch") #pragma comment(lib, "pathcch")
#pragma comment(lib, "Shell32") // ShellExecuteW #pragma comment(lib, "Shell32") // ShellExecuteW
#pragma comment(lib, "shlwapi") #pragma comment(lib, "shlwapi")
#pragma comment(lib, "user32")
// TODO: Technically we only need this library for custom window titlebars to get access to DWM
// functions. Otherwise this API surface is not used in the DN OS layer.
#pragma comment(lib, "dwmapi")
#endif #endif
#if defined(DN_NO_WINDOWS_H_REPLACEMENT_HEADER) || defined(_INC_WINDOWS) #if defined(DN_NO_WINDOWS_H_REPLACEMENT_HEADER) || defined(_INC_WINDOWS)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> // LONG #include <Windows.h> // LONG
#include <bcrypt.h> // DN_OS_SecureRNGBytes -> BCryptOpenAlgorithmProvider ... etc #include <dwmapi.h> // DwmExtendFrameIntoClientArea...
#include <shellapi.h> // DN_Win_MakeProcessDPIAware -> SetProcessDpiAwareProc #include <bcrypt.h> // DN_OS_SecureRNGBytes -> BCryptOpenAlgorithmProvider ... etc
#include <shlwapi.h> // PathRelativePathTO #include <shellapi.h> // DN_Win_MakeProcessDPIAware -> SetProcessDpiAwareProc
#include <pathcch.h> // PathCchCanonicalizeEx #include <ShellScalingApi.h> // MONITOR_DPI_TYPE
#include <winhttp.h> // WinHttp* #include <shlwapi.h> // PathRelativePathTO
#include <psapi.h> // PROCESS_MEMORY_COUNTERS_EX2 #include <pathcch.h> // PathCchCanonicalizeEx
#include <commdlg.h> // OPENFILENAMEW #include <winhttp.h> // WinHttp*
#include <psapi.h> // PROCESS_MEMORY_COUNTERS_EX2
#include <commdlg.h> // OPENFILENAMEW
#include <DbgHelp.h> #include <DbgHelp.h>
#include <windowsx.h> // GET_X_PARAM
#else #else
DN_MSVC_WARNING_PUSH DN_MSVC_WARNING_PUSH
DN_MSVC_WARNING_DISABLE(4201) // warning C4201: nonstandard extension used: nameless struct/union DN_MSVC_WARNING_DISABLE(4201) // warning C4201: nonstandard extension used: nameless struct/union
@@ -57,9 +65,10 @@
typedef void * HANDLE; typedef void * HANDLE;
typedef HANDLE HLOCAL; typedef HANDLE HLOCAL;
typedef unsigned __int64 WPARAM; typedef unsigned __int64 WPARAM;
typedef LONG_PTR LPARAM; typedef LONG_PTR LPARAM;
typedef LONG_PTR LRESULT; typedef LONG_PTR LRESULT;
typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
#define MAX_PATH 260 #define MAX_PATH 260
@@ -68,6 +77,11 @@
DWORD dwHighDateTime; DWORD dwHighDateTime;
} FILETIME, *PFILETIME, *LPFILETIME; } FILETIME, *PFILETIME, *LPFILETIME;
#define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff))
#define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
// NOTE: shared/winerror.h ///////////////////////////////////////////////////////////////////// // NOTE: shared/winerror.h /////////////////////////////////////////////////////////////////////
// NOTE: GetModuleFileNameW // NOTE: GetModuleFileNameW
#define ERROR_INSUFFICIENT_BUFFER 122L // dderror #define ERROR_INSUFFICIENT_BUFFER 122L // dderror
@@ -87,6 +101,7 @@
typedef wchar_t WCHAR; // wc, 16-bit UNICODE character typedef wchar_t WCHAR; // wc, 16-bit UNICODE character
typedef CHAR * NPSTR, *LPSTR, *PSTR; typedef CHAR * NPSTR, *LPSTR, *PSTR;
typedef WCHAR * NWPSTR, *LPWSTR, *PWSTR; typedef WCHAR * NWPSTR, *LPWSTR, *PWSTR;
typedef const WCHAR* LPCWSTR, *PCWSTR;
typedef long HRESULT; typedef long HRESULT;
// NOTE: VirtualAlloc: Allocation Type // NOTE: VirtualAlloc: Allocation Type
@@ -372,6 +387,11 @@
LONG y; LONG y;
} POINT, *PPOINT, *NPPOINT, *LPPOINT; } POINT, *PPOINT, *NPPOINT, *LPPOINT;
struct HMONITOR__ {
int unused;
};
typedef struct HMONITOR__ *HMONITOR;
// NOTE: handleapi.h /////////////////////////////////////////////////////////////////////////// // NOTE: handleapi.h ///////////////////////////////////////////////////////////////////////////
#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1) #define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)
@@ -670,7 +690,59 @@
RECT rcDevice; RECT rcDevice;
#endif #endif
} WINDOWPLACEMENT; } WINDOWPLACEMENT;
typedef struct tagWINDOWPOS {
HWND hwnd;
HWND hwndInsertAfter;
int x;
int y;
int cx;
int cy;
UINT flags;
} WINDOWPOS, *LPWINDOWPOS, *PWINDOWPOS;
typedef struct tagNCCALCSIZE_PARAMS {
RECT rgrc[3];
PWINDOWPOS lppos;
} NCCALCSIZE_PARAMS, *LPNCCALCSIZE_PARAMS;
typedef WINDOWPLACEMENT *PWINDOWPLACEMENT, *LPWINDOWPLACEMENT; typedef WINDOWPLACEMENT *PWINDOWPLACEMENT, *LPWINDOWPLACEMENT;
typedef LRESULT (__stdcall* WNDPROC)(HWND, UINT, WPARAM, LPARAM);
#define WM_NCHITTEST 0x0084
#define WS_OVERLAPPED 0x00000000L
#define WS_POPUP 0x80000000L
#define WS_CHILD 0x40000000L
#define WS_MINIMIZE 0x20000000L
#define WS_VISIBLE 0x10000000L
#define WS_DISABLED 0x08000000L
#define WS_CLIPSIBLINGS 0x04000000L
#define WS_CLIPCHILDREN 0x02000000L
#define WS_MAXIMIZE 0x01000000L
#define WS_CAPTION 0x00C00000L /* WS_BORDER | WS_DLGFRAME */
#define WS_BORDER 0x00800000L
#define WS_DLGFRAME 0x00400000L
#define WS_VSCROLL 0x00200000L
#define WS_HSCROLL 0x00100000L
#define WS_SYSMENU 0x00080000L
#define WS_THICKFRAME 0x00040000L
#define WS_GROUP 0x00020000L
#define WS_TABSTOP 0x00010000L
#define WS_MINIMIZEBOX 0x00020000L
#define WS_MAXIMIZEBOX 0x00010000L
#define WS_TILED WS_OVERLAPPED
#define WS_ICONIC WS_MINIMIZE
#define WS_SIZEBOX WS_THICKFRAME
#define WS_TILEDWINDOW WS_OVERLAPPEDWINDOW
#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | \
WS_CAPTION | \
WS_SYSMENU | \
WS_THICKFRAME | \
WS_MINIMIZEBOX | \
WS_MAXIMIZEBOX)
#define SW_HIDE 0 #define SW_HIDE 0
#define SW_NORMAL 1 #define SW_NORMAL 1
@@ -678,22 +750,107 @@
#define SW_MAXIMIZE 3 #define SW_MAXIMIZE 3
#define SW_SHOWNOACTIVATE 4 #define SW_SHOWNOACTIVATE 4
#define SW_SHOW 5 #define SW_SHOW 5
#define SW_MINIMIZE 6
#define SW_RESTORE 9 #define SW_RESTORE 9
#define SW_FORCEMINIMIZE 11 #define SW_FORCEMINIMIZE 11
#define SWP_NOSIZE 0x0001
#define SWP_NOMOVE 0x0002
#define SWP_NOZORDER 0x0004
#define SWP_NOREDRAW 0x0008
#define SWP_NOACTIVATE 0x0010
#define SWP_FRAMECHANGED 0x0020 /* The frame changed: send WM_NCCALCSIZE */
#define SWP_SHOWWINDOW 0x0040
#define SWP_HIDEWINDOW 0x0080
#define SWP_NOCOPYBITS 0x0100
#define SWP_NOOWNERZORDER 0x0200 /* Don't do owner Z ordering */
#define SWP_NOSENDCHANGING 0x0400 /* Don't send WM_WINDOWPOSCHANGING */
#define SWP_DRAWFRAME SWP_FRAMECHANGED
#define SWP_NOREPOSITION SWP_NOOWNERZORDER
#define SM_CXEDGE 45
#define SM_CYEDGE 46
#define SM_CXFRAME 32
#define SM_CYFRAME 33
#define SM_CXPADDEDBORDER 92
#define GWLP_WNDPROC (-4)
#define GWL_STYLE (-16)
#define WS_OVERLAPPED 0x00000000L
#define WM_NCCALCSIZE 0x0083
// WM_NCHITTEST and MOUSEHOOKSTRUCT Mouse Position Codes
#define HTERROR (-2)
#define HTTRANSPARENT (-1)
#define HTNOWHERE 0
#define HTCLIENT 1
#define HTCAPTION 2
#define HTSYSMENU 3
#define HTGROWBOX 4
#define HTSIZE HTGROWBOX
#define HTMENU 5
#define HTHSCROLL 6
#define HTVSCROLL 7
#define HTMINBUTTON 8
#define HTMAXBUTTON 9
#define HTLEFT 10
#define HTRIGHT 11
#define HTTOP 12
#define HTTOPLEFT 13
#define HTTOPRIGHT 14
#define HTBOTTOM 15
#define HTBOTTOMLEFT 16
#define HTBOTTOMRIGHT 17
#define HTBORDER 18
#define HTREDUCE HTMINBUTTON
#define HTZOOM HTMAXBUTTON
#define HTSIZEFIRST HTLEFT
#define HTSIZELAST HTBOTTOMRIGHT
#if(WINVER >= 0x0400)
#define HTOBJECT 19
#define HTCLOSE 20
#define HTHELP 21
#endif /* WINVER >= 0x0400 */
extern "C" extern "C"
{ {
__declspec(dllimport) BOOL __stdcall GetWindowRect (HWND hWnd, RECT *lpRect); __declspec(dllimport) BOOL __stdcall GetWindowRect (HWND hWnd, RECT *lpRect);
__declspec(dllimport) BOOL __stdcall SetWindowPos (HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags); __declspec(dllimport) BOOL __stdcall SetWindowPos (HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags);
__declspec(dllimport) UINT __stdcall GetWindowModuleFileNameA(HWND hwnd, LPSTR pszFileName, UINT cchFileNameMax); __declspec(dllimport) UINT __stdcall GetWindowModuleFileNameA(HWND hwnd, LPSTR pszFileName, UINT cchFileNameMax);
__declspec(dllimport) BOOL __stdcall ShowWindow (HWND hWnd, int nCmdShow); __declspec(dllimport) BOOL __stdcall ShowWindow (HWND hWnd, int nCmdShow);
__declspec(dllimport) BOOL __stdcall GetWindowPlacement (HWND hWnd, WINDOWPLACEMENT *lpwndpl); __declspec(dllimport) BOOL __stdcall GetWindowPlacement (HWND hWnd, WINDOWPLACEMENT *lpwndpl);
__declspec(dllimport) BOOL __stdcall IsIconic (HWND hWnd); __declspec(dllimport) BOOL __stdcall IsIconic (HWND hWnd);
__declspec(dllimport) BOOL __stdcall BringWindowToTop (HWND hWnd); __declspec(dllimport) BOOL __stdcall IsZoomed (HWND hWnd);
__declspec(dllimport) BOOL __stdcall SetForegroundWindow (HWND hWnd); __declspec(dllimport) BOOL __stdcall BringWindowToTop (HWND hWnd);
__declspec(dllimport) HWND __stdcall SetFocus (HWND hWnd); __declspec(dllimport) BOOL __stdcall SetForegroundWindow (HWND hWnd);
__declspec(dllimport) HWND __stdcall GetForegroundWindow (); __declspec(dllimport) HWND __stdcall SetFocus (HWND hWnd);
__declspec(dllimport) BOOL __stdcall SetWindowTextW (HWND hWnd, LPCWSTR lpString); __declspec(dllimport) HWND __stdcall GetForegroundWindow ();
__declspec(dllimport) BOOL __stdcall SetWindowTextW (HWND hWnd, LPCWSTR lpString);
__declspec(dllimport) UINT __stdcall GetDoubleClickTime ();
__declspec(dllimport) LONG_PTR __stdcall GetWindowLongPtrW (HWND hWnd, int nIndex);
__declspec(dllimport) LONG_PTR __stdcall SetWindowLongPtrW (HWND hWnd, int nIndex, LONG_PTR dwNewLong);
__declspec(dllimport) LONG __stdcall GetWindowLongW (HWND hWnd, int nIndex);
__declspec(dllimport) LRESULT __stdcall CallWindowProcW (WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
__declspec(dllimport) int __stdcall GetSystemMetrics (int nIndex);
__declspec(dllimport) BOOL __stdcall ScreenToClient (HWND hWnd, LPPOINT lpPoint);
__declspec(dllimport) LRESULT __stdcall DefWindowProcW (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
}
// NOTE: um/dwmapi.h //////////////////////////////////////////////////////////////////////////
typedef struct _MARGINS
{
int cxLeftWidth; // width of left border that retains its size
int cxRightWidth; // width of right border that retains its size
int cyTopHeight; // height of top border that retains its size
int cyBottomHeight; // height of bottom border that retains its size
} MARGINS, *PMARGINS;
extern "C"
{
__declspec(dllimport) HRESULT __stdcall DwmExtendFrameIntoClientArea(HWND hWnd, const MARGINS* pMarInset);
} }
// NOTE: um/wininet.h ////////////////////////////////////////////////////////////////////////// // NOTE: um/wininet.h //////////////////////////////////////////////////////////////////////////
@@ -1363,6 +1520,14 @@
#define EXCEPTION_CONTINUE_SEARCH 0 #define EXCEPTION_CONTINUE_SEARCH 0
#define EXCEPTION_CONTINUE_EXECUTION (-1) #define EXCEPTION_CONTINUE_EXECUTION (-1)
// NOTE: um/shellscalingapi.h
typedef enum MONITOR_DPI_TYPE {
MDT_EFFECTIVE_DPI = 0,
MDT_ANGULAR_DPI = 1,
MDT_RAW_DPI = 2,
MDT_DEFAULT = MDT_EFFECTIVE_DPI
} MONITOR_DPI_TYPE;
DN_MSVC_WARNING_POP DN_MSVC_WARNING_POP
#endif // !defined(_INC_WINDOWS) #endif // !defined(_INC_WINDOWS)
#endif // !defined(DN_OS_WINDOWS_H) #endif // !defined(DN_OS_WINDOWS_H)
+1 -1
View File
@@ -800,7 +800,7 @@ DN_TestCore DN_SHA3_TestSuite(DN_Arena *arena)
void DN_SHA3_TestSuiteThenOutput(DN_Str8FromTestCoreFlags flags) void DN_SHA3_TestSuiteThenOutput(DN_Str8FromTestCoreFlags flags)
{ {
DN_Arena arena = DN_ArenaFromHeap(DN_Megabytes(1), DN_Kilobytes(64), DN_MemFlags_Nil, DN_OS_HeapInitDefault()); DN_Arena arena = DN_ArenaFromHeap(DN_Megabytes(1), DN_Kilobytes(64), DN_MemFlags_Nil, DN_OS_HeapInitDefault(), "DN SHA3 Tests");
DN_TestCore test = DN_SHA3_TestSuite(&arena); DN_TestCore test = DN_SHA3_TestSuite(&arena);
DN_Str8 output = DN_Str8FromTestCore(&test, &arena, flags); DN_Str8 output = DN_Str8FromTestCore(&test, &arena, flags);
printf("%.*s", DN_Str8PrintFmt(output)); printf("%.*s", DN_Str8PrintFmt(output));
+862 -381
View File
File diff suppressed because it is too large Load Diff
+807 -518
View File
File diff suppressed because it is too large Load Diff
+8 -6
View File
@@ -34,17 +34,18 @@ pushd %build_dir%
:: GR- Disable C RTTI :: GR- Disable C RTTI
:: Oi Use CPU Intrinsics :: Oi Use CPU Intrinsics
:: Z7 Combine multi-debug files to one debug file :: Z7 Combine multi-debug files to one debug file
set flags=
set flags=%flags% %script_dir%\Source\dn_tests.cpp set flags=%flags% %script_dir%\Source\dn_tests.cpp
set msvc_driver_flags=-EHa -GR- -Od -Oi -Z7 -wd4201 -W4 -nologo %flags% -fsanitize=address set msvc_driver_flags=-EHa -GR- -Od -Oi -Z7 -wd4201 -W4 -nologo %flags% -fsanitize=address
where /q emcc && ( where /q emcc && (
echo [BUILD] Emscripten emcc detected, compiling ... echo [BUILD] Emscripten emcc detected, compiling ...
call emcc -g -msimd128 -msse2 %flags% -o %build_dir%\dn_tests_emcc.js -s FETCH=1 -pthread -s ASYNCIFY=1 -lwebsocket -Wall || echo EMCC build failed&& exit /b 1 call emcc -g -msimd128 -msse2 !flags! -o %build_dir%\dn_tests_emcc.js -s FETCH=1 -pthread -s ASYNCIFY=1 -lwebsocket -Wall || echo EMCC build failed&& exit /b 1
) )
where /q cl && ( where /q cl && (
echo [BUILD] MSVC cl detected, compiling ... echo [BUILD] MSVC cl detected, compiling ...
set msvc_cmd=cl -MTd %msvc_driver_flags% -analyze -Fe:dn_tests_msvc -Fo:dn_tests_msvc set msvc_cmd=cl -MTd !msvc_driver_flags! -analyze -Fe:dn_tests_msvc -Fo:dn_tests_msvc
if exist %build_dir%/Curl/Install/lib/libcurl-d.lib ( if exist %build_dir%/Curl/Install/lib/libcurl-d.lib (
set msvc_cmd=!msvc_cmd! -D DN_WITH_NET_CURL=1 -I %build_dir%/Curl/Install/include %build_dir%/Curl/Install/lib/libcurl-d.lib crypt32.lib ws2_32.lib advapi32.lib wldap32.lib iphlpapi.lib secur32.lib set msvc_cmd=!msvc_cmd! -D DN_WITH_NET_CURL=1 -I %build_dir%/Curl/Install/include %build_dir%/Curl/Install/lib/libcurl-d.lib crypt32.lib ws2_32.lib advapi32.lib wldap32.lib iphlpapi.lib secur32.lib
) )
@@ -52,20 +53,21 @@ pushd %build_dir%
REM Build the single header REM Build the single header
powershell -Command "$time = Measure-Command { !msvc_cmd! | Out-Default }; Write-Host '[BUILD] msvc:'$time.TotalSeconds's'; exit $LASTEXITCODE" || echo MSVC build failed&& exit /b 1 powershell -Command "$time = Measure-Command { !msvc_cmd! | Out-Default }; Write-Host '[BUILD] msvc:'$time.TotalSeconds's'; exit $LASTEXITCODE" || echo MSVC build failed&& exit /b 1
echo [BUILD] Single header generator ... echo [BUILD] Single header generator: USE_SINGLE_HEADER not defined...
call cl %script_dir%\single_header_generator.cpp -Z7 -nologo -link || echo Single header generator build failed&& exit /b 1 call cl %script_dir%\single_header_generator.cpp -Z7 -nologo -link || echo Single header generator build failed&& exit /b 1
call %build_dir%\single_header_generator.exe %script_dir%\Source %script_dir%\Single-Header || echo Single header generation failed&& exit /b 1 call %build_dir%\single_header_generator.exe %script_dir%\Source %script_dir%\Single-Header || echo Single header generation failed&& exit /b 1
REM Build the single header using the single header (to test that the generated single header) REM Build the single header using the single header (to test that the generated single header)
echo [BUILD] Single header generator: USE_SINGLE_HEADER defined...
call cl %script_dir%\single_header_generator.cpp -Z7 -nologo -D USE_SINGLE_HEADER -link || echo Single header generator build failed&& exit /b 1 call cl %script_dir%\single_header_generator.cpp -Z7 -nologo -D USE_SINGLE_HEADER -link || echo Single header generator build failed&& exit /b 1
call %build_dir%\single_header_generator.exe %script_dir%\Source %script_dir%\Single-Header || echo Single header generation failed&& exit /b 1 call %build_dir%\single_header_generator.exe %script_dir%\Source %script_dir%\Single-Header || echo Single header generation failed&& exit /b 1
) )
where /q clang-cl && ( where /q clang-cl && (
echo [BUILD] LLVM clang-cl detected, compiling ... echo [BUILD] LLVM clang-cl detected, compiling ...
set clang_cmd=clang-cl -MT %msvc_driver_flags% -fsanitize=undefined -Fe:dn_tests_clang -link set clang_cmd=clang-cl -MT !msvc_driver_flags! -fsanitize=undefined -Fe:dn_tests_clang -link
powershell -Command "$time = Measure-Command { !clang_cmd! | Out-Default }; Write-Host '[BUILD] clang-cl:'$time.TotalSeconds's'; exit $LASTEXITCODE" || echo CLANG build failed&& exit /b 1 powershell -Command "$time = Measure-Command { !clang_cmd! | Out-Default }; Write-Host '[BUILD] clang-cl:'$time.TotalSeconds's'; exit $LASTEXITCODE" || echo CLANG build failed&& exit /b 1
) )
exit /b 1 popd
popd exit /b 0