|
|
Microsoft Windows NT Build 297 06-28-1992
Sample: Migrating PM Menus to Win32 Summary: MENUS is a migration sample which demonstrates taking a PM application code demonstrating menu functionality, and converting it to Win32 code. The sample is not intended to demonstrate the best Win32 code possible to show menu functionality, but instead tries to emulate the original PM applications as closely as possible using as close to the same API functions as possible. Two tools were used in converting this application: RESCONV.EXE, a tool which converts PM resource files to Win32 format; and IMAGCONV.EXE, a tool which converts PM image files to Win32 format. More Information: The Sample: The original PM sample shows several functions available. MENUS.C emulates that functionality as closely as possible. Under the Cascade Sample menu, there is an item which will allow you to switch to another menu, an item called Cascade which demonstrates cascading menus, and another item called Disable Cascade which will enable/disable the Cascade item and will draw a check mark beside itself while the cascaded item is disabled. The second item on the Action Bar, "BITMAPS", is itself a bitmap. When selected it opens to six other bitmaps. The third item is a message which tells you that if you press and release the second mouse button in the client space, a Popup will appear at the location of the cursor. If you choose to switch menus by choosing Switch Menus from the Cascade Sample menu (or pressing the accelerator key F2) you will get a completely new menu with the option "Menu Item". This option opens up to allow you to switch back, or to add an item to the Action Bar. When choosing "Add Item" a new functioning menu item is added to the Action Bar with the text "1000", and it has an active sub option "6000". Select "Add Item" again and another item will appear on the Action Bar "1001", with an option "6001". This pattern continues, wrapping the Action Bar around to the window as appropriate. Using the Tools: Using IMAGCONV.EXE is fairly straight forward. However, there are some things to know about Windows resource files and the RESCONV.EXE utility before using it. In PM you can define bitmaps as menu items in the .RC file. In Windows this is unsupported. As a result, the string MIS_BITMAP will be flagged. You will have to remove any reference to bitmaps from your menu in the .RC file. The code in MENUS.C demonstrates how to construct such a menu item instead. Also, as a result of being able to define bitmaps in a PM menu, often times the bitmap might be declared using a number to identify it i.e. "BITMAP 9 My.BMP". The RESCONV.EXE utility will change this line to "9 BITMAP My.BMP". You may choose to use a string value in the place of the number value i.e. "nine BITMAP My.BMP". Another characteristic of RESCONV.EXE is it will take the menu declaration of the PM code "MENU ID_RESOURCE" and change it to put the symbolic constant in front i.e. "ID_RESOURCE MENU". Windows often uses a string value in this place. You can opt to change the symbolic constant to a string i.e. "ID_Resource", or you can type cast the value in the Window Class structure i.e. "wc.lpszMenuName = (LPTSTR)ID_RESOURCE" (see MENUS.C in defining the wc variable for the RegisterClass call). In PM MIS_HELP tells PM that a special WM_HELP message will be sent if the Help menu item is selected. In Windows this is not supported, therefore you will have to modify your code to handle the Help under the WM_COMMAND message. You will also have to modify your .RC file as the RESCONV.EXE will flag MIS_HELP and will not write the line its on to the target resource file. For Accelerator tables, RESCONV.EXE will also change a line "ACCELTABLE ID_RESOURCE" to be "ID_RESOURCE ACCELERATORS". Again you have the option to change the symbolic constant to a string, or to cast it as a LPTSTR in your source code. Another thing to know about Accelerators is how they are handled in Windows: although in PM their use is almost transparent in your source code, in Windows they must be loaded and translated around the message loop. To see an example of how this is done, look at the message loop in MENUS.C, or search the text for LoadAccelerators and TranslateAccelerators. Although RESCONV.EXE made other changes to the resource file, for the most part they should be transparent to your code.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.