5 void WIN32_OP_D_FAIL(
const wchar_t * _Message,
const wchar_t *_File,
unsigned _Line);
11 SetLastError(NO_ERROR); \ 12 if (!(OP)) WIN32_OP_FAIL(); \ 16 #define WIN32_OP_CRITICAL(WHAT, OP) \ 18 SetLastError(NO_ERROR); \ 19 if (!(OP)) WIN32_OP_FAIL_CRITICAL(WHAT); \ 25 #define WIN32_OP_D(OP) \ 27 SetLastError(NO_ERROR); \ 28 if (!(OP)) WIN32_OP_D_FAIL(PFC_WIDESTRING(#OP), PFC_WIDESTRING(__FILE__), __LINE__); \ 32 #define WIN32_OP_D(OP) (void)( (OP), 0); 41 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);
59 template<
typename t_array>
61 PFC_STATIC_ASSERT(
sizeof(p_array[0]) == 1 );
65 template<
typename t_array>
67 PFC_STATIC_ASSERT(
sizeof(p_array[0]) == 1 );
68 if (OpenClipboard(NULL)) {
69 HANDLE handle = GetClipboardData(p_format);
78 p_array.set_size(size);
83 memcpy(p_array.get_ptr(),lock.
GetPtr(),size);
96 if (FAILED(OleInitialize(NULL)))
throw pfc::exception(
"OleInitialize() failure");
109 if (FAILED(CoInitialize(NULL)))
throw pfc::exception(
"CoInitialize() failed");
112 if (FAILED(CoInitializeEx(NULL, params)))
throw pfc::exception(
"CoInitialize() failed");
126 const DWORD ver = GetVersion();
127 return (WORD)HIBYTE(LOWORD(ver)) | ((WORD)LOBYTE(LOWORD(ver)) << 8);
130 #if _WIN32_WINNT >= 0x501 131 #define WS_EX_COMPOSITED_Safe() WS_EX_COMPOSITED 145 m_oldState = IsWindowEnabled(m_window);
146 EnableWindow(m_window,p_state);
149 EnableWindow(m_window,m_oldState);
162 m_oldCol = SetTextColor(dc,col);
165 SetTextColor(m_dc,m_oldCol);
179 void Close() throw() {CloseHandle(Detach());}
180 PFC_CLASS_NOT_COPYABLE_EX(CloseHandleScope)
193 if (m_wnd) api->remove(m_wnd);
195 if (m_wnd) api->add(m_wnd);
214 static LRESULT
Handler(NMHDR* hdr,
int subItemFrom = 0,
int subItemCnt = 1) {
215 NMLVFINDITEM *
info =
reinterpret_cast<NMLVFINDITEM*
>(hdr);
216 const HWND wnd = hdr->hwndFrom;
217 if (info->lvfi.flags & LVFI_NEARESTXY)
return -1;
218 const size_t count = _ItemCount(wnd);
219 if (count == 0)
return -1;
220 const size_t base = (size_t) info->iStart % count;
221 for(
size_t walk = 0; walk < count; ++walk) {
222 const size_t index = (walk + base) % count;
223 for(
int subItem = subItemFrom; subItem < subItemFrom + subItemCnt; ++subItem) {
224 if (StringPrefixMatch(info->lvfi.psz, _ItemText(wnd, index, subItem)))
return (LRESULT) index;
227 for(
size_t walk = 0; walk < count; ++walk) {
228 const size_t index = (walk + base) % count;
229 for(
int subItem = subItemFrom; subItem < subItemFrom + subItemCnt; ++subItem) {
230 if (StringPartialMatch(info->lvfi.psz, _ItemText(wnd, index, subItem)))
return (LRESULT) index;
237 return (
wchar_t) CharLower((
wchar_t*)c);
242 wchar_t c1 = part[walk], c2 = str[walk];
243 if (c1 == 0)
return true;
244 if (c2 == 0)
return false;
245 if (myCharLower(c1) != myCharLower(c2))
return false;
255 wchar_t c1 = part[walk], c2 = str[base + walk];
256 if (c1 == 0)
return true;
257 if (c2 == 0)
return false;
258 if (myCharLower(c1) != myCharLower(c2))
break;
266 return ListView_GetItemCount(wnd);
268 static const wchar_t *
_ItemText(HWND wnd,
size_t index,
int subItem = 0) {
269 NMLVDISPINFO
info = {};
270 info.hdr.code = LVN_GETDISPINFO;
271 info.hdr.idFrom = GetDlgCtrlID(wnd);
272 info.hdr.hwndFrom = wnd;
273 info.item.iItem = index;
274 info.item.iSubItem = subItem;
275 info.item.mask = LVIF_TEXT;
276 ::SendMessage(::GetParent(wnd), WM_NOTIFY, info.hdr.idFrom, reinterpret_cast<LPARAM>(&info));
277 if (info.item.pszText == NULL)
return L
"";
278 return info.item.pszText;
296 static LPTOP_LEVEL_EXCEPTION_FILTER
_GetEH() {
297 LPTOP_LEVEL_EXCEPTION_FILTER rv = SetUnhandledExceptionFilter(NULL);
298 SetUnhandledExceptionFilter(rv);
302 CDLL(
const wchar_t * Name) : hMod() {
306 void Load(
const wchar_t * Name) {
307 PFC_ASSERT( hMod == NULL );
309 auto handlerBefore = _GetEH();
311 WIN32_OP( hMod = LoadLibrary(Name) );
313 PFC_ASSERT( handlerBefore == _GetEH() );
319 if (hMod) FreeLibrary(hMod);
321 template<
typename funcptr_t>
void Bind(funcptr_t & outFunc,
const char * name) {
322 WIN32_OP( outFunc = (funcptr_t)GetProcAddress(hMod, name) );
327 PFC_CLASS_NOT_COPYABLE_EX(
CDLL);
332 void open(
const char * inPath, file::ptr inReader,
abort_callback & aborter);
337 open( inPath, inReader, aborter );
344 const wchar_t *
Path()
const {
return m_path.c_str();}
354 CMutex(
const TCHAR * name = NULL);
void SetDefaultMenuItem(HMENU p_menu, unsigned p_id)
CloseHandleScope(HANDLE handle)
void GetOSVersionStringAppend(pfc::string_base &out)
CModelessDialogEntry(HWND p_wnd)
const registerclass_scope_delayed & operator=(const registerclass_scope_delayed &)
static DWORD WS_EX_COMPOSITED_Safe()
registerclass_scope_delayed(const registerclass_scope_delayed &)
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)
CoInitializeScope(DWORD params)
CGlobalLockScope CGlobalLock
EnableWindowScope(HWND p_window, BOOL p_state)
static WORD GetOSVersion()
void info(const char *p_message)
static bool StringPartialMatch(const wchar_t *part, const wchar_t *str)
typedef BOOL(WINAPI *pPowerSetRequest_t)(__in HANDLE PowerRequest
static LPTOP_LEVEL_EXCEPTION_FILTER _GetEH()
~registerclass_scope_delayed()
static LRESULT Handler(NMHDR *hdr, int subItemFrom=0, int subItemCnt=1)
unsigned QueryScreenDPI()
static wchar_t myCharLower(wchar_t c)
static bool StringPrefixMatch(const wchar_t *part, const wchar_t *str)
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL()
t_type replace_t(t_type &p_var, const t_newval &p_newval)
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
void GetOSVersionString(pfc::string_base &out)
bool IsMenuNonEmpty(HMENU menu)
winLocalFileScope(const char *inPath, file::ptr inReader, abort_callback &aborter)
void WIN32_OP_D_FAIL(const wchar_t *_Message, const wchar_t *_File, unsigned _Line)
void Bind(funcptr_t &outFunc, const char *name)
static bool GetClipboardDataBlock(UINT p_format, t_array &p_array)
const wchar_t * Path() const
void Load(const wchar_t *Name)
static size_t _ItemCount(HWND wnd)
static const wchar_t * _ItemText(HWND wnd, size_t index, int subItem=0)
CDLL(const wchar_t *Name)
registerclass_scope_delayed()
SetTextColorScope(HDC dc, COLORREF col)
bool SetClipboardDataBlock(UINT p_format, const void *p_block, t_size p_block_size)
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL_CRITICAL(const char *what)
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
bool is_registered() const