[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Sending keyboard text to a static text box

Hi,
I am trying to create a simple C++ App under WTL that contains a little routine  to pass a few words of text typed from the keyboard so that it appears in a static text box (I dont want to use an Edit box for this if it is possible to avoid it).  I have tried to intercept keyboard commands but because it is a static text box no windows messages eg. WM_CHAR  are generated.  I can see other windows messages with Spy++(WM_GETTEXT etc) sent to the correct window when I press a key but my message handler will not intercept these, (I assume the Windows System has got there first).  I can set the focus and create a flashing cursor etc in the static text box and write a programm created string to it under program control, without any problems.  Any ideas how to do this trivial task please?
Thanks
Rob.
0
racurrell
Asked:
racurrell
  • 2
1 Solution
 
GregorTheEyeCommented:
Where is a 'message pick cycle' inside your program. Normally WTL will hide it for you, but you can easily find it. It looks like:

MSG oMsg
while(::GetMessage(&oMsg, ...))
{
  ::TranslateMessage(&oMsg);
  ::DispatchMessage(&oMsg);
}

You can catch WM_KEYDOWN just after it's received by GetMessage() function, like this:

while(::GetMessage(&oMsg, ...))
{
  if(WM_KEYDOWN == oMsg.message && MyWindowHWND() == oMsg.hwn)
  {
    // do work here
  }

where MyWindowHWND() is some way to get a window handle of dialog/window in question (one with a static)

Your messages are eated by ::IsDialogMessage() and/or ::DefWindowProc() functions since active window (static) don't handle WM_KEYDOWN

Another way (more clean) is to SUBCLASS your static and catch WM_KEYDOWN / WM_CHAR inside subclassed DlgProc() message handler function you will create. But this requires some accurate programming.
0
 
racurrellAuthor Commented:
Hi GregorTheEye, I will try your suggestions, the window is already subclasssed so that the text received on the serial port is displayed in a different colour (that all works OK) so I can try doing the Message catches you suggest there, I will let you know how it goes.  I thought it was probably ::IsDialogMessage() and/or ::DefWindowProc() functions that were getting there first and eating the messages but my experience is a bit limited with that aspect of programming.
Thanks again.
Rob.
0
 
racurrellAuthor Commented:
Thanks
0

Featured Post

Technology Partners: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now