Solved

how to disable right mouse click in dialog box

Posted on 2002-03-07
4
901 Views
Last Modified: 2013-11-20
hello, i have overloaded the common CFileDialog in an attempt to prevent the user from changing directories.  I have been trying to disable the right mouse button so that the user cannot create a new directory, but i have been unsuccessful.  Overloading the PreTranslateMessage function won't work for me, maybe i'm putting it in the wrong place or something.  Can anyone set me straight with this?

_ryan
0
Comment
Question by:tetsuo
  • 2
  • 2
4 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 6849596
Hi,

Check the following link, it may satisfy all ur needs

http://www.codeguru.com/dialog/QuickLaunch.shtml

Try it out.
VinExpert
0
 
LVL 8

Accepted Solution

by:
VinExpert earned 100 total points
ID: 6849701
Hi,

From that sample modify the function as bellow to handle the WM_CONTEXTMENU message

LRESULT CALLBACK Hooker(int nCode, WPARAM wParam,  LPARAM lParam)
{
     TCHAR szClassName[MAX_CHAR];
     TCHAR szItemName [MAX_CHAR];
     TCHAR szEditBuff [MAX_CHAR];
     LVITEM item;
     static HWND hWndToolbar = NULL; // Persist
         
     CWPSTRUCT* x = (CWPSTRUCT*)lParam;
     GetClassName(x -> hwnd, szClassName, MAX_CHAR);
     
     if(strcmp(_strlwr(szClassName), "toolbarwindow32") == 0)
     {
          if(!CCustomFileDlg::OnceOnly) // Save toolbar's handle only once
          {
               hWndToolbar = x -> hwnd;
               ++CCustomFileDlg::OnceOnly;
          }
     }
     
     if(strcmp(_strlwr(szClassName), "syslistview32") == 0)
     {
          //Nullify the context menu option...
          if(x -> message == WM_CONTEXTMENU)
          {          
               PostMessage(x->hwnd, WM_LBUTTONDOWN, 0, 0);
               PostMessage(x->hwnd, WM_LBUTTONUP, 0, 0);
          }

          switch(x -> message)
          {
               
          case WM_NCPAINT : // Needed if there are no items to display
          case LAST_LISTVIEW_MSG : // Magic message sent after all items are inserted
         
               int count = ListView_GetItemCount(x -> hwnd);
                   
               for(int i = 0; i < count; i++)
               {
                    item.mask     = LVIF_TEXT | LVIF_PARAM;
                    item.iItem = i;
                    item.iSubItem = 0;
                    item.pszText = szItemName;  
                    item.cchTextMax = MAX_CHAR;
                    ListView_GetItem(x -> hwnd, &item);
                    int val = GetFileAttributes(szItemName);
                    if(val == FILE_ATTRIBUTE_DIRECTORY)
                          ListView_DeleteItem(x -> hwnd, i);
                    break;
               }
          } // end switch
          HideToolbarBtns(hWndToolbar);
     } // end if

     if(strcmp(_strlwr(szClassName), "edit") == 0)
     {
          switch(x -> message)
          {
               case EDIT_ENTER:     // User presses Enter
               
                    ::GetWindowText(x -> hwnd, szEditBuff, MAX_CHAR);
                   
                    if(ParseForDelims(szEditBuff))
                         ::SetWindowText(x -> hwnd, "");
                    break;

          } // end switch

     }     // end if

     return CallNextHookEx(HookHandle, nCode, wParam, lParam);
}

I do see some kinda flicker some times when I right click, but, as of now thats the quick solution I believe.

Try it out.
VinExpert
0
 

Author Comment

by:tetsuo
ID: 6858204
ok, but the user can still press backspace in the list box to go up a directory.  if i try to check for WM_KEYDOWN


    if(strcmp(_strlwr(szClassName), "syslistview32") == 0)
    {
         if(x -> message == WM_KEYDOWN)
         {
              //do something...
         }
    }

nothing happens.  if i try to trap the backspace key


    if(strcmp(_strlwr(szClassName), "syslistview32") == 0)
    {
         if(x -> wParam == VK_BACK)
         {
              //do something...
         }
    }

it only catches it every third time i press it.  and i'm still not sure how to prevent the directory change.  can you provide additional help on this?

_ryan
0
 

Author Comment

by:tetsuo
ID: 6858210
oops.  disregard that last comment, i have added in the OTHER question it was meant for.  sorry.  

yes VinExpert, you have effectively demonstrated how to deactivate right click in the list box.  thank you

_ryan
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now