#include #define APP_NAME "wave_piano" #define MIDIMSG(msg,channel,data1,data2) (DWORD)((msg<<4) | channel | (data1<<8) | (data2<<16)) int sum(const int counts[],const int num){ int sum=0; for(int i=0;i0) data1--; midiOutShortMsg(hMidi,MIDIMSG(0xC,0,data1,0)); wsprintf(str,"音色 = %d , 打鍵強度 = %d",data1,data2); SetWindowText(hWnd,str); return 0; case VK_UP: if(data2<0x7F) data2++; wsprintf(str,"音色 = %d , 打鍵強度 = %d",data1,data2); SetWindowText(hWnd,str); return 0; case VK_DOWN: if(data2>0) data2--; wsprintf(str,"音色 = %d , 打鍵強度 = %d",data1,data2); SetWindowText(hWnd,str); return 0; } return 0; case WM_DESTROY: DeleteObject(hBrush); midiOutReset(hMidi); midiOutClose(hMidi); PostQuitMessage(0); return 0; } return DefWindowProc(hWnd,uMsg,wParam,lParam); } int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, PSTR lpCmdLine,int nCmdShow) { WNDCLASS wc; MSG msg; RECT rc={0,0,368,134}; wc.style =CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc =WindowProc; wc.cbClsExtra =0; wc.cbWndExtra =0; wc.hInstance =hInstance; wc.hIcon =LoadIcon(NULL,IDI_APPLICATION); wc.hCursor =LoadCursor(NULL,IDC_ARROW); wc.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName =NULL; wc.lpszClassName =APP_NAME; if(!RegisterClass(&wc)) return 0; AdjustWindowRect(&rc,WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME,NULL); if(CreateWindow( APP_NAME,TEXT(__FILE__), (WS_OVERLAPPEDWINDOW | WS_VISIBLE) & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME, CW_USEDEFAULT,CW_USEDEFAULT, rc.right-rc.left+1,rc.bottom-rc.top+1, NULL,NULL,hInstance,NULL)==NULL) return 0; while(GetMessage(&msg,NULL,0,0)>0){ TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; }