Solved

Intercepting mouse/keyboard events from a CFileDialog type window

Posted on 1997-06-17
6
440 Views
Last Modified: 2013-11-20
How do you intercept mouse and keyboard events from a CFileDialog type window?

Basically what I am trying to do is disable the right mouse button when a user is in the CFile dialog as well as disable the delete button on the keyboard (prevent deletion of a file).

I have tried setting up the hook procedure and using Spy to monitor the messages, but the keyboard and mouse messages do not seem to trigger the hook procedure. I have also tried the CWnd::PreTranslateMessage but this does not seem to work for the CDialog class (according to the documentation is works for the CWndApp class only.

Can anyone help?
0
Comment
Question by:alkarimk
6 Comments
 
LVL 4

Expert Comment

by:mbhakta
ID: 1302149
Try deriving a class from CFileDialog and now add your WM_CHAR and WM_MOUSE* etc in this class. Now use this class instead of the CFileDialog.


0
 

Author Comment

by:alkarimk
ID: 1302150
The solution you suggested did not work for us.  My code is compiled/linked into a DLL and the executable is a console application.

Here is a copy of my mapping:
class CMyFileDialog : public CFileDialog
{
public:
   CMyFileDialog();

protected:
   //{{AFX_MSG(CMyFileDialog)
   afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
   afx_msg void OnRButtonDown( UINT, CPoint );
   virtual BOOL OnInitDialog();
   //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(CMyFileDialog, CFileDialog)
      //{{AFX_MSG_MAP(CMyFileDialog)
      ON_WM_CHAR( )
   ON_WM_RBUTTONDOWN( )
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

Note that Spy does not seem to get the WM_CHAR message.
Any ideas on what could be wrong?
0
 

Author Comment

by:alkarimk
ID: 1302151
Refer to comment above.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Expert Comment

by:KDM
ID: 1302152
This may be a "stupid space trick," but I wonder if you aren't using the WM_RBUTTONDOWN() routine as a subroutine of WM_CHAR(). If that's so, you might consider creating a subroutine just for WM_RBUTTONDOWN(). I discovered by accident that you can disable menu commands (such as exit app) by creating an event specific subroutine... And then putting nothing in it.

It's a nutty idea, and it probably won't work, so I'm making this a comment rather than an answer.
0
 
LVL 4

Accepted Solution

by:
mbhakta earned 50 total points
ID: 1302153
If you look at the CDialog::DoModal() source code in MFC he does a pretty interesting thing to make his dialog modal. First he makes the dialog topmost for that application. Then he disables the parent window. This way the dialog appears to be modal. And another reason the mouse and keyboard handlers won't work is because in the DoModal() he recreates the dialog once again but by using SDK. So I suggest you override the DoModal() and follow his steps. Don't recreate the dialog using SDK, instead use ShowWindow() and SetWindowsPos() and EnableWindow() to get it going. Now you should be able to see the messages mapping to your CMyFileDialog class.
0
 
LVL 3

Expert Comment

by:vinniew
ID: 1302154
When you say that Spy didn't get the WM_CHAR message, did it get the Rbuttondown?  Also, Did you enable processing of *all* messages?  Last suggestion:  find the mfc source and modify it for your purposes.  
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 91
Expand data scrubbing tool 13 32
Change owner from userA to server Local Administrators 7 62
mapBully challenge 6 134
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

773 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