我不會取標題,大體上我想用win32,模仿windows的記事本,寫個記事本程序,最後讓我的程序和微軟的程序在外觀和功能上都差不多。這樣一來我可以學到一些新知識,鞏固舊的知識。
一、首先做個菜單欄吧。建個menu.rc文件,參照微軟的記事本,裡面寫上這些:
1 //menu.rc 2 3 #define IDM_MAIN 0x2000 4 #define IDM_NEW 0x4101 5 #define IDM_OPEN 0x4102 6 #define IDM_SAVE 0x4103 7 #define IDM_SAVEAS 0x4104 8 #define IDM_SETTING 0x4105 9 #define IDM_PRINT 0x4106 10 #define IDM_EXIT 0x4107 11 12 #define IDM_DUDO 0x4201 13 #define IDM_CUTE 0x4202 14 #define IDM_COPY 0x4203 15 #define IDM_PASTE 0x4204 16 #define IDM_DELETE 0x4205 17 #define IDM_FINDE 0x4206 18 #define IDM_FINDENEXT 0x4207 19 #define IDM_REPLACE 0x4208 20 #define IDM_GOTO 0x4209 21 #define IDM_SELETEALL 0x4210 22 #define IDM_DATE 0x4211 23 24 25 #define IDM_WORDWRAP 0x4301 26 #define IDM_FONT 0x4302 27 28 #define IDM_STATUS 0x4401 29 30 #define IDM_HELP 0x4501 31 #define IDM_ABOUT 0x4502 32 33 34 IDM_MAIN menu discardable 35 BEGIN 36 popup "文件(&F)" 37 BEGIN 38 menuitem "新建(&N)", IDM_NEW 39 menuitem "打開文件(&O)", IDM_OPEN 40 menuitem "保存(&S)", IDM_SAVE 41 menuitem "另存為(&A)", IDM_SAVEAS 42 menuitem separator 43 menuitem "頁面設置(&U)", IDM_SETTING 44 menuitem "打印(&P)", IDM_PRINT 45 menuitem separator 46 menuitem "退出(&E)", IDM_EXIT 47 END 48 popup "編輯(&E)" 49 BEGIN 50 menuitem "撤銷(&U)", IDM_DUDO GRAYED 51 menuitem separator 52 menuitem "剪切(&T)", IDM_CUTE GRAYED 53 menuitem "復制(&C)", IDM_COPY GRAYED 54 menuitem "粘貼(&P)", IDM_PASTE 55 menuitem "刪除(&L)", IDM_DELETE GRAYED 56 menuitem separator 57 menuitem "查找(&F)", IDM_FINDE GRAYED 58 menuitem "查找下一個(&N)",IDM_FINDENEXT GRAYED 59 menuitem "替換(&R)", IDM_REPLACE 60 menuitem "轉到(&G)", IDM_GOTO GRAYED 61 menuitem separator 62 menuitem "全選(&A)", IDM_SELETEALL 63 menuitem "時間日期(&D)", IDM_DATE 64 end 65 popup "格式(&O)" 66 BEGIN 67 menuitem "自動換行(&T)", IDM_WORDWRAP 68 menuitem "字體(&T)", IDM_FONT 69 END 70 popup "查看(&V)" 71 BEGIN 72 menuitem "狀態欄(&S)", IDM_STATUS GRAYED 73 END 74 popup "幫助(&H)" 75 BEGIN 76 menuitem "查看幫助(&H)", IDM_HELP 77 menuitem separator 78 menuitem "關於記事本(&A)", IDM_ABOUT 79 END 80 END
最後在主程序的創建窗口函數中,把菜單欄的句柄傳進去
hwnd = CreateWindow (szAppName, TEXT ("無標題-記事本"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, LoadMenu(hInstance,MAKEINTRESOURCE(IDM_MAIN)), hInstance, NULL) ;
這樣運行程序,菜單欄就出來了
編程系列文章"。作者不知道是誰