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

How to add more than 10,000 lines to EditBox in Dialog?

xianyao-chen
Beginner
990 Views
Dear Sir,
I tried to add more than 10,000 lines to Edit Boxes in Dialog so that I could copy them to clipboard and save, if not all 10,000 lines can be saved, I perfer as much as possible final lines could be saved. How I can do it?
Please do me a favour.

I have tried the following codes, which listed in the boards before:
SUBROUTINE AppendEditText(Dlg, ID, sText)
TYPE(Dialog):: Dlg
INTEGER:: ID
CHARACTER(*):: sText

CHARACTER(LEN=LEN(sText)+1):: szText
INTEGER:: hwndEdit, i

hwndEdit = GetDlgItem(Dlg%hWnd, ID)
szText=TRIM(sText)//CHAR(0)
nLength = SendMessage ( hwndEdit, WM_GETTEXTLENGTH, 0, 0 )
i = SendMessage ( hwndEdit, EM_SETSEL, nLength, nLength )
i = SendMessage ( hwndEdit, EM_REPLACESEL, 0, LOC(szText))
END SUBROUTINE AppendEditText

With this method, I could add multi-lines to EditBox, but after some lines, it will stop work.

Thanks in advance

Yao
xianyaochen@yahoo.com.cn
0 Kudos
7 Replies
Jugoslav_Dujic
Valued Contributor II
990 Views

Which operating system? Docs (vaguely) imply that the limit of text of edit controls on Windows 9x is 64 kB, while the limit on Windows 2000/XP is 2GB. It's not stated very explicitly though -- see e.g. EM_LIMITTEXT -- if the limit for manual entering is 64 kB, it's probably true as well for programatic entering of the text. (Also, I recall that early versions of Notepad had 64 kB limit, becauseit actuallyhosts a multiline edit control).

If you're on Win2000+, well, I'm not sure.

In any case, you could probably applysimilar SETSEL/REPLACESEL logic to delete the first couple of bytes when nLength is close to e.g. 60 kB. (If you need to delete one line at a time, return value from EM_GETLINE tells you how long a line is).

Jugoslav

0 Kudos
xianyao-chen
Beginner
990 Views
Thanks.

The operating system is XP. I use sendmessage(hwndEdit, EM_LimitText, 0,0) to change the default limit of length of input character (30,000). But I donot think it is a good idea because it sound like I use maximum resource.

How I can output multilines like "cmd.exe" does, deleting first line when the output exceeds the specified number? Is the following procedure suitable and efficient?
At each time,
step 1, read all characters in EditBox,
step 2, truncate first line and add the new output lines at the end
step 3, select all, replace all using EM_ReplaceSEL

thanks,

Yao
0 Kudos
Steven_L_Intel1
Employee
990 Views
cmd.exe uses a console window. However, the size of the window, and whether or not you can use select/copy, is controlled by the user and isn't, I don't think, programmable (I could be mistaken on this, though.)
Please describe your application in more detail, perhaps we can think of another way to do what you want. Offhand, I would say that writing the lines to a file and opening NOTEPAD on it (or a ShellExecute "open" call) would be quite effective - you'd get the entire contents in a window from which you can copy/paste to your heart's content. The only trick would be closing it down when you're done - I suppose that would require use of CreateProcess to activate it.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
990 Views
I suggest the following scheme instead of coping with entire contents of an edit box:
integer:: i, ist, nlength character(10):: line character(100):: dummy
include "resource.fd"
do i=1,4000 nLength = DlgSendCtrlMessage(dlg, IDC_EDIT1, WM_GETTEXTLENGTH, 0, 0) !If length is too long, delete the first line: if (nLength.gt.29000) then !CVF Help is little outdated. MSDN says that the first word of buffer pointed !to by EM_GETLINE:wParam must contain length of the buffer on input: dummy(1:1)=transfer(int2(len(dummy)), "a") !Length of first line: nLength = DlgSendCtrlMessage(dlg, IDC_EDIT1, EM_GETLINE, 0, loc(dummy)) !Add 2 to nLength to select terminating char(13)//char(10) ist = DlgSendCtrlMessage(dlg, IDC_EDIT1, EM_SETSEL, 0, nLength+2) !Replace with empty string: ist = DlgSendCtrlMessage(dlg, IDC_EDIT1, EM_REPLACESEL, 0, loc(""C)) !New length nLength = DlgSendCtrlMessage(dlg, IDC_EDIT1, WM_GETTEXTLENGTH, 0, 0) end if
ist = DlgSendCtrlMessage(dlg, IDC_EDIT1, EM_SETSEL, nLength, nLength) write(line,"(i6.6,a3)") i, char(13)//char(10)//char(0) ist = DlgSendCtrlMessage(dlg, IDC_EDIT1, EM_REPLACESEL, 0, loc(line)) end do
You'll have to adjust it a little to suit your needs but I hope you get the idea.
Jugoslav
0 Kudos
xianyao-chen
Beginner
990 Views
I would like to add the output of a program to an EditBox in dialog, the total output lines exceed 10,000 lines. And also I just need the last 200 lines at each steps, so it is not necessary to keep all output lines in memory. This is quite similar as the program running in Console window (e.g. cmd.exe) when output lines exceed specific lines (e.g. 200), it will delete first line and add the new line at the end. I am now trying the subroutine suggested by jugoslavdujic. Thanks very much.

Yao
0 Kudos
xianyao-chen
Beginner
990 Views
I modified the code like following

SUBROUTINE AppendEditText(Dlg, ID, sText, NewLine)
TYPE(Dialog):: Dlg
INTEGER:: ID
CHARACTER(*):: sText
integer :: nLength
logical :: NewLine

CHARACTER(LEN=LEN(sText)+1):: szText
INTEGER:: ist
character(len=2) :: dummy

szText=TRIM(sText)//CHAR(0)
nLength = DlgSendCtrlMessage(Dlg,ID, WM_GETTEXTLENGTH, 0 ,0)
if (nLength > 29000 .and. NewLine) then
dummy(1:1)=transfer(int2(len(dummy)), "a")
!Length of first line:
nLength = DlgSendCtrlMessage(Dlg, ID, EM_GETLINE, 0, loc(dummy))

!Add 2 to nLength to select terminating char(13)//char(10)
ist = DlgSendCtrlMessage(Dlg, ID, EM_SETSEL, 0, nLength+2)
!Replace with empty string:
ist = DlgSendCtrlMessage(Dlg, ID, EM_REPLACESEL, 0, loc(""C))
!New length
nLength = DlgSendCtrlMessage(Dlg, ID, WM_GETTEXTLENGTH, 0, 0)
end if
if (NewLine) then
nLengthLast = nLength
endif

ist = DlgSendCtrlMessage(Dlg, ID, EM_SETSEL, nLengthLast, nLength)
ist = DlgSendCtrlMessage(Dlg,ID, EM_REPLACESEL, 0, LOC(szText))
END SUBROUTINE AppendEditText

where nLengthLast is another parameter to remember the last length of the contents in EditBox
so that I could use this subroutine to add some output in the same line in EditBox and add some output in new line, which is determined by variable : NewLine. When using EM_GetLine,
wparam = 0 means topmost line of multiline EditBox, is there another parameter store the bottom-most line?

Thanks

Yao
0 Kudos
Jugoslav_Dujic
Valued Contributor II
990 Views

See EM_GETLINECOUNT.

Jugoslav

0 Kudos
Reply