Click here to Skip to main content
15,921,062 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Closing an application. Pin
mcgahanfl16-Jun-05 3:26
mcgahanfl16-Jun-05 3:26 
GeneralBuilding question Pin
Lampros Giampouras15-Jun-05 2:49
Lampros Giampouras15-Jun-05 2:49 
GeneralRe: Building question Pin
Cedric Moonen15-Jun-05 3:24
Cedric Moonen15-Jun-05 3:24 
GeneralRe: Building question Pin
normanS15-Jun-05 3:53
normanS15-Jun-05 3:53 
GeneralRe: Building question Pin
Lampros Giampouras15-Jun-05 14:09
Lampros Giampouras15-Jun-05 14:09 
GeneralRe: Building question Pin
squidev15-Jun-05 15:46
squidev15-Jun-05 15:46 
GeneralRe: Building question Pin
Lampros Giampouras16-Jun-05 9:11
Lampros Giampouras16-Jun-05 9:11 
Generalweird errors Pin
Anonymous15-Jun-05 2:29
Anonymous15-Jun-05 2:29 
Hi everyone, forgive me if my errors will seem trivial to you, I've only recently starting working with Windows programming and MFC (although I've had plenty of experience programming in console), and my program doesn't seem to work as expected.

First of all, let me explain what it should do and how it's set up. Basically, I have a dialog box with 5 edit boxes and 1 "ok" button on it. I'm trying to get the dialog boxes to work like the ones for the registration key with one little extra feature. The caret should jump to the next box after 5 characters are put into one box, and also if the user uses copy/paste command, the pasted text gets split into the boxes. Well, I wrote the program that should do all this, but there are some things that happen that should not happen and I have no clue why. Basically I have the first 4 boxes carry identical code:

<br />
void Dlg2::OnChangeEdit1() <br />
{<br />
	// TODO: If this is a RICHEDIT control, the control will not<br />
	// send this notification unless you override the CDialog::OnInitDialog()<br />
	// function and call CRichEditCtrl().SetEventMask()<br />
	// with the ENM_CHANGE flag ORed into the mask.<br />
	<br />
	// TODO: Add your control notification handler code here<br />
	CWnd* m_wEdit1=GetDlgItem(IDC_EDIT1);<br />
	m_wEdit1->GetWindowText(key1);<br />
	temp=key1.GetLength();<br />
	if (temp>4)<br />
	{<br />
		temp-=5;<br />
		CWnd* m_wEdit2=GetDlgItem(IDC_EDIT2);<br />
		m_wEdit2->SetWindowText ( _T(key1.Right(temp))); //has to be done before next command, otherwise we change the text in left window beofre right window<br />
		m_wEdit1->GetWindowText(key1);<br />
		if(temp>0) m_wEdit1->SetWindowText ( _T(key1.Left(5)));<br />
		m_wEdit2->SetFocus();<br />
	}<br />
}<br />


and the fifth box just limits the maximum text to 5. The above code works fine for typing the key in manually, the cursor switches to next window after 5 characters are typed in. However, copy/pasting the code in doesn't work like I expected it to. Instead, the first box gets all of the pasted text, the 2nd gets all but the first 5 characters, and so on. So for example if I type in "abcdefghijklmno", the first box will have "abcdefghijklmno", 2nd will have "fghijklmno" and 3rd "klmno".

Now here is what's even weirder. If I take the exact same code from above, change the "if (temp>4)" statement to "if (temp>5)" and remove the "if (temp>0)" part from the "if (temp>0) m_wEdit1->SetWindowText(_T(key1.Left(5)));" then the copy/pasting works like it should with each box only receiving 5 characters, but when the text is put in manually the cursor goes right before the last character when it is moved to the new box. This makes sense, since I never ordered the caret to move, but as I will explain in a moment even ordering it to move won't do anything. Another thing is, if I leave the "if (temp>4)" message alone, and just remove the "if (temp>0)" part, the program crashes when it processes the 5th character. This I don't udnerstand either, the if is in front of the statement that selects the 5 characters to be put into the first box. Therefore it's guaranteed that when the user puts in 5 characters there should be enough characters for the first box, yet it always crashes after 5th character is put in (or when the message is pasted into it that's longer than 5 characters). I'm very confused by this error as well.

Last, but not least, the caret isn't moving. If I add the code below to the code above after the last line (SetFocus one) then it gives the same result as if there is no code at all:

<br />
		CPoint myPoint = m_wEdit2->GetCaretPos();<br />
		CDC* pDC = m_wEdit2->GetDC();<br />
		myPoint.x += (pDC->GetTextExtent (_T(key1.Right(temp)), temp)).cx;<br />
		SetCaretPos (myPoint);<br />


And I don't understand why this doesn't work either. Basically all I'm doing is taking the current caret position, figuring out the physical length of the text, and offsetting the caret. But it doesn't get offset. I even tried creating a new function "OnSetFocusEdit2" so that it gets called as soon as focus is set to second edit box, which box 1 does when it finishes and copying the caret code there instead, but still no effect. If anyone can explain to me these weird happenings, I would appreciate it.
GeneralRe: weird errors Pin
Blake Miller15-Jun-05 4:44
Blake Miller15-Jun-05 4:44 
GeneralRe: weird errors Pin
David Crow15-Jun-05 5:40
David Crow15-Jun-05 5:40 
GeneralCListCtrl Class Help! Pin
mahanagarjuna15-Jun-05 2:12
mahanagarjuna15-Jun-05 2:12 
GeneralMessage for ListView Pin
Duy Nghia15-Jun-05 1:27
Duy Nghia15-Jun-05 1:27 
GeneralRe: Message for ListView Pin
David Crow15-Jun-05 4:53
David Crow15-Jun-05 4:53 
GeneralRe: Message for ListView Pin
Duy Nghia15-Jun-05 15:35
Duy Nghia15-Jun-05 15:35 
GeneralRe: Message for ListView Pin
David Crow16-Jun-05 2:47
David Crow16-Jun-05 2:47 
GeneralCreating Multiple Document Interface using a CRichEditCtrl Pin
dittygrail15-Jun-05 1:17
dittygrail15-Jun-05 1:17 
GeneralOwner Draw List Box &amp; GetText() Pin
Jon Hulatt15-Jun-05 1:14
Jon Hulatt15-Jun-05 1:14 
GeneralRe: Owner Draw List Box &amp; GetText() Pin
Terence Russell1-Jun-23 8:19
Terence Russell1-Jun-23 8:19 
GeneralTime In Microseconds Pin
sweep12315-Jun-05 1:08
sweep12315-Jun-05 1:08 
Questiongetting the upper left pixel of HBITMAP? Pin
ThinkingPrometheus15-Jun-05 0:30
ThinkingPrometheus15-Jun-05 0:30 
AnswerRe: getting the upper left pixel of HBITMAP? Pin
ThatsAlok15-Jun-05 0:49
ThatsAlok15-Jun-05 0:49 
GeneralRe: getting the upper left pixel of HBITMAP? Pin
ThinkingPrometheus15-Jun-05 3:38
ThinkingPrometheus15-Jun-05 3:38 
GeneralRe: getting the upper left pixel of HBITMAP? Pin
Bob Stanneveld15-Jun-05 4:29
Bob Stanneveld15-Jun-05 4:29 
GeneralRe: getting the upper left pixel of HBITMAP? Pin
ThinkingPrometheus15-Jun-05 5:49
ThinkingPrometheus15-Jun-05 5:49 
GeneralRe: getting the upper left pixel of HBITMAP? Pin
Bob Stanneveld15-Jun-05 5:54
Bob Stanneveld15-Jun-05 5:54 

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.