Dynamic Menu Creation and Processing...

This is a discussion on Dynamic Menu Creation and Processing... within the Windows Programming forums, part of the Platform Specific Boards category; I have run into a block trying to figure out how I can load specific files from a directory into ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    11

    Dynamic Menu Creation and Processing...

    I have run into a block trying to figure out how I can load specific files from a directory into a menu and click them to launch to files. I have no problems loading my menu up, the problem comes in with the Windows Processing.

    Basically I increment an integer to add files sequentially, like so...

    Code:
    void loadMenu(HMENU hMenu) {
         char *RecentDocs;
         RecentDocs = GetRecentDocs();
    
         strcat(RecentDocs, "\\*.lnk");
    
         int iMenuCount = 0, bMenu = 0;
         HANDLE hFile = 0;
         WIN32_FIND_DATA wfs;
         hFile = FindFirstFile(RecentDocs, &wfs);
         DWORD dwError;
    
         iMenuCount = GetMenuItemCount(hMenu);
         while (iMenuCount > -1) {
              RemoveMenu(hMenu, iMenuCount, MF_BYPOSITION);
              iMenuCount--;
         }
    
         if (hFile != INVALID_HANDLE_VALUE && hFile != NULL) {
              if (IsValidFile(wfs.cFileName) == 1) {
                   bMenu++;
                   AppendMenu(hMenu, MF_STRING, (mnuFiles + bMenu), left(wfs.cFileName, strlen(wfs.cFileName) - 4));
              }
              while (FindNextFile(hFile, &wfs) != 0) {
                   if (IsValidFile(wfs.cFileName) == 1) {
                        bMenu++;
    		            AppendMenu(hMenu, MF_STRING, (mnuFiles + bMenu), left(wfs.cFileName, strlen(wfs.cFileName) - 4));
                   }
              }
              dwError = GetLastError();
              if (dwError == ERROR_NO_MORE_FILES) {
                  FindClose(hFile);
              }
         }
         if (bMenu == 0) {
              AppendMenu(hMenu, MF_STRING | MF_GRAYED, 0, "(Empty)");
         }
    }
    mnuFiles above being a globally defined as 460 and the function IsValidFile verifies that the file is not a directory.

    The problem is now how I can get the menu text information (so from there I can create the file path and launch the file). Trying to use GetMenuString has caused crashes.

    I can't find if the menu id information is maybe in the lparam part of the processing.

    Any insight would be greatly appreciated.

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    11

    Solved

    I figured it out after much pain, here is what is in my Windows Procedure (Just a messagebox for the text right now but it works)...

    Code:
         default: {
              char sTemp[MAX_PATH];
              if (GetMenuString(hFiles, LOWORD(wParam), sTemp, MAX_PATH, MF_BYCOMMAND)) {
                   MessageBox(hWnd, sTemp, "Test", 0);
              }
         }
    Hope that helps others!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Creating File for File Processing
    By Dampecram in forum C Programming
    Replies: 2
    Last Post: 12-07-2008, 01:26 AM
  2. What I've got so far, creating a menu system:
    By Shamino in forum Game Programming
    Replies: 4
    Last Post: 06-15-2007, 04:03 AM
  3. Thread creation
    By C3Pnuts in forum C++ Programming
    Replies: 0
    Last Post: 04-11-2006, 06:54 AM
  4. Using a lot of processing time!
    By nickname_changed in forum C++ Programming
    Replies: 0
    Last Post: 09-25-2003, 04:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21