MFC - OnKeyDown event.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2005
Posts: 43
Reputation: Nedals is an unknown quantity at this point 
Solved Threads: 0
Nedals Nedals is offline Offline
Light Poster

MFC - OnKeyDown event.

 
0
  #1
Mar 4th, 2006
In CApplView I create a Login Form.
  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...
  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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: MFC - OnKeyDown event.

 
0
  #2
Mar 5th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 43
Reputation: Nedals is an unknown quantity at this point 
Solved Threads: 0
Nedals Nedals is offline Offline
Light Poster

Re: MFC - OnKeyDown event.

 
0
  #3
Mar 5th, 2006
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.
Originally Posted by WolfPack
What Compiler of VC are you using?
I'm using Visual C++ 6.0
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC