Source code of Windows XP (NT5)
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.

137 lines
2.8 KiB

  1. // main.cpp
  2. //
  3. // Copyright 2000 Microsoft Corporation, all rights reserved
  4. //
  5. // Created 2-00 anbrad
  6. //
  7. #include <shellapi.h>
  8. #include "resource.h"
  9. #include "shelltray.h"
  10. #include "netwatch.h"
  11. #define _GLOBALS
  12. #include "main.h"
  13. #include "update.h"
  14. #define TIMER_NUM 1
  15. #define TIMER_FREQUENCY 5000
  16. LRESULT CALLBACK MainWindowProc (
  17. HWND hwnd,
  18. UINT unMsg,
  19. WPARAM wParam,
  20. LPARAM lParam)
  21. {
  22. BOOL fDoDefault = FALSE;
  23. LRESULT lr = 0;
  24. switch (unMsg)
  25. {
  26. case WM_CREATE:
  27. AddTrayIcon(hwnd);
  28. StartListening(hwnd);
  29. break;
  30. case WM_DESTROY:
  31. StopCapture();
  32. RemoveTrayIcon(hwnd);
  33. if (g_unTimer)
  34. {
  35. KillTimer (hwnd, g_unTimer);
  36. g_unTimer = 0;
  37. }
  38. PostQuitMessage (0);
  39. break;
  40. case WM_USER_TRAYCALLBACK:
  41. ProcessTrayCallback(hwnd, wParam, lParam);
  42. break;
  43. default:
  44. fDoDefault = TRUE;
  45. }
  46. if (fDoDefault)
  47. {
  48. lr = DefWindowProc (hwnd, unMsg, wParam, lParam);
  49. }
  50. return lr;
  51. }
  52. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE pPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  53. {
  54. MSG msg;
  55. WNDCLASSEX wcex;
  56. g_hInst = GetModuleHandle (NULL);
  57. //
  58. // Register our window class.
  59. //
  60. ZeroMemory (&wcex, sizeof(wcex));
  61. wcex.cbSize = sizeof(wcex);
  62. wcex.style = CS_HREDRAW | CS_VREDRAW;
  63. wcex.lpfnWndProc = MainWindowProc;
  64. wcex.hInstance = g_hInst;
  65. wcex.hCursor = LoadCursor (NULL, IDC_ARROW);
  66. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  67. wcex.lpszClassName = SZ_MAIN_WINDOW_CLASS_NAME;
  68. if (!RegisterClassEx (&wcex))
  69. return 0;
  70. if (!CheckForUpdate())
  71. {
  72. _tcscpy(g_szMsg, "Updating netwatch.exe");
  73. HWND hDlg = CreateDialog(
  74. g_hInst,
  75. MAKEINTRESOURCE(IDD_MESSAGE),
  76. NULL,
  77. DlgProcMsg);
  78. ShowWindow(hDlg, SW_SHOWNORMAL);
  79. while (GetMessage (&msg, NULL, 0, 0))
  80. {
  81. TranslateMessage (&msg);
  82. DispatchMessage (&msg);
  83. }
  84. return 0;
  85. }
  86. // Create our main window.
  87. //
  88. HWND hwnd;
  89. hwnd = CreateWindowEx (
  90. 0,
  91. SZ_MAIN_WINDOW_CLASS_NAME,
  92. SZ_MAIN_WINDOW_TITLE,
  93. WS_OVERLAPPEDWINDOW,
  94. 0, 0, 0, 0,
  95. NULL, NULL, g_hInst, NULL);
  96. if (hwnd)
  97. {
  98. ShowWindow (hwnd, SW_HIDE);
  99. // Main message loop.
  100. //
  101. while (GetMessage (&msg, NULL, 0, 0))
  102. {
  103. TranslateMessage (&msg);
  104. DispatchMessage (&msg);
  105. }
  106. }
  107. UnregisterClass (SZ_MAIN_WINDOW_CLASS_NAME, g_hInst);
  108. return 0;
  109. }