Solved

how to disable right mouse click in dialog box

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 120
Expand LInux Boot partition remotly 3 90
Include multiple hostnames in this command? 3 55
sumHeights2  challenge 7 103
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: 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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

785 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