-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos_windows.h
137 lines (112 loc) · 3.58 KB
/
os_windows.h
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <stdio.h>
#include <dwmapi.h>
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_syswm.h>
void SetWindowAttributes(HWND hwnd) {
BOOL fForceIconic = TRUE;
BOOL fHasIconicBitmap = TRUE;
DwmSetWindowAttribute(
hwnd,
DWMWA_FORCE_ICONIC_REPRESENTATION,
&fForceIconic,
sizeof(fForceIconic));
DwmSetWindowAttribute(
hwnd,
DWMWA_HAS_ICONIC_BITMAP,
&fHasIconicBitmap,
sizeof(fHasIconicBitmap));
printf("succesfully called DwmSetWindowAttribute\n");
}
UINT GetSysWMmsgType(SDL_SysWMmsg* msg) {
return msg->msg.win.msg;
}
uint32_t GetIconicThumbnailMaxWidth(SDL_SysWMmsg* msg) {
return HIWORD(msg->msg.win.lParam);
}
uint32_t GetIconicThumbnailMaxHeight(SDL_SysWMmsg* msg) {
return LOWORD(msg->msg.win.lParam);
}
void SetIconicThumbnail(HWND hwnd, uint32_t w, uint32_t h, const BYTE* data) {
// bitmap creation based on windows7 sdk sample
HDC hdcMem = CreateCompatibleDC(NULL);
if (hdcMem == NULL) {
fprintf(stderr, "something went wrong when preparing thumbnail bitmap\n");
return;
}
BITMAPINFO bmi;
ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = w;
bmi.bmiHeader.biHeight = -h;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
PBYTE pbDS = NULL;
HBITMAP bmp = CreateDIBSection(hdcMem, &bmi, DIB_RGB_COLORS, (VOID**)&pbDS, NULL, 0);
if (bmp == NULL) {
fprintf(stderr, "something went wrong when allocating thumbnail bitmap\n");
return;
}
for (int y = 0; y < (int)h; y++) {
for (int x = 0; x < (int)w; x++) {
int k = x*(int)h + y;
pbDS[0] = data[k*4+0];
pbDS[1] = data[k*4+1];
pbDS[2] = data[k*4+2];
pbDS[3] = data[k*4+3];
pbDS += 4;
}
}
DeleteDC(hdcMem);
//HBITMAP bmp = CreateBitmap(w, h, 1, 32, data);
HRESULT res = DwmSetIconicThumbnail(hwnd, bmp, 0);
if (res != S_OK) {
fprintf(stderr, "something went wrong when setting iconic thumbnail (%d, %#06x, %#010x)\n", res, res, bmp);
}
DeleteObject(bmp);
}
void SetIconicLivePreview(HWND hwnd, uint32_t w, uint32_t h, const BYTE* data) {
// bitmap creation based on windows7 sdk sample
HDC hdcMem = CreateCompatibleDC(NULL);
if (hdcMem == NULL) {
fprintf(stderr, "something went wrong when preparing thumbnail bitmap\n");
return;
}
BITMAPINFO bmi;
ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = w;
bmi.bmiHeader.biHeight = -h;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
PBYTE pbDS = NULL;
HBITMAP bmp = CreateDIBSection(hdcMem, &bmi, DIB_RGB_COLORS, (VOID**)&pbDS, NULL, 0);
if (bmp == NULL) {
fprintf(stderr, "something went wrong when allocating thumbnail bitmap\n");
return;
}
for (int y = 0; y < (int)h; y++) {
for (int x = 0; x < (int)w; x++) {
int k = x*(int)h + y;
pbDS[0] = data[k*4+0];
pbDS[1] = data[k*4+1];
pbDS[2] = data[k*4+2];
pbDS[3] = data[k*4+3];
pbDS += 4;
}
}
DeleteDC(hdcMem);
//HBITMAP bmp = CreateBitmap(w, h, 1, 32, data);
POINT ptOffset;
ptOffset.x = 0;
ptOffset.y = 0;
HRESULT res = DwmSetIconicLivePreviewBitmap(hwnd, bmp, &ptOffset, DWM_SIT_DISPLAYFRAME);
if (res != S_OK) {
fprintf(stderr, "something went wrong when setting iconic live preview (%d, %#06x, %#010x)\n", res, res, bmp);
}
DeleteObject(bmp);
}
void InvalidateIconicBitmaps(HWND hwnd) {
if (DwmInvalidateIconicBitmaps(hwnd) != S_OK) {
fprintf(stderr, "something went wrong when invalidating thumbnail\n");
}
}