Click here to Skip to main content
15,902,299 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: LoadLibraryW("C:\abc.dll") fails Pin
Code-o-mat14-Mar-12 0:40
Code-o-mat14-Mar-12 0:40 
GeneralRe: LoadLibraryW("C:\abc.dll") fails Pin
Code-o-mat14-Mar-12 0:42
Code-o-mat14-Mar-12 0:42 
AnswerRe: LoadLibraryW("C:\abc.dll") fails Pin
Jochen Arndt14-Mar-12 0:56
professionalJochen Arndt14-Mar-12 0:56 
AnswerRe: LoadLibraryW("C:\abc.dll") fails Pin
Richard MacCutchan14-Mar-12 1:18
mveRichard MacCutchan14-Mar-12 1:18 
AnswerRe: LoadLibraryW("C:\abc.dll") fails Pin
CPallini14-Mar-12 23:06
mveCPallini14-Mar-12 23:06 
QuestionCMFCMaskedEdit class Pin
David Crow13-Mar-12 10:00
David Crow13-Mar-12 10:00 
AnswerRe: CMFCMaskedEdit class Pin
«_Superman_»13-Mar-12 17:08
professional«_Superman_»13-Mar-12 17:08 
AnswerRe: CMFCMaskedEdit class Pin
Randor 13-Mar-12 17:43
professional Randor 13-Mar-12 17:43 
David,

When MFC controls exhibit strange behavior I always take a look at the source code for the control located in the \VC\atlmfc\src\mfc installation path.

If you look at the Microsoft implementation within afxmaskededit.cpp you will find that the CMFCMaskedEdit class handles the WM_GETTEXTLENGTH,WM_GETTEXT and WM_SETTEXT messages overriding the default CWnd behavior. The CMFCMaskedEdit class is actually returning the length of an internal CString buffer in response to the WM_GETTEXTLENGTH message.

Therefore the Microsoft documentation that states: 'EN_CHANGE notification code is sent when the user has taken an action that may have altered text in an edit control. Unlike the EN_UPDATE notification code, this notification code is sent after the system updates the screen.' would not apply to this particular window class.

Unfortunately you will have to implement something outside the box here. A couple of ideas:

Option [1] Highlight all of the code in afxmaskededit.cpp and afxmaskededit.h and copy/paste into DavidCrowsMaskedEdit new class and change/improve the behavior.

Option [2] You could override PreTranslateMessage and check for the WM_KEYUP message belonging to the CMFCMaskedEdit control. Once the control has recieved this message... the CMFCMaskedEdit should have updated its internal buffer because it does its filtering in response to the WM_CHAR message. Note that this method will not handle copy/cut/paste from the clipboard so your mileage may vary.

C++
BOOL YourMaskDlg::PreTranslateMessage(MSG* pMsg)
{
	if(WM_KEYUP == pMsg->message)
	{
		if(::GetDlgCtrlID(pMsg->hwnd) == m_YourMaskEdit.GetDlgCtrlID())
		{
			int iLength = m_YourMaskEdit.GetWindowTextLength();
	
			if(iLength)
			{
				CString str;
				m_YourMaskEdit.EnableGetMaskedCharsOnly(TRUE);
				m_YourMaskEdit.GetWindowText(str);
				str.Remove(_T('_'));

				BOOL UserAddedText = str.GetLength();
			}
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}


Option [3] You could actually get the window text or text length in your WM_CTLCOLOR handler. Something like:

C++
HBRUSH YourMaskDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	if(pWnd->GetDlgCtrlID() == m_YourMaskEdit.GetDlgCtrlID())
	{
		//Check to see if user added some text
	}
	return hbr;
}


I know it seems like a complete hack... by looking at window text in the WM_CTLCOLOR handler but that is actually how Dr. Joseph Newcomer did it in his old validating CEdit class.

That is really all I can think of for solving your problem. To be honest I generally avoid many of the MFC classes... I usually reinvent the wheel... because sometimes my wheels are more round. And if my new wheel ends up square... well at least I learned something in the process. Big Grin | :-D

Best Wishes,
-David Delaune
Questionc++ win32 Listview, File List, show folder and app icon using SHGetFileInfo Pin
jkirkerx13-Mar-12 7:59
professionaljkirkerx13-Mar-12 7:59 
QuestionRe: c++ win32 Listview, File List, show folder and app icon using SHGetFileInfo Pin
enhzflep13-Mar-12 13:35
enhzflep13-Mar-12 13:35 
AnswerRe: c++ win32 Listview, File List, show folder and app icon using SHGetFileInfo Pin
jkirkerx13-Mar-12 16:14
professionaljkirkerx13-Mar-12 16:14 
GeneralRe: c++ win32 Listview, File List, show folder and app icon using SHGetFileInfo Pin
enhzflep13-Mar-12 16:58
enhzflep13-Mar-12 16:58 
JokeRe: c++ win32 Listview, File List, show folder and app icon using SHGetFileInfo Pin
jkirkerx13-Mar-12 17:45
professionaljkirkerx13-Mar-12 17:45 
AnswerWell that took a couple of hours to figure out Pin
jkirkerx14-Mar-12 12:07
professionaljkirkerx14-Mar-12 12:07 
Questionhow to read flash drive type reader? Pin
Le@rner12-Mar-12 23:46
Le@rner12-Mar-12 23:46 
AnswerRe: how to read flash drive type reader? Pin
Richard MacCutchan13-Mar-12 0:47
mveRichard MacCutchan13-Mar-12 0:47 
QuestionRe: how to read flash drive type reader? Pin
David Crow13-Mar-12 3:48
David Crow13-Mar-12 3:48 
Questiondocumentation c++ gui Pin
yahya7712-Mar-12 7:46
yahya7712-Mar-12 7:46 
AnswerRe: documentation c++ gui Pin
Maximilien12-Mar-12 7:59
Maximilien12-Mar-12 7:59 
GeneralRe: documentation c++ gui Pin
yahya7712-Mar-12 8:25
yahya7712-Mar-12 8:25 
AnswerRe: documentation c++ gui Pin
Richard MacCutchan12-Mar-12 8:00
mveRichard MacCutchan12-Mar-12 8:00 
AnswerRe: documentation c++ gui Pin
CPallini12-Mar-12 22:58
mveCPallini12-Mar-12 22:58 
Questiontoolbar not being loaded for dialog dll---extension dll Pin
appollosputnik12-Mar-12 4:09
appollosputnik12-Mar-12 4:09 
QuestionRe: toolbar not being loaded for dialog dll---extension dll Pin
Richard MacCutchan12-Mar-12 8:03
mveRichard MacCutchan12-Mar-12 8:03 
AnswerRe: toolbar not being loaded for dialog dll---extension dll Pin
appollosputnik12-Mar-12 21:24
appollosputnik12-Mar-12 21:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.