1 // Scintilla source code edit control 2 /** @file PlatWin.h 3 ** Implementation of platform facilities on Windows. 4 **/ 5 // Copyright 1998-2011 by Neil Hodgson <[email protected]> 6 // The License.txt file describes the conditions under which this software may be distributed. 7 8 #ifndef PLATWIN_H 9 #define PLATWIN_H 10 11 namespace Scintilla { 12 13 #ifndef USER_DEFAULT_SCREEN_DPI 14 #define USER_DEFAULT_SCREEN_DPI 96 15 #endif 16 17 extern void Platform_Initialise(void *hInstance) noexcept; 18 19 extern void Platform_Finalise(bool fromDllMain) noexcept; 20 21 constexpr RECT RectFromPRectangle(PRectangle prc) noexcept { 22 RECT rc = { static_cast<LONG>(prc.left), static_cast<LONG>(prc.top), 23 static_cast<LONG>(prc.right), static_cast<LONG>(prc.bottom) }; 24 return rc; 25 } 26 27 constexpr POINT POINTFromPoint(Point pt) noexcept { 28 return POINT{ static_cast<LONG>(pt.x), static_cast<LONG>(pt.y) }; 29 } 30 31 constexpr Point PointFromPOINT(POINT pt) noexcept { 32 return Point::FromInts(pt.x, pt.y); 33 } 34 35 constexpr HWND HwndFromWindowID(WindowID wid) noexcept { 36 return static_cast<HWND>(wid); 37 } 38 39 inline HWND HwndFromWindow(const Window &w) noexcept { 40 return HwndFromWindowID(w.GetID()); 41 } 42 43 void *PointerFromWindow(HWND hWnd) noexcept; 44 void SetWindowPointer(HWND hWnd, void *ptr) noexcept; 45 46 /// Find a function in a DLL and convert to a function pointer. 47 /// This avoids undefined and conditionally defined behaviour. 48 template<typename T> 49 T DLLFunction(HMODULE hModule, LPCSTR lpProcName) noexcept { 50 if (!hModule) { 51 return nullptr; 52 } 53 FARPROC function = ::GetProcAddress(hModule, lpProcName); 54 static_assert(sizeof(T) == sizeof(function)); 55 T fp; 56 memcpy(&fp, &function, sizeof(T)); 57 return fp; 58 } 59 60 // Release an IUnknown* and set to nullptr. 61 // While IUnknown::Release must be noexcept, it isn't marked as such so produces 62 // warnings which are avoided by the catch. 63 template <class T> 64 void ReleaseUnknown(T *&ppUnknown) noexcept { 65 if (ppUnknown) { 66 try { 67 ppUnknown->Release(); 68 } 69 catch (...) { 70 // Never occurs 71 } 72 ppUnknown = nullptr; 73 } 74 } 75 76 77 UINT DpiForWindow(WindowID wid) noexcept; 78 79 int SystemMetricsForDpi(int nIndex, UINT dpi) noexcept; 80 81 HCURSOR LoadReverseArrowCursor(UINT dpi) noexcept; 82 83 #if defined(USE_D2D) 84 extern bool LoadD2D(); 85 extern ID2D1Factory *pD2DFactory; 86 extern IDWriteFactory *pIDWriteFactory; 87 #endif 88 89 } 90 91 #endif 92