@@ -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}
0 commit comments