Solved

how to disable right mouse click in dialog box

Posted on 2002-03-07
4
934 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 45
Expand macro to ask for filename column 8 37
viewing source code from eclipse 13 110
wordmultiple challenge 12 141
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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