Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

about edit notification...

shiptar
Beginner
741 Views
hello,
i am trying to restart an updown control attached edit boxwith a new value which is entered by a user. to do that jugoslavsaid that to use EN_CHANGE. i did it as follows;
...
if (Loword(wParam).EQ.IDC_Edit1)then
if (Hiword(wParam).EQ.EN_CHANGE) then
iret = GetDlgItemText(hDlg, IDC_Edit1, text, MaxCharacter)
read(text, *, iostat=iErr) value1
nPos1 = (value1*scaling1)
if(nPos1 .le. min1) nPos1 = min1
if(nPos1 .ge. max1) nPos1 = max1
write(text,'(f5.1)') nPos1
iret = SetDlgItemText(hDlg, IDC_Edit1, trim(adjustl(text))//char(0) )
iret = SendMessage(hSpin1,UDM_SETPOS,0,MAKELONG(nPos1,0))
end if
DlgProc = 1
return
end if
...
but an error happened;
"unhadled exception in win28.exe: 0xC00000FD : Stack overflow"
and cursor flashed in that line
"write(text,'(f5.1)') nPos1"
what could be the reason? and is it goodto warn a user if it enters a value out of range?
thank you,
ercan
0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
741 Views
Hmmm... it looks as if you're creating an infinite recursion somehow. It doesn't matter where it crashed -- it matters what your "call stack" debug window show. I think that this was the sequence of events (don't have time to verify it):
- user typed something; EN_CHANGE was generated
- you set the text of the edit control via SetDlgItemText. That function detects that the contents are changed and sends an EN_CHANGE message
- you set the text of the edit control via SetDlgItemText. That function detects that the contents are changed and sends an EN_CHANGE message
- you set the text of the edit control via SetDlgItemText. That function detects that the contents are changed and sends an EN_CHANGE message...
...until you exhaust the stack.
To break that chain, you should SetDlgItemText only if you detect that the input was invalid & fix it. Next time an EN_CHANGE arrives, the text will bevalidand the chain won't be generated. Also, have an eye whether UDM_SETPOS starts a similar sequence of events (I believe not, but test it.)
It's highly recommended that you declare all your WndProcs RECURSIVE.
Input validation is certainly A Good Thing. Otherwise, your program will work on GIGO principle (garbage-in-garbage-out).
Jugoslav
0 Kudos
shiptar
Beginner
741 Views
you mean i should insert SetDlgItemText before DlgProc=1 ? like that;
if (Loword(wParam).EQ.IDC_Edit1)then
if (Hiword(wParam).EQ.EN_CHANGE) then
iret = GetDlgItemText(hDlg, IDC_Edit1, text, MaxCharacter)
read(text, *, iostat=iErr) value1
nPos1 = (value1*scaling1)
if(nPos1 .le. min1) nPos1 = min1
if(nPos1 .ge. max1) nPos1 = max1
write(text,'(f5.1)') nPos1
end if
iret = SetDlgItemText(hDlg, IDC_Edit1, trim(adjustl(text))//char(0) )
iret = SendMessage(hSpin1,UDM_SETPOS,0,MAKELONG(nPos1,0))
DlgProc = 1
return
end if
and i think i delared my DialogProc as an interfacein MainWndProc...like,
interface
integer function*4 DialogProc(wparam...)
...
end function
end interface
and what is that GIGO principle? sounds not good...
thank you
0 Kudos
Jugoslav_Dujic
Valued Contributor II
741 Views

No, I mean that you should call SetDlgItemText only if you detect an out-of range value:

if(nPos1.le.min1 .or. nPos1.ge.max1) then

nPos1 = min1
if(nPos1 .ge. max1) nPos1 = max1
write(text,'(f5.1)') nPos1
end if
iret = SetDlgItemText(hDlg, IDC_Edit1, trim(adjustl(text))//char(0) )

0 Kudos
Jugoslav_Dujic
Valued Contributor II
741 Views

No, I mean that you should call SetDlgItemText only if you detect an out-of range value:

if(nPos1.le.min1 .or. nPos1.ge.max1) then

nPos1 = min1
if(nPos1 .ge. max1) nPos1 = max1
write(text,'(f5.1)') nPos1
end if
iret = SetDlgItemText(hDlg, IDC_Edit1, trim(adjustl(text))//char(0) )

0 Kudos
Reply