Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CFileDialog and PreTranslateMessage

171 views
Skip to first unread message

Janiv Ratson

unread,
Aug 10, 2005, 12:04:43 PM8/10/05
to
Hello, I have a CFileDialog derived class.
I want to handle the backspace key down in my derived class.
I added PreTranslateMessage handler to my class but it never gets in there
(Why?).
What can I do in order to handle the Back_Space key down in my derived
class?
Thanks,
Janiv Ratson.


RainMan

unread,
Aug 10, 2005, 4:26:07 PM8/10/05
to
First of all you did not mention what control you want to receive
notification when del key was pressed.
Secondly you should not use PreTranslateMessage in this manner; it was not
designed for that and it is a source of many problems that usually are not
foreseen.

You have to provide more detailed information about your problem.

You can go to CodeGuru and lookup FAQ for reasons why not to use
PreTranslateMessage. See questions about how to suppress Enter key from
closing a dialog.

--
RainMan

Joseph M. Newcomer

unread,
Aug 10, 2005, 5:00:34 PM8/10/05
to
What messages are you handling? Generally, redefining a key as significant as backspace
in a dialog as rigidly specified as CFileDialog is begging for problems, but you need to
show us some code so we can offer some ideas. Why do you need to redefine the meaning of
the backspace key?
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

KMA

unread,
Aug 11, 2005, 1:47:03 AM8/11/05
to
Just off the top of my head, I'm assuming that you added the handler in your
CMyFileDialog class.

I suspect the nub of the probem lies in the fact that your class is not the
hierarchical parent of the dialog that you see on the screen. To put it
another way, your class actually becomes a child of the file open dialog
window. Use Spy to look at the hierarchy and you'll see what I mean. It
appears that the real dialog window (which I assume does get the message)
examines the various messages and decides to whom it should pass on
messages.

But that's just off the top of my head.


"Janiv Ratson" <ja...@aoe6.net> wrote in message
news:eEU9Q1bn...@TK2MSFTNGP09.phx.gbl...

Janiv Ratson

unread,
Aug 11, 2005, 3:44:57 AM8/11/05
to
Hello and thanks,
I'll try to explain myself better.

If you'll open a windows standard File Dialog and set the focus on the
listcontrol(where the folders and files are shown), and than you press the
Back_Space button, the list control will change directory to the parent one,
another press on the Backspace button will again take you to the parent
directory and so on.
What I want to do in my derived CFileDialog is to enable the user to go up
one level(directory), until a specific directory, Hence limit the user
capability to go to up level until the root directory.
I want to limit the user directories to choose a file from.

I hope it is clear enough.
Thanks,
Janiv Ratson.


"KMA" <k...@chum.com> wrote in message news:ddeooo$eh8$1...@atlas.ip-plus.net...

KMA

unread,
Aug 11, 2005, 3:33:05 AM8/11/05
to
Janiv,

Then you could be in luck. The real parent dialog does send some useful
messages to your class, one of which is overriden as OnFolderChange. At
least in this handler you get to find out when the user has tried to change
folder. I guess you can trap this and take action to prevent access to
particular folders. I haven't actually tested this.

"Janiv Ratson" <ja...@aoe6.net> wrote in message

news:Oi9MqCk...@TK2MSFTNGP09.phx.gbl...

Janiv Ratson

unread,
Aug 11, 2005, 5:46:48 AM8/11/05
to
Hello and thanks,
I tried that, but the OnFolderChange notification is sent to me after the
folder has changed, and I want to prevent the change of the directory.
Thanks,
Janiv Ratson.

"KMA" <k...@chum.com> wrote in message news:ddeuvh$eud$1...@atlas.ip-plus.net...

KMA

unread,
Aug 11, 2005, 5:03:42 AM8/11/05
to
Alright. Use Spy to find out who gets the keydown message. I assume it's the
listctrl, or rather that the listctrl must have focus for this functionality
to happen.

Then you need to hook this window/ctrl in order to intercept the
WM_KEYDOWNs. When you get VK_BACK as an input paramter you need to fugure if
the user is allowed to go up one dir and either call the default
functionality or not accordingly.

Do bear in mind that the listctrl is held within a container, so to locate
it you have to do a bit of jiggery pokkery through the dialog hieracrchy,
but Spy will show you where it is.

"Janiv Ratson" <ja...@aoe6.net> wrote in message

news:uElSwGln...@tk2msftngp13.phx.gbl...

Janiv Ratson

unread,
Aug 11, 2005, 6:10:11 AM8/11/05
to
Thanks,
How do I hook this window to get the messages?
Thanks,
Janiv Ratson.

"KMA" <k...@chum.com> wrote in message news:ddf49f$f9b$1...@atlas.ip-plus.net...

KMA

unread,
Aug 11, 2005, 5:30:48 AM8/11/05
to
Well, it's a bit involved. Best bet is to Google Paul DiLascia CFileDialog
etc. He wrote a good explanation of how to customise the common dialogs.

"Janiv Ratson" <ja...@aoe6.net> wrote in message

news:OU4y0Tln...@TK2MSFTNGP09.phx.gbl...

Alexander Grigoriev

unread,
Aug 12, 2005, 10:09:35 AM8/12/05
to
There are different ways to change the current folder in that dialog, and
baskspace doesn't cover them.

You may have better luck with SHBrowseForFolder, in the mode when it display
files. You can set a tree root for that dialog.

"Janiv Ratson" <ja...@aoe6.net> wrote in message

news:Oi9MqCk...@TK2MSFTNGP09.phx.gbl...

Janiv Ratson

unread,
Aug 14, 2005, 3:53:59 AM8/14/05
to
The back space button command changes folder one level up in CFileDialog.
This is what I want to change.
I want that back space will do some special behavior (I wanna override the
back space handle).
Thanks,
Janiv Ratson

"Alexander Grigoriev" <al...@earthlink.net> wrote in message
news:%230NK7d0...@TK2MSFTNGP12.phx.gbl...

Janiv Ratson

unread,
Sep 5, 2005, 5:27:45 AM9/5/05
to
The Solution:

extern HINSTANCE ghConfigToolCommonInstance; //the dll instance

LRESULT CALLBACK MyOwnMessageProc( int code, // hook code
WPARAM wParam, // not used
LPARAM lParam) // message data
{
if (code == MSGF_DIALOGBOX)
{
MSG *pmsg = (MSG*)lParam;

switch (pmsg->message)
{
case WM_KEYDOWN:
if(pmsg->wParam == VK_BACK)
{
TRACE(_T("Backspace is pressed!\n"));
return 1; //Do not process Message
}
break;
}

}
return 0;
}

CDerivedFileDialog::OnInitDialog:
SetWindowsHookEx(WH_SYSMSGFILTER,MyOwnMessageProc,ghConfigToolCommonInstance,0);

"Janiv Ratson" <ja...@aoe6.net> wrote in message
news:eEU9Q1bn...@TK2MSFTNGP09.phx.gbl...

0 new messages