Solved

Intercepting mouse/keyboard events from a CFileDialog type window

Posted on 1997-06-17
6
443 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
Industry Leaders: 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

734 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