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.

197 lines
5.3 KiB

  1. // scanpnl.cpp : Defines the entry point for the application.
  2. //
  3. #include "stdafx.h"
  4. ///////////////////////////////////////////////////////////////////////////////
  5. // application globals
  6. HINSTANCE g_hInst; // current instance of main application
  7. HKEY g_hFakeEventKey; // event trigger key
  8. HKEY g_hFakeEventKeyLocalService; // event trigger key
  9. ///////////////////////////////////////////////////////////////////////////////
  10. // main application
  11. int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
  12. {
  13. if (!hInstance) {
  14. return 0;
  15. }
  16. g_hInst = hInstance;
  17. //
  18. // open registry HKEY (Local System - legacy)
  19. //
  20. DWORD dwDisposition = 0;
  21. if (RegCreateKeyEx(HKEY_USERS,
  22. HKEY_WIASCANR_FAKE_EVENTS,
  23. 0,
  24. NULL,
  25. 0,
  26. KEY_ALL_ACCESS,
  27. NULL,
  28. &g_hFakeEventKey,
  29. &dwDisposition) == ERROR_SUCCESS) {
  30. }
  31. //
  32. // open registry HKEY (Local Service - .NET server release)
  33. //
  34. dwDisposition = 0;
  35. if (RegCreateKeyEx(HKEY_USERS,
  36. HKEY_WIASCANR_FAKE_EVENTS_LOCAL_SERVICE,
  37. 0,
  38. NULL,
  39. 0,
  40. KEY_ALL_ACCESS,
  41. NULL,
  42. &g_hFakeEventKeyLocalService,
  43. &dwDisposition) == ERROR_SUCCESS) {
  44. }
  45. //
  46. // display front panel dialog
  47. //
  48. DialogBox(hInstance, (LPCTSTR)IDD_SCANPANEL_DIALOG, NULL, MainWindowProc);
  49. //
  50. // close registry HKEY
  51. //
  52. if (g_hFakeEventKey) {
  53. RegCloseKey(g_hFakeEventKey);
  54. g_hFakeEventKey = NULL;
  55. }
  56. if (g_hFakeEventKeyLocalService) {
  57. RegCloseKey(g_hFakeEventKeyLocalService);
  58. g_hFakeEventKeyLocalService = NULL;
  59. }
  60. return 0;
  61. }
  62. INT_PTR CALLBACK MainWindowProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  63. {
  64. switch (message) {
  65. case WM_INITDIALOG:
  66. return TRUE;
  67. case WM_COMMAND:
  68. switch (LOWORD(wParam)) {
  69. case IDC_SCAN_BUTTON:
  70. FireFakeEvent(hDlg,ID_FAKE_SCANBUTTON);
  71. break;
  72. case IDC_COPY_BUTTON:
  73. FireFakeEvent(hDlg,ID_FAKE_COPYBUTTON);
  74. break;
  75. case IDC_FAX_BUTTON:
  76. FireFakeEvent(hDlg,ID_FAKE_FAXBUTTON);
  77. break;
  78. default:
  79. break;
  80. }
  81. return TRUE;
  82. case WM_CLOSE:
  83. EndDialog(hDlg, LOWORD(wParam));
  84. return TRUE;
  85. default:
  86. break;
  87. }
  88. return FALSE;
  89. }
  90. VOID FireFakeEvent(HWND hDlg, DWORD dwEventCode)
  91. {
  92. BOOL bEventSuccess = FALSE;
  93. if (g_hFakeEventKey) {
  94. //
  95. // write a clearing entry, to reset the previous event code
  96. //
  97. DWORD dwClearEventCode = 0;
  98. if (RegSetValueEx(g_hFakeEventKey,
  99. WIASCANR_DWORD_FAKE_EVENT_CODE,
  100. 0,
  101. REG_DWORD,
  102. (BYTE*)&dwClearEventCode,
  103. sizeof(dwClearEventCode)) == ERROR_SUCCESS) {
  104. //
  105. // event is cleared
  106. //
  107. if (RegSetValueEx(g_hFakeEventKey,
  108. WIASCANR_DWORD_FAKE_EVENT_CODE,
  109. 0,
  110. REG_DWORD,
  111. (BYTE*)&dwEventCode,
  112. sizeof(dwEventCode)) == ERROR_SUCCESS) {
  113. //
  114. // value was set
  115. //
  116. bEventSuccess = TRUE;
  117. }
  118. }
  119. }
  120. if(g_hFakeEventKeyLocalService) {
  121. //
  122. // write a clearing entry, to reset the previous event code
  123. //
  124. DWORD dwClearEventCode = 0;
  125. if (RegSetValueEx(g_hFakeEventKeyLocalService,
  126. WIASCANR_DWORD_FAKE_EVENT_CODE,
  127. 0,
  128. REG_DWORD,
  129. (BYTE*)&dwClearEventCode,
  130. sizeof(dwClearEventCode)) == ERROR_SUCCESS) {
  131. //
  132. // event is cleared
  133. //
  134. if (RegSetValueEx(g_hFakeEventKeyLocalService,
  135. WIASCANR_DWORD_FAKE_EVENT_CODE,
  136. 0,
  137. REG_DWORD,
  138. (BYTE*)&dwEventCode,
  139. sizeof(dwEventCode)) == ERROR_SUCCESS) {
  140. //
  141. // value was set
  142. //
  143. bEventSuccess = TRUE;
  144. }
  145. }
  146. }
  147. //
  148. // display an error message box, when the application can not fire the fake event
  149. //
  150. if(!bEventSuccess){
  151. TCHAR szErrorString[MAX_PATH];
  152. memset(szErrorString,0,sizeof(szErrorString));
  153. if(LoadString(g_hInst,IDS_FIRE_FAKE_EVENT_FAILED,szErrorString,(sizeof(szErrorString)/sizeof(szErrorString[0]))) > 0){
  154. //
  155. // display error message box
  156. //
  157. MessageBox(hDlg,szErrorString,NULL,MB_OK|MB_ICONEXCLAMATION);
  158. }
  159. }
  160. }