Solved

BCPP 3.1 - Trapping the Enter key

Posted on 1997-06-06
12
5,880 Views
Last Modified: 2013-12-26
I am attempting to treat the Enter key as a Tab key in BCPP 3.1.  The PreProcessMsg is not available in this version.

I think the answer lies in overriding the DispatchAMessage routine but I can't figure out how to call the TWindowsObject::DispatchAMessage routine from my routine.

The declaration is:

virtual void DispatchAMessage(WORD AMsg, RTMessage AMessage, void (TWindowsObject::* _FAR) (RTMessage));

I cannot figure out how to pass the third argument to the standard TWindowsObject routine.

Maybe I'm on the wrong track anyway.  My goal is catching the Enter key in a modal dialog.

Many thanks!

-Keith

0
Comment
Question by:keith_mc
  • 5
  • 2
  • 2
  • +3
12 Comments
 
LVL 3

Expert Comment

by:gaohong
Comment Utility
Hi, I could not recall the exact name of Key Down message in BC++
3.1. Anyway, you have to handle WM_KEYDOWN message and check
if it is VK_RETURN in your window callback, then call the same
function to handle tab key.  Check out the RTMessage structure and SDI, same semantics for WPARAM and LPARAM.

BTW, better to move to OWL2.0, and it is only cost 50$ in most
of stores to get BC++4.52, which is pretty good.

Hope this helps
gary xie
0
 

Author Comment

by:keith_mc
Comment Utility
I certainly do appreciate the response.  However, I don't think that the answer is valid.  I've tried overriding the wm_keydown routine in order to grab the Enter key.  However, wm_keydown is never called in response to the Enter key in a dialog.  The actual winsight message trace upon pressing the Enter key is:

31D0 "Enhancement"  WM_USER+0x0000  Sent  wp=0000  lp=0000:0000
31D0 "Enhancement"  WM_USER+0x0000  Returns 1397424129 (534B:0001)
31D0 "Enhancement"  WM_COMMAND  Sent  Notify BN_CLICKED  from hwnd 3634  id 1

Perhaps the key is in catching the second WM_USER message.


0
 
LVL 3

Expert Comment

by:gaohong
Comment Utility
As I said I do not have bc3.1 here. Check your comments, WM_USER
gives me a little hint. If memory serves me, you should have
these in .h file.

  virtual void  WMKeyDown(RTMessage Msg)
                = [WM_FIRST + WM_KEYDOWN];

In case you are not using WM_FIRST.

If you write in SDK Window API, in your window procedure, you have to catch WM_KEYDOWN message, I see no reason, BC3.1 would alter that.
 
If it still does not do what you want, reject me again

good luck

0
 

Author Comment

by:keith_mc
Comment Utility
Hello,

My declaration is as you proposed, WM_FIRST included.

virtual void WMKeyDown(RTMessage Msg)= [WM_FIRST + WM_KEYDOWN];

In a derived TWindow, this function catches all key presses.  In a dialog however, the keypresses are directed to the child elements of the dialog or they are translated into button commands.  If I run Winsight and watch the message flow starting from the moment before the Enter key is pressed, I will never see a WM_KEYDOWN message.  This leads me to believe that I am not failing to catch the WM_KEYDOWN message.  Rather, I think that is not being sent.  Something is translating the Enter key into a BN_CLICKED message before I get a shot at it.  I can show you the entire Winsight log if it might help.

I do appreciate you thoughts on this!

-Keith

0
 
LVL 6

Expert Comment

by:jpk041897
Comment Utility
I haven't used OWL in over 6 months and 3.1 in over 3 years:-)

But, from what I recall,  the WM_KeyDown message could not be proccesed at all. What you had to do was to use Borland controls and process BBN_SETFOCUS messages, these messages indicate that a given control gained focus by an action that was not generated by a mouse. You could then trap the standard behaviour of the Default push button to send a WM_KEYDOWN message if a given flag, controlled by the BBN_SETFOCUS message, has been set.

As I said erlier, I'm rather rusty with OWL, so I'm not even sure if I'm mixing OWL versions here so I'm posting as a comment.

Please let me know if I remembered correctly.
0
 

Author Comment

by:keith_mc
Comment Utility
Thanks for the BBN_SETFOCUS suggestion.

However, I think that we're talking different versions of OWL.  You can trap the WM_KEYDOWN message.  In fact, I rely on this to accomplish other tasks.  And, there is no BBN_SETFOCUS message.  The message flow is WM_USER, WM_USER and BN_CLICKED.  Perhaps there is a way to examine the WM_USER messages for a clue as to whether the BN_CLICKED message was generated by Enter or the mouse.  Why are these WM_USER messages sent anyway?  And why is there no WM_KEYDOWN message generated?  It appears that Windows is translating the Enter key into a BN_CLICKED message without giving me a change to intercept it.  Again, the messages generated upon pressing the Enter key are:

WM_USER+0x0000 Sent wp=0000 lp=0000:0000
WM_USER+0x0000 Returns 1397424129 (534B:0001)
WM_COMMAND Sent Notify BN_CLICKED from hwnd 3634 id 1

I know that an upgrade will solve this problem.  However, I've been working on this application for 5 months and I don't relish the idea of changing tools when I am so close to finishing.  

Besides, I'm curious.  I've found that you learn a lot of peripheral things while pursuing a problem like this.

Sincere thanks for the help!


0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 6

Expert Comment

by:jpk041897
Comment Utility
I seem to recall that not all Windows messages that should have were processed by OWL 1. You sometimes had to process messages in an alternate method.

I belive it had to do with overriding WMCooman, setting up a message loop to test for WM_KEYDOWN and calling deafult proccesing if it was any other message.

I belive it was the same technique as used to change the background color of dialog box.

Hope this helps.
0
 

Author Comment

by:keith_mc
Comment Utility
I think you may have given me a good clue here.  I'll work with the WMCommand routine and see what I can do.  I'll let you know.

Thanks
0
 
LVL 2

Expert Comment

by:JensUniweb
Comment Utility
The reason that you don't get the WM_KEYDOWN for VK_RETURN in your dialog box is because the default Dialog message handler is intercepting it. You can make your messagehandler the one recieving the messages first. Then send the once you don't handle to the default dialog message handler. I don't remember how this is done in OWL 1.0. But there is a standard windows function for it.I can check my old manualls for you. It will take untill tomorrow.
0
 

Accepted Solution

by:
ocurance earned 210 total points
Comment Utility
I remember trapping the Enter key in a very tricky fashion in BC++3.1.  I would create an OK button, enable it but hide it.  Pressing enter on this dialog always activates it's handler, so in a sense you've just trapped the enter key.  Not as complex as you were looking for, but it always worked for me!

Good luck,
Roger.
0
 

Author Comment

by:keith_mc
Comment Utility
Thanks.  Using a hidden Ok button would work from a functional standpoint.  However, I would much rather figure out how to allow my dialogs to intercept the keypresses.  This would also be useful in other cases, such as responding to function keys in a dialog.  

There was a comment from JensUniweb about this.  Any followup?
0
 
LVL 5

Expert Comment

by:Alkali_Guy
Comment Utility
0

Featured Post

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).

Join & Write a Comment

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

16 Experts available now in Live!

Get 1:1 Help Now