944,103 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 17322
  • C++ RSS
Mar 4th, 2006
0

MFC - OnKeyDown event.

Expand Post »
In CApplView I create a Login Form.
C++ Syntax (Toggle Plain Text)
  1. void CApplView::Login_Entry(CDC *pDC) {
  2. ..
  3. if (pUserid == NULL) {
  4. pUserid = new CEdit;
  5. pUserid->Create(WS_CHILD|WS_VISIBLE|WS_BORDER, CRect(x,y1,w,h), this, IDC_USER);
  6. pPasswd = new CEdit;
  7. pPasswd->Create(WS_CHILD|WS_VISIBLE|WS_BORDER, CRect(x,y2,w,h), this, IDC_PASS);
  8. pbLogin = new CButton(); pbLogin->Create("Login",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(x,y3,w,h), this, IDB_LOGIN);
  9. }
  10. }
How do I add code to set the focus on pPasswd when TAB or RETN is entered in pUserid?
Something like...
C++ Syntax (Toggle Plain Text)
  1. OnKeyDown (in pUserid)
  2. if ((char == VK_RETURN) || (char == VK_TAB)) {
  3. pPasswd->SetFocus();
  4. }
I cannot figure out how to incorporate the event in the MESSAGE MAP.
Similar Threads
Reputation Points: 11
Solved Threads: 0
Light Poster
Nedals is offline Offline
43 posts
since Dec 2005
Mar 5th, 2006
0

Re: MFC - OnKeyDown event.

You want to add a "Event Handler" for the event of pressing a Tab key or Return key?
What Compiler of VC are you using?
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Mar 5th, 2006
0

Re: MFC - OnKeyDown event.

Quote originally posted by WolfPack ...
You want to add a "Event Handler" for the event of pressing a Tab key or Return key?
Not exactly. The event handler would be similar to that second bit of code I include above.

I can include, in my MESSAGE MAP,
ON_WM_KEYDOWN()

and write a handler function..
void CApplView::OnKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags) {...}

That will work to capture a key stroke when the main window has focus. I want it to capture the key stroke when pUserid has the focus. I know I can do this by creating a new class derived from CEdit, but I thought there must be a simpler way.
Quote originally posted by WolfPack ...
What Compiler of VC are you using?
I'm using Visual C++ 6.0
Reputation Points: 11
Solved Threads: 0
Light Poster
Nedals is offline Offline
43 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: File Processing C++
Next Thread in C++ Forum Timeline: Constructor Error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC