Skip to content

Commit eaae6d0

Browse files
committed
[WLANWIZ] Move helper functions outside of ATL callbacks
1 parent b666784 commit eaae6d0

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
@@ -168,12 +168,6 @@ class CWlanWizard : public CDialogImpl<CWlanWizard>
168168
/* Listbox specific variables */
169169
DWORD dwSelectedItemID = 0;
170170

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

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

dll/shellext/wlanwiz/scan.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,6 @@
1212
#include <string>
1313
#include <vector>
1414

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

dll/shellext/wlanwiz/wlanwiz.cpp

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

6868
}
6969

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

0 commit comments

Comments
 (0)