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.

162 lines
4.1 KiB

  1. /*
  2. init.c
  3. initialisation, termination and error handling code
  4. */
  5. #include <stdio.h>
  6. #include <windows.h>
  7. #include "PlaySnd.h"
  8. #include <stdarg.h>
  9. /***************************************************************************
  10. @doc INTERNAL
  11. @api BOOL | InitApp | Initialise the application.
  12. @rdesc The return value is TRUE if the application is successfully
  13. initialised, otherwise it is FALSE.
  14. ***************************************************************************/
  15. BOOL InitApp()
  16. {
  17. WNDCLASS wc;
  18. // set up our module handle for resource loading etc.
  19. ghModule = GetModuleHandle(NULL);
  20. // get the name of our app
  21. WinEval(LoadString(ghModule, IDS_APPNAME, szAppName, sizeof(szAppName)));
  22. // load the profile info
  23. bSync = GetProfileInt(szAppName, "bSync", 0);
  24. bNoWait = GetProfileInt(szAppName, "bNoWait", 0);
  25. bResourceID = GetProfileInt(szAppName, "bResourceID", 0);
  26. #ifdef MEDIA_DEBUG
  27. // If we are in DEBUG mode, get debug level for this module
  28. dGetDebugLevel(szAppName);
  29. dprintf(("started (debug level %d)", __iDebugLevel));
  30. #endif
  31. // define the class of the main window
  32. wc.lpszClassName = szAppName;
  33. wc.style = CS_HREDRAW | CS_VREDRAW;
  34. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  35. wc.hIcon = LoadIcon(ghModule, MAKEINTRESOURCE(IDI_ICON));
  36. wc.lpszMenuName = MAKEINTRESOURCE(IDM_MENU); // "Menu";
  37. wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
  38. wc.hInstance = ghModule;
  39. wc.lpfnWndProc = (WNDPROC)MainWndProc;
  40. wc.cbClsExtra = 0;
  41. wc.cbWndExtra = 0;
  42. WinEval(RegisterClass(&wc));
  43. // create a window for the application
  44. ghwndMain = CreateWindow(szAppName,
  45. szAppName,
  46. WS_OVERLAPPEDWINDOW,
  47. GetSystemMetrics(SM_CXSCREEN) / 8,
  48. GetSystemMetrics(SM_CYSCREEN) / 4,
  49. GetSystemMetrics(SM_CXSCREEN) * 4 / 5,
  50. GetSystemMetrics(SM_CYSCREEN) / 3,
  51. (HWND)NULL,
  52. (HMENU)NULL,
  53. ghModule,
  54. (LPSTR)NULL
  55. );
  56. WinAssert(ghwndMain);
  57. #ifdef MEDIA_DEBUG
  58. dDbgSetDebugMenuLevel(__iDebugLevel); // set debug menu state
  59. #endif
  60. ShowWindow(ghwndMain, SW_SHOWNORMAL);
  61. UpdateWindow(ghwndMain); // paint it
  62. return TRUE;
  63. }
  64. /***************************************************************************
  65. @doc INTERNAL
  66. @api void | CreateApp | Initialise the application when WM_CREATE
  67. message is received.
  68. @parm HWND | hWnd | Handle to the parent window.
  69. @rdesc There is no return value.
  70. ***************************************************************************/
  71. void CreateApp(HWND hWnd)
  72. {
  73. hWnd;
  74. }
  75. /***************************************************************************
  76. @doc INTERNAL
  77. @api void | TerminateApp | Terminate the application.
  78. @parm LPSTR | lpszFormat | A printf style format string
  79. @parm ... | ... | Printf style args
  80. @rdesc There is no return value.
  81. ***************************************************************************/
  82. void TerminateApp()
  83. {
  84. char buf[20];
  85. // save profile info
  86. sprintf(buf, "%d", bSync);
  87. WriteProfileString(szAppName, "bSync", buf);
  88. sprintf(buf, "%d", bNoWait);
  89. WriteProfileString(szAppName, "bNoWait", buf);
  90. sprintf(buf, "%d", bResourceID);
  91. WriteProfileString(szAppName, "bResourceID", buf);
  92. dprintf(("ending", szAppName));
  93. dSaveDebugLevel(szAppName);
  94. }
  95. /***************************************************************************
  96. @doc INTERNAL
  97. @api void | Error | Show an error message box.
  98. @rdesc There is no return value.
  99. ***************************************************************************/
  100. void Error(LPSTR lpszFormat, ...)
  101. {
  102. int i;
  103. char buf[256];
  104. va_list va;
  105. va_start(va, lpszFormat);
  106. i = vsprintf(buf, lpszFormat, va);
  107. va_end(va);
  108. MessageBeep(MB_ICONEXCLAMATION);
  109. MessageBox(ghwndMain, buf, szAppName, MB_OK | MB_ICONEXCLAMATION);
  110. }