1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#include "stdafx.h"
char * __cdecl strstri(char *a, const char *b)
{
char * x, *y;
if (!a || !b) return FALSE;
x = _strdup(a);
y = _strdup(b);
x = _strupr(x);
y = _strupr(y);
char * pos = strstr(x, y);
if (pos)
{
char * retval = a + (pos - x);
free(x);
free(y);
return retval;
}
free(x);
free(y);
return nullptr;
}
void TRACE_ERROR()
{
uint32_t t = GetLastError();
LPVOID lpMsgBuf;
if (!FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
t,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR)&lpMsgBuf,
0,
nullptr))
{
// Handle the error.
return;
}
#ifdef _DEBUG
MessageBox(nullptr, (LPCTSTR)lpMsgBuf, L"Error", MB_OK | MB_ICONINFORMATION);
DebugBreak();
#endif
LocalFree(lpMsgBuf);
}
// load small icon (not shared) it IS NEED to be destroyed
HICON LoadSmallIcon(HINSTANCE hInstance, int index)
{
wchar_t filename[MAX_PATH] = { 0 };
GetModuleFileName(hInstance, filename, MAX_PATH);
HICON hIcon = nullptr;
ExtractIconEx(filename, index, nullptr, &hIcon, 1);
return hIcon;
}
BOOL DestroyIcon_protect(HICON icon)
{
if (icon) return DestroyIcon(icon);
return FALSE;
}
void GetMonitorRectFromWindow(HWND hWnd, RECT *rc)
{
POINT pt;
GetWindowRect(hWnd, rc);
pt.x = rc->left;
pt.y = rc->top;
MONITORINFO monitorInfo;
HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST); // always returns a valid value
monitorInfo.cbSize = sizeof(MONITORINFO);
if (GetMonitorInfoW(hMonitor, &monitorInfo)) {
memcpy(rc, &monitorInfo.rcMonitor, sizeof(RECT));
return;
}
// "generic" win95/NT support, also serves as failsafe
rc->left = 0;
rc->top = 0;
rc->bottom = GetSystemMetrics(SM_CYSCREEN);
rc->right = GetSystemMetrics(SM_CXSCREEN);
}
|