Solved

Intercepting mouse/keyboard events from a CFileDialog type window

Posted on 1997-06-17
6
445 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
[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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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