| | |
Subclassed Editbox Control: Do I need to create 2 subclasses for two edit controls?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 6
Reputation:
Solved Threads: 0
Subclassed Editbox Control: Do I need to create 2 subclasses for two edit controls?
0
#1 Jul 21st, 2005
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?
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?
Re: Subclassed Editbox Control: Do I need to create 2 subclasses for two edit control
0
#2 Jul 21st, 2005
•
•
•
•
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?
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.
•
•
Join Date: Jul 2005
Posts: 6
Reputation:
Solved Threads: 0
Re: Subclassed Editbox Control: Do I need to create 2 subclasses for two edit controls?
0
#3 Jul 23rd, 2005
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:
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.
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)
void CMyEditControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default char pressedKey; pressedKey = char(nChar); short keystate; switch(nChar) { case VK_SHIFT: // do whatever case VK_LEFT: // do whatever } }
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.
Re: Subclassed Editbox Control: Do I need to create 2 subclasses for two edit controls?
0
#4 Jul 23rd, 2005
![]() |
Similar Threads
- GUI colouring (C++)
- create aspx page in runtime (C#)
- create an app drag & drop controls in asp.net (ASP.NET)
- CSocket: How do I do this? (C++)
- Saving a file using C++ (C++)
- Adodc? Data Control? (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: ?A Simple Win32 GUI Introduction Snippet?
- Next Thread: Need help passing a multi-dimensional array
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





