mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-10 08:17:51 -06:00
Win32 specific: Using SHChangeNotifyRegister to get notifications
on removable media insert / eject events. From now on we no more poll for removable media on Windows. Thanks @mjgtp from prusaprinters.org See the following discussion: https://forum.prusaprinters.org/forum/prusaslicer/prusaslicer-trying-to-access-my-floppy-disk-a The final working code sample was taken from Chromium source code, volume_mount_watcher_win.cc
This commit is contained in:
parent
3fdd643f49
commit
58192ba6c2
4 changed files with 73 additions and 11 deletions
|
@ -33,6 +33,7 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <dbt.h>
|
||||
#include <shlobj.h>
|
||||
#endif // _WIN32
|
||||
|
||||
namespace Slic3r {
|
||||
|
@ -127,6 +128,30 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
|
|||
// DEV_BROADCAST_HANDLE NotificationFilter = { 0 };
|
||||
// NotificationFilter.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
|
||||
// NotificationFilter.dbch_devicetype = DBT_DEVTYP_HANDLE;
|
||||
|
||||
// Using Win32 Shell API to register for media insert / removal events.
|
||||
LPITEMIDLIST ppidl;
|
||||
if (SHGetSpecialFolderLocation(this->GetHWND(), CSIDL_DESKTOP, &ppidl) == NOERROR) {
|
||||
SHChangeNotifyEntry shCNE;
|
||||
shCNE.pidl = ppidl;
|
||||
shCNE.fRecursive = TRUE;
|
||||
// Returns a positive integer registration identifier (ID).
|
||||
// Returns zero if out of memory or in response to invalid parameters.
|
||||
m_ulSHChangeNotifyRegister = SHChangeNotifyRegister(this->GetHWND(), // Hwnd to receive notification
|
||||
SHCNE_DISKEVENTS, // Event types of interest (sources)
|
||||
SHCNE_MEDIAINSERTED | SHCNE_MEDIAREMOVED,
|
||||
//SHCNE_UPDATEITEM, // Events of interest - use SHCNE_ALLEVENTS for all events
|
||||
WM_USER_MEDIACHANGED, // Notification message to be sent upon the event
|
||||
1, // Number of entries in the pfsne array
|
||||
&shCNE); // Array of SHChangeNotifyEntry structures that
|
||||
// contain the notifications. This array should
|
||||
// always be set to one when calling SHChnageNotifyRegister
|
||||
// or SHChangeNotifyDeregister will not work properly.
|
||||
assert(m_ulSHChangeNotifyRegister != 0); // Shell notification failed
|
||||
} else {
|
||||
// Failed to get desktop location
|
||||
assert(false);
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
// propagate event
|
||||
|
@ -161,8 +186,14 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
|
|||
void MainFrame::shutdown()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
::UnregisterDeviceNotification(HDEVNOTIFY(m_hDeviceNotify));
|
||||
m_hDeviceNotify = nullptr;
|
||||
if (m_hDeviceNotify) {
|
||||
::UnregisterDeviceNotification(HDEVNOTIFY(m_hDeviceNotify));
|
||||
m_hDeviceNotify = nullptr;
|
||||
}
|
||||
if (m_ulSHChangeNotifyRegister) {
|
||||
SHChangeNotifyDeregister(m_ulSHChangeNotifyRegister);
|
||||
m_ulSHChangeNotifyRegister = 0;
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
if (m_plater)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue