我不会取标题,大体上我想用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) ;
这样运行程序,菜单栏就出来了
菜单栏的写法可以参考“windows sdk编程系列文章"。作者不知道是谁