944,183 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3597
  • C++ RSS
Jul 21st, 2005
0

Subclassed Editbox Control: Do I need to create 2 subclasses for two edit controls?

Expand Post »
Hi there.

I am using

Operating System: Windows XP
Project: Visual Studio 2003 C++ MFC Dialog Based Application

I subclassed an edit box control because I want to capture the WM_KEYDOWN messages when a user enters characters in the edit box. I need this because I want to measure the time interval between keystrokes for the phrase (a password in this case) that the user enters in the edit box.

But I want the user to enter the password twice, once in one edit box and again in another. So I created two edit boxes and then to each edit box added a control variable of type the custom edit box subclass I created.

Now the problem is that when a enter a character in either of the edit boxes, the OnKeyDown function of the subclass is called.

How do I know in which edit box did the user type in the key?

Should I rather create two subclasses for the edit boxes, and create a control variable for the one editbox that is of type: the one subclass, and to the other editbox I add a control variable that is of type: the other subclass?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BenPage is offline Offline
6 posts
since Jul 2005
Jul 21st, 2005
0

Re: Subclassed Editbox Control: Do I need to create 2 subclasses for two edit control

Quote originally posted by BenPage ...
I want the user to enter the password twice, once in one edit box and again in another. So I created two edit boxes and then to each edit box added a control variable of type the custom edit box subclass I created.

Now the problem is that when a enter a character in either of the edit boxes, the OnKeyDown function of the subclass is called.

How do I know in which edit box did the user type in the key?
I barely can understand that thing about "a control variable of type....". Are you implementing what I suggested a few days ago??

In such case, I would compare the passed hWnd with one of the two edit boxes' hWnd's:

(hWnd==GetDlgItem(GetParent(hWnd),IDC_PASSWORD1))
or
(hWnd==GetDlgItem(GetParent(hWnd),IDC_PASSWORD2))

And decide accordingly.
Reputation Points: 12
Solved Threads: 4
Junior Poster
Alvein is offline Offline
104 posts
since Jul 2005
Jul 23rd, 2005
0

Re: Subclassed Editbox Control: Do I need to create 2 subclasses for two edit controls?

Hi Alvein

I am not processing in the WndProc function where the HWND handle is passed as parameter.

Lets say the class that I created, the custom edit box class, is called CMyEditControl. Then the function that I use to process the event that a key was pressed in the edit box looks like this:

C++ Syntax (Toggle Plain Text)
  1. void CMyEditControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  2. {
  3. // TODO: Add your message handler code here and/or call default
  4.  
  5. char pressedKey;
  6. pressedKey = char(nChar);
  7. short keystate;
  8.  
  9. switch(nChar)
  10. {
  11. case VK_SHIFT:
  12. // do whatever
  13. case VK_LEFT:
  14. // do whatever
  15. }
  16.  
  17. }

where CMyEditControl is the custom edit box class I created.

The OnKeyDown is the default name for the event handler( the one that MFC creates for you). How do I get hold of the HWND handle from here (from within this function).

This above function is called when any of the edit boxes generates a WM_KEYDOWN message, I want to know how to know which one it was.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BenPage is offline Offline
6 posts
since Jul 2005
Jul 23rd, 2005
0

Re: Subclassed Editbox Control: Do I need to create 2 subclasses for two edit controls?

Thinkin aloud....is it possible to include a protected variable in your custom class, and initialize it accordingly in the constructor? that way you could simply check its value in the OnKeyDown() event.
Reputation Points: 12
Solved Threads: 4
Junior Poster
Alvein is offline Offline
104 posts
since Jul 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: ?A Simple Win32 GUI Introduction Snippet?
Next Thread in C++ Forum Timeline: Need help passing a multi-dimensional array





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


Follow us on Twitter


© 2011 DaniWeb® LLC