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.

85 lines
2.5 KiB

  1. #include <windows.h>
  2. #include "autorun.h"
  3. #include "resource.h"
  4. #include "dlgapp.h"
  5. #include "util.h"
  6. // FIRST ITEM MUST ALWAYS BE EXIT_AUTORUN
  7. const int c_aiMain[] = {EXIT_AUTORUN, INSTALL_WINNT, SUPPORT_TOOLS, COMPAT_TOOLS};
  8. const int c_aiWhistler[] = {EXIT_AUTORUN, INSTALL_WINNT, LAUNCH_ARP, SUPPORT_TOOLS, COMPAT_TOOLS};
  9. // IA64 gets bare options, Server SKUs get minimal options, Professional and Personal get full options
  10. #if defined(_IA64_)
  11. const int c_aiSupport[] = {EXIT_AUTORUN, BROWSE_CD, VIEW_RELNOTES, INSTALL_CLR, BACK};
  12. #else
  13. #if BUILD_SERVER_VERSION | BUILD_ADVANCED_SERVER_VERSION | BUILD_DATACENTER_VERSION | BUILD_BLADE_VERSION | BUILD_SMALL_BUSINESS_VERSION
  14. const int c_aiSupport[] = {EXIT_AUTORUN, TS_CLIENT, BROWSE_CD, VIEW_RELNOTES, INSTALL_CLR, BACK};
  15. #else
  16. const int c_aiSupport[] = {EXIT_AUTORUN, TS_CLIENT, HOMENET_WIZ, MIGRATION_WIZ, BROWSE_CD, VIEW_RELNOTES, INSTALL_CLR, BACK};
  17. #endif
  18. #endif
  19. const int c_aiCompat[] = {EXIT_AUTORUN, COMPAT_LOCAL, COMPAT_WEB, BACK};
  20. const int c_cMain = ARRAYSIZE(c_aiMain);
  21. const int c_cWhistler = ARRAYSIZE(c_aiWhistler);
  22. const int c_cSupport = ARRAYSIZE(c_aiSupport);
  23. const int c_cCompat = ARRAYSIZE(c_aiCompat);
  24. // Code to ensure only one instance of a particular window is running
  25. HANDLE CheckForOtherInstance(HINSTANCE hInstance)
  26. {
  27. TCHAR szCaption[128];
  28. HANDLE hMutex;
  29. LoadStringAuto(hInstance, IDS_TITLEBAR, szCaption, 128);
  30. // We create a named mutex with our window caption just as a way to check
  31. // if we are already running autorun.exe. Only if we are the first to
  32. // create the mutex do we continue.
  33. hMutex = CreateMutex (NULL, FALSE, szCaption);
  34. if ( !hMutex )
  35. {
  36. // failed to create the mutex
  37. return 0;
  38. }
  39. else if (GetLastError() == ERROR_ALREADY_EXISTS)
  40. {
  41. // Mutex created but by someone else, activate that window
  42. HWND hwnd = FindWindow( WINDOW_CLASS, szCaption );
  43. SetForegroundWindow(hwnd);
  44. CloseHandle(hMutex);
  45. return 0;
  46. }
  47. // we are the first
  48. return hMutex;
  49. }
  50. /**
  51. * This function is the main entry point into our application.
  52. *
  53. * @return int Exit code.
  54. */
  55. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin, int nShowCmd )
  56. {
  57. HANDLE hMutex = CheckForOtherInstance(hInstance);
  58. if ( hMutex )
  59. {
  60. CDlgApp dlgapp;
  61. dlgapp.Register(hInstance);
  62. if ( dlgapp.InitializeData(lpCmdLin) )
  63. {
  64. dlgapp.Create(nShowCmd);
  65. dlgapp.MessageLoop();
  66. }
  67. CloseHandle(hMutex);
  68. }
  69. return 0;
  70. }