Skip to content

Commit 1b0aa6a

Browse files
committed
[WLANWIZ] Move helper functions outside of ATL callbacks
1 parent 48184d6 commit 1b0aa6a

File tree

5 files changed

+94
-85
lines changed

5 files changed

+94
-85
lines changed

dll/shellext/wlanwiz/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ list(APPEND SOURCE
99
wlanwiz.cpp
1010
advsettings.cpp
1111
draw.cpp
12+
helpers.cpp
1213
keyb.cpp
1314
scan.cpp
1415
subclassproc_lb.cpp

dll/shellext/wlanwiz/helpers.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* PROJECT: ReactOS Shell
3+
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4+
* PURPOSE: ReactOS Wizard for Wireless Network Connections (Helper Functions)
5+
* COPYRIGHT: Copyright 2024-2025 Vitaly Orekhov <[email protected]>
6+
*/
7+
#include "main.h"
8+
9+
ATL::CStringW CWlanWizard::APNameToUnicode(_In_ PDOT11_SSID pDot11Ssid)
10+
{
11+
int iSSIDLengthWide = MultiByteToWideChar(CP_UTF8, 0, reinterpret_cast<LPCSTR>(pDot11Ssid->ucSSID), pDot11Ssid->uSSIDLength, NULL, 0);
12+
13+
ATL::CStringW cswSSID = ATL::CStringW(L"", iSSIDLengthWide);
14+
MultiByteToWideChar(CP_UTF8, 0, reinterpret_cast<LPCSTR>(pDot11Ssid->ucSSID), pDot11Ssid->uSSIDLength, cswSSID.GetBuffer(), iSSIDLengthWide);
15+
16+
return cswSSID;
17+
}
18+
19+
void CWlanWizard::TryInsertToKnown(_Inout_ std::set<DWORD>& setProfiles, _In_ DWORD dwIndex)
20+
{
21+
PWLAN_AVAILABLE_NETWORK pWlanNetwork = &this->lstWlanNetworks->Network[dwIndex];
22+
23+
if ((pWlanNetwork->dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE) == WLAN_AVAILABLE_NETWORK_HAS_PROFILE)
24+
{
25+
if (APNameToUnicode(&pWlanNetwork->dot11Ssid) == pWlanNetwork->strProfileName)
26+
setProfiles.insert(dwIndex);
27+
}
28+
}
29+
30+
void CWlanWizard::TryInsertToAdHoc(_Inout_ std::set<DWORD>& setAdHoc, _In_ DWORD dwIndex)
31+
{
32+
PWLAN_AVAILABLE_NETWORK pWlanNetwork = &this->lstWlanNetworks->Network[dwIndex];
33+
34+
if (pWlanNetwork->dot11BssType == dot11_BSS_type_independent)
35+
setAdHoc.insert(dwIndex);
36+
}
37+
38+
DWORD CWlanWizard::TryFindConnected(_In_ DWORD dwIndex)
39+
{
40+
PWLAN_AVAILABLE_NETWORK pWlanNetwork = &this->lstWlanNetworks->Network[dwIndex];
41+
42+
if ((pWlanNetwork->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) == WLAN_AVAILABLE_NETWORK_CONNECTED)
43+
return dwIndex;
44+
45+
return MAXDWORD;
46+
}
47+
48+
HWND CWlanWizard::CreateToolTip(_In_ int nID)
49+
{
50+
ATL::CStringW cswTooltip;
51+
BOOL bLoaded = cswTooltip.LoadStringW(nID + 40);
52+
53+
if (!nID || !bLoaded)
54+
return FALSE;
55+
56+
HWND hDlgItem = this->GetDlgItem(nID);
57+
ATL::CWindow hWndTip = ::CreateWindowExW(NULL,
58+
TOOLTIPS_CLASSW,
59+
NULL,
60+
WS_POPUP,
61+
CW_USEDEFAULT,
62+
CW_USEDEFAULT,
63+
CW_USEDEFAULT,
64+
CW_USEDEFAULT,
65+
this->m_hWnd,
66+
NULL,
67+
wlanwiz_hInstance,
68+
NULL);
69+
70+
if (!hDlgItem || !hWndTip)
71+
return NULL;
72+
73+
TOOLINFOW toolInfo =
74+
{
75+
.cbSize = sizeof(toolInfo),
76+
.uFlags = TTF_IDISHWND | TTF_SUBCLASS,
77+
.hwnd = this->m_hWnd,
78+
.uId = reinterpret_cast<UINT_PTR>(hDlgItem),
79+
.lpszText = cswTooltip.GetBuffer()
80+
};
81+
82+
hWndTip.SendMessageW(TTM_ADDTOOL, NULL, reinterpret_cast<LPARAM>(&toolInfo));
83+
84+
return hWndTip;
85+
}

dll/shellext/wlanwiz/main.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,6 @@ class CWlanWizard : public CDialogImpl<CWlanWizard>
167167
/* Listbox specific variables */
168168
DWORD dwSelectedItemID = 0;
169169

170-
HWND CreateToolTip(int toolID);
171-
static DWORD WINAPI ScanNetworksThread(_In_ LPVOID lpParameter);
172-
void TryInsertToAdHoc(std::set<DWORD>& setAdHoc, DWORD dwIndex);
173-
void TryInsertToKnown(std::set<DWORD>& setProfiles, DWORD dwIndex);
174-
DWORD TryFindConnected(DWORD dwIndex);
175-
176170
LRESULT OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
177171
LRESULT OnDrawItem(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
178172
LRESULT OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
@@ -201,4 +195,12 @@ class CWlanWizard : public CDialogImpl<CWlanWizard>
201195

202196
/* ALT_MSG_MAP 4 */
203197
LRESULT OnPaintGroupBox(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
198+
199+
/* Helper functions */
200+
HWND CreateToolTip(_In_ int toolID);
201+
static DWORD WINAPI ScanNetworksThread(_In_ LPVOID lpParameter);
202+
static ATL::CStringW APNameToUnicode(_In_ PDOT11_SSID dot11Ssid);
203+
void TryInsertToAdHoc(_Inout_ std::set<DWORD>& setAdHoc, _In_ DWORD dwIndex);
204+
void TryInsertToKnown(_Inout_ std::set<DWORD>& setProfiles, _In_ DWORD dwIndex);
205+
DWORD TryFindConnected(_In_ DWORD dwIndex);
204206
};

dll/shellext/wlanwiz/scan.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,6 @@
1010
#include <numeric>
1111
#include <vector>
1212

13-
/* Convert SSID from UTF-8 to UTF-16 */
14-
static ATL::CStringW APNameToUnicode(PDOT11_SSID dot11Ssid)
15-
{
16-
int iSSIDLengthWide = MultiByteToWideChar(CP_UTF8, 0, reinterpret_cast<LPCSTR>(dot11Ssid->ucSSID), dot11Ssid->uSSIDLength, NULL, 0);
17-
18-
ATL::CStringW cswSSID = ATL::CStringW(L"", iSSIDLengthWide);
19-
MultiByteToWideChar(CP_UTF8, 0, reinterpret_cast<LPCSTR>(dot11Ssid->ucSSID), dot11Ssid->uSSIDLength, cswSSID.GetBuffer(), iSSIDLengthWide);
20-
21-
return cswSSID;
22-
}
23-
24-
void CWlanWizard::TryInsertToKnown(std::set<DWORD>& setProfiles, DWORD dwIndex)
25-
{
26-
PWLAN_AVAILABLE_NETWORK pWlanNetwork = &this->lstWlanNetworks->Network[dwIndex];
27-
28-
if ((pWlanNetwork->dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE) == WLAN_AVAILABLE_NETWORK_HAS_PROFILE)
29-
{
30-
std::wstring_view wsvSSID = APNameToUnicode(&pWlanNetwork->dot11Ssid);
31-
32-
if (wsvSSID == pWlanNetwork->strProfileName)
33-
setProfiles.insert(dwIndex);
34-
}
35-
}
36-
37-
void CWlanWizard::TryInsertToAdHoc(std::set<DWORD>& setAdHoc, DWORD dwIndex)
38-
{
39-
PWLAN_AVAILABLE_NETWORK pWlanNetwork = &this->lstWlanNetworks->Network[dwIndex];
40-
41-
if (pWlanNetwork->dot11BssType == dot11_BSS_type_independent)
42-
setAdHoc.insert(dwIndex);
43-
}
44-
45-
DWORD CWlanWizard::TryFindConnected(DWORD dwIndex)
46-
{
47-
PWLAN_AVAILABLE_NETWORK pWlanNetwork = &this->lstWlanNetworks->Network[dwIndex];
48-
49-
if ((pWlanNetwork->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) == WLAN_AVAILABLE_NETWORK_CONNECTED)
50-
return dwIndex;
51-
52-
return MAXDWORD;
53-
}
54-
5513
LRESULT CWlanWizard::OnScanNetworks(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
5614
{
5715
MSG msg;

dll/shellext/wlanwiz/wlanwiz.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,6 @@ WlanWizOpen(HWND, HINSTANCE, LPCSTR lpszCmdLine, int) {
6666

6767
}
6868

69-
HWND CWlanWizard::CreateToolTip(int nID)
70-
{
71-
ATL::CStringW cswTooltip;
72-
BOOL bLoaded = cswTooltip.LoadStringW(nID + 40);
73-
74-
if (!nID || !bLoaded)
75-
return FALSE;
76-
77-
HWND hDlgItem = this->GetDlgItem(nID);
78-
ATL::CWindow hWndTip = ::CreateWindowExW(NULL,
79-
TOOLTIPS_CLASSW,
80-
NULL,
81-
WS_POPUP,
82-
CW_USEDEFAULT,
83-
CW_USEDEFAULT,
84-
CW_USEDEFAULT,
85-
CW_USEDEFAULT,
86-
this->m_hWnd,
87-
NULL,
88-
wlanwiz_hInstance,
89-
NULL);
90-
91-
if (!hDlgItem || !hWndTip)
92-
return NULL;
93-
94-
TOOLINFOW toolInfo = { 0 };
95-
toolInfo.cbSize = sizeof(toolInfo);
96-
toolInfo.hwnd = this->m_hWnd;
97-
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
98-
toolInfo.uId = reinterpret_cast<UINT_PTR>(hDlgItem);
99-
toolInfo.lpszText = cswTooltip.GetBuffer();
100-
101-
hWndTip.SendMessageW(TTM_ADDTOOL, NULL, reinterpret_cast<LPARAM>(&toolInfo));
102-
103-
return hWndTip;
104-
}
105-
10669
void CWlanWizard::PreCloseCleanup()
10770
{
10871
CoTaskMemFree(gModule.m_sGUID);

0 commit comments

Comments
 (0)