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.

200 lines
6.0 KiB

  1. /****************************************************************************
  2. *
  3. * init.c
  4. *
  5. * Copyright (c) 1991 Microsoft Corporation. All Rights Reserved.
  6. *
  7. ***************************************************************************/
  8. #include <windows.h>
  9. #include <mmsystem.h>
  10. #include "sbtest.h"
  11. /****************************************************************************
  12. *
  13. * public data
  14. *
  15. ***************************************************************************/
  16. HANDLE hAccTable; // handle to keyboard accelerator table
  17. HWND hMainWnd; // main window
  18. int gInstBase;
  19. BOOL InitFirstInstance(HANDLE hInstance)
  20. {
  21. WNDCLASS wc;
  22. // define the class of window we want to register
  23. wc.lpszClassName = szAppName;
  24. wc.style = CS_HREDRAW | CS_VREDRAW;
  25. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  26. wc.hIcon = LoadIcon(hInstance, "Icon");
  27. wc.lpszMenuName = "Menu";
  28. wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  29. wc.hInstance = hInstance;
  30. wc.lpfnWndProc = MainWndProc;
  31. wc.cbClsExtra = 0;
  32. wc.cbWndExtra = 0;
  33. if (!RegisterClass(&wc))
  34. return FALSE;
  35. // define a class for our keyboard
  36. wc.lpszClassName = "SYNTHKEYS";
  37. wc.style = CS_HREDRAW | CS_VREDRAW;
  38. wc.hCursor = LoadCursor(NULL, IDC_UPARROW);
  39. wc.hIcon = NULL;
  40. wc.lpszMenuName = NULL;
  41. wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  42. wc.hInstance = hInstance;
  43. wc.lpfnWndProc = KeyWndProc;
  44. wc.cbClsExtra = 0;
  45. wc.cbWndExtra = 0;
  46. if (!RegisterClass(&wc))
  47. return FALSE;
  48. // define a class for our position display
  49. wc.lpszClassName = "POSITION";
  50. wc.style = CS_HREDRAW | CS_VREDRAW;
  51. wc.hCursor = LoadCursor(NULL, IDC_UPARROW);
  52. wc.hIcon = NULL;
  53. wc.lpszMenuName = NULL;
  54. wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  55. wc.hInstance = hInstance;
  56. wc.lpfnWndProc = PosWndProc;
  57. wc.cbClsExtra = 0;
  58. wc.cbWndExtra = 0;
  59. if (!RegisterClass(&wc))
  60. return FALSE;
  61. // define a class for our selector
  62. wc.lpszClassName = "SELECTOR";
  63. wc.style = CS_HREDRAW | CS_VREDRAW;
  64. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  65. wc.hIcon = NULL;
  66. wc.lpszMenuName = NULL;
  67. wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  68. wc.hInstance = hInstance;
  69. wc.lpfnWndProc = InstWndProc;
  70. wc.cbClsExtra = 0;
  71. wc.cbWndExtra = 0;
  72. if (!RegisterClass(&wc))
  73. return FALSE;
  74. fDebug = 0;
  75. return TRUE;
  76. }
  77. BOOL InitEveryInstance(HANDLE hInstance, int cmdShow)
  78. {
  79. // create a window for the application
  80. hMainWnd = CreateWindow(szAppName, // class name
  81. szAppName, // caption text
  82. WS_OVERLAPPEDWINDOW, // window style
  83. CW_USEDEFAULT,
  84. CW_USEDEFAULT,
  85. CW_USEDEFAULT,
  86. CW_USEDEFAULT,
  87. (HWND)NULL, // handle of parent window
  88. (HMENU)NULL, // menu handle (default class)
  89. hInstance, // handle to window instance
  90. (LPSTR)NULL); // no params to pass on
  91. if (!hMainWnd)
  92. return FALSE;
  93. ShowWindow(hMainWnd, cmdShow); // display window as open or icon
  94. UpdateWindow(hMainWnd); // paint it
  95. // load the keyboard accelerator table
  96. hAccTable = LoadAccelerators(hInstance, "AccTable");
  97. if (!hAccTable)
  98. return FALSE;
  99. gInstBase = GetProfileInt(szAppName, "InstrumentBase", 0);
  100. return TRUE;
  101. }
  102. void InitMenus(HWND hWnd)
  103. {
  104. UINT n;
  105. UINT wDevice;
  106. UINT wRet;
  107. HMENU hMenu;
  108. MIDIOUTCAPS moc;
  109. MIDIINCAPS mic;
  110. hMenu = GetMenu(hWnd);
  111. // no output device is the default
  112. ModifyMenu(hMenu, IDM_D0, MF_BYCOMMAND | MF_ENABLED | MF_STRING,
  113. IDM_D0, "None");
  114. CheckMenuItem(hMenu, IDM_D0, MF_CHECKED);
  115. n = midiOutGetNumDevs();
  116. for (wDevice = 1; wDevice <= n; wDevice++) {
  117. wRet = midiOutGetDevCaps(wDevice - 1, &moc, sizeof(moc));
  118. if (wRet == 0) {
  119. ModifyMenu(hMenu, wDevice + IDM_D0,
  120. MF_BYCOMMAND | MF_ENABLED | MF_STRING,
  121. wDevice + IDM_D0, moc.szPname);
  122. }
  123. else {
  124. ModifyMenu(hMenu, wDevice + IDM_D0,
  125. MF_BYCOMMAND | MF_ENABLED | MF_STRING,
  126. wDevice + IDM_D0, "ERROR");
  127. }
  128. }
  129. for (wDevice = n + 1; wDevice < LASTPORT; wDevice++)
  130. DeleteMenu(hMenu, wDevice + IDM_D0, MF_BYCOMMAND);
  131. ModifyMenu(hMenu, LASTPORT + IDM_D0, MF_BYCOMMAND | MF_ENABLED | MF_STRING,
  132. LASTPORT + IDM_D0, "MIDI MAPPER");
  133. // no input device is the default
  134. ModifyMenu(hMenu, IDM_I0, MF_BYCOMMAND | MF_ENABLED | MF_STRING,
  135. IDM_I0, "None");
  136. CheckMenuItem(hMenu, IDM_I0, MF_CHECKED);
  137. n = midiInGetNumDevs();
  138. for (wDevice = 1; wDevice <= n; wDevice++) {
  139. wRet = midiInGetDevCaps(wDevice - 1, &mic, sizeof(mic));
  140. if (wRet == 0) {
  141. ModifyMenu(hMenu, wDevice + IDM_I0,
  142. MF_BYCOMMAND | MF_ENABLED | MF_STRING,
  143. wDevice + IDM_I0, mic.szPname);
  144. }
  145. else {
  146. ModifyMenu(hMenu, wDevice + IDM_I0,
  147. MF_BYCOMMAND | MF_ENABLED | MF_STRING,
  148. wDevice + IDM_I0, "ERROR");
  149. }
  150. }
  151. for (wDevice = n + 1; wDevice <= LASTPORT; wDevice++)
  152. DeleteMenu(hMenu, wDevice + IDM_I0, MF_BYCOMMAND);
  153. EnableMenuItem(hMenu, IDM_STARTMIDIIN, MF_GRAYED);
  154. EnableMenuItem(hMenu, IDM_STOPMIDIIN, MF_GRAYED);
  155. EnableMenuItem(hMenu, IDM_PROFSTART, MF_ENABLED);
  156. EnableMenuItem(hMenu, IDM_PROFSTOP, MF_GRAYED);
  157. }
  158. int sbtestError(LPSTR msg)
  159. {
  160. MessageBeep(0);
  161. return MessageBox(hMainWnd, msg, szAppName, MB_OK);
  162. }