我不会取标题,大体上我想用win32,模仿windows的记事本,写个记事本程序,最后让我的程序和微软的程序在外观和功能上都差不多。这样一来我可以学到一些新知识,巩固旧的知识。
一、首先做个菜单栏吧。建个menu.rc文件,参照微软的记事本,里面写上这些:
//menu.rc #define IDM_MAIN 0x2000
#define IDM_NEW 0x4101
#define IDM_OPEN 0x4102
#define IDM_SAVE 0x4103
#define IDM_SAVEAS 0x4104
#define IDM_SETTING 0x4105
#define IDM_PRINT 0x4106
#define IDM_EXIT 0x4107 #define IDM_DUDO 0x4201
#define IDM_CUTE 0x4202
#define IDM_COPY 0x4203
#define IDM_PASTE 0x4204
#define IDM_DELETE 0x4205
#define IDM_FINDE 0x4206
#define IDM_FINDENEXT 0x4207
#define IDM_REPLACE 0x4208
#define IDM_GOTO 0x4209
#define IDM_SELETEALL 0x4210
#define IDM_DATE 0x4211 #define IDM_WORDWRAP 0x4301
#define IDM_FONT 0x4302 #define IDM_STATUS 0x4401 #define IDM_HELP 0x4501
#define IDM_ABOUT 0x4502 IDM_MAIN menu discardable
BEGIN
popup "文件(&F)"
BEGIN
menuitem "新建(&N)", IDM_NEW
menuitem "打开文件(&O)", IDM_OPEN
menuitem "保存(&S)", IDM_SAVE
menuitem "另存为(&A)", IDM_SAVEAS
menuitem separator
menuitem "页面设置(&U)", IDM_SETTING
menuitem "打印(&P)", IDM_PRINT
menuitem separator
menuitem "退出(&E)", IDM_EXIT
END
popup "编辑(&E)"
BEGIN
menuitem "撤销(&U)", IDM_DUDO GRAYED
menuitem separator
menuitem "剪切(&T)", IDM_CUTE GRAYED
menuitem "复制(&C)", IDM_COPY GRAYED
menuitem "粘贴(&P)", IDM_PASTE
menuitem "删除(&L)", IDM_DELETE GRAYED
menuitem separator
menuitem "查找(&F)", IDM_FINDE GRAYED
menuitem "查找下一个(&N)",IDM_FINDENEXT GRAYED
menuitem "替换(&R)", IDM_REPLACE
menuitem "转到(&G)", IDM_GOTO GRAYED
menuitem separator
menuitem "全选(&A)", IDM_SELETEALL
menuitem "时间日期(&D)", IDM_DATE
end
popup "格式(&O)"
BEGIN
menuitem "自动换行(&T)", IDM_WORDWRAP
menuitem "字体(&T)", IDM_FONT
END
popup "查看(&V)"
BEGIN
menuitem "状态栏(&S)", IDM_STATUS GRAYED
END
popup "帮助(&H)"
BEGIN
menuitem "查看帮助(&H)", IDM_HELP
menuitem separator
menuitem "关于记事本(&A)", IDM_ABOUT
END
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编程系列文章"。作者不知道是谁