Skip to content

Commit 5ee71b2

Browse files
committed
Add icon to Windows build, guard focus stealing.
1 parent 12e232a commit 5ee71b2

File tree

7 files changed

+29
-17
lines changed

7 files changed

+29
-17
lines changed

builds/msvc/libbitcoin.ico

113 KB
Binary file not shown.

builds/msvc/resource.h

90 Bytes
Binary file not shown.

builds/msvc/resource.rc

852 Bytes
Binary file not shown.

builds/msvc/vs2022/bs/bs.vcxproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,7 @@
187187
<ItemGroup>
188188
<Natvis Include="..\..\debug.natvis" />
189189
</ItemGroup>
190-
</Project>
190+
<ItemGroup>
191+
<Image Include="..\..\libbitcoin.ico" />
192+
</ItemGroup>
193+
</Project>

builds/msvc/vs2022/bs/bs.vcxproj.filters

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,9 @@
119119
<Filter>resource</Filter>
120120
</ResourceCompile>
121121
</ItemGroup>
122-
</Project>
122+
<ItemGroup>
123+
<Image Include="..\..\libbitcoin.ico">
124+
<Filter>resource</Filter>
125+
</Image>
126+
</ItemGroup>
127+
</Project>

console/executor_windows.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ BOOL WINAPI executor::control_handler(DWORD signal)
5959
}
6060

6161
// static
62-
LRESULT CALLBACK executor::window_proc(HWND handle, UINT message, WPARAM wparam,
63-
LPARAM lparam)
62+
LRESULT CALLBACK executor::window_proc(HWND handle, UINT message,
63+
WPARAM wparam, LPARAM lparam)
6464
{
6565
switch (message)
6666
{
@@ -69,7 +69,7 @@ LRESULT CALLBACK executor::window_proc(HWND handle, UINT message, WPARAM wparam,
6969
case WM_QUERYENDSESSION:
7070
{
7171
::ShutdownBlockReasonCreate(handle, window_text);
72-
stop(possible_narrow_sign_cast<int>(message));
72+
executor::handle_stop(possible_narrow_sign_cast<int>(message));
7373
return FALSE;
7474
}
7575
default:
@@ -83,28 +83,32 @@ void executor::create_hidden_window()
8383
{
8484
thread_ = std::thread([this]()
8585
{
86-
const WNDCLASSW window_class
86+
const auto instance = ::GetModuleHandleW(NULL);
87+
const WNDCLASSEXW window_class
8788
{
89+
.cbSize = sizeof(WNDCLASSEXW),
90+
.style = CS_HREDRAW | CS_VREDRAW,
8891
.lpfnWndProc = &executor::window_proc,
89-
.hInstance = ::GetModuleHandleW(NULL),
90-
.lpszClassName = window_name
92+
.hInstance = instance,
93+
.hIcon = ::LoadIconW(instance, MAKEINTRESOURCEW(101)),
94+
.lpszClassName = window_name,
95+
.hIconSm = ::LoadIconW(instance, MAKEINTRESOURCEW(101))
9196
};
9297

9398
// fault
94-
if (is_zero(::RegisterClassW(&window_class)))
99+
if (is_zero(::RegisterClassExW(&window_class)))
95100
return;
96101

97-
// Window must be visible (?) to capture shutdown.
102+
// Zero sizing results in title bar only.
103+
// WS_EX_NOACTIVATE: prevents focus-stealing.
104+
// WS_VISIBLE: required to capture WM_QUERYENDSESSION.
98105
window_ = ::CreateWindowExW
99106
(
100-
0u,
107+
WS_EX_NOACTIVATE,
101108
window_name,
102109
window_title,
103110
WS_VISIBLE,
104-
CW_USEDEFAULT,
105-
CW_USEDEFAULT,
106-
400,
107-
300,
111+
0, 0, 0, 0,
108112
NULL,
109113
NULL,
110114
::GetModuleHandleW(NULL),
@@ -139,10 +143,10 @@ void executor::destroy_hidden_window()
139143
if (!is_null(window_))
140144
{
141145
::DestroyWindow(window_);
142-
window_ = nullptr;
146+
window_ = NULL;
143147
}
144148

145-
const HWND handle = ::GetConsoleWindow();
149+
const auto handle = ::GetConsoleWindow();
146150
if (!is_null(handle))
147151
::ShutdownBlockReasonDestroy(handle);
148152
}

console/libbitcoin.ico

-361 KB
Binary file not shown.

0 commit comments

Comments
 (0)