Solved

Intercepting mouse/keyboard events from a CFileDialog type window

Posted on 1997-06-17
6
442 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
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!

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Smart Camera scanning and reading information 3 121
noX challenge 17 134
Sed question 2 123
x-bar in Google Sheets 2 94
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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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