- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
Its entirely possible that I'm doing something goofy, but I can't understand why the following code doesn't work as one might reasonably expect.
Based on the test outputs below, the SetWindowText command would appearto bealtering a variable when it should not. Also strange is how the 'fieldText' variable seems to always retain the correct value when shown through a write statement, but not when used with SetWindowText.
Code:
integer(2), parameter :: STR_LENGTH = 16 character(STR_LENGTH) :: fieldText integer(2) :: SET_EM_MAXITS
SET_EM_MAXITS = 1000 write(fieldText, '(I0)') SET_EM_MAXITS
! the '17' isn't anything special here: write(17, *) "set1: ", SET_EM_MAXITS, TRIM(fieldText) ! this write statement produces the following: ! set1: 1000 1000
! ?? what is wrong with this line: ?? iret = SetWindowText(hEditMaxits, TRIM(fieldText))
write(17, *) "set2: ", SET_EM_MAXITS, TRIM(fieldText), iret ! this write statement produces the following: ! set2: 100 1000 1
The problem is that when this set of code is called,displayed in the edit box with handle hEditMaxits is an incorrect value of 100 instead of the desired 1000.
Incidentally,the same problem occurs with/without either the TRIM() and/or any ''C string terminator. Also it occurs when compiled in both Debug and Release configurations.
Thanks in advance for any insights - Richard
Win32 application written using CVF 6.6c
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For the start, you must char(0)-terminate any string that goes to Win32 API functions (except for few where it's explicitly said that you need not, like TextOut). So, you need either
SetWindowText(hEditMaxits, TRIM(fieldText)//char(0)or
write(fieldText, '(I0,A)') SET_EM_MAXITS,char(0),whichever is more convenient. (Also, SetDlgItemInt(hWndParent, idEditControl, int4(SET_EM_MAXITS)) should also work).
Message Edited by JugoslavDujic on 04-18-200606:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Indeed Jugoslav, thanks.
However, even with the appropriate null terminators placed on the string, this same problem exhibits itself.
Also, using SetDlgItemInt resulted in no change to the write statements, nor to the text populated in the edit box.
Richard
However, even with the appropriate null terminators placed on the string, this same problem exhibits itself.
Also, using SetDlgItemInt resulted in no change to the write statements, nor to the text populated in the edit box.
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Then, you must have a pretty hidden bug elsewhere. I assume you have array bounds checking switched on? However, it's not a panacea -- there are the cases where it cannot catch the memory overwrite.
Few hints as to how to approach the problem:
- Open "Memory" debug window and type LOC(SET_EM_MAXITS) there. Go step by step and watch which statement alters the value.
- In Debug/Breakpoints/Data you can do a similar thing (type SET_EM_MAXITS) and you'll get notified when the value changes (note that the feature is, erm, quirky).
- In "Memory" window you can also verify that you're correctly writing terminal char(0) into the string.
I doubt it has anything to do with SetWindowText. Does SendMessage(WM_SETTEXT) produce the same behavior?
Few hints as to how to approach the problem:
- Open "Memory" debug window and type LOC(SET_EM_MAXITS) there. Go step by step and watch which statement alters the value.
- In Debug/Breakpoints/Data you can do a similar thing (type SET_EM_MAXITS) and you'll get notified when the value changes (note that the feature is, erm, quirky).
- In "Memory" window you can also verify that you're correctly writing terminal char(0) into the string.
I doubt it has anything to do with SetWindowText. Does SendMessage(WM_SETTEXT) produce the same behavior?

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page