Solved

Intercepting mouse/keyboard events from a CFileDialog type window

Posted on 1997-06-17
6
431 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
Comment Utility
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
Comment Utility
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
Comment Utility
Refer to comment above.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Expert Comment

by:KDM
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 99
if loop in java 3 114
sum67 challenge 35 88
Unix Command -- Challenging  question 7 78
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…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now