comparison foosdk/sdk/foobar2000/helpers/win32_misc.h @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #pragma once
2
3 #ifdef _WIN32
4
5
6 #include <libPPUI/win32_op.h>
7 #include <libPPUI/win32_utility.h>
8
9
10 class mutexScope {
11 public:
12 mutexScope(HANDLE hMutex_, abort_callback & abort);
13 ~mutexScope();
14 private:
15 PFC_CLASS_NOT_COPYABLE_EX(mutexScope);
16 HANDLE hMutex;
17 };
18
19 #ifdef FOOBAR2000_DESKTOP_WINDOWS
20
21 class registerclass_scope_delayed {
22 public:
23 registerclass_scope_delayed() {}
24 bool is_registered() const {return m_class != 0;}
25 void toggle_on(UINT p_style,WNDPROC p_wndproc,int p_clsextra,int p_wndextra,HICON p_icon,HCURSOR p_cursor,HBRUSH p_background,const TCHAR * p_classname,const TCHAR * p_menuname);
26 void toggle_off();
27 ATOM get_class() const {return m_class;}
28
29 ~registerclass_scope_delayed() {toggle_off();}
30 private:
31 registerclass_scope_delayed(const registerclass_scope_delayed &) = delete;
32 const registerclass_scope_delayed & operator=(const registerclass_scope_delayed &) = delete;
33
34 ATOM m_class = 0;
35 };
36
37
38 typedef CGlobalLockScope CGlobalLock; // compatibility
39
40 class OleInitializeScope {
41 public:
42 OleInitializeScope();
43 ~OleInitializeScope();
44
45 private:
46 PFC_CLASS_NOT_COPYABLE_EX(OleInitializeScope);
47 };
48
49 class CoInitializeScope {
50 public:
51 CoInitializeScope();
52 CoInitializeScope(DWORD params);
53 ~CoInitializeScope();
54 private:
55 PFC_CLASS_NOT_COPYABLE_EX(CoInitializeScope)
56 };
57
58 WORD GetOSVersion();
59
60 #if _WIN32_WINNT >= 0x501
61 #define WS_EX_COMPOSITED_Safe() WS_EX_COMPOSITED
62 #else
63 static DWORD WS_EX_COMPOSITED_Safe() {
64 return (GetOSVersion() < 0x501) ? 0 : 0x02000000L;
65 }
66 #endif
67
68
69 class CModelessDialogEntry {
70 public:
71 CModelessDialogEntry() : m_wnd() {}
72 CModelessDialogEntry(HWND p_wnd) : m_wnd() {Set(p_wnd);}
73 ~CModelessDialogEntry() {Set(NULL);}
74
75 void Set(HWND p_new);
76 private:
77 PFC_CLASS_NOT_COPYABLE_EX(CModelessDialogEntry);
78 HWND m_wnd;
79 };
80
81 class CDLL {
82 public:
83 #ifdef _DEBUG
84 static LPTOP_LEVEL_EXCEPTION_FILTER _GetEH() {
85 LPTOP_LEVEL_EXCEPTION_FILTER rv = SetUnhandledExceptionFilter(NULL);
86 SetUnhandledExceptionFilter(rv);
87 return rv;
88 }
89 #endif
90 CDLL(const wchar_t * Name) : hMod() {
91 Load(Name);
92 }
93 CDLL() : hMod() {}
94 void Load(const wchar_t * Name) {
95 PFC_ASSERT( hMod == NULL );
96 #ifdef _DEBUG
97 auto handlerBefore = _GetEH();
98 #endif
99 WIN32_OP( hMod = LoadLibrary(Name) );
100 #ifdef _DEBUG
101 PFC_ASSERT( handlerBefore == _GetEH() );
102 #endif
103 }
104
105
106 ~CDLL() {
107 if (hMod) FreeLibrary(hMod);
108 }
109 template<typename funcptr_t> void Bind(funcptr_t & outFunc, const char * name) {
110 WIN32_OP( outFunc = (funcptr_t)GetProcAddress(hMod, name) );
111 }
112
113 HMODULE hMod;
114
115 PFC_CLASS_NOT_COPYABLE_EX(CDLL);
116 };
117
118 class winLocalFileScope {
119 public:
120 void open(const char * inPath, file::ptr inReader, abort_callback & aborter);
121 void close();
122
123 winLocalFileScope() {}
124 winLocalFileScope(const char * inPath, file::ptr inReader, abort_callback & aborter) : m_isTemp() {
125 open(inPath, inReader, aborter);
126 }
127
128 ~winLocalFileScope() {
129 close();
130 }
131
132 const wchar_t * Path() const { return m_path.c_str(); }
133 bool isTemp() const { return m_isTemp; }
134 private:
135 bool m_isTemp = false;
136 std::wstring m_path;
137 };
138
139 #endif // FOOBAR2000_DESKTOP_WINDOWS
140
141
142 class CMutex {
143 public:
144 CMutex(const TCHAR * name = NULL);
145 ~CMutex();
146 HANDLE Handle() {return m_hMutex;}
147 static void AcquireByHandle( HANDLE hMutex, abort_callback & aborter );
148 void Acquire( abort_callback& aborter );
149 void Release();
150 private:
151 CMutex(const CMutex&) = delete; void operator=(const CMutex&) = delete;
152 HANDLE m_hMutex;
153 };
154
155 class CMutexScope {
156 public:
157 CMutexScope(CMutex & mutex, DWORD timeOutMS, const char * timeOutBugMsg);
158 CMutexScope(CMutex & mutex);
159 CMutexScope(CMutex & mutex, abort_callback & aborter);
160 ~CMutexScope();
161 private:
162 CMutexScope(const CMutexScope &) = delete; void operator=(const CMutexScope&) = delete;
163 CMutex & m_mutex;
164 };
165
166 bool IsWindowsS();
167
168 #else
169
170 class OleInitializeScope {};
171 class CoInitializeScope {};
172
173 #endif // _WIN32