ReactOS  0.4.14-dev-998-g623dd26
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 
27  column.mask = LVCF_WIDTH | LVCF_TEXT;
28  column.pszText = szLetter;
29  column.cx = 75;
30  ListView_InsertColumn(hListView, 0, &column);
31 
32  column.mask = LVCF_WIDTH | LVCF_TEXT;
33  column.pszText = szPath;
34  column.cx = 150;
35  ListView_InsertColumn(hListView, 1, &column);
36 }
37 
39 {
40  LV_ITEM item;
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:
174  DisconnectDriveExit(hDlg);
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 }
#define LV_ITEM
Definition: commctrl.h:2333
#define IDI_DISCONNECT_NET_DRIVES
Definition: resource.h:15
_Must_inspect_result_ typedef _In_ PVOID Unused
Definition: iotypes.h:1129
#define ListView_GetNextItem(hwnd, i, flags)
Definition: commctrl.h:2430
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
static INT_PTR CALLBACK DisconnectDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define LR_SHARED
Definition: winuser.h:1090
#define CONNECT_UPDATE_PROFILE
Definition: winnetwk.h:87
#define IMAGE_ICON
Definition: winuser.h:212
#define LVCF_WIDTH
Definition: commctrl.h:2583
#define LVSIL_SMALL
Definition: commctrl.h:2295
HRESULT hr
Definition: shlfolder.c:183
#define LVCF_TEXT
Definition: commctrl.h:2584
#define WN_SUCCESS
Definition: winnetwk.h:111
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
#define _countof(array)
Definition: fontsub.cpp:30
#define ListView_GetItemText(hwndLV, i, iSubItem_, pszText_, cchTextMax_)
Definition: commctrl.h:2680
#define LV_COLUMN
Definition: commctrl.h:2543
#define LVN_ITEMCHANGED
Definition: commctrl.h:3127
#define WNetCancelConnection2
Definition: winnetwk.h:607
#define CALLBACK
Definition: compat.h:27
LPSTR lpLocalName
Definition: winnetwk.h:171
#define ZeroMemory
Definition: winbase.h:1642
#define SM_CYSMICON
Definition: winuser.h:1003
VOID UpdateButtonStatus(WPARAM wParam, LPARAM lParam, HWND hDlg)
#define LVNI_SELECTED
Definition: commctrl.h:2420
UINT_PTR WPARAM
Definition: windef.h:207
WINE_DEFAULT_DEBUG_CHANNEL(netplwiz)
#define IDD_DISCONNECTDRIVES
Definition: resource.h:12
#define ListView_InsertItem(hwnd, pitem)
Definition: commctrl.h:2404
int32_t INT_PTR
Definition: typedefs.h:63
#define IDS_DRIVE_LETTER
Definition: resource.h:19
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:57
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
struct tagNMHDR * LPNMHDR
#define ICON_SMALL
Definition: tnclass.cpp:48
#define ILC_COLOR32
Definition: commctrl.h:354
#define LVIF_TEXT
Definition: commctrl.h:2305
UINT code
Definition: winuser.h:3134
#define RESOURCE_CONNECTED
Definition: winnetwk.h:58
#define ListView_InsertColumn(hwnd, iCol, pcol)
Definition: commctrl.h:2632
HRESULT WINAPI SHDisconnectNetDrives(PVOID Unused)
HIMAGELIST WINAPI ImageList_Create(INT cx, INT cy, UINT flags, INT cInitial, INT cGrow)
Definition: imagelist.c:804
#define ListView_GetSelectedCount(hwndLV)
Definition: commctrl.h:2705
HINSTANCE hInstance
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:1956
#define ListView_SetImageList(hwnd, himl, iImageList)
Definition: commctrl.h:2300
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4374
#define WNetOpenEnum
Definition: winnetwk.h:598
#define IDC_CONNECTEDDRIVELIST
Definition: resource.h:8
#define ListView_SetItemText(hwndLV, i, iSubItem_, pszText_)
Definition: commctrl.h:2687
char TCHAR
Definition: xmlstorage.h:189
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define LR_DEFAULTSIZE
Definition: winuser.h:1084
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define WINAPI
Definition: msvc.h:6
#define LVIF_IMAGE
Definition: commctrl.h:2306
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
INT WINAPI ImageList_AddIcon(HIMAGELIST himl, HICON hIcon)
Definition: imagelist.c:540
#define SM_CXSMICON
Definition: winuser.h:1002
#define ID_OK
Definition: resource.h:9
static const WCHAR L[]
Definition: oid.c:1250
#define ILC_MASK
Definition: commctrl.h:347
DWORD WINAPI WNetCloseEnum(HANDLE hEnum)
Definition: wnet.c:1760
#define WM_COMMAND
Definition: winuser.h:1722
HWND hwndFrom
Definition: winuser.h:3132
#define WNetEnumResource
Definition: winnetwk.h:599
#define RESOURCETYPE_DISK
Definition: winnetwk.h:64
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define S_OK
Definition: intsafe.h:59
#define LR_COPYFROMRESOURCE
Definition: winuser.h:1089
#define IDS_NETWORK_PATH
Definition: resource.h:20
static ATOM item
Definition: dde.c:856
HICON hIcon
Definition: msconfig.c:44
LPCWSTR szPath
Definition: env.c:35
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
unsigned int UINT
Definition: ndis.h:50
#define WN_NO_MORE_ENTRIES
Definition: winnetwk.h:146
LPSTR lpRemoteName
Definition: winnetwk.h:172
VOID InitializeListView(HWND hDlg)
#define WN_MORE_DATA
Definition: winnetwk.h:117
HICON hIconSm
Definition: msconfig.c:44
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:847
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
GLenum GLenum GLvoid GLvoid * column
Definition: glext.h:5664
#define IDCANCEL
Definition: winuser.h:825
DWORD DisconnectDriveExit(HWND hDlg)
#define LR_DEFAULTCOLOR
Definition: winuser.h:1077
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
static HMODULE hShell32
Definition: string.c:34
#define HeapFree(x, y, z)
Definition: compat.h:402
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define WM_NOTIFY
Definition: richedit.h:61
#define ICON_BIG
Definition: tnclass.cpp:51
VOID EnumerateConnectedDrives(HWND hDlg)