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.

755 lines
20 KiB

  1. #define STRICT
  2. #include "windows.h"
  3. #include "windowsx.h"
  4. #include "tapi.h"
  5. #include "shellapi.h"
  6. #include "watchit.h"
  7. #include "tapiperf.h"
  8. #if DBG
  9. #define DBGOUT(arg) DbgPrt arg
  10. VOID
  11. DbgPrt(
  12. IN DWORD dwDbgLevel,
  13. IN PCHAR DbgMessage,
  14. IN ...
  15. );
  16. #define DOFUNC(arg1,arg2) DoFunc(arg1,arg2)
  17. #else
  18. #define DBGOUT(arg)
  19. #define DOFUNC(arg1,arg2) DoFunc(arg1)
  20. #endif
  21. //***************************************************************************
  22. static TCHAR gszHELPfilename [] = TEXT("watchit.HLP");
  23. static TCHAR gszwatchitClassName[] = TEXT("WATCHIT_Class");
  24. static TCHAR gszAppName[64];
  25. #define MAXBUFSIZE (256)
  26. typedef LONG (* PERFPROC)(PERFBLOCK *);
  27. PERFPROC glpfnInternalPerformance = NULL;
  28. BOOL gfTapiSrvRunning = FALSE;
  29. PPERFBLOCK gpPerfBlock = NULL;
  30. HWND ghWndMain;
  31. HINSTANCE ghInst;
  32. HINSTANCE ghTapiInst;
  33. HLINEAPP ghLineApp;
  34. TCHAR gszBuf[MAXBUFSIZE];
  35. //***************************************************************************
  36. //***************************************************************************
  37. //***************************************************************************
  38. UINT LoadUI()
  39. {
  40. return(0);
  41. }
  42. //***************************************************************************
  43. UINT ReadINI()
  44. {
  45. return( 0 );
  46. }
  47. //***************************************************************************
  48. //***************************************************************************
  49. //***************************************************************************
  50. void CheckForTapiSrv()
  51. {
  52. SC_HANDLE sc, scTapiSrv;
  53. SERVICE_STATUS ServStat;
  54. sc = OpenSCManager(NULL,
  55. NULL,
  56. GENERIC_READ);
  57. if (NULL == sc)
  58. {
  59. return;
  60. }
  61. gfTapiSrvRunning = FALSE;
  62. scTapiSrv = OpenService(sc,
  63. TEXT("TAPISRV"),
  64. SERVICE_QUERY_STATUS);
  65. if (!QueryServiceStatus(scTapiSrv,
  66. &ServStat))
  67. {
  68. }
  69. if (ServStat.dwCurrentState != SERVICE_RUNNING)
  70. {
  71. }
  72. else
  73. {
  74. gfTapiSrvRunning = TRUE;
  75. }
  76. if (gfTapiSrvRunning)
  77. {
  78. ghTapiInst = LoadLibrary(TEXT("tapi32.dll"));
  79. if (!ghTapiInst)
  80. {
  81. }
  82. else
  83. {
  84. glpfnInternalPerformance = (PERFPROC)GetProcAddress( ghTapiInst,
  85. "internalPerformance");
  86. }
  87. if (!glpfnInternalPerformance)
  88. {
  89. //TODO: Say something!
  90. }
  91. }
  92. CloseServiceHandle(sc);
  93. }
  94. //***************************************************************************
  95. //***************************************************************************
  96. //***************************************************************************
  97. INT_PTR CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  98. {
  99. static HICON hIconLarge;
  100. static HICON hIconSmall;
  101. static HICON hIconDeadTapiSrv;
  102. static BOOL fStarted = FALSE;
  103. static BOOL fDoSmall = FALSE;
  104. static const DWORD aMenuHelpIDs[] =
  105. {
  106. // IDD_DBUTTONPOUND, IDH_DIALER_DIAL_KEYPAD,
  107. 0, 0
  108. };
  109. //MessageBox(GetFocus(), "WM_INI", "Hitting", MB_OK);
  110. switch (msg)
  111. {
  112. case WM_ERASEBKGND:
  113. return( 1 ); // We handled it. No, really... would I lie? :-)
  114. case WM_TIMER:
  115. {
  116. RECT rect;
  117. if ( fStarted )
  118. {
  119. // SetDlgItemText( ghWndMain, IDC_AVG_TIME_TO_NEXT_CUE, szInfo );
  120. fStarted = TRUE;
  121. }
  122. DBGOUT((0, "Heartbeat..."));
  123. // InvalidateRect( ghWndMain, NULL, TRUE );
  124. rect.left = 0;
  125. rect.top = 0;
  126. rect.right = 32;
  127. rect.bottom = 32;
  128. InvalidateRect( ghWndMain, &rect, FALSE );
  129. fDoSmall = !(fDoSmall);
  130. }
  131. break;
  132. case WM_INITDIALOG:
  133. {
  134. //MessageBox(GetFocus(), "WM_INI", "Hitting", MB_OK);
  135. hIconLarge = LoadIcon( ghInst, (LPCTSTR) MAKEINTRESOURCE( IDI_LARGE ) );
  136. hIconSmall = LoadIcon( ghInst, (LPCTSTR) MAKEINTRESOURCE( IDI_SMALL ) );
  137. hIconDeadTapiSrv = LoadIcon( ghInst, (LPCTSTR) MAKEINTRESOURCE( IDI_DEADTAPISRV ) );
  138. SetTimer( hwnd, 1, 1000, NULL );
  139. return TRUE;
  140. }
  141. case WM_SYSCOMMAND:
  142. switch( (DWORD) wParam )
  143. {
  144. case SC_CLOSE:
  145. PostQuitMessage(0);
  146. }
  147. break;
  148. //
  149. // processes clicks on controls when
  150. // context mode help is selected
  151. //
  152. case WM_HELP:
  153. WinHelp (
  154. (HWND)( (LPHELPINFO) lParam)->hItemHandle,
  155. gszHELPfilename,
  156. HELP_WM_HELP,
  157. (ULONG_PTR)(LPVOID) aMenuHelpIDs
  158. );
  159. return TRUE;
  160. //
  161. // processes right-clicks on controls
  162. //
  163. case WM_CONTEXTMENU:
  164. WinHelp (
  165. (HWND)wParam,
  166. gszHELPfilename,
  167. HELP_CONTEXTMENU,
  168. (ULONG_PTR)(LPVOID)aMenuHelpIDs
  169. );
  170. return TRUE;
  171. case WM_COMMAND:
  172. {
  173. switch( LOWORD( (DWORD)wParam ) )
  174. {
  175. // FILE menu
  176. case IDM_EXIT:
  177. PostQuitMessage(0);
  178. return TRUE;
  179. // HELP menu
  180. case IDM_HELP_CONTENTS:
  181. WinHelp(ghWndMain, gszHELPfilename, HELP_CONTENTS, 0);
  182. return TRUE;
  183. case IDM_HELP_WHATSTHIS:
  184. PostMessage(ghWndMain, WM_SYSCOMMAND, SC_CONTEXTHELP, 0);
  185. return TRUE;
  186. case IDM_ABOUT:
  187. ShellAbout(
  188. ghWndMain,
  189. gszAppName,
  190. TEXT(""),
  191. LoadIcon(ghInst, (LPCTSTR)IDI_LARGE)
  192. );
  193. // DialogBoxParam(
  194. // ghInst,
  195. // MAKEINTRESOURCE(IDD_ABOUT),
  196. // ghWndMain,
  197. // AboutProc,
  198. // 0
  199. // );
  200. return TRUE;
  201. } // end switch (LOWORD((DWORD)wParam)) { ... }
  202. break; // end case WM_COMMAND
  203. }
  204. case WM_PAINT:
  205. {
  206. PAINTSTRUCT ps;
  207. RECT rc;
  208. HDC hdcMem;
  209. HBITMAP hbmMem, hbmOld;
  210. BeginPaint(hwnd, &ps);
  211. //
  212. // Get the size of the client rectangle.
  213. //
  214. GetClientRect(hwnd, &rc);
  215. //
  216. // Create a compatible DC.
  217. //
  218. hdcMem = CreateCompatibleDC(ps.hdc);
  219. //
  220. // Create a bitmap big enough for our client rectangle.
  221. //
  222. hbmMem = CreateCompatibleBitmap(ps.hdc,
  223. rc.right-rc.left,
  224. rc.bottom-rc.top);
  225. //
  226. // Select the bitmap into the off-screen DC.
  227. //
  228. hbmOld = (HBITMAP)SelectObject(hdcMem, hbmMem);
  229. //
  230. // Erase the background.
  231. //
  232. // hbrBkGnd = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  233. // hbrBkGnd = CreateSolidBrush(COLOR_3DFACE + 1);
  234. // FillRect(hdcMem, &rc, hbrBkGnd);
  235. FillRect(hdcMem, &rc, (HBRUSH)(COLOR_3DFACE + 1) );
  236. // DeleteObject(hbrBkGnd);
  237. //
  238. // Render the image into the offscreen DC.
  239. //
  240. SetBkMode(hdcMem, TRANSPARENT);
  241. // if(IsIconic(ghWndMain))
  242. // DrawIcon(ps.hdc, 0, 0, fDoSmall ? hIconSmall : hIconLarge);
  243. // else
  244. {
  245. int nSize;
  246. if ( gpPerfBlock )
  247. {
  248. if (
  249. ( NULL == glpfnInternalPerformance )
  250. ||
  251. ( LINEERR_OPERATIONFAILED ==
  252. glpfnInternalPerformance(gpPerfBlock) )
  253. )
  254. {
  255. gpPerfBlock->dwClientApps = 1;
  256. DrawIcon( hdcMem,
  257. 0,
  258. 0,
  259. hIconDeadTapiSrv
  260. );
  261. //
  262. // Check again so that next time around, we'll
  263. // display stuff if TAPISRV has started
  264. //
  265. CheckForTapiSrv();
  266. }
  267. else
  268. {
  269. DrawIcon( hdcMem,
  270. 0,
  271. 0,
  272. fDoSmall ? hIconSmall : hIconLarge
  273. );
  274. }
  275. //
  276. // Blt the changes to the screen DC.
  277. //
  278. BitBlt(ps.hdc,
  279. rc.left, rc.top,
  280. rc.right-rc.left, rc.bottom-rc.top,
  281. hdcMem,
  282. 0, 0,
  283. SRCCOPY);
  284. nSize = wsprintf( gszBuf,
  285. TEXT("%ld"),
  286. gpPerfBlock->dwClientApps - 1 // don't count me
  287. );
  288. SetDlgItemText( ghWndMain, IDC_NUMCLIENTSTEXT, gszBuf );
  289. nSize = wsprintf( gszBuf,
  290. TEXT("%ld"),
  291. gpPerfBlock->dwCurrentOutgoingCalls
  292. );
  293. SetDlgItemText( ghWndMain, IDC_NUMOUTCALLSTEXT, gszBuf );
  294. nSize = wsprintf( gszBuf,
  295. TEXT("%ld"),
  296. gpPerfBlock->dwCurrentIncomingCalls
  297. );
  298. SetDlgItemText( ghWndMain, IDC_NUMINCALLSTEXT, gszBuf );
  299. }
  300. }
  301. //
  302. // Done with off-screen bitmap and DC.
  303. //
  304. SelectObject(hdcMem, hbmOld);
  305. DeleteObject(hbmMem);
  306. DeleteDC(hdcMem);
  307. EndPaint(ghWndMain, &ps);
  308. return TRUE;
  309. }
  310. default:
  311. ;
  312. // return DefDlgProc( hwnd, msg, wParam, lParam );
  313. // return DefWindowProc( hwnd, msg, wParam, lParam );
  314. } // switch (msg) { ... }
  315. return FALSE;
  316. }
  317. //***************************************************************************
  318. //***************************************************************************
  319. //***************************************************************************
  320. void FAR PASCAL TAPICallback( DWORD hDevice,
  321. DWORD dwMsg,
  322. DWORD dwCallbackInstance,
  323. DWORD dwParam1,
  324. DWORD dwParam2,
  325. DWORD dwParam3
  326. )
  327. {
  328. }
  329. //***************************************************************************
  330. //***************************************************************************
  331. //***************************************************************************
  332. int WINAPI WinMain (
  333. HINSTANCE hInstance,
  334. HINSTANCE hPrevInstance,
  335. LPSTR lpCmdLine,
  336. int nCmdShow
  337. )
  338. {
  339. // HACCEL hAccel;
  340. MSG msg;
  341. // DWORD errCode;
  342. // HANDLE hImHere;
  343. // DWORD dwNumDevs;
  344. // DWORD dwAPIVersion = 0x00020000;
  345. // LINEINITIALIZEEXPARAMS LineInitializeExParams = {
  346. // sizeof( LINEINITIALIZEEXPARAMS ),
  347. // 0,
  348. // 0,
  349. // 0,
  350. // 0,
  351. // 0
  352. // };
  353. // MessageBox(GetFocus(), "Starting", "Starting", MB_OK);
  354. DBGOUT((0, "starting"));
  355. ghInst = GetModuleHandle( NULL );
  356. LoadString( ghInst,
  357. WATCHIT_STRING_FRIENDLYNAME,
  358. gszAppName,
  359. sizeof(gszAppName)/sizeof(TCHAR)
  360. );
  361. //
  362. // //
  363. // // Now, let's see if we've already got an instance of ourself
  364. // //
  365. // hImHere = CreateMutex(NULL, TRUE, "watchit_IveBeenStartedMutex");
  366. //
  367. //
  368. // //
  369. // // Is there another one of us already here?
  370. // if ( ERROR_ALREADY_EXISTS == GetLastError() )
  371. // {
  372. // HWND hDialerWnd;
  373. //
  374. // hDialerWnd = FindWindow(gszDialerClassName,
  375. // NULL);
  376. //
  377. // SetForegroundWindow(hDialerWnd);
  378. //
  379. // CloseHandle( hImHere );
  380. // return 0;
  381. // }
  382. {
  383. WNDCLASS wc;
  384. wc.style = CS_DBLCLKS | CS_SAVEBITS | CS_BYTEALIGNWINDOW;
  385. wc.lpfnWndProc = DefDlgProc;
  386. wc.cbClsExtra = 0;
  387. wc.cbWndExtra = DLGWINDOWEXTRA;
  388. wc.hInstance = ghInst;
  389. wc.hIcon = LoadIcon(ghInst, MAKEINTRESOURCE(IDI_LARGE) );
  390. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  391. wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
  392. wc.lpszMenuName = NULL;
  393. wc.lpszClassName = gszwatchitClassName;
  394. if ( 0 == RegisterClass(&wc) )
  395. {
  396. DBGOUT((0, "RegisterClass failed. GetLastError() = 0x%08lx",
  397. GetLastError() ));
  398. return 0;
  399. }
  400. }
  401. DBGOUT((0, "about to create"));
  402. // create the dialog box and set it with info
  403. // from the .INI file
  404. ghWndMain = CreateDialog (
  405. ghInst,
  406. (LPCTSTR)MAKEINTRESOURCE(IDD_MAIN_WATCHIT),
  407. (HWND)NULL,
  408. MainWndProc
  409. );
  410. if ( ReadINI() )
  411. {
  412. MessageBox( GetFocus(),
  413. TEXT("INI File is broken."),
  414. TEXT("This is not good"),
  415. MB_OK
  416. );
  417. }
  418. if ( LoadUI() )
  419. {
  420. MessageBox( GetFocus(),
  421. TEXT("UI Load is broken."),
  422. TEXT("This is not good"),
  423. MB_OK
  424. );
  425. }
  426. CheckForTapiSrv();
  427. gpPerfBlock = (PPERFBLOCK)LocalAlloc(LPTR, sizeof(PERFBLOCK));
  428. // errCode = lineInitializeEx(
  429. // &ghLineApp,
  430. // NULL,
  431. // TAPICallback,
  432. // gszAppName,
  433. // &dwNumDevs,
  434. // &dwAPIVersion,
  435. // &LineInitializeExParams
  436. // );
  437. ShowWindow(ghWndMain, SW_SHOW);
  438. UpdateWindow(ghWndMain);
  439. // hAccel = LoadAccelerators(ghInst, gszAppName);
  440. while ( GetMessage( &msg, NULL, 0, 0 ) )
  441. {
  442. if ( ghWndMain == NULL || !IsDialogMessage( ghWndMain, &msg ) )
  443. {
  444. // if(!TranslateAccelerator(ghWndMain, hAccel, &msg))
  445. {
  446. TranslateMessage(&msg);
  447. DispatchMessage(&msg);
  448. }
  449. }
  450. }
  451. //
  452. // CloseHandle( hImHere );
  453. //
  454. KillTimer( ghWndMain, 1);
  455. if ( gpPerfBlock )
  456. {
  457. LocalFree( gpPerfBlock );
  458. }
  459. if ( ghTapiInst )
  460. {
  461. FreeLibrary( ghTapiInst );
  462. }
  463. return (int) msg.wParam;
  464. }
  465. #if DBG
  466. #include "stdarg.h"
  467. #include "stdio.h"
  468. VOID
  469. DbgPrt(
  470. IN DWORD dwDbgLevel,
  471. IN PCHAR lpszFormat,
  472. IN ...
  473. )
  474. /*++
  475. Routine Description:
  476. Formats the incoming debug message & calls DbgPrint
  477. Arguments:
  478. DbgLevel - level of message verboseness
  479. DbgMessage - printf-style format string, followed by appropriate
  480. list of arguments
  481. Return Value:
  482. --*/
  483. {
  484. static DWORD gdwDebugLevel = 0; //HACKHACK
  485. if (dwDbgLevel <= gdwDebugLevel)
  486. {
  487. CHAR buf[256] = "WATCHIT: ";
  488. va_list ap;
  489. va_start(ap, lpszFormat);
  490. wvsprintfA (&buf[8],
  491. lpszFormat,
  492. ap
  493. );
  494. lstrcatA(buf, "\n");
  495. OutputDebugStringA(buf);
  496. va_end(ap);
  497. }
  498. }
  499. #endif
  500. // //***************************************************************************
  501. // //***************************************************************************
  502. // //***************************************************************************
  503. // BOOL CALLBACK AboutProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  504. // {
  505. // switch(msg)
  506. // {
  507. // case WM_INITDIALOG:
  508. // {
  509. // TCHAR sz[MAXBUFSIZE];
  510. // TCHAR szLabel[MAXBUFSIZE];
  511. //
  512. // // sets up the version number for Windows
  513. // GetDlgItemText(hwnd, IDD_ATEXTTITLE, sz, MAXBUFSIZE);
  514. // wsprintf(
  515. // szLabel,
  516. // sz,
  517. // LOWORD(GetVersion()) & 0xFF,
  518. // HIBYTE(LOWORD(GetVersion)) == 10 ? 1 : 0
  519. // );
  520. // SetDlgItemText(hwnd, IDD_ATEXTTITLE, szLabel);
  521. //
  522. // /* // sets up version number for Dialer
  523. // GetDlgItemText(hwnd, IDD_ATEXTVERSION, sz, MAXBUFSIZE);
  524. // wsprintf(szLabel, sz, VER_MAJOR, VER_MINOR, VER_BUILD);
  525. //
  526. //
  527. // { // strip off build number for release copies
  528. // DWORD i;
  529. // LPSTR ch = szLabel;
  530. //
  531. // for (i = 0; i < 2 && *ch; ++ch)
  532. // {
  533. // if(*ch == '.')
  534. // ++i;
  535. // if(i == 2)
  536. // *ch = 0;
  537. // }
  538. //
  539. // SetDlgItemText(hwnd ,IDD_ATEXTVERSION, szLabel);
  540. // } */
  541. //
  542. //
  543. // /* // get free memory information
  544. // GetDlgItemText(hwnd, IDD_ATEXTFREEMEM, sz, MAXBUFSIZE);
  545. // wsprintf(szLabel, sz, GetFreeSpace(0)>>10);
  546. // SetDlgItemText(hwnd, IDD_ATEXTFREEMEM, szLabel);
  547. //
  548. // // get free resources information
  549. // GetDlgItemText(hwnd, IDD_ATEXTRESOURCE, sz,MAXBUFSIZE);
  550. // wsprintf(szLabel, sz, GetFreeSystemResources(0));
  551. // SetDlgItemText(hwnd, IDD_ATEXTRESOURCE, szLabel); */
  552. //
  553. // return TRUE;
  554. // }
  555. //
  556. // case WM_COMMAND:
  557. // if(LOWORD((DWORD)wParam) == IDOK)
  558. // {
  559. // EndDialog(hwnd, TRUE);
  560. // return TRUE;
  561. // }
  562. // break;
  563. // }
  564. // return FALSE;
  565. // }