LMMS
Loading...
Searching...
No Matches
juce_win32_HiddenMessageWindow.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
28{
29public:
30 HiddenMessageWindow (const TCHAR* const messageWindowName, WNDPROC wndProc)
31 {
32 String className ("JUCE_");
34
35 HMODULE moduleHandle = (HMODULE) Process::getCurrentModuleInstanceHandle();
36
37 WNDCLASSEX wc = {};
38 wc.cbSize = sizeof (wc);
39 wc.lpfnWndProc = wndProc;
40 wc.cbWndExtra = 4;
41 wc.hInstance = moduleHandle;
42 wc.lpszClassName = className.toWideCharPointer();
43
44 atom = RegisterClassEx (&wc);
45 jassert (atom != 0);
46
47 hwnd = CreateWindow (getClassNameFromAtom(), messageWindowName,
48 0, 0, 0, 0, 0,
49 nullptr, nullptr, moduleHandle, nullptr);
50 jassert (hwnd != nullptr);
51 }
52
54 {
56 UnregisterClass (getClassNameFromAtom(), nullptr);
57 }
58
59 inline HWND getHWND() const noexcept { return hwnd; }
60
61private:
62 ATOM atom;
64
66};
67
68//==============================================================================
70{
71public:
72 static bool isJUCEWindow (HWND hwnd) noexcept
73 {
75 }
76
77 static void setAsJUCEWindow (HWND hwnd, bool isJuceWindow) noexcept
78 {
80 }
81
82private:
84 {
85 static auto number = (LONG_PTR) Random().nextInt64();
86 return number;
87 }
88};
89
90//==============================================================================
92{
93public:
99
100 virtual void systemDeviceChanged() = 0;
101
103 {
104 // We'll pause before sending a message, because on device removal, the OS hasn't always updated
105 // its device lists correctly at this point. This also helps avoid repeated callbacks.
106 startTimer (500);
107 }
108
109private:
111
113 const WPARAM wParam, const LPARAM lParam)
114 {
115 if (message == WM_DEVICECHANGE
116 && (wParam == 0x8000 /*DBT_DEVICEARRIVAL*/
117 || wParam == 0x8004 /*DBT_DEVICEREMOVECOMPLETE*/
118 || wParam == 0x0007 /*DBT_DEVNODES_CHANGED*/))
119 {
121 ->triggerAsyncDeviceChangeCallback();
122 }
123
124 return DefWindowProc (h, message, wParam, lParam);
125 }
126
127 void timerCallback() override
128 {
129 stopTimer();
131 }
132};
133
134} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
static void message(int level, const char *fmt,...)
Definition adplugdb.cpp:120
static String toHexString(int number)
Definition String.cpp:1830
void timerCallback() override
Definition juce_win32_HiddenMessageWindow.h:127
virtual void systemDeviceChanged()=0
void triggerAsyncDeviceChangeCallback()
Definition juce_win32_HiddenMessageWindow.h:102
DeviceChangeDetector(const wchar_t *const name)
Definition juce_win32_HiddenMessageWindow.h:94
static LRESULT CALLBACK deviceChangeEventCallback(HWND h, const UINT message, const WPARAM wParam, const LPARAM lParam)
Definition juce_win32_HiddenMessageWindow.h:112
HiddenMessageWindow messageWindow
Definition juce_win32_HiddenMessageWindow.h:110
Definition juce_win32_HiddenMessageWindow.h:28
~HiddenMessageWindow()
Definition juce_win32_HiddenMessageWindow.h:53
HiddenMessageWindow(const TCHAR *const messageWindowName, WNDPROC wndProc)
Definition juce_win32_HiddenMessageWindow.h:30
HWND getHWND() const noexcept
Definition juce_win32_HiddenMessageWindow.h:59
ATOM atom
Definition juce_win32_HiddenMessageWindow.h:62
HWND hwnd
Definition juce_win32_HiddenMessageWindow.h:63
LPCTSTR getClassNameFromAtom() noexcept
Definition juce_win32_HiddenMessageWindow.h:65
Definition juce_win32_HiddenMessageWindow.h:70
static bool isJUCEWindow(HWND hwnd) noexcept
Definition juce_win32_HiddenMessageWindow.h:72
static void setAsJUCEWindow(HWND hwnd, bool isJuceWindow) noexcept
Definition juce_win32_HiddenMessageWindow.h:77
static LONG_PTR getImprobableWindowNumber() noexcept
Definition juce_win32_HiddenMessageWindow.h:83
Definition juce_Random.h:35
int64 nextInt64() noexcept
Definition juce_Random.cpp:92
Definition juce_String.h:53
const wchar_t * toWideCharPointer() const
Definition juce_String.cpp:2079
static int64 getHighResolutionTicks() noexcept
Definition juce_linux_SystemStats.cpp:313
void stopTimer() noexcept
Definition juce_Timer.cpp:357
Timer() noexcept
Definition juce_Timer.cpp:316
void startTimer(int intervalInMilliseconds) noexcept
Definition juce_Timer.cpp:332
static const char * name
Definition pugl.h:1582
#define jassert(expression)
Definition carla_juce.cpp:31
HWND__ * HWND
Definition juce_win32_Direct2DGraphicsContext.h:31
unsigned int pointer_sized_uint
Definition juce_MathsFunctions.h:82
RECT const char void HWND hwnd
Definition swell-functions.h:1066
LONG_PTR LRESULT
Definition swell-types.h:171
unsigned int UINT
Definition swell-types.h:166
LONG_PTR LPARAM
Definition swell-types.h:170
intptr_t LONG_PTR
Definition swell-types.h:42
ULONG_PTR WPARAM
Definition swell-types.h:169
LRESULT(* WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition swell-types.h:587
#define CALLBACK
Definition swell-types.h:635
const char * LPCTSTR
Definition swell-types.h:190
LRESULT DefWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition swell-wnd-generic.cpp:7223
void DestroyWindow(HWND hwnd)
Definition swell-wnd-generic.cpp:449
uch h[RAND_HEAD_LEN]
Definition crypt.c:459
#define GetWindowLongPtr(a, b)
Definition wdltypes.h:63
#define SetWindowLongPtr(a, b, c)
Definition wdltypes.h:62
#define GWLP_USERDATA
Definition win.c:30
LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition win.c:953
#define const
Definition zconf.h:137