ReactOS 0.4.15-dev-7131-ge4d03f4
SHDisconnectNetDrives.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Shell
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Implements the Disconnct Network Drive dialog
5 * COPYRIGHT: Copyright 2018 Jared Smudde (computerwhiz02@hotmail.com)
6 */
7
8#include "netplwiz.h"
9#include <wine/debug.h>
10
12
14
16{
17 HWND hListView = GetDlgItem(hDlg, IDC_CONNECTEDDRIVELIST);
19 WCHAR szLetter[100], szPath[100];
20
21 if (hListView == NULL)
22 return;
23
24 LoadStringW(hInstance, IDS_DRIVE_LETTER, szLetter, _countof(szLetter));
26
28 column.pszText = szLetter;
29 column.cx = 75;
30 ListView_InsertColumn(hListView, 0, &column);
31
33 column.pszText = szPath;
34 column.cx = 150;
35 ListView_InsertColumn(hListView, 1, &column);
36}
37
39{
41 HIMAGELIST hImgList;
42 HICON hIconDrive = NULL;
44 HWND hListView = GetDlgItem(hDlg, IDC_CONNECTEDDRIVELIST);
45
46 DWORD dRet;
47 HANDLE hEnum;
48 LPNETRESOURCE lpRes;
49 DWORD dwSize = 0x1000;
50 DWORD dwCount = -1;
51 LPNETRESOURCE lpCur;
52
53 /* List View Icons */
54 hShell32 = GetModuleHandleW(L"shell32.dll");
55 if (hShell32 == NULL)
56 return;
57
61 if (hIconDrive == NULL)
62 return;
63
64 hImgList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 1, 1);
65 if (hImgList == NULL)
66 {
67 DestroyIcon(hIconDrive);
68 return;
69 }
70
71 ImageList_AddIcon(hImgList, hIconDrive);
72 DestroyIcon(hIconDrive);
73 ListView_SetImageList(hListView, hImgList, LVSIL_SMALL);
74
76 if (dRet != WN_SUCCESS)
77 {
78 return;
79 }
80
81 lpRes = HeapAlloc(GetProcessHeap(), 0, dwSize);
82 if (!lpRes)
83 {
84 WNetCloseEnum(hEnum);
85 return;
86 }
87
88 do
89 {
90 ZeroMemory(lpRes, dwSize);
91 dRet = WNetEnumResource(hEnum, &dwCount, lpRes, &dwSize);
92 if (dRet == WN_SUCCESS || dRet == WN_MORE_DATA)
93 {
94 lpCur = lpRes;
95 for (; dwCount; dwCount--)
96 {
97 ZeroMemory(&item, sizeof(item));
98 item.mask = LVIF_TEXT | LVIF_IMAGE;
99 item.iImage = 0;
100 item.pszText = lpCur->lpLocalName;
101 item.lParam = 0;
102 item.iItem = ListView_InsertItem(hListView, &item);
103 ListView_SetItemText(hListView, item.iItem, 1, lpCur->lpRemoteName);
104 lpCur++;
105 }
106 }
107 } while (dRet != WN_NO_MORE_ENTRIES);
108
109 HeapFree(GetProcessHeap(), 0, lpRes);
110 WNetCloseEnum(hEnum);
111}
112
113
115{
116 LPNMHDR pnmh = (LPNMHDR)lParam;
117 HWND hListView = GetDlgItem(hDlg, IDC_CONNECTEDDRIVELIST);
118 HWND hOkButton = GetDlgItem(hDlg, ID_OK);
119
120 if (pnmh->hwndFrom == hListView)
121 {
122 switch (pnmh->code)
123 {
124 case LVN_ITEMCHANGED:
125 if (ListView_GetSelectedCount(hListView))
126 {
127 EnableWindow(hOkButton, TRUE);
128 }
129 else
130 {
131 EnableWindow(hOkButton, FALSE);
132 }
133 break;
134 }
135 }
136}
137
139{
140 TCHAR driveLetter[10];
141 HRESULT hr;
142 HWND hListView = GetDlgItem(hDlg, IDC_CONNECTEDDRIVELIST);
143 INT nItem = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);
144
145 if (nItem == -1)
146 return 0;
147
148 ListView_GetItemText(hListView, nItem, 0, driveLetter, _countof(driveLetter));
150
151 EndDialog(hDlg, ID_OK);
152 return hr;
153}
154
156{
158 switch (uMsg)
159 {
160 case WM_INITDIALOG:
163 SendMessageW(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
164 SendMessageW(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
166 InitializeListView(hDlg);
168 return TRUE;
169
170 case WM_COMMAND:
171 switch (LOWORD(wParam))
172 {
173 case ID_OK:
175 break;
176 case IDCANCEL:
177 EndDialog(hDlg, IDCANCEL);
178 break;
179 }
180 break;
181
182 case WM_NOTIFY:
184 break;
185
186 default:
187 return FALSE;
188 }
189
190 return TRUE;
191}
192
194{
196 return S_OK;
197}
VOID InitializeListView(HWND hDlg)
VOID UpdateButtonStatus(WPARAM wParam, LPARAM lParam, HWND hDlg)
static INT_PTR CALLBACK DisconnectDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
VOID EnumerateConnectedDrives(HWND hDlg)
HINSTANCE hInstance
DWORD DisconnectDriveExit(HWND hDlg)
HRESULT WINAPI SHDisconnectNetDrives(PVOID Unused)
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define IDD_DISCONNECTDRIVES
Definition: resource.h:12
#define ID_OK
Definition: resource.h:9
#define IDI_DISCONNECT_NET_DRIVES
Definition: resource.h:15
#define IDS_DRIVE_LETTER
Definition: resource.h:19
#define IDS_NETWORK_PATH
Definition: resource.h:20
#define IDC_CONNECTEDDRIVELIST
Definition: resource.h:8
HIMAGELIST WINAPI ImageList_Create(INT cx, INT cy, UINT flags, INT cInitial, INT cGrow)
Definition: imagelist.c:804
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:52
#define Unused(x)
Definition: atlwin.h:28
LPCWSTR szPath
Definition: env.c:37
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
static HICON
Definition: imagelist.c:84
static HMODULE hShell32
Definition: string.c:34
static ATOM item
Definition: dde.c:856
HICON hIcon
Definition: msconfig.c:44
HICON hIconSm
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define LVSIL_SMALL
Definition: commctrl.h:2299
#define ListView_InsertItem(hwnd, pitem)
Definition: commctrl.h:2408
#define ListView_InsertColumn(hwnd, iCol, pcol)
Definition: commctrl.h:2636
#define ListView_SetImageList(hwnd, himl, iImageList)
Definition: commctrl.h:2304
#define LVNI_SELECTED
Definition: commctrl.h:2424
#define ListView_GetItemText(hwndLV, i, iSubItem_, pszText_, cchTextMax_)
Definition: commctrl.h:2684
#define LVCF_WIDTH
Definition: commctrl.h:2587
#define ILC_COLOR32
Definition: commctrl.h:358
#define ListView_GetNextItem(hwnd, i, flags)
Definition: commctrl.h:2434
#define ListView_GetSelectedCount(hwndLV)
Definition: commctrl.h:2709
#define LV_ITEM
Definition: commctrl.h:2337
#define ListView_SetItemText(hwndLV, i, iSubItem_, pszText_)
Definition: commctrl.h:2691
#define LVIF_TEXT
Definition: commctrl.h:2309
#define ImageList_AddIcon(himl, hicon)
Definition: commctrl.h:415
#define ILC_MASK
Definition: commctrl.h:351
#define LVIF_IMAGE
Definition: commctrl.h:2310
#define LVN_ITEMCHANGED
Definition: commctrl.h:3131
#define LVCF_TEXT
Definition: commctrl.h:2588
#define LV_COLUMN
Definition: commctrl.h:2547
#define WM_NOTIFY
Definition: richedit.h:61
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: sndvol32.h:68
LPSTR lpLocalName
Definition: winnetwk.h:171
LPSTR lpRemoteName
Definition: winnetwk.h:172
UINT code
Definition: winuser.h:3158
HWND hwndFrom
Definition: winuser.h:3156
#define ICON_BIG
Definition: tnclass.cpp:51
#define ICON_SMALL
Definition: tnclass.cpp:48
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#define ZeroMemory
Definition: winbase.h:1712
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define RESOURCE_CONNECTED
Definition: winnetwk.h:58
#define CONNECT_UPDATE_PROFILE
Definition: winnetwk.h:87
#define RESOURCETYPE_DISK
Definition: winnetwk.h:64
#define WN_MORE_DATA
Definition: winnetwk.h:117
#define WN_SUCCESS
Definition: winnetwk.h:111
#define WNetEnumResource
Definition: winnetwk.h:599
#define WNetOpenEnum
Definition: winnetwk.h:598
#define WNetCancelConnection2
Definition: winnetwk.h:607
#define WN_NO_MORE_ENTRIES
Definition: winnetwk.h:146
#define IDCANCEL
Definition: winuser.h:830
#define IMAGE_ICON
Definition: winuser.h:212
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define LR_COPYFROMRESOURCE
Definition: winuser.h:1098
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4398
#define WM_COMMAND
Definition: winuser.h:1739
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE hInst, _In_ LPCWSTR name, _In_ UINT type, _In_ int cx, _In_ int cy, _In_ UINT fuLoad)
Definition: cursoricon.c:2172
#define SM_CYSMICON
Definition: winuser.h:1012
#define WM_INITDIALOG
Definition: winuser.h:1738
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:1956
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define SM_CXSMICON
Definition: winuser.h:1011
struct tagNMHDR * LPNMHDR
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define LR_SHARED
Definition: winuser.h:1099
#define LR_DEFAULTCOLOR
Definition: winuser.h:1086
#define LR_DEFAULTSIZE
Definition: winuser.h:1093
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
int WINAPI GetSystemMetrics(_In_ int)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
DWORD WINAPI WNetCloseEnum(HANDLE hEnum)
Definition: wnet.c:1760
char TCHAR
Definition: xmlstorage.h:189
__wchar_t WCHAR
Definition: xmlstorage.h:180