资源描述:
《c语言钢琴程序代码》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、把以下程序复制粘贴到Visualc++6.0,点编译与连接,不要点编译,不然会出错,这个程序就没用了,在强调一下:点编译与链接。然后点执行,就可以开始弹钢琴了。最后附有一些歌曲的代码,你可以试试看。//钢琴.cpp:Definestheentrypointfortheapplication.//#include"stdafx.h"#include"resource.h"#includetypedefvoid(*TYPEFUNCREATE)(HWNDhwnd);typedefvoid(*TYPEFUNPLAY)(charch);#defineMAX_
2、LOADSTRING100//GlobalVariables:HINSTANCEhInst;//currentinstanceTCHARszTitle[MAX_LOADSTRING];//ThetitlebartextTCHARszWindowClass[MAX_LOADSTRING];//ThetitlebartextTYPEFUNCREATEg_pCreateFun=NULL;TYPEFUNPLAYg_pPlayFun=NULL;TYPEFUNCREATEg_pReleaseFun=NULL;HMODULEg_hdll=NULL;BOOLg_isHack=FAL
3、SE;LPCTSTRg_szSoundFile[]={"sound1.txt","sound2.txt","sound3.txt"};intg_nFileIndex=0;intg_nCurPosition=0;//Fowarddeclarationsoffunctionsincludedinthiscodemodule:ATOMMyRegisterClass(HINSTANCEhInstance);BOOLInitInstance(HINSTANCE,int);LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);LRESU
4、LTCALLBACKAbout(HWND,UINT,WPARAM,LPARAM);intAPIENTRYWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow){//TODO:Placecodehere.MSGmsg;HACCELhAccelTable;//InitializeglobalstringsLoadString(hInstance,IDS_APP_TITLE,szTitle,MAX_LOADSTRING);LoadString(hInstance,IDC_M
5、Y,szWindowClass,MAX_LOADSTRING);MyRegisterClass(hInstance);//Performapplicationinitialization:if(!InitInstance(hInstance,nCmdShow)){returnFALSE;}hAccelTable=LoadAccelerators(hInstance,(LPCTSTR)IDC_MY);//Mainmessageloop:while(GetMessage(&msg,NULL,0,0)){if(!TranslateAccelerator(msg.hwnd,
6、hAccelTable,&msg)){TranslateMessage(&msg);DispatchMessage(&msg);}}returnmsg.wParam;}////FUNCTION:MyRegisterClass()////PURPOSE:Registersthewindowclass.////COMMENTS:////Thisfunctionanditsusageisonlynecessaryifyouwantthiscode//tobecompatiblewithWin32systemspriortothe'RegisterClassEx'//fun
7、ctionthatwasaddedtoWindows95.Itisimportanttocallthisfunction//sothattheapplicationwillget'wellformed'smalliconsassociated//withit.//ATOMMyRegisterClass(HINSTANCEhInstance){WNDCLASSEXwcex;wcex.cbSize=sizeof(WNDCLASSEX);wcex.style=CS_HREDRAW
8、CS_VREDRAW;wcex.lpfnWndProc=(WNDPROC)WndProc