Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

900 lines
31 KiB

  1. // SMBRDR.C
  2. #ifndef UNICODE
  3. #define UNICODE
  4. #endif
  5. #include <windows.h>
  6. #include <shellapi.h>
  7. #include <stdlib.h>
  8. #include "srfunc.h"
  9. #include "resource.h"
  10. int WINAPI WinMain(
  11. HINSTANCE hInstance, // handle to current instance
  12. HINSTANCE hPrevInstance, // handle to previous instance
  13. LPSTR lpCmdLine, // pointer to command line
  14. int nCmdShow // show state of window
  15. );
  16. INT_PTR CALLBACK SmbRdrDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  17. INT_PTR CALLBACK ProviderDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  18. INT_PTR CALLBACK StatisticsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  19. #define APP_TITLE TEXT("SMB MiniRDR")
  20. #define INSTALL_NOTICE TEXT("Mini Redirector is not completely installed.\n") \
  21. TEXT("Do you wish to complete this now?")
  22. #define INSTALL_REPLY TEXT("Sorry, the install must finish before using the SMB MiniRDR.")
  23. #define INSTALL_FAIL APP_TITLE TEXT(" installation failed to complete.")
  24. #define INSTALL_FILES APP_TITLE TEXT(" necessary files aren't present.")
  25. #define INSTALL_OTHER APP_TITLE TEXT(" not properly installed.")
  26. #define NOSTATS TEXT("Statistics display is unimplemented at this time.\n") \
  27. TEXT("Please check back with the next version.")
  28. #define OPERROR TEXT("Error attempting operation.")
  29. #define TASK_TIP APP_TITLE TEXT(" Control")
  30. #define WM_SHNOTIFY WM_USER + 100
  31. #define WM_RDRSTATECHANGE WM_USER + 200
  32. #define TIMER_ID 54321
  33. typedef struct _DLGDATASTRUCT
  34. {
  35. HWND hDlg;
  36. ULONG_PTR RdrState;
  37. HBRUSH hRedBrush;
  38. HBRUSH hGrnBrush;
  39. HBRUSH hBluBrush;
  40. HBRUSH hWhtBrush;
  41. HBRUSH hYelBrush;
  42. HINSTANCE hInstance;
  43. ULONG_PTR ElapsedStartTime;
  44. ULONG_PTR Action;
  45. HANDLE hActionThread;
  46. HANDLE hBusyThread;
  47. HANDLE hBusySignal;
  48. } DLGDATASTRUCT, *PDLGDATASTRUCT;
  49. VOID InitiateAction( PDLGDATASTRUCT pdds );
  50. DWORD ActionProc( PDLGDATASTRUCT pdds );
  51. VOID IndicateWait( PDLGDATASTRUCT pdds );
  52. VOID UnindicateWait( PDLGDATASTRUCT pdds );
  53. DWORD BusyProc( PDLGDATASTRUCT pdds );
  54. #define GetDDS( _x_ ) (PDLGDATASTRUCT) GetWindowLongPtr( _x_, DWLP_USER )
  55. int WINAPI WinMain(
  56. HINSTANCE hInstance,
  57. HINSTANCE hPrevInstance,
  58. LPSTR lpCmdLine,
  59. int nCmdShow)
  60. {
  61. MSG msg;
  62. HANDLE hSingleInstance;
  63. msg.wParam = 1;
  64. hSingleInstance = CreateMutex( NULL, 0, APP_TITLE TEXT(" MUTEX") );
  65. if ( GetLastError( ) != ERROR_ALREADY_EXISTS )
  66. {
  67. BOOL RdrIsInstalled;
  68. ULONG_PTR SetupStatus;
  69. SetupStatus = RdrInstallCheck( );
  70. RdrIsInstalled = ( SetupStatus == SETUP_COMPLETE );
  71. if ( !RdrIsInstalled )
  72. {
  73. int answer;
  74. if ( SetupStatus == SETUP_INCOMPLETE )
  75. {
  76. answer = MessageBox( NULL, INSTALL_NOTICE, APP_TITLE, MB_YESNOCANCEL | MB_DEFBUTTON1 | MB_ICONEXCLAMATION );
  77. if ( answer == IDYES )
  78. {
  79. if ( !( RdrIsInstalled = RdrCompleteSetup( ) ) )
  80. {
  81. MessageBox( NULL, INSTALL_FAIL, APP_TITLE, MB_OK | MB_ICONERROR );
  82. }
  83. }
  84. else if ( answer == IDNO )
  85. {
  86. MessageBox( NULL, INSTALL_REPLY, APP_TITLE, MB_OK | MB_ICONINFORMATION );
  87. }
  88. }
  89. else if ( SetupStatus == SETUP_MISSING_FILE )
  90. {
  91. MessageBox( NULL, INSTALL_FILES, APP_TITLE, MB_OK | MB_ICONERROR );
  92. }
  93. else
  94. {
  95. MessageBox( NULL, INSTALL_OTHER, APP_TITLE, MB_OK | MB_ICONERROR );
  96. }
  97. }
  98. if ( RdrIsInstalled )
  99. {
  100. HWND hDlg;
  101. DLGDATASTRUCT dds;
  102. dds.hRedBrush = CreateSolidBrush( RGB( 255, 0, 0 ) );
  103. dds.hGrnBrush = CreateSolidBrush( RGB( 0, 255, 0 ) );
  104. dds.hBluBrush = CreateSolidBrush( RGB( 0, 0, 255 ) );
  105. dds.hWhtBrush = CreateSolidBrush( RGB( 255, 255, 255 ) );
  106. dds.hYelBrush = CreateSolidBrush( RGB( 255, 255, 127 ) );
  107. dds.hInstance = hInstance;
  108. dds.ElapsedStartTime = 0;
  109. dds.Action = 0;
  110. dds.hActionThread = NULL;
  111. dds.hBusyThread = NULL;
  112. dds.hBusySignal = NULL;
  113. dds.hDlg = NULL;
  114. dds.RdrState = RDR_NULL_STATE;
  115. hDlg = CreateDialogParam( hInstance, MAKEINTRESOURCE(IDD_SMBRDR), NULL, SmbRdrDlgProc, (LPARAM) &dds );
  116. if ( hDlg )
  117. {
  118. NOTIFYICONDATA nid;
  119. dds.hDlg = hDlg;
  120. nid.cbSize = sizeof( NOTIFYICONDATA );
  121. nid.hWnd = hDlg;
  122. nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
  123. nid.uID = IDI_SMBRDR;
  124. nid.uCallbackMessage = WM_SHNOTIFY;
  125. nid.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(IDI_SMBRDR ) );
  126. lstrcpy( nid.szTip, TASK_TIP );
  127. Shell_NotifyIcon( NIM_ADD, &nid );
  128. PostMessage( hDlg, WM_SETICON, ICON_SMALL, (LPARAM) nid.hIcon );
  129. PostMessage( hDlg, WM_SETICON, ICON_BIG, (LPARAM) nid.hIcon );
  130. while ( GetMessage( &msg, NULL, 0, 0 ) )
  131. {
  132. if ( !IsWindow( hDlg ) || !IsDialogMessage( hDlg, &msg ) )
  133. {
  134. TranslateMessage( &msg );
  135. DispatchMessage( &msg );
  136. }
  137. }
  138. Shell_NotifyIcon( NIM_DELETE, &nid );
  139. if ( nid.hIcon )
  140. {
  141. DestroyIcon( nid.hIcon );
  142. }
  143. }
  144. DeleteObject( dds.hRedBrush );
  145. DeleteObject( dds.hGrnBrush );
  146. DeleteObject( dds.hBluBrush );
  147. DeleteObject( dds.hWhtBrush );
  148. DeleteObject( dds.hYelBrush );
  149. if ( dds.hActionThread )
  150. {
  151. WaitForSingleObject( dds.hActionThread, INFINITE );
  152. CloseHandle( dds.hActionThread );
  153. dds.hActionThread = NULL;
  154. }
  155. }
  156. }
  157. else
  158. {
  159. HWND hDlg = FindWindow( NULL, APP_TITLE );
  160. SetForegroundWindow( hDlg );
  161. if ( !IsWindowVisible( hDlg ) )
  162. {
  163. ShowWindow( hDlg, SW_SHOWNORMAL );
  164. }
  165. }
  166. CloseHandle( hSingleInstance );
  167. return (int) msg.wParam;
  168. }
  169. INT_PTR CALLBACK SmbRdrDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  170. {
  171. switch ( message )
  172. {
  173. case WM_INITDIALOG:
  174. {
  175. PDLGDATASTRUCT pdds = (PDLGDATASTRUCT) lParam;
  176. RECT rect;
  177. ULONG_PTR CurrentState;
  178. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  179. CurrentState = RdrGetInitialState( );
  180. CheckRadioButton( hDlg, IDC_DRVLOAD, IDC_DRVUNLOAD,
  181. CurrentState > RDR_UNLOADING ? IDC_DRVLOAD : IDC_DRVUNLOAD );
  182. CheckRadioButton( hDlg, IDC_RDRSTART, IDC_RDRSTOP,
  183. CurrentState > RDR_STOPPING ? IDC_RDRSTART : IDC_RDRSTOP );
  184. pdds->Action = ACTION_NONE;
  185. PostMessage( hDlg, WM_RDRSTATECHANGE, 0, CurrentState );
  186. SetDlgItemText( hDlg, IDC_STARTTIME, TEXT( "00:00" ) );
  187. SetTimer( hDlg, TIMER_ID, 1000, NULL );
  188. GetWindowRect( hDlg, &rect );
  189. rect.right -= rect.left;
  190. rect.bottom -= rect.top;
  191. rect.left = ( GetSystemMetrics( SM_CXSCREEN ) - rect.right ) / 2;
  192. rect.top = ( GetSystemMetrics( SM_CYSCREEN ) - rect.bottom ) / 3;
  193. MoveWindow( hDlg,
  194. rect.left,
  195. rect.top,
  196. rect.right,
  197. rect.bottom,
  198. FALSE );
  199. }
  200. break;
  201. case WM_COMMAND:
  202. {
  203. PDLGDATASTRUCT pdds = GetDDS( hDlg );
  204. switch ( LOWORD( wParam ) )
  205. {
  206. case IDC_DRVLOAD:
  207. case IDC_DRVUNLOAD:
  208. {
  209. if ( HIWORD( wParam ) == BN_CLICKED )
  210. {
  211. ULONG_PTR NewState, action;
  212. action = ( IsDlgButtonChecked( hDlg, IDC_DRVLOAD ) == BST_CHECKED ) ?
  213. ACTION_LOAD : ACTION_UNLOAD;
  214. NewState = RdrGetNextState( action, pdds->RdrState );
  215. if ( NewState != RDR_NULL_STATE )
  216. {
  217. pdds->Action = action;
  218. PostMessage( hDlg, WM_RDRSTATECHANGE, 0, NewState );
  219. }
  220. }
  221. }
  222. break;
  223. case IDC_RDRSTART:
  224. case IDC_RDRSTOP:
  225. {
  226. if ( HIWORD( wParam ) == BN_CLICKED )
  227. {
  228. ULONG_PTR NewState, action;
  229. action = ( IsDlgButtonChecked( hDlg, IDC_RDRSTART ) == BST_CHECKED ) ?
  230. ACTION_START : ACTION_STOP;
  231. NewState = RdrGetNextState( action, pdds->RdrState );
  232. if ( NewState != RDR_NULL_STATE )
  233. {
  234. pdds->Action = action;
  235. PostMessage( hDlg, WM_RDRSTATECHANGE, 0, NewState );
  236. }
  237. }
  238. }
  239. break;
  240. case IDC_STATISTICS:
  241. MessageBox( hDlg, NOSTATS, APP_TITLE, MB_OK | MB_ICONINFORMATION );
  242. //DialogBox( pdds->hInstance, MAKEINTRESOURCE(IDD_STATISTICS), hDlg, StatisticsDlgProc );
  243. break;
  244. case IDC_PROVIDER:
  245. DialogBox( pdds->hInstance, MAKEINTRESOURCE(IDD_PROVIDER), hDlg, ProviderDlgProc );
  246. break;
  247. case IDC_HIDE:
  248. {
  249. PostMessage( hDlg, WM_SYSCOMMAND, SC_MINIMIZE, -1 );
  250. }
  251. break;
  252. }
  253. }
  254. break;
  255. case WM_RDRSTATECHANGE:
  256. {
  257. //Enter();
  258. PDLGDATASTRUCT pdds = GetDDS( hDlg );
  259. // must be a transitional state
  260. if ( (ULONG_PTR) lParam != pdds->RdrState )
  261. {
  262. pdds->RdrState = (ULONG_PTR) lParam;
  263. EnableWindow( GetDlgItem( hDlg, IDC_DRVLOAD ),
  264. ( pdds->RdrState == RDR_UNLOADED )|| ( pdds->RdrState == RDR_LOADED ) || ( pdds->RdrState == RDR_STOPPED ));
  265. EnableWindow( GetDlgItem( hDlg, IDC_DRVUNLOAD ),
  266. ( pdds->RdrState == RDR_UNLOADED )|| ( pdds->RdrState == RDR_LOADED ) || ( pdds->RdrState == RDR_STOPPED ));
  267. EnableWindow( GetDlgItem( hDlg, IDC_RDRSTART ),
  268. (pdds->RdrState == RDR_LOADED )||(pdds->RdrState == RDR_STOPPED) || (pdds->RdrState == RDR_STARTED ) );
  269. EnableWindow( GetDlgItem( hDlg, IDC_RDRSTOP ),
  270. (pdds->RdrState == RDR_LOADED )||(pdds->RdrState == RDR_STOPPED) || (pdds->RdrState == RDR_STARTED ) );
  271. switch ( lParam )
  272. {
  273. case RDR_UNLOADED:
  274. SetDlgItemText( hDlg, IDC_LOADSTATUS, TEXT("Driver Unloaded" ) );
  275. break;
  276. case RDR_UNLOADING:
  277. SetDlgItemText( hDlg, IDC_LOADSTATUS, TEXT("Driver Unloading" ) );
  278. InitiateAction( pdds );
  279. break;
  280. case RDR_LOADING:
  281. SetDlgItemText( hDlg, IDC_LOADSTATUS, TEXT("Driver Loading" ) );
  282. InitiateAction( pdds );
  283. break;
  284. case RDR_LOADED:
  285. SetDlgItemText( hDlg, IDC_LOADSTATUS, TEXT("Driver Loaded" ) );
  286. break;
  287. case RDR_STOPPING:
  288. SetDlgItemText( hDlg, IDC_STARTSTATUS, TEXT("RDR Stopping" ) );
  289. InitiateAction( pdds );
  290. break;
  291. case RDR_STOPPED:
  292. SetDlgItemText( hDlg, IDC_STARTSTATUS, TEXT("RDR Stopped" ) );
  293. pdds->ElapsedStartTime = 0;
  294. SetDlgItemText( hDlg, IDC_STARTTIME, TEXT( "00:00" ) );
  295. break;
  296. case RDR_STARTING:
  297. SetDlgItemText( hDlg, IDC_STARTSTATUS, TEXT("RDR Starting" ) );
  298. InitiateAction( pdds );
  299. break;
  300. case RDR_STARTED:
  301. SetDlgItemText( hDlg, IDC_STARTSTATUS, TEXT("RDR Started" ) );
  302. break;
  303. default:
  304. break;
  305. }
  306. }
  307. if ( pdds->Action == ACTION_ERROR )
  308. {
  309. MessageBox( hDlg, OPERROR, APP_TITLE, MB_OK | MB_ICONERROR );
  310. }
  311. //Leave();
  312. }
  313. break;
  314. case WM_TIMER:
  315. {
  316. TCHAR timestring[8];
  317. PDLGDATASTRUCT pdds = GetDDS( hDlg );
  318. if ( wParam == TIMER_ID && pdds->RdrState > RDR_STOPPED )
  319. {
  320. pdds->ElapsedStartTime++;
  321. wsprintf( timestring, TEXT("%02d:%02d"), pdds->ElapsedStartTime / 60,
  322. pdds->ElapsedStartTime % 60 );
  323. SetDlgItemText( hDlg, IDC_STARTTIME, timestring );
  324. }
  325. }
  326. break;
  327. case WM_CTLCOLORSTATIC:
  328. {
  329. PDLGDATASTRUCT pdds = GetDDS( hDlg );
  330. HBRUSH hBkBrush;
  331. switch ( GetWindowLongPtr( (HWND) lParam, GWL_ID ) )
  332. {
  333. case IDC_DRVCONTROLTEXT:
  334. case IDC_RDRCONTROLTEXT:
  335. case IDC_SETTINGSTEXT:
  336. SetBkMode( (HDC) wParam, TRANSPARENT );
  337. hBkBrush = pdds->hWhtBrush;
  338. break;
  339. case IDC_LOADSTATUS:
  340. {
  341. SetBkMode( (HDC) wParam, TRANSPARENT );
  342. if ( pdds->RdrState < RDR_UNLOADING )
  343. {
  344. hBkBrush = pdds->hRedBrush;
  345. }
  346. else if ( pdds->RdrState < RDR_LOADED )
  347. {
  348. hBkBrush = pdds->hYelBrush;
  349. }
  350. else
  351. {
  352. hBkBrush = pdds->hGrnBrush;
  353. }
  354. }
  355. break;
  356. case IDC_STARTSTATUS:
  357. {
  358. SetBkMode( (HDC) wParam, TRANSPARENT );
  359. if ( pdds->RdrState < RDR_STOPPING )
  360. {
  361. hBkBrush = pdds->hRedBrush;
  362. }
  363. else if ( pdds->RdrState < RDR_STARTED )
  364. {
  365. hBkBrush = pdds->hYelBrush;
  366. }
  367. else
  368. {
  369. hBkBrush = pdds->hGrnBrush;
  370. }
  371. }
  372. break;
  373. case IDC_BUSY:
  374. default:
  375. hBkBrush = (HBRUSH) FALSE;
  376. break;
  377. }
  378. return (INT_PTR) hBkBrush;
  379. }
  380. break;
  381. case WM_SETICON:
  382. {
  383. // catch it on the second pass so it has the previous icon to now draw
  384. if ( wParam == ICON_BIG )
  385. {
  386. ShowWindow( hDlg, SW_SHOWNORMAL );
  387. }
  388. }
  389. break;
  390. case WM_SHNOTIFY:
  391. {
  392. if ( wParam == IDI_SMBRDR )
  393. {
  394. if ( lParam == WM_LBUTTONDBLCLK )
  395. {
  396. if ( IsWindowVisible( hDlg ) )
  397. {
  398. SetForegroundWindow( hDlg );
  399. }
  400. else
  401. {
  402. ShowWindow( hDlg, SW_RESTORE );
  403. }
  404. }
  405. else if ( lParam == WM_RBUTTONDOWN && !IsWindowVisible( hDlg ) )
  406. {
  407. HMENU hPopup = CreatePopupMenu( );
  408. POINT cursorpos;
  409. HWND hfgrd;
  410. ULONG_PTR popselect;
  411. GetCursorPos( &cursorpos );
  412. if ( hPopup )
  413. {
  414. PDLGDATASTRUCT pdds = GetDDS( hDlg );
  415. MENUITEMINFO mii;
  416. ZeroMemory( &mii, sizeof( MENUITEMINFO ) );
  417. mii.cbSize = sizeof( MENUITEMINFO );
  418. mii.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;
  419. mii.fType = MFT_STRING;
  420. mii.wID = IDM_OPEN;
  421. mii.fState = MFS_DEFAULT;
  422. mii.fMask |= MIIM_STATE;
  423. mii.dwTypeData = TEXT("Open ") APP_TITLE TEXT(" Control");
  424. InsertMenuItem( hPopup, 0, TRUE, &mii );
  425. mii.wID = IDM_CLOSE;
  426. mii.fMask &= ~MIIM_STATE;
  427. mii.fState &= ~MFS_DEFAULT;
  428. mii.dwTypeData = TEXT("Exit");
  429. InsertMenuItem( hPopup, 1, TRUE, &mii );
  430. if ( ( pdds->RdrState == RDR_STOPPED ) ||
  431. (pdds->RdrState == RDR_STARTED ) ||
  432. (pdds->RdrState == RDR_LOADED ) )
  433. {
  434. mii.wID = 0;
  435. mii.fMask = MIIM_TYPE;
  436. mii.dwTypeData = NULL;
  437. mii.fType = MFT_SEPARATOR;
  438. InsertMenuItem( hPopup, 2, TRUE, &mii );
  439. mii.fType = MFT_STRING;
  440. mii.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;
  441. if ( ( pdds->RdrState == RDR_STOPPED ) ||
  442. (pdds->RdrState == RDR_LOADED ) )
  443. {
  444. mii.wID = IDM_START;
  445. mii.dwTypeData = TEXT( "Start the RDR" );
  446. InsertMenuItem( hPopup, 3, TRUE, &mii );
  447. }
  448. else if ( pdds->RdrState == RDR_STARTED )
  449. {
  450. mii.wID = IDM_STOP;
  451. mii.dwTypeData = TEXT( "Stop the RDR" );
  452. InsertMenuItem( hPopup, 3, TRUE, &mii );
  453. }
  454. }
  455. SetActiveWindow( hDlg );
  456. popselect = TrackPopupMenu( hPopup,
  457. TPM_LEFTBUTTON | TPM_RIGHTALIGN | TPM_BOTTOMALIGN |
  458. TPM_NONOTIFY | TPM_RETURNCMD,
  459. cursorpos.x,
  460. cursorpos.y,
  461. 0,
  462. hDlg,
  463. NULL );
  464. DestroyMenu( hPopup );
  465. switch ( popselect )
  466. {
  467. case IDM_OPEN:
  468. {
  469. ShowWindow( hDlg, SW_SHOWNORMAL );
  470. }
  471. break;
  472. case IDM_CLOSE:
  473. {
  474. PostMessage( hDlg, WM_CLOSE, 0, 0 );
  475. }
  476. break;
  477. case IDM_START:
  478. {
  479. CheckRadioButton( hDlg, IDC_RDRSTART, IDC_RDRSTOP, IDC_RDRSTART );
  480. PostMessage( hDlg, WM_COMMAND, MAKELONG(IDC_RDRSTART, BN_CLICKED),
  481. (LPARAM) GetDlgItem( hDlg, IDC_RDRSTART) );
  482. }
  483. break;
  484. case IDM_STOP:
  485. {
  486. CheckRadioButton( hDlg, IDC_RDRSTART, IDC_RDRSTOP, IDC_RDRSTOP );
  487. PostMessage( hDlg, WM_COMMAND, MAKELONG(IDC_RDRSTOP, BN_CLICKED),
  488. (LPARAM) GetDlgItem( hDlg, IDC_RDRSTOP) );
  489. }
  490. break;
  491. default:
  492. break;
  493. }
  494. }
  495. }
  496. }
  497. }
  498. break;
  499. case WM_SYSCOMMAND:
  500. {
  501. if ( wParam == SC_MINIMIZE )
  502. {
  503. ShowWindow( hDlg, SW_HIDE );
  504. return TRUE;
  505. }
  506. }
  507. break;
  508. case WM_CLOSE:
  509. {
  510. PDLGDATASTRUCT pdds = GetDDS( hDlg );
  511. if ( pdds->hActionThread )
  512. {
  513. if ( WaitForSingleObject( pdds->hActionThread, 0 ) != WAIT_OBJECT_0 )
  514. {
  515. return TRUE;
  516. }
  517. }
  518. if ( pdds->RdrState == RDR_STARTED )
  519. {
  520. return TRUE;
  521. }
  522. DestroyWindow( hDlg );
  523. }
  524. break;
  525. case WM_DESTROY:
  526. KillTimer( hDlg, TIMER_ID );
  527. PostQuitMessage( 0 );
  528. break;
  529. }
  530. return 0;
  531. }
  532. INT_PTR CALLBACK ProviderDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  533. {
  534. switch (message)
  535. {
  536. case WM_INITDIALOG:
  537. {
  538. ULONG_PTR count, len, nIndex;
  539. LPTSTR OrderString = NULL, marker, ptr;
  540. #if 0 // #ifdef UNICODE
  541. TCHAR btntext[10];
  542. btntext[0] = 0x25b2; // up arrow in unicode char set
  543. lstrcpy( &btntext[1], TEXT(" Move Up" ));
  544. SetDlgItemText( hDlg, IDC_MOVEUP, btntext );
  545. btntext[0] = 0x25bc; // down arrow in unicode char set
  546. lstrcpy( &btntext[1], TEXT(" Move Dn" ));
  547. SetDlgItemText( hDlg, IDC_MOVEDN, btntext );
  548. #endif
  549. len = RdrGetProviderOrderString( &OrderString );
  550. marker = OrderString;
  551. for ( count = 0, ptr = OrderString; ptr && count <= len; count++, ptr++ )
  552. {
  553. switch ( *ptr )
  554. {
  555. case TEXT(','):
  556. {
  557. if ( count > 0 && ptr > marker )
  558. {
  559. *ptr = TEXT('\0');
  560. SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_ADDSTRING, 0, (LPARAM) marker );
  561. *ptr = TEXT(',');
  562. }
  563. marker = ptr + 1;
  564. }
  565. break;
  566. case TEXT('\0'):
  567. {
  568. if ( count > 0 && ptr > marker )
  569. {
  570. SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_ADDSTRING, 0, (LPARAM) marker );
  571. }
  572. }
  573. break;
  574. case TEXT(' '):
  575. marker = ptr + 1;
  576. break;
  577. default:
  578. break;
  579. }
  580. }
  581. if ( OrderString )
  582. {
  583. free( OrderString );
  584. }
  585. nIndex = SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_FINDSTRING,
  586. (WPARAM) -1, (LPARAM) PROVIDER_NAME );
  587. SetWindowLongPtr( hDlg, DWLP_USER, nIndex );
  588. if ( nIndex == LB_ERR)
  589. {
  590. nIndex = 0;
  591. EnableWindow( GetDlgItem( hDlg, IDC_MOVEUP ), FALSE );
  592. EnableWindow( GetDlgItem( hDlg, IDC_MOVEDN ), FALSE );
  593. }
  594. SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_SETCURSEL,
  595. (WPARAM) nIndex, 0 );
  596. }
  597. break;
  598. case WM_COMMAND:
  599. {
  600. switch ( LOWORD( wParam ) )
  601. {
  602. case IDC_ORDERLIST:
  603. {
  604. if ( HIWORD( wParam ) == LBN_SELCHANGE )
  605. {
  606. ULONG_PTR staticsel, cursel;
  607. staticsel = GetWindowLongPtr( hDlg, DWLP_USER );
  608. cursel = SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_GETCURSEL, 0, 0 );
  609. if ( staticsel != cursel && staticsel != LB_ERR )
  610. {
  611. SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_SETCURSEL,
  612. (WPARAM) staticsel, 0 );
  613. }
  614. }
  615. }
  616. break;
  617. case IDC_MOVEUP:
  618. case IDC_MOVEDN:
  619. {
  620. ULONG_PTR staticsel, items, len;
  621. LPTSTR pstr;
  622. staticsel = GetWindowLongPtr( hDlg, DWLP_USER );
  623. items = SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_GETCOUNT,0 ,0 );
  624. if ( staticsel != LB_ERR && items != LB_ERR )
  625. {
  626. len = SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_GETTEXTLEN, staticsel, 0 );
  627. pstr = malloc( (len + 1 ) * sizeof(TCHAR) );
  628. if ( pstr )
  629. {
  630. if ( LOWORD( wParam ) == IDC_MOVEUP && staticsel > 0 )
  631. {
  632. SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_GETTEXT, staticsel, (LPARAM) pstr );
  633. SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_DELETESTRING, staticsel, 0 );
  634. SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_INSERTSTRING, --staticsel, (LPARAM) pstr );
  635. }
  636. else if ( (LOWORD( wParam ) == IDC_MOVEDN) && (items > 0) && (staticsel < (items - 1) ) )
  637. {
  638. SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_GETTEXT, staticsel, (LPARAM) pstr );
  639. SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_DELETESTRING, staticsel, 0 );
  640. SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_INSERTSTRING, ++staticsel, (LPARAM) pstr );
  641. }
  642. free( pstr );
  643. SetWindowLongPtr( hDlg, DWLP_USER, staticsel );
  644. SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_SETCURSEL, staticsel, 0 );
  645. }
  646. }
  647. }
  648. break;
  649. case IDOK:
  650. {
  651. LPTSTR OrderString, pstr;
  652. ULONG_PTR items, len = 0, index;
  653. items = SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_GETCOUNT,0 ,0 );
  654. if ( items != LB_ERR )
  655. {
  656. for ( index = 0; items > 0 && index < items; index++ )
  657. {
  658. len += SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_GETTEXTLEN, index, 0 );
  659. }
  660. len += items; //commas and ending null
  661. OrderString = pstr = malloc( len * sizeof( TCHAR ) );
  662. if ( OrderString )
  663. {
  664. for ( index = 0; items > 0 && index < items; index++ )
  665. {
  666. len = SendDlgItemMessage( hDlg, IDC_ORDERLIST, LB_GETTEXT, index, (LPARAM) pstr );
  667. pstr += len;
  668. *pstr++ = ( index < ( items - 1 ) ) ? TEXT(',') : TEXT('\0');
  669. }
  670. RdrSetProviderOrderString( OrderString );
  671. free( OrderString );
  672. }
  673. }
  674. }
  675. case IDCANCEL:
  676. PostMessage( hDlg, WM_CLOSE, 0, 0 );
  677. break;
  678. }
  679. }
  680. break;
  681. case WM_CLOSE:
  682. EndDialog( hDlg, 0 );
  683. break;
  684. }
  685. return FALSE;
  686. }
  687. INT_PTR CALLBACK StatisticsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  688. {
  689. switch (message)
  690. {
  691. case WM_COMMAND:
  692. {
  693. switch ( LOWORD( wParam ) )
  694. {
  695. case IDOK:
  696. PostMessage( hDlg, WM_CLOSE, 0, 0 );
  697. break;
  698. }
  699. }
  700. break;
  701. case WM_CLOSE:
  702. EndDialog( hDlg, 0 );
  703. break;
  704. }
  705. return FALSE;
  706. }
  707. VOID IndicateWait( PDLGDATASTRUCT pdds )
  708. {
  709. pdds->hBusySignal = CreateEvent( NULL, FALSE, FALSE, NULL );
  710. pdds->hBusyThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) BusyProc, pdds, 0, NULL );
  711. }
  712. VOID UnindicateWait( PDLGDATASTRUCT pdds )
  713. {
  714. SetEvent( pdds->hBusySignal );
  715. WaitForSingleObject( pdds->hBusyThread, 1000 );
  716. CloseHandle( pdds->hBusyThread );
  717. CloseHandle( pdds->hBusySignal );
  718. pdds->hBusyThread = NULL;
  719. pdds->hBusySignal = NULL;
  720. }
  721. VOID InitiateAction( PDLGDATASTRUCT pdds )
  722. {
  723. if ( pdds->hActionThread )
  724. {
  725. WaitForSingleObject( pdds->hActionThread, INFINITE );
  726. CloseHandle( pdds->hActionThread );
  727. pdds->hActionThread = NULL;
  728. }
  729. //pdds->Action = ACTION_TRANS;
  730. pdds->hActionThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) ActionProc, pdds, 0, NULL );
  731. }
  732. DWORD ActionProc( PDLGDATASTRUCT pdds )
  733. {
  734. ULONG_PTR newstate;
  735. BOOL success;
  736. IndicateWait( pdds );
  737. success = RdrDoAction( pdds->Action );
  738. UnindicateWait( pdds );
  739. pdds->Action = success ? ACTION_TRANS : ACTION_ERROR;
  740. newstate = RdrGetNextState( pdds->Action, pdds->RdrState );
  741. PostMessage( pdds->hDlg, WM_RDRSTATECHANGE, 0, newstate );
  742. return 0;
  743. }
  744. DWORD BusyProc( PDLGDATASTRUCT pdds )
  745. {
  746. HDC hDC;
  747. HWND hBusyWnd = GetDlgItem( pdds->hDlg, IDC_BUSY );
  748. ULONG pos = 0, width;
  749. RECT clRect, mRect;
  750. GetClientRect( hBusyWnd, &clRect );
  751. mRect.left = clRect.left;
  752. mRect.top = clRect.top + clRect.bottom / 6;
  753. mRect.right = width = clRect.right / 8;
  754. mRect.bottom = clRect.bottom - clRect.bottom / 6;
  755. while ( WaitForSingleObject( pdds->hBusySignal, 100 ) == WAIT_TIMEOUT )
  756. {
  757. hDC = GetDC( hBusyWnd );
  758. FillRect( hDC, &clRect, pdds->hWhtBrush );
  759. FillRect( hDC, &mRect, pdds->hBluBrush );
  760. mRect.left += width;
  761. mRect.right += width;
  762. if ( mRect.right > clRect.right )
  763. {
  764. mRect.left = 0;
  765. mRect.right = width;
  766. }
  767. ReleaseDC( hBusyWnd, hDC );
  768. }
  769. InvalidateRect( hBusyWnd, NULL, TRUE );
  770. return 0;
  771. }