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
+187 -22
View File
@@ -13,19 +13,27 @@
#pragma comment(lib, "pathcch")
#pragma comment(lib, "Shell32") // ShellExecuteW
#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
#if defined(DN_NO_WINDOWS_H_REPLACEMENT_HEADER) || defined(_INC_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h> // LONG
#include <bcrypt.h> // DN_OS_SecureRNGBytes -> BCryptOpenAlgorithmProvider ... etc
#include <shellapi.h> // DN_Win_MakeProcessDPIAware -> SetProcessDpiAwareProc
#include <shlwapi.h> // PathRelativePathTO
#include <pathcch.h> // PathCchCanonicalizeEx
#include <winhttp.h> // WinHttp*
#include <psapi.h> // PROCESS_MEMORY_COUNTERS_EX2
#include <commdlg.h> // OPENFILENAMEW
#include <Windows.h> // LONG
#include <dwmapi.h> // DwmExtendFrameIntoClientArea...
#include <bcrypt.h> // DN_OS_SecureRNGBytes -> BCryptOpenAlgorithmProvider ... etc
#include <shellapi.h> // DN_Win_MakeProcessDPIAware -> SetProcessDpiAwareProc
#include <ShellScalingApi.h> // MONITOR_DPI_TYPE
#include <shlwapi.h> // PathRelativePathTO
#include <pathcch.h> // PathCchCanonicalizeEx
#include <winhttp.h> // WinHttp*
#include <psapi.h> // PROCESS_MEMORY_COUNTERS_EX2
#include <commdlg.h> // OPENFILENAMEW
#include <DbgHelp.h>
#include <windowsx.h> // GET_X_PARAM
#else
DN_MSVC_WARNING_PUSH
DN_MSVC_WARNING_DISABLE(4201) // warning C4201: nonstandard extension used: nameless struct/union
@@ -57,9 +65,10 @@
typedef void * HANDLE;
typedef HANDLE HLOCAL;
typedef unsigned __int64 WPARAM;
typedef LONG_PTR LPARAM;
typedef LONG_PTR LRESULT;
typedef unsigned __int64 WPARAM;
typedef LONG_PTR LPARAM;
typedef LONG_PTR LRESULT;
typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
#define MAX_PATH 260
@@ -68,6 +77,11 @@
DWORD dwHighDateTime;
} 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: GetModuleFileNameW
#define ERROR_INSUFFICIENT_BUFFER 122L // dderror
@@ -87,6 +101,7 @@
typedef wchar_t WCHAR; // wc, 16-bit UNICODE character
typedef CHAR * NPSTR, *LPSTR, *PSTR;
typedef WCHAR * NWPSTR, *LPWSTR, *PWSTR;
typedef const WCHAR* LPCWSTR, *PCWSTR;
typedef long HRESULT;
// NOTE: VirtualAlloc: Allocation Type
@@ -372,6 +387,11 @@
LONG y;
} POINT, *PPOINT, *NPPOINT, *LPPOINT;
struct HMONITOR__ {
int unused;
};
typedef struct HMONITOR__ *HMONITOR;
// NOTE: handleapi.h ///////////////////////////////////////////////////////////////////////////
#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)
@@ -670,7 +690,59 @@
RECT rcDevice;
#endif
} 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 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_NORMAL 1
@@ -678,22 +750,107 @@
#define SW_MAXIMIZE 3
#define SW_SHOWNOACTIVATE 4
#define SW_SHOW 5
#define SW_MINIMIZE 6
#define SW_RESTORE 9
#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"
{
__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) UINT __stdcall GetWindowModuleFileNameA(HWND hwnd, LPSTR pszFileName, UINT cchFileNameMax);
__declspec(dllimport) BOOL __stdcall ShowWindow (HWND hWnd, int nCmdShow);
__declspec(dllimport) BOOL __stdcall GetWindowPlacement (HWND hWnd, WINDOWPLACEMENT *lpwndpl);
__declspec(dllimport) BOOL __stdcall IsIconic (HWND hWnd);
__declspec(dllimport) BOOL __stdcall BringWindowToTop (HWND hWnd);
__declspec(dllimport) BOOL __stdcall SetForegroundWindow (HWND hWnd);
__declspec(dllimport) HWND __stdcall SetFocus (HWND hWnd);
__declspec(dllimport) HWND __stdcall GetForegroundWindow ();
__declspec(dllimport) BOOL __stdcall SetWindowTextW (HWND hWnd, LPCWSTR lpString);
__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) UINT __stdcall GetWindowModuleFileNameA(HWND hwnd, LPSTR pszFileName, UINT cchFileNameMax);
__declspec(dllimport) BOOL __stdcall ShowWindow (HWND hWnd, int nCmdShow);
__declspec(dllimport) BOOL __stdcall GetWindowPlacement (HWND hWnd, WINDOWPLACEMENT *lpwndpl);
__declspec(dllimport) BOOL __stdcall IsIconic (HWND hWnd);
__declspec(dllimport) BOOL __stdcall IsZoomed (HWND hWnd);
__declspec(dllimport) BOOL __stdcall BringWindowToTop (HWND hWnd);
__declspec(dllimport) BOOL __stdcall SetForegroundWindow (HWND hWnd);
__declspec(dllimport) HWND __stdcall SetFocus (HWND hWnd);
__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 //////////////////////////////////////////////////////////////////////////
@@ -1363,6 +1520,14 @@
#define EXCEPTION_CONTINUE_SEARCH 0
#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
#endif // !defined(_INC_WINDOWS)
#endif // !defined(DN_OS_WINDOWS_H)