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.

170 lines
4.4 KiB

  1. /****************************************************************************
  2. *
  3. * inst.c
  4. *
  5. * Copyright (c) 1991 Microsoft Corporation. All Rights Reserved.
  6. *
  7. ***************************************************************************/
  8. #include <windows.h>
  9. #include <mmsystem.h>
  10. #include "wincom.h"
  11. #include "sbtest.h"
  12. /****************************************************************************
  13. *
  14. * public data
  15. *
  16. ***************************************************************************/
  17. HWND hInstWnd;
  18. BYTE bInstrument = 0;
  19. /****************************************************************************
  20. *
  21. * local data
  22. *
  23. ***************************************************************************/
  24. static int width;
  25. static int height;
  26. static TEXTMETRIC tm;
  27. /****************************************************************************
  28. *
  29. * internal function prototypes
  30. *
  31. ***************************************************************************/
  32. static void Paint(HWND hWnd, HDC hDC);
  33. void CreateInstrument(HWND hWnd)
  34. {
  35. HDC hDC;
  36. POINT pt;
  37. int w, h;
  38. hDC = GetDC(hWnd);
  39. GetTextMetrics(hDC, &tm);
  40. ReleaseDC(hWnd, hDC);
  41. w = tm.tmMaxCharWidth * 3;
  42. h = tm.tmHeight + tm.tmExternalLeading;
  43. width = w * 8;
  44. height = h * 16;
  45. GetCursorPos(&pt);
  46. hInstWnd = CreateWindow("SELECTOR",
  47. "Instrument",
  48. WS_POPUP | WS_CAPTION | WS_VISIBLE | WS_SYSMENU,
  49. pt.x, pt.y,
  50. width,
  51. height + GetSystemMetrics(SM_CYCAPTION),
  52. hWnd,
  53. NULL,
  54. ghInst,
  55. NULL);
  56. }
  57. static void Paint(HWND hWnd, HDC hDC)
  58. {
  59. int x, y;
  60. char szVal[20];
  61. RECT rect;
  62. for (y = 0; y < 16; y++) {
  63. for (x = 0; x < 8; x++) {
  64. wsprintf(szVal, "%d", y * 8 + x + gInstBase);
  65. TextOut(hDC,
  66. width * x / 8 + tm.tmMaxCharWidth / 2,
  67. height * y / 16,
  68. szVal,
  69. lstrlen(szVal));
  70. }
  71. }
  72. for (y = 0; y < 16; y++) {
  73. MoveToEx(hDC, 0, height * y / 16, NULL);
  74. LineTo(hDC, width, height * y / 16);
  75. }
  76. for (x = 0; x < 8; x++) {
  77. MoveToEx(hDC, width * x / 8, 0, NULL);
  78. LineTo(hDC, width * x / 8, height);
  79. }
  80. rect.left = ((bInstrument % 8) * (width / 8)) + 1;
  81. rect.right = rect.left + (width / 8) - 1;
  82. rect.top = ((bInstrument / 8) * (height / 16)) + 1;
  83. rect.bottom = rect.top + (height / 16) - 1;
  84. InvertRect(hDC, &rect);
  85. }
  86. long FAR PASCAL InstWndProc(HWND hWnd, unsigned message, UINT wParam, LONG lParam)
  87. {
  88. PAINTSTRUCT ps; // paint structure
  89. int x, y;
  90. SHORTMSG sm;
  91. HMENU hMenu;
  92. RECT rect;
  93. // process any messages we want
  94. switch (message) {
  95. case WM_CREATE:
  96. hMenu = GetMenu(hMainWnd);
  97. CheckMenuItem(hMenu, IDM_INSTRUMENT, MF_CHECKED);
  98. break;
  99. case WM_LBUTTONDOWN:
  100. // revert old patch
  101. rect.left = ((bInstrument % 8) * (width / 8)) + 1;
  102. rect.right = rect.left + (width / 8) - 1;
  103. rect.top = ((bInstrument / 8) * (height / 16)) + 1;
  104. rect.bottom = rect.top + (height / 16) - 1;
  105. InvalidateRect(hWnd, &rect, TRUE);
  106. // calculate new patch
  107. x = LOWORD(lParam) * 8 / width;
  108. y = HIWORD(lParam) * 16 / height;
  109. bInstrument = (BYTE) y * 8 + x;
  110. sm.b[0] = (BYTE) 0xC0 + bChannel;
  111. sm.b[1] = bInstrument;
  112. // invert new patch
  113. rect.left = ((bInstrument % 8) * (width / 8)) + 1;
  114. rect.right = rect.left + (width / 8) - 1;
  115. rect.top = ((bInstrument / 8) * (height / 16)) + 1;
  116. rect.bottom = rect.top + (height / 16) - 1;
  117. InvalidateRect(hWnd, &rect, TRUE);
  118. // send patch change message
  119. if (hMidiOut) {
  120. midiOutShortMsg(hMidiOut, sm.dw);
  121. if (ISBITSET(fDebug, DEBUG_PATCH))
  122. sprintf(ach, "\nPatch Change to %d on Channel %d",
  123. bInstrument, bChannel);
  124. dbgOut;
  125. }
  126. break;
  127. case WM_PAINT:
  128. BeginPaint(hWnd, &ps);
  129. Paint(hWnd, ps.hdc);
  130. EndPaint(hWnd, &ps);
  131. break;
  132. case WM_DESTROY:
  133. hMenu = GetMenu(hMainWnd);
  134. CheckMenuItem(hMenu, IDM_INSTRUMENT, MF_UNCHECKED);
  135. hInstWnd = NULL;
  136. break;
  137. default:
  138. return DefWindowProc(hWnd, message, wParam, lParam);
  139. break;
  140. }
  141. return NULL;
  142. }