Easily implement Sindows 98 dynamic menu

zhaozj2021-02-11  174

Easily implement Sindows 98 dynamic menu

In Windows 98, it must be very wonderful when you use the dynamic menu for the first time. In fact, in Windows 98, it is easy to dynamically establish the entire pop-up menu and can add it to an existing menu. First, use the API function createPPMenu () to create the menu, the function prototype is as follows: HMENU CreatePopUpMenu (Void); This function creates an empty menu and returns the menu handle. After the menu is created, use appendmenu () to add menu items. After the menu construct is completed, you can add it to the existing menu. The menu created using the createPopupMenu () function must be discarded. If the menu is connected to a window, it will be discarded. When the calling the deleteMenu () function clears the menu from the parent menu, it will be discarded. The dynamic menu can also be discarded by calling the destroymenu () function. This program is compiled by Visual C 6.0 in the Chinese version of Windows 98 system. After running, if you click on the "Add Menu" sub-project, you will have a surprised discovery when you click on the "Add Menu" subproject. Attachment Procedure DMenu.c, resource description file DMENU.RC and header file DMENU.H.

// windows98 dynamic menu source program - DMenu.c # include #include #include #include "dmenu.h" LRESULT CALLBACK WNDPROC (hwnd, uint, wparam, LPARAM); char * szWinName = "Win98Main"; // winclass nameint WINAPI WinMain (HINSTANCE hThisInst, HINSTANCE hPrevInst, PSTR pszCmdLine, int nCmdShow) {HWND hwnd; MSG uMsg; WNDCLASS wndclass; HACCEL hAccel; // definition screen wndclass. style = 0; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hThisInst; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = GetStockObject (WHITE_BRUSH); wndclass.lpszMenuName = "SampleMenu"; wndclass.lpszClassName = szWinName; // Register the window class RegisterClass (& wndclass); // create the window hwnd = CreateWindow (szWinName, "Windows 98 dynamic menu" WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, NULL, hThisInst, NULL); // load the accelerator table hAccel = LoadAccelerators (hThisInst, "SampleMenu"); // display window ShowWindow (hwnd, nCmdShow); UpdateWindow (hwnd ); // Create a message loop while (getMessage (& UMSG, NULL, 0)) {IF (! TRANSLATEACCELERATOR (HWND, Haccel, & UMSG)) TranslateMessage (& UMSG); DispatchMessage (& UMSG);}}} Return Umsg.wparam;} // Window function processing various messages, Called by WINDOWS system LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {HMENU hmenu, hsubmenu, hpopup; int return_value; switch (message) {case WM_COMMAND: switch (LOWORD (wParam)) {case IDM_EXIT: MessageBox (HWND, Exit Program "," Exit ", MB_OK; PostquitMessage (0); Break; Case IDM_ADDITEM: // Add Menu HMENU = GetMenu (HWND); // Main Melt Silk Handle Hsubmenu = GetSubmenu (HMENU, 0 ); // Pop-up menu handle // Create a new pop-up menu HPopup = createPopupMenu (); // Add new menu item Appendmenu (HPOPUP, MF_ENABLED, IDM_NEW, "Dynamic Menu 1");

转载请注明原文地址:https://www.9cbs.com/read-5473.html

New Post(0)