I will not take the title, in general I would like to use Win32, imitate the Windows Notepad, write a notepad program, finally let my program and Microsoft's program in the appearance and function are similar. So I can learn some new knowledge and consolidate the old knowledge.
First, make a menu bar. To build a menu.rc file, refer to Microsoft's Notepad, which reads:
1 //menu.rc
Two
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
Eleven
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
Twenty-three
Twenty-four
25 #define IDM_WORDWRAP 0x4301
26 #define IDM_FONT 0x4302
Twenty-seven
28 #define IDM_STATUS 0x4401
Twenty-nine
30 #define IDM_HELP 0x4501
31 #define IDM_ABOUT 0x4502
Thirty-two
Thirty-three
34 IDM_MAIN menu discardable
35 BEGIN
36 pop "file"
37 BEGIN
38 MenuItem & new, IDM? NEW
39 MenuItem "& open file", IDM "open"
40 MenuItem & save, IDM & save
41 MenuItem & save as, IDM & SaveAs
42 menuitem separator
43 MenuItem "page setup", IDM "setting"
44 MenuItem "& print", IDM "print"
45 menuitem separator
46 MenuItem & exit, IDM > Exit
47 END
48 & popup "Edit"
49 BEGIN
50 MenuItem & undo, IDM
51 menuitem separator
52 MenuItem "cut", IDM "cut graded"
53 MenuItem & copy, IDM > copy grayed
54 MenuItem & paste, IDM & paste
55 MenuItem "& delete", IDM "delete graded"
56 menuitem separator
57 MenuItem "& find", IDM "& find graded
58 MenuItem "& find next", IDM > findenext graded
59 MenuItem "& replace", IDM "replace"
60 MenuItem "& go", IDM "& goto graded
61 menuitem separator
62 MenuItem "& select all", IDM [seleteall
63 MenuItem "time & date", IDM "date"
64 end
65 & pop "format"
66 BEGIN
67 MenuItem "& wrap", IDM > WordWrap
68 MenuItem & font, IDM? Font
69 END
70 pop "view"
71 BEGIN
72 MenuItem & status bar, IDM > status graded
73 END
74 pop "help"
75 BEGIN
76 MenuItem & view help, IDM? Help
77 menuitem separator
78 MenuItem "& about NOTEPAD", IDM > about
79 END
80 END
Finally, in the main program's creation window function, the menu bar handle is passed in
hwnd = CreateWindow (szAppName,
Text ("Untitled NOTEPAD"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
LoadMenu(hInstance,MAKEINTRESOURCE(IDM_MAIN)),
HInstance,
NULL);
So running the program, the menu bar is out
The menu bar can be written as a reference to the Windows SDK Programming series article. The author doesn't know who it is.
Win32 Notepad Program (i)