?
Solved

how to disable right mouse click in dialog box

Posted on 2002-03-07
4
Medium Priority
?
972 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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

762 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