Solved

how to disable right mouse click in dialog box

Posted on 2002-03-07
4
954 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

726 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