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.

1422 lines
35 KiB

  1. #include "main.h"
  2. #include "resource.h"
  3. CRITICAL_SECTION ReportResults;
  4. #include <Richedit.h>
  5. // Globals
  6. HINSTANCE g_hinst;
  7. HWND g_hWnd;
  8. BOOL ContinuePing = FALSE;
  9. TCHAR g_szPingEvent[] = _T("PingEvent");
  10. BOOL g_bMonitoring = FALSE;
  11. HANDLE g_hPingEvent = NULL;
  12. DWORD g_CurrentIndex = -1;
  13. double RunningTime = 0.0;
  14. DWORD TotalFilesProcessed = 0;
  15. DWORD TotalUploadFailures = 0;
  16. DWORD TotalUnknownErrors = 0;
  17. DWORD TotalTimeouts = 0;
  18. time_t appStart = 0;
  19. time_t appStop = 0;
  20. MONITOR_OPTIONS g_MonitorOptions;
  21. DWORD dwBufferPos = 0;
  22. TCHAR LogFileName[MAX_PATH];
  23. HANDLE hLogFile = INVALID_HANDLE_VALUE;
  24. time_t LogStart = 0;
  25. double TotalUploadTime = 0.0;
  26. double AvgUploadTime = 0.0;
  27. double TotalProcessTime = 0.0;
  28. double AvgProcessTime = 0.0;
  29. double TotalRecQueueTime = 0.0;
  30. double TotalSndQueueTime = 0.0;
  31. double TotalThreadTime = 0.0;
  32. BOOL UpdateListView(HWND hwnd, PSITESTATS pStats )
  33. {
  34. LVITEM lvi;
  35. TCHAR Temp[100];
  36. double ElapsedTime;
  37. ZeroMemory(&lvi, sizeof LVITEM);
  38. TCHAR tmpbuf[128];
  39. HWND hListControl = GetDlgItem( hwnd, IDC_LIST1);
  40. COLORREF CurrentColor;
  41. HWND hEditBox;
  42. lvi.mask = LVIF_TEXT | LVIF_STATE;
  43. lvi.state = 0;
  44. lvi.stateMask = 0;
  45. if ( (!_tcscmp(_T("FAILED"), pStats->UploadStatus) )|| (!_tcscmp(_T("FAILED"), pStats->ProcessStatus)) )
  46. {
  47. // ListView_SetItemState( hListControl, g_CurrentIndex, LVIS_DROPHILITED,LVIS_DROPHILITED);
  48. // hEditBox = ListView_GetEditControl(hListControl);
  49. // SendMessage(hEditBox, EM_SETBKGNDCOLOR, 0, RGB(100,0,0));
  50. lvi.state = LVIS_DROPHILITED;
  51. }
  52. ++g_CurrentIndex;
  53. if (g_CurrentIndex > 1000)
  54. {
  55. ListView_DeleteItem(hListControl,0);
  56. g_CurrentIndex -=1;
  57. }
  58. lvi.iItem = g_CurrentIndex ;
  59. // lvI.iImage = index;
  60. lvi.iSubItem = 0;
  61. lvi.pszText = pStats->UploadTime;
  62. ListView_InsertItem(hListControl,&lvi);
  63. lvi.iSubItem = 1;
  64. lvi.pszText = pStats->UploadStatus;
  65. ListView_SetItem(hListControl,&lvi);
  66. lvi.iSubItem = 2;
  67. lvi.pszText = pStats->ProcessingTime;
  68. ListView_SetItem(hListControl, &lvi);
  69. lvi.iSubItem = 3;
  70. lvi.pszText = pStats->ProcessStatus;
  71. ListView_SetItem(hListControl, &lvi);
  72. lvi.iSubItem = 4;
  73. lvi.pszText = pStats->ThreadExecution;
  74. ListView_SetItem(hListControl, &lvi);
  75. lvi.iSubItem = 5;
  76. lvi.pszText = pStats->ReceiveQueueTime;
  77. ListView_SetItem(hListControl, &lvi);
  78. lvi.iSubItem = 6;
  79. lvi.pszText = pStats->SendQueueTime;
  80. ListView_SetItem(hListControl, &lvi);
  81. lvi.iSubItem = 7;
  82. lvi.pszText = pStats->ReturnedUrl;
  83. ListView_SetItem(hListControl, &lvi);
  84. lvi.iSubItem = 8;
  85. lvi.pszText = pStats->ErrorString;;
  86. ListView_SetItem(hListControl, &lvi);
  87. ListView_EnsureVisible(hListControl, g_CurrentIndex, FALSE);
  88. _itot(TotalFilesProcessed,Temp, 10);
  89. SetDlgItemText(hwnd, IDC_EDIT3, Temp);
  90. _itot (TotalTimeouts,Temp, 10);
  91. SetDlgItemText(hwnd, IDC_EDIT2, Temp);
  92. _itot(TotalUploadFailures,Temp,10);
  93. SetDlgItemText(hwnd, IDC_EDIT4, Temp);
  94. _itot(TotalUnknownErrors,Temp,10);
  95. SetDlgItemText(hwnd, IDC_EDIT6, Temp);
  96. time(&appStop);
  97. ElapsedTime = difftime(appStop, appStart);
  98. StringCbPrintf(Temp, sizeof Temp, _T("%6.02f"), ElapsedTime);
  99. SetDlgItemText(hwnd, IDC_EDIT5, Temp);
  100. SetDlgItemText(hwnd, IDC_EDIT1, pStats->AvgUploadTime);
  101. SetDlgItemText(hwnd, IDC_EDIT7, pStats->AvgProcessTime);
  102. SetDlgItemText(hwnd, IDC_EDIT8, pStats->ThreadExecution);
  103. SetDlgItemText(hwnd, IDC_EDIT9, pStats->SendQueueTime);
  104. SetDlgItemText(hwnd, IDC_EDIT10, pStats->ReceiveQueueTime);
  105. LogMessage(_T("%s %s,%s,%s,%s,%s,%s,%s,%s,%s,%s"),_tstrdate(tmpbuf), _tstrtime( tmpbuf ),
  106. pStats->UploadTime, pStats->UploadStatus,
  107. pStats->ProcessingTime, pStats->ProcessStatus,
  108. pStats->ThreadExecution, pStats->ReceiveQueueTime, pStats->SendQueueTime,
  109. pStats->ReturnedUrl,
  110. pStats->ErrorString);
  111. return TRUE;
  112. }
  113. void GetRegData()
  114. {
  115. }
  116. DWORD Upload(TCHAR *SourceFileName, TCHAR *VirtualDir, TCHAR *HostName, TCHAR *RemoteFileName)
  117. {
  118. static const TCHAR *pszAccept[] = {_T("*.*"), 0};
  119. //TCHAR RemoteFileName[MAX_PATH]; // Host/Virtualdirectory/filename
  120. BOOL bRet = FALSE;
  121. BOOL UploadSuccess = FALSE;
  122. DWORD dwBytesRead = 0;
  123. DWORD dwBytesWritten = 0;
  124. DWORD ResponseCode = 0;
  125. DWORD ResLength = 255;
  126. DWORD index = 0;
  127. DWORD ErrorCode = 0;
  128. HINTERNET hSession = NULL;
  129. HINTERNET hConnect = NULL;
  130. HINTERNET hRequest = NULL;
  131. INTERNET_BUFFERS BufferIn = {0};
  132. INTERNET_BUFFERS BufferOut = {0};
  133. HANDLE hFile = INVALID_HANDLE_VALUE;
  134. BYTE *pBuffer;
  135. BOOL bOnce = FALSE;
  136. GUID guidNewGuid;
  137. char *szGuidRaw = NULL;
  138. HRESULT hResult = S_OK;
  139. wchar_t *wszGuidRaw = NULL;
  140. TCHAR DestinationName[MAX_PATH];
  141. CoInitialize(NULL);
  142. hResult = CoCreateGuid(&guidNewGuid);
  143. if (FAILED(hResult))
  144. {
  145. //-------------What do we send here....
  146. //goto ERRORS;
  147. ;
  148. }
  149. else
  150. {
  151. if (UuidToStringW(&guidNewGuid, &wszGuidRaw) == RPC_S_OK)
  152. {
  153. if ( (szGuidRaw = (char *) malloc ( wcslen(wszGuidRaw)*2 )) != NULL)
  154. {
  155. // clear the memory
  156. ZeroMemory(szGuidRaw, wcslen(wszGuidRaw) * 2);
  157. wcstombs( szGuidRaw, wszGuidRaw, wcslen(wszGuidRaw));
  158. }
  159. else
  160. {
  161. // LogMessage(_T("Memory allocation failed: ErrorCode:%d"),GetLastError());
  162. ErrorCode = GetLastError();
  163. goto cleanup;
  164. }
  165. }
  166. }
  167. StringCbPrintf(DestinationName, MAX_PATH * sizeof TCHAR, _T("\\%s\\%s%s"),VirtualDir,szGuidRaw + 19, PathFindFileName(SourceFileName));
  168. StringCbPrintf(RemoteFileName, MAX_PATH * sizeof TCHAR, _T("%s%s"),szGuidRaw + 19, PathFindFileName(SourceFileName));
  169. hSession = InternetOpen( _T("IsapiStress"),
  170. INTERNET_OPEN_TYPE_PRECONFIG,
  171. NULL,
  172. NULL,
  173. 0);
  174. if (!hSession)
  175. {
  176. // LogMessage(_T("Failed to create an internet session."));
  177. CoUninitialize();
  178. ErrorCode = GetLastError();
  179. goto cleanup;
  180. }
  181. hConnect = InternetConnect(hSession,
  182. HostName,
  183. INTERNET_DEFAULT_HTTP_PORT,
  184. NULL,
  185. NULL,
  186. INTERNET_SERVICE_HTTP,
  187. 0,
  188. NULL);
  189. if (hConnect == INVALID_HANDLE_VALUE)
  190. {
  191. // LogMessage(_T("Failed to create an internet connection."));
  192. ErrorCode = GetLastError();
  193. goto cleanup;
  194. }
  195. // LogMessage(_T("Connecting to: %s"),HostName);
  196. // LogMessage(_T("Uploading file: %s"),DestinationName);
  197. hRequest = HttpOpenRequest( hConnect,
  198. _T("PUT"),
  199. DestinationName,
  200. NULL,
  201. NULL,
  202. pszAccept,
  203. INTERNET_FLAG_NEED_FILE|INTERNET_FLAG_NO_CACHE_WRITE ,
  204. 0);
  205. if (hRequest != INVALID_HANDLE_VALUE)
  206. {
  207. hFile = CreateFile( SourceFileName,
  208. GENERIC_READ,
  209. FILE_SHARE_READ,
  210. NULL,
  211. OPEN_EXISTING,
  212. FILE_ATTRIBUTE_NORMAL,
  213. NULL);
  214. if (hFile != INVALID_HANDLE_VALUE)
  215. {
  216. // Clear the buffer
  217. if ( (pBuffer = (BYTE *)malloc (70000)) != NULL)
  218. {
  219. BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS );
  220. BufferIn.Next = NULL;
  221. BufferIn.lpcszHeader = NULL;
  222. BufferIn.dwHeadersLength = 0;
  223. BufferIn.dwHeadersTotal = 0;
  224. BufferIn.lpvBuffer = NULL;
  225. BufferIn.dwBufferLength = 0;
  226. BufferIn.dwOffsetLow = 0;
  227. BufferIn.dwOffsetHigh = 0;
  228. BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);
  229. FillMemory(pBuffer, 70000,'/0'); // Fill buffer with data
  230. DWORD dwBuffLen = sizeof DWORD;
  231. if(!HttpSendRequestEx( hRequest,
  232. &BufferIn,
  233. NULL,
  234. HSR_INITIATE,
  235. 0))
  236. {
  237. // LogMessage(_T("HttpSendRequestEx Failed."));
  238. }
  239. else
  240. {
  241. do
  242. {
  243. dwBytesRead = 0;
  244. bRet = ReadFile(hFile,
  245. pBuffer,
  246. 70000,
  247. &dwBytesRead,
  248. NULL);
  249. if (bRet != 0)
  250. {
  251. bRet = InternetWriteFile(hRequest,
  252. pBuffer,
  253. dwBytesRead,
  254. &dwBytesWritten);
  255. if ( (!bRet) || (dwBytesWritten==0) )
  256. {
  257. // LogMessage(_T("Error Writting File: %d"),ErrorCode = GetLastError());
  258. }
  259. }
  260. } while (dwBytesRead == sizeof (pBuffer));
  261. CloseHandle(hFile);
  262. hFile = INVALID_HANDLE_VALUE;
  263. bRet = HttpEndRequest( hRequest,
  264. NULL,
  265. 0,
  266. 0);
  267. if (bRet)
  268. {
  269. ResponseCode = 0;
  270. HttpQueryInfo(hRequest,
  271. HTTP_QUERY_STATUS_CODE |HTTP_QUERY_FLAG_NUMBER,
  272. &ResponseCode,
  273. &ResLength,
  274. &index);
  275. if ( (ResponseCode != 200) && (ResponseCode != 201))
  276. {
  277. ErrorCode=ResponseCode;
  278. // LogMessage(_T("IIS Response Code = %d"),ResponseCode);
  279. // Cleanup for retry
  280. }
  281. else
  282. {
  283. ErrorCode = 0;
  284. // LogMessage(_T("IIS Response Code = %d"),ResponseCode);
  285. UploadSuccess = TRUE;
  286. }
  287. }
  288. else
  289. {
  290. ErrorCode = GetLastError();
  291. // LogMessage(_T("HttpEndrequest Returned an Error: %d"), ErrorCode);
  292. }
  293. }
  294. }
  295. else
  296. {
  297. ErrorCode = GetLastError();
  298. // LogMessage(_T("Failed to allocate buffer memory"));
  299. }
  300. }
  301. else
  302. {
  303. ErrorCode = -1;
  304. // LogMessage(_T("Failed to Open Source File"));
  305. }
  306. }
  307. else
  308. {
  309. ErrorCode = GetLastError();
  310. // LogMessage(_T("Failed to Create Put Request"));
  311. }
  312. cleanup:
  313. // Clean up
  314. if (hFile!= INVALID_HANDLE_VALUE)
  315. {
  316. CloseHandle (hFile);
  317. hFile = INVALID_HANDLE_VALUE;
  318. }
  319. if (hSession)
  320. {
  321. InternetCloseHandle(hSession);
  322. hSession = INVALID_HANDLE_VALUE;
  323. }
  324. if (hConnect)
  325. {
  326. InternetCloseHandle(hConnect);
  327. hConnect = INVALID_HANDLE_VALUE;
  328. }
  329. if (hRequest)
  330. {
  331. InternetCloseHandle(hRequest);
  332. hRequest = INVALID_HANDLE_VALUE;
  333. }
  334. if (pBuffer)
  335. {
  336. free (pBuffer);
  337. pBuffer = NULL;
  338. }
  339. if (wszGuidRaw)
  340. {
  341. RpcStringFreeW(&wszGuidRaw);
  342. wszGuidRaw = NULL;
  343. }
  344. if (szGuidRaw)
  345. {
  346. free(szGuidRaw);
  347. szGuidRaw = NULL;
  348. }
  349. CoUninitialize();
  350. return ErrorCode;
  351. }
  352. DWORD GetResponseUrl(TCHAR * HostName, TCHAR *RemoteFileName,TCHAR *ResponseURL)
  353. {
  354. TCHAR IsapiUrl[255];
  355. TCHAR *pUploadUrl = NULL;
  356. TCHAR *temp = NULL;
  357. BOOL bRet = FALSE;
  358. DWORD dwUrlLength = 0;
  359. DWORD ErrorCode = 0;
  360. DWORD dwLastError = 0;
  361. TCHAR NewState;
  362. HINTERNET hSession;
  363. HINTERNET hRedirUrl;
  364. BOOL bOnce = FALSE;
  365. DWORD dwBuffLen = 0;
  366. DWORD dwFlags = 0;
  367. TCHAR LocalUrl[255];
  368. ZeroMemory (IsapiUrl, sizeof IsapiUrl);
  369. ZeroMemory (LocalUrl, sizeof LocalUrl);
  370. HINTERNET hUrlFile = NULL;
  371. StringCbPrintf (IsapiUrl,sizeof IsapiUrl, _T("http://%s/isapi/oca_extension.dll?id=%s&Type=5"),HostName, RemoteFileName);
  372. // LogMessage(_T("Connecting to url: %s"),IsapiUrl);
  373. //StringCbPrintf (IsapiUrl,sizeof IsapiUrl, _T("http://www.microsoft.com"));
  374. hSession = InternetOpen(_T("Isapi Stress"),
  375. INTERNET_OPEN_TYPE_PRECONFIG,
  376. NULL,
  377. NULL,
  378. 0);
  379. if (hSession)
  380. {
  381. // Open the url we want to connect to.
  382. hUrlFile = InternetOpenUrl(hSession,
  383. IsapiUrl,
  384. NULL,
  385. 0,
  386. 0,
  387. 0);
  388. // Read the page returned by the isapi dll.
  389. TCHAR buffer[255] ;
  390. ZeroMemory (buffer, sizeof buffer);
  391. DWORD dwBytesRead = 0;
  392. BOOL bRead = InternetReadFile(hUrlFile,
  393. buffer,
  394. sizeof(buffer),
  395. &dwBytesRead);
  396. //buffer[sizeof (buffer) -1] = _T('\0');
  397. StringCbCopy (ResponseURL, sizeof buffer, buffer);
  398. // LogMessage(_T("Received URL: %s"), ResponseURL);
  399. }
  400. InternetCloseHandle(hUrlFile);
  401. InternetCloseHandle(hSession);
  402. return 0;
  403. }
  404. ULONG __stdcall ThreadFunc(void * args)
  405. {
  406. SITESTATS Stats;
  407. HANDLE hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, g_szPingEvent);
  408. time_t UploadStart;
  409. time_t UploadStop;
  410. time_t ProcessStart;
  411. time_t ProcessStop;
  412. TCHAR ReturnedUrl[255];
  413. TCHAR RemoteFileName[MAX_PATH];
  414. DWORD ResponseCode = 0;
  415. int ResponseCode1 = 0;
  416. ZeroMemory( &Stats, sizeof SITESTATS);
  417. int iCode = 0;
  418. TCHAR *pCode = NULL;
  419. DWORD tempTime = 0;
  420. time(&appStart);
  421. // LogMessage(_T("Pinging Site: %s"), g_MonitorOptions.ServerName);
  422. // LogMessage(_T("----------------"));
  423. double ElapsedTime;
  424. do
  425. {
  426. UploadStart = 0;
  427. UploadStop = 0;
  428. ProcessStart = 0;
  429. ProcessStop = 0;
  430. ZeroMemory(RemoteFileName, sizeof RemoteFileName);
  431. ZeroMemory(ReturnedUrl, sizeof ReturnedUrl);
  432. ZeroMemory(&Stats, sizeof SITESTATS);
  433. if (g_MonitorOptions.UploadSingle)
  434. {
  435. if (g_MonitorOptions.CollectUploadTime)
  436. {
  437. // Start upload timer
  438. time( &UploadStart);
  439. // UploadSingle(g_MonitorOptions.ServerName, g_MonitorOptions.dwSiteID, g_MonitorOptions.FilePath,g_MonitorOptions.bUploadMethod);
  440. ResponseCode = Upload(g_MonitorOptions.FilePath,
  441. g_MonitorOptions.VirtualDirectory,
  442. g_MonitorOptions.ServerName ,
  443. RemoteFileName);
  444. if (ResponseCode == 0)
  445. StringCbCopy(Stats.UploadStatus,sizeof Stats.UploadStatus, _T("Succeded"));
  446. else
  447. StringCbCopy(Stats.UploadStatus ,sizeof Stats.UploadStatus,_T("FAILED"));
  448. // End UploadTimer
  449. time( &UploadStop);
  450. //MessageBox(NULL,Stats.UploadStatus,NULL,MB_OK);
  451. }
  452. else
  453. {
  454. // UploadSingle(g_MonitorOptions.ServerName, g_MonitorOptions.dwSiteID, g_MonitorOptions.FilePath,g_MonitorOptions.bUploadMethod);
  455. }
  456. }
  457. else
  458. {
  459. // find first file loop
  460. }
  461. if ((g_MonitorOptions.CollectProcessTime) && (ResponseCode == 0))
  462. {
  463. time ( &ProcessStart);
  464. ResponseCode1 = GetResponseUrl(g_MonitorOptions.ServerName,
  465. RemoteFileName,
  466. ReturnedUrl);
  467. if (ResponseCode1 == 0)
  468. {
  469. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("Succeded"));
  470. }
  471. else
  472. {
  473. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  474. }
  475. // GetReturnUrl();
  476. time ( &ProcessStop);
  477. // end process timer
  478. }
  479. else
  480. {
  481. //GetReturnUrl();
  482. }
  483. // Fill in the stats structure
  484. ElapsedTime = difftime(UploadStop,UploadStart) ;
  485. StringCbPrintf(Stats.UploadTime, sizeof Stats.UploadTime, _T("%6.2f\0"),ElapsedTime);
  486. ++TotalFilesProcessed;
  487. if (ResponseCode == 0)
  488. {
  489. TotalUploadTime += ElapsedTime;
  490. AvgUploadTime = TotalUploadTime / (TotalFilesProcessed - TotalUploadFailures) ;
  491. ElapsedTime = difftime(ProcessStop,ProcessStart) ;
  492. TotalProcessTime += ElapsedTime;
  493. AvgProcessTime = TotalProcessTime / (TotalFilesProcessed - TotalUploadFailures) ;
  494. StringCbPrintf(Stats.AvgProcessTime, sizeof AvgProcessTime, _T("%2.2f"), AvgProcessTime);
  495. StringCbPrintf(Stats.ProcessingTime,sizeof Stats.ProcessingTime, _T( "%6.2f\0"),ElapsedTime);
  496. StringCbCopy(Stats.ReturnedUrl, sizeof Stats.ReturnedUrl, ReturnedUrl);
  497. StringCbPrintf(Stats.AvgUploadTime, sizeof AvgUploadTime, _T("%2.2f"), AvgUploadTime);
  498. // Update the List View Control
  499. }
  500. else
  501. {
  502. ++TotalUploadFailures;
  503. goto Done;
  504. }
  505. pCode = _tcsstr( ReturnedUrl,_T("Code="));
  506. if (pCode)
  507. {
  508. pCode += 5; // skip past the = sign
  509. iCode = _ttoi(pCode);
  510. switch (iCode)
  511. {
  512. case MESSAGE_RECEIVE_TIMEOUT:
  513. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("Timed out waiting for Kd response")) == S_OK)
  514. {
  515. ++TotalTimeouts;
  516. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  517. }
  518. break;
  519. case FAILED_TO_SEND_MESSAGE:
  520. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("Failed to send MQ message to the queue")) == S_OK)
  521. {
  522. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  523. ++TotalUnknownErrors;
  524. }
  525. break;
  526. case FAILED_CONNECT_SEND:
  527. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("Failed to connect to the outgoing queue")) == S_OK)
  528. {
  529. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  530. ++TotalUnknownErrors;
  531. }
  532. break;
  533. case FAILED_CONNECT_RECEIVE:
  534. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("Failed to connect to the Incomming message queue")) == S_OK)
  535. {
  536. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  537. ++TotalUnknownErrors;
  538. }
  539. break;
  540. case FILE_NOT_FOUND:
  541. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("File Not Found. Either the upload failed or the watson server could not be reached.")) == S_OK)
  542. {
  543. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  544. ++TotalUnknownErrors;
  545. }
  546. break;
  547. case EXCEEDED_MAX_THREAD_COUNT:
  548. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("EXCEEDED THE MAX THREAD COUNT")) == S_OK)
  549. {
  550. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  551. ++TotalFilesProcessed;
  552. }
  553. break;
  554. case FAILED_TO_IMPERSONATE_USER:
  555. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("Failed to impersonate the Anonymous user account")) == S_OK)
  556. {
  557. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  558. ++TotalUnknownErrors;
  559. }
  560. break;
  561. case FAILED_TO_PARSE_QUERYSTRING:
  562. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("Failed to parse the query string")) == S_OK)
  563. {
  564. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  565. ++TotalUnknownErrors;
  566. }
  567. break;
  568. case INVALID_TYPE_SPECIFIED:
  569. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("An Invalid type was specified on the URL")) == S_OK)
  570. {
  571. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  572. ++TotalUnknownErrors;
  573. }
  574. break;
  575. case FAILED_TO_COPY_FILE:
  576. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("Failed to copy the file from Watson server locally")) == S_OK)
  577. {
  578. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  579. ++TotalUnknownErrors;
  580. }
  581. break;
  582. case INTERNAL_ERROR:
  583. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("INTERNAL ERROR!!!")) == S_OK)
  584. {
  585. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  586. ++TotalUnknownErrors;
  587. }
  588. break;
  589. case FAILED_RECONNECT_RECEIVE:
  590. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("Failed to reconnect to the Receiving queue")) == S_OK)
  591. {
  592. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  593. ++TotalUnknownErrors;
  594. }
  595. break;
  596. case FAILED_TO_CREATE_CURSOR:
  597. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("Failed to create Receive queue Cursor")) == S_OK)
  598. {
  599. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  600. ++TotalUnknownErrors;
  601. }
  602. break;
  603. case FAILED_TO_CREATE_GUID:
  604. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("Failed to create a guid for the current message")) == S_OK)
  605. {
  606. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  607. ++TotalUnknownErrors;
  608. }
  609. break;
  610. default:
  611. ++TotalUnknownErrors;
  612. break;
  613. }
  614. }
  615. else
  616. {
  617. if (!_tcscmp(ReturnedUrl,_T("\0")))
  618. {
  619. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("The Web server did not return a URL. Possibly the server is unavailable or being restarted.")) == S_OK)
  620. {
  621. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  622. ++TotalUnknownErrors;
  623. }
  624. }
  625. if (_tcsstr( ReturnedUrl,_T("HTTP://")))
  626. {
  627. if (StringCbCopy(Stats.ErrorString, sizeof Stats.ErrorString,_T("The Web server redirected us to an incorrect page. Possibly the server is unavailable or being restarted.")) == S_OK)
  628. {
  629. StringCbCopy(Stats.ProcessStatus ,sizeof Stats.ProcessStatus, _T("FAILED"));
  630. ++TotalUnknownErrors;
  631. }
  632. }
  633. }
  634. Done:
  635. // Get PerfCounters if available
  636. if (pCode = _tcsstr( ReturnedUrl, _T("PerfThread=")))
  637. {
  638. pCode += 11;
  639. tempTime = _ttol( pCode );
  640. StringCbPrintf(Stats.ThreadExecution, sizeof Stats.ThreadExecution, _T("%6.2f"), (double)tempTime /1000);
  641. }
  642. if (pCode = _tcsstr( ReturnedUrl, _T("PerfSendQueue=")))
  643. {
  644. pCode += 14;
  645. tempTime = _ttol( pCode );
  646. StringCbPrintf(Stats.SendQueueTime, sizeof Stats.SendQueueTime, _T("%6.2f"), (double)tempTime /1000);
  647. }
  648. if (pCode = _tcsstr( ReturnedUrl, _T("PerfRecvQueue=")))
  649. {
  650. pCode += 14;
  651. tempTime = _ttol( pCode );
  652. StringCbPrintf(Stats.ReceiveQueueTime, sizeof Stats.ReceiveQueueTime, _T("%6.2f"), (double)tempTime /1000);
  653. }
  654. UpdateListView(g_hWnd, &Stats);
  655. } while (WaitForSingleObject (hEvent, g_MonitorOptions.dwPingRate) != WAIT_OBJECT_0);
  656. CloseHandle (hEvent);
  657. g_bMonitoring = FALSE;
  658. ExitThread(0);
  659. return 0;
  660. }
  661. BOOL OnStartSitePing(HWND hwnd)
  662. {
  663. DWORD ThreadId;
  664. HANDLE hThread;
  665. if (!g_bMonitoring)
  666. {
  667. g_hPingEvent = CreateEvent(NULL,FALSE, FALSE, g_szPingEvent);
  668. hThread = CreateThread(NULL, 0, &ThreadFunc,NULL,0,&ThreadId );
  669. g_bMonitoring = TRUE;
  670. CloseHandle (hThread);
  671. }
  672. else
  673. {
  674. MessageBox(hwnd, _T("Site Ping is already running"), NULL, MB_OK);
  675. }
  676. return TRUE;
  677. }
  678. BOOL InitListView(HWND hwnd)
  679. {
  680. HWND hListControl = GetDlgItem(hwnd, IDC_LIST1);
  681. TCHAR szText[][100] = { _T("Upload Time"),
  682. _T("Upload Status"),
  683. _T("Response Time"),
  684. _T("Process Status"),
  685. _T("Thread Time"),
  686. _T("ReciveQ Time"),
  687. _T("SendQ Time"),
  688. _T("Returned Url"),
  689. _T("Error")}; // temporary buffer
  690. LVCOLUMN lvc;
  691. int iCol;
  692. // Set the extended styles
  693. ListView_SetExtendedListViewStyleEx(hListControl,LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_FULLROWSELECT,LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
  694. // Initialize the LVCOLUMN structure.
  695. // The mask specifies that the format, width, text, and subitem
  696. // members of the structure are valid.
  697. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  698. // Add the columns.
  699. for (iCol = 0; iCol < C_COLUMNS; iCol++)
  700. {
  701. lvc.iSubItem = iCol;
  702. lvc.pszText = szText[iCol];
  703. lvc.cx = 100; // width of column in pixels
  704. lvc.fmt = LVCFMT_LEFT; // left-aligned column
  705. if (ListView_InsertColumn(hListControl, iCol, &lvc) == -1)
  706. return FALSE;
  707. }
  708. return TRUE;
  709. }
  710. VOID WINAPI OnDialogInit(HWND hwndDlg)
  711. {
  712. InitListView(hwndDlg);
  713. GetRegData();
  714. HICON hIcon = LoadIcon(g_hinst, MAKEINTRESOURCE(IDR_MAINFRAME));
  715. SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
  716. SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
  717. // Fill Options structure with default values.
  718. ZeroMemory(&g_MonitorOptions, sizeof MONITOR_OPTIONS);
  719. g_MonitorOptions.bUploadMethod = TRUE;
  720. g_MonitorOptions.dwPingRate = 1000;
  721. g_MonitorOptions.CollectProcessTime = TRUE;
  722. g_MonitorOptions.CollectUploadTime = TRUE;
  723. g_MonitorOptions.UploadSingle = TRUE;
  724. StringCbCopy(g_MonitorOptions.ServerName,sizeof g_MonitorOptions.ServerName, _T("ocatest.msbpn.com"));
  725. g_MonitorOptions.iSeverIndex = 1;
  726. StringCbCopy(g_MonitorOptions.VirtualDirectory, sizeof g_MonitorOptions.VirtualDirectory, _T("OCA"));
  727. StringCbCopy(LogFileName,sizeof LogFileName, _T("c:\\SiteMon.csv"));
  728. }
  729. void OnOptionsOk(HWND hwnd)
  730. {
  731. HANDLE hControl = NULL;
  732. TCHAR szDlgText[255];
  733. TCHAR szServer[MAX_PATH];
  734. TCHAR *temp;
  735. TCHAR szTempDelay[30];
  736. ZeroMemory (szDlgText, sizeof szDlgText);
  737. // Get the option settings from the dialog and store them in the global options Structure.
  738. //GetDlgItem(hwnd, IDC_EDIT1);
  739. GetDlgItemText(hwnd, IDC_EDIT1, szDlgText, (sizeof szDlgText) / sizeof szDlgText[0]);
  740. StringCbCopy ( g_MonitorOptions.LogFileName, sizeof g_MonitorOptions.LogFileName, szDlgText);
  741. if (IsDlgButtonChecked(hwnd, IDC_RADIO1))
  742. {
  743. g_MonitorOptions.bUploadMethod = TRUE;
  744. }
  745. else
  746. {
  747. if (IsDlgButtonChecked(hwnd, IDC_RADIO2))
  748. g_MonitorOptions.bUploadMethod = FALSE;
  749. }
  750. if (IsDlgButtonChecked (hwnd, IDC_RADIO3))
  751. {
  752. GetDlgItemText(hwnd, IDC_EDIT5,g_MonitorOptions.FilePath, MAX_PATH );
  753. g_MonitorOptions.UploadSingle = TRUE;
  754. }
  755. else
  756. {
  757. GetDlgItemText(hwnd, IDC_EDIT5,g_MonitorOptions.Directory, MAX_PATH );
  758. g_MonitorOptions.UploadSingle = FALSE;
  759. }
  760. GetDlgItemText(hwnd, IDC_EDIT6, szTempDelay, 30);
  761. g_MonitorOptions.dwPingRate = atol (szTempDelay);
  762. if (g_MonitorOptions.dwPingRate <= 0)
  763. {
  764. g_MonitorOptions.dwPingRate = 1000;
  765. }
  766. g_MonitorOptions.iSeverIndex = ComboBox_GetCurSel(GetDlgItem(hwnd, IDC_COMBO1));
  767. GetDlgItemText(hwnd, IDC_COMBO1, szServer, MAX_PATH);
  768. temp = szServer+_tcslen(szServer);
  769. while (*temp != _T('-'))
  770. {
  771. --temp;
  772. }
  773. // skip the -
  774. --temp;
  775. *temp = _T('\0');
  776. StringCbCopy(g_MonitorOptions.ServerName, sizeof g_MonitorOptions.ServerName, szServer);
  777. // MessageBox(hwnd, szDlgText, "Value of Text Resource", MB_OK);
  778. }
  779. void On_OptionsInit(HWND hwnd)
  780. {
  781. HWND hComboBox;
  782. // read app reg key for user specified settings.
  783. //GetRegData( );
  784. CheckDlgButton(hwnd, IDC_RADIO1, TRUE);
  785. CheckDlgButton(hwnd, IDC_RADIO3, TRUE);
  786. CheckDlgButton(hwnd, IDC_CHECK2, TRUE);
  787. CheckDlgButton(hwnd, IDC_CHECK3, TRUE);
  788. // Populate the combo box
  789. hComboBox = GetDlgItem(hwnd, IDC_COMBO1);
  790. ComboBox_InsertString(hComboBox, 0, _T("oca.microsoft.com - 908"));
  791. ComboBox_InsertString(hComboBox, 1, _T("ocatest - 909"));
  792. ComboBox_InsertString(hComboBox, 2, _T("ocatest.msbpn.com - 910"));
  793. ComboBox_SetCurSel(hComboBox, g_MonitorOptions.iSeverIndex);
  794. SetDlgItemText(hwnd, IDC_EDIT6, _T("1000"));
  795. SetDlgItemText(hwnd, IDC_EDIT5 , g_MonitorOptions.FilePath);
  796. }
  797. void On_Browse(HWND hwnd)
  798. {
  799. HWND hParent = hwnd;
  800. // char *WindowTitle;
  801. // determine the language and Load the resource strings.
  802. TCHAR String1[] = _T("Cab Files (*.cab)");
  803. TCHAR String2[] = _T("All Files (*.*)");
  804. static TCHAR szFilterW[400];
  805. // LoadStringW(::_Module.GetModuleInstance(), IDS_STRING_ENU_DMPFILE, String1, 200);
  806. // LoadStringW(::_Module.GetModuleInstance(), IDS_STRING_ENU_ALLFILES, String2, 200);
  807. // Build the buffer;
  808. TCHAR Pattern1[] = _T("*.cab");
  809. TCHAR Pattern2[] = _T("*.*");
  810. TCHAR * src;
  811. TCHAR *dest;
  812. src = String1;
  813. dest = szFilterW;
  814. while (*src != _T('\0'))
  815. {
  816. *dest = *src;
  817. src ++;
  818. dest ++;
  819. }
  820. src = Pattern1;
  821. *dest = _T('\0');
  822. ++dest;
  823. while (*src != _T('\0'))
  824. {
  825. *dest = *src;
  826. src ++;
  827. dest ++;
  828. }
  829. *dest = _T('\0');
  830. ++dest;
  831. src = String2;
  832. while (*src != _T('\0'))
  833. {
  834. *dest = *src;
  835. src ++;
  836. dest ++;
  837. }
  838. src = Pattern2;
  839. *dest = _T('\0');
  840. ++dest;
  841. while (*src != _T('\0'))
  842. {
  843. *dest = *src;
  844. src ++;
  845. dest ++;
  846. }
  847. *dest = _T('\0');
  848. ++dest;
  849. *dest = _T('\0');
  850. BOOL Return = FALSE;
  851. TCHAR szFileNameW [MAX_PATH] = _T("\0");
  852. TCHAR szDefaultPathW[MAX_PATH] = _T("\0");
  853. OPENFILENAME ofn;
  854. GetWindowsDirectory(szDefaultPathW,MAX_PATH);
  855. ofn.lStructSize = sizeof (OPENFILENAME);
  856. ofn.lpstrFilter = szFilterW;
  857. ofn.lpstrInitialDir = szDefaultPathW;
  858. ofn.lpstrFile = szFileNameW;
  859. ofn.hInstance = NULL;
  860. ofn.hwndOwner = hParent;
  861. ofn.lCustData = NULL;
  862. ofn.Flags = 0;
  863. ofn.lpstrDefExt = _T("*.cab");
  864. ofn.lpstrCustomFilter = NULL;
  865. ofn.nMaxFile = MAX_PATH;
  866. ofn.lpstrFileTitle = NULL;
  867. ofn.lpstrTitle = NULL;
  868. ofn.nFileOffset = 0;
  869. ofn.nFileExtension = 0;
  870. ofn.lpfnHook = NULL;
  871. ofn.lpTemplateName = NULL;
  872. if (GetOpenFileName(&ofn))
  873. {
  874. SetDlgItemText(hwnd, IDC_EDIT5, ofn.lpstrFile);
  875. }
  876. }
  877. LRESULT CALLBACK OptionsDlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  878. {
  879. switch (iMsg)
  880. {
  881. case WM_INITDIALOG:
  882. {
  883. On_OptionsInit(hwnd);
  884. return TRUE;
  885. }
  886. case WM_COMMAND:
  887. {
  888. switch (LOWORD(wParam))
  889. {
  890. case IDOK:
  891. OnOptionsOk(hwnd);
  892. EndDialog(hwnd, 0);
  893. // Save the current option settings
  894. return TRUE;
  895. case IDCANCEL:
  896. EndDialog(hwnd, 0);
  897. return TRUE;
  898. case ID_APPLY:
  899. OnOptionsOk(hwnd);
  900. // Save the current option settings
  901. return TRUE;
  902. case IDC_BROWSE:
  903. On_Browse(hwnd);
  904. return TRUE;
  905. }
  906. break;
  907. }
  908. case WM_NOTIFY:
  909. return DefDlgProc(hwnd, iMsg, wParam, lParam);
  910. }
  911. return 0;
  912. }
  913. void On_Options(HWND hwnd)
  914. {
  915. DialogBox(g_hinst,MAKEINTRESOURCE(IDD_COLLECTION_OPTIONS) ,hwnd, (DLGPROC) OptionsDlgProc);
  916. // Fill in the dialog items based on the current options.
  917. // For now set the default settings.
  918. }
  919. void On_DlgSize(HWND hwnd)
  920. {
  921. RECT rcDlg;
  922. RECT rcList;
  923. GetClientRect(hwnd, &rcDlg);
  924. SetWindowPos(GetDlgItem(hwnd, IDC_LIST1), NULL, rcDlg.left, rcDlg.top, rcDlg.right- rcDlg.left, (rcDlg.bottom - rcDlg.top) /2, SWP_NOMOVE);
  925. GetWindowRect (GetDlgItem(hwnd, IDC_LIST1), &rcList);
  926. ScreenToClient(GetDlgItem(hwnd, IDC_LIST1), (LPPOINT)&rcList.left);
  927. ScreenToClient(GetDlgItem(hwnd, IDC_LIST1), (LPPOINT)&rcList.right);
  928. // SetWindowPos(GetDlgItem(hwnd, IDC_CUSTOM1), NULL, rcDlg.left, rcList.bottom + 5, rcDlg.right- rcDlg.left, 5,0);
  929. // SetWindowPos(GetDlgItem(hwnd, IDC_EDIT1), NULL, rcDlg.left, rcList.bottom + 15, rcDlg.right- rcDlg.left, rcDlg.bottom - rcList.bottom - 10, 0);
  930. }
  931. /*
  932. void OnSliderMoved(HWND hwnd, RECT *rcList)
  933. {
  934. GetWindowRect(GetDlgItem(hwnd, IDC_LIST), &r);
  935. size2 = r.right - r.left;
  936. GetWindowRect(GetDlgItem(hwnd, IDC_BUCKETS), &r);
  937. MapWindowPoints(NULL, hwnd, (POINT *)&r, 2);
  938. size1 = max(0, GET_Y_LPARAM(lParam) - r.top - cDragOffset);
  939. GetClientRect(hwnd, &r);
  940. // AutoLayoutMain(hwnd, pidal, r.bottom - r.top, r.right - r.left, size1, size2);
  941. }
  942. */
  943. void ResetCounters(HWND hwnd)
  944. {
  945. RunningTime = 0.0;
  946. TotalFilesProcessed = 0;
  947. TotalUploadFailures = 0;
  948. TotalUnknownErrors = 0;
  949. TotalTimeouts = 0;
  950. appStart = 0;
  951. appStop = 0;
  952. TotalUploadTime = 0.0;
  953. TotalProcessTime = 0;
  954. // Clear the list view
  955. ListView_DeleteAllItems(GetDlgItem(hwnd, IDC_LIST1));
  956. g_CurrentIndex = -1;
  957. }
  958. LRESULT CALLBACK MainDlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  959. {
  960. // char TempString[255];
  961. static int cDragOffset;
  962. BOOL fCapture = FALSE;
  963. switch (iMsg)
  964. {
  965. case WM_INITDIALOG:
  966. OnDialogInit(hwnd);
  967. return TRUE;
  968. case WM_CLOSE:
  969. if (g_hPingEvent)
  970. {
  971. CloseHandle(g_hPingEvent);
  972. g_hPingEvent = NULL;
  973. }
  974. PostQuitMessage(0);
  975. return TRUE;
  976. /* case WM_LBUTTONUP:
  977. if (fCapture)
  978. {
  979. RECT r;
  980. int size1, size2;
  981. // On_SliderMoved( hwnd, r.bottom - r.top, r.right- r.left);
  982. ReleaseCapture();
  983. fCapture = FALSE;
  984. return TRUE;
  985. }
  986. break;
  987. */
  988. case WM_COMMAND:
  989. {
  990. switch (LOWORD(wParam))
  991. {
  992. case ID_FILE_STARTSITEPING:
  993. OnStartSitePing(hwnd);
  994. return TRUE;
  995. case ID_FILE_STOPSITEPING:
  996. if (g_bMonitoring)
  997. {
  998. SetEvent(g_hPingEvent);
  999. Sleep(1000);
  1000. if (g_hPingEvent)
  1001. {
  1002. CloseHandle(g_hPingEvent);
  1003. g_hPingEvent= NULL;
  1004. }
  1005. g_bMonitoring = FALSE;
  1006. }
  1007. return TRUE;
  1008. case ID_TOOLS_OPTIONS:
  1009. On_Options(hwnd);
  1010. return TRUE;
  1011. case ID_TOOLS_LOGGING:
  1012. On_ToolsLogging(hwnd);
  1013. return TRUE;
  1014. case ID_FILE_RESTARTPING:
  1015. if (g_bMonitoring)
  1016. {
  1017. SetEvent(g_hPingEvent);
  1018. if (g_hPingEvent)
  1019. {
  1020. CloseHandle(g_hPingEvent);
  1021. g_hPingEvent = NULL;
  1022. }
  1023. g_bMonitoring = FALSE;
  1024. ResetCounters(hwnd);
  1025. if (hLogFile != INVALID_HANDLE_VALUE)
  1026. {
  1027. CloseHandle(hLogFile);
  1028. LogStart = 0;
  1029. hLogFile = INVALID_HANDLE_VALUE;
  1030. }
  1031. OnStartSitePing(hwnd);
  1032. }
  1033. /* case IDC_CUSTOM1:
  1034. {
  1035. RECT r;
  1036. GetWindowRect(GetDlgItem(hwnd, IDC_LIST1), &r);
  1037. cDragOffset = GET_Y_LPARAM(GetMessagePos()) - r.right;
  1038. fCapture = TRUE;;
  1039. SetCapture(hwnd);
  1040. return 0;
  1041. }
  1042. */
  1043. }
  1044. }
  1045. case WM_SIZE:
  1046. // On_DlgSize(hwnd);
  1047. return FALSE;
  1048. case WM_NOTIFY:
  1049. {
  1050. switch(wParam)
  1051. {
  1052. case IDC_LIST1:
  1053. switch(((NMHDR *)lParam)->code)
  1054. {
  1055. case LVN_ITEMCHANGED:
  1056. return TRUE;
  1057. case LVN_COLUMNCLICK:
  1058. {
  1059. return TRUE;
  1060. }
  1061. case LVN_GETDISPINFO:
  1062. {
  1063. return TRUE;
  1064. }
  1065. }
  1066. }
  1067. break;
  1068. }
  1069. case WM_DESTROY:
  1070. if (g_hPingEvent)
  1071. {
  1072. if (hLogFile != INVALID_HANDLE_VALUE)
  1073. {
  1074. CloseHandle(hLogFile);
  1075. hLogFile = INVALID_HANDLE_VALUE;
  1076. }
  1077. CloseHandle(g_hPingEvent);
  1078. g_hPingEvent= NULL;
  1079. }
  1080. break;
  1081. }
  1082. return FALSE;
  1083. }
  1084. LRESULT CALLBACK MySliderProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  1085. {
  1086. switch(iMsg)
  1087. {
  1088. case WM_CREATE:
  1089. return 0;
  1090. case WM_PAINT:
  1091. {
  1092. PAINTSTRUCT ps;
  1093. HDC hdc = BeginPaint(hwnd, &ps);
  1094. HPEN hpenOld = (HPEN)SelectObject(hdc, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_ACTIVEBORDER)));
  1095. MoveToEx(hdc, ps.rcPaint.left, 0, NULL);
  1096. LineTo(hdc, ps.rcPaint.right,0);
  1097. MoveToEx(hdc, ps.rcPaint.left, 2, NULL);
  1098. LineTo(hdc, ps.rcPaint.right,2);
  1099. MoveToEx(hdc, ps.rcPaint.left, 3, NULL);
  1100. LineTo(hdc, ps.rcPaint.right,3);
  1101. DeleteObject(SelectObject(hdc, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DHIGHLIGHT))));
  1102. MoveToEx(hdc, ps.rcPaint.left, 1, NULL);
  1103. LineTo(hdc, ps.rcPaint.right,1);
  1104. DeleteObject(SelectObject(hdc, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW))));
  1105. SelectObject(hdc, GetSysColorBrush(COLOR_3DLIGHT));
  1106. MoveToEx(hdc, ps.rcPaint.left, 4, NULL);
  1107. LineTo(hdc, ps.rcPaint.right,4);
  1108. DeleteObject(SelectObject(hdc, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW))));
  1109. SelectObject(hdc, GetSysColorBrush(COLOR_3DLIGHT));
  1110. MoveToEx(hdc, ps.rcPaint.left, 5, NULL);
  1111. LineTo(hdc, ps.rcPaint.right,5);
  1112. DeleteObject(SelectObject(hdc, hpenOld));
  1113. EndPaint(hwnd, &ps);
  1114. return 0;
  1115. };
  1116. case WM_LBUTTONDOWN:
  1117. PostMessage(GetParent(hwnd), WM_COMMAND, GetWindowLong(hwnd, GWL_ID), (LPARAM)hwnd);
  1118. return 0;
  1119. };
  1120. return DefWindowProcW(hwnd, iMsg, wParam, lParam);
  1121. };
  1122. void InitWindowClasses()
  1123. {
  1124. WNDCLASSEXW wc;
  1125. wc.cbSize = sizeof(WNDCLASSEXW);
  1126. wc.style = CS_HREDRAW | CS_VREDRAW;
  1127. wc.lpfnWndProc = MySliderProc;
  1128. wc.cbClsExtra = 0;
  1129. wc.cbWndExtra = 0;
  1130. wc.hInstance = g_hinst;
  1131. wc.hIcon = NULL;
  1132. wc.hCursor = LoadCursor(NULL, IDC_SIZENS);
  1133. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
  1134. wc.lpszMenuName = NULL;
  1135. wc.lpszClassName = L"MySliderClass";
  1136. wc.hIconSm = NULL;
  1137. RegisterClassExW(&wc);
  1138. }
  1139. int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR szCmdLine,
  1140. int nShowCmd)
  1141. {
  1142. MSG msg;
  1143. HWND hwnd;
  1144. INITCOMMONCONTROLSEX InitCtrls;
  1145. InitializeCriticalSection(&ReportResults);
  1146. InitCommonControlsEx(&InitCtrls);
  1147. InitWindowClasses();
  1148. g_hinst = hinst;
  1149. LoadIcon(hinst, MAKEINTRESOURCE(IDR_MAINFRAME));
  1150. hwnd = CreateDialog(g_hinst, MAKEINTRESOURCE(IDD_MAIN) ,NULL,
  1151. (DLGPROC)MainDlgProc);
  1152. g_hWnd = hwnd;
  1153. if (hwnd)
  1154. {
  1155. while(GetMessageW(&msg, NULL, 0, 0))
  1156. //if (!TranslateAcceleratorW(hwnd, hAccel, &msg))
  1157. if (!IsDialogMessageW(hwnd, &msg))
  1158. {
  1159. TranslateMessage(&msg);
  1160. DispatchMessageW(&msg);
  1161. }
  1162. }
  1163. return 0;
  1164. }