-
Feb 1st, 2015, 01:46 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] TextBox API functions (for bypassing 64K limit)
I have found only one function here (to load huge file into textbox): https://www.planet-source-code.com/v...69294&lngWId=1
But I also need functions for selecting all text, because native VB functions (.SelStart, .SelLength) can't do that due to 64K characters limit. I know it has to do with SendMessage API but I'm not expert in that field.
Can someone help me to write such replacement functions?
EDIT: Found it, here are functions for loading and selecting huge text into TextBox:
VB Code:
Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long 'Private Declare Function GetWindowTextLength Lib "user32" _ Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long Private Const WM_SETTEXT = &HC 'Private Const WM_GETTEXTLENGTH = &HE Private Const EM_SETSEL = &HB1 Function LoadBig(txt As TextBox, FileOrString As String, Optional IsString As Boolean, Optional Pre As String) On Error GoTo E Dim TempText As String Dim iret As Long If Not IsString Then Dim FileNum As Integer FileNum = FreeFile ' Open the selected file. Open FileOrString For Input As #FileNum TempText = Pre & StrConv(InputB(LOF(FileNum), FileNum), vbUnicode) Else: TempText = Pre & FileOrString End If DoEvents txt.Text = "" iret = SendMessage(txt.hWnd, WM_SETTEXT, 0&, ByVal TempText) 'iret = SendMessage(txt.hWnd, WM_GETTEXTLENGTH, 0&, ByVal 0&) 'Debug.Print "WM_GETTEXTLENGTH: " & iret TempText = "" E: If Not IsString Then Close #FileNum End Function Function SelectT(txt As TextBox, SelStart As Long, SelEnd As Long) Dim iret As Long Res = SendMessage(txt.hWnd, EM_SETSEL, SelStart, SelEnd) End Function
Last edited by MikiSoft; Feb 1st, 2015 at 02:35 PM.
-
Feb 1st, 2015, 02:21 PM
#2
Re: [RESOLVED] TextBox API functions (for bypassing 64K limit)
Why not just use a rich text box control instead?
Burn the land and boil the sea
You can't take the sky from me
~T
-
Feb 1st, 2015, 02:36 PM
#3
Thread Starter
Hyperactive Member
Re: [RESOLVED] TextBox API functions (for bypassing 64K limit)
Originally Posted by Gruff
Why not just use a rich text box control instead?
I don't want to be dependent on any extra components, it's unnecessary because all I want here is simple textbox which can load unlimited characters.
-
Feb 1st, 2015, 04:12 PM
#4
Re: [RESOLVED] TextBox API functions (for bypassing 64K limit)
I'm not sure why this was marked RESOLVED then. Ok, I see your EDIT now. But that's a cryptic way to resolve a question here.
But a search should turn up tons of copy/paste code, or even an inside-out Class to do this e.g. Re: Create Class and put new methods/property for a control.
-
Feb 1st, 2015, 04:25 PM
#5
Re: [RESOLVED] TextBox API functions (for bypassing 64K limit)
Originally Posted by MikiSoft
I don't want to be dependent on any extra components, it's unnecessary because all I want here is simple textbox which can load unlimited characters.
Careful with that approach. Loading a 1+ GB file may take quite some time. Even with Wndows Notepad, very large files take quite awhile to load. I think a better, much harder, approach would be to create a paging system for large files, i.e., chunk-type reader. Many here have probably created their own "huge file reader" applications in the past & if interested, may want to pose a few questions along that line of thought
-
Feb 1st, 2015, 04:29 PM
#6
Re: [RESOLVED] TextBox API functions (for bypassing 64K limit)
I doubt he needs to deal with files approaching or exceeding 1GB, but it is still a point well taken since beyond a certain point usability really drops anyway.
I'm reminded of the RegEdit treeview pane at the left where trying to make small scrollbar moves can launch you far, far away from where you were working.
-
Feb 2nd, 2015, 05:10 AM
#7
Thread Starter
Hyperactive Member
Re: [RESOLVED] TextBox API functions (for bypassing 64K limit)
Thanks for suggestions. I needed this to load files with maximum size of not more than a few megabytes.
Last edited by MikiSoft; Feb 2nd, 2015 at 06:01 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|