[RESOLVED] TextBox API functions (for bypassing 64K limit)-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] TextBox API functions (for bypassing 64K limit)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    461

    Resolved [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:
    1. Private Declare Function SendMessage Lib "user32" _
    2.       Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
    3.       ByVal wParam As Long, lParam As Any) As Long
    4.      
    5.    'Private Declare Function GetWindowTextLength Lib "user32" _
    6.       Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
    7.  
    8.    Private Const WM_SETTEXT = &HC
    9.    'Private Const WM_GETTEXTLENGTH = &HE
    10.    Private Const EM_SETSEL = &HB1
    11.  
    12. Function LoadBig(txt As TextBox, FileOrString As String, Optional IsString As Boolean, Optional Pre As String)
    13.     On Error GoTo E
    14.    
    15.     Dim TempText As String
    16.     Dim iret As Long
    17.     If Not IsString Then
    18.     Dim FileNum As Integer
    19.     FileNum = FreeFile
    20.     ' Open the selected file.
    21.     Open FileOrString For Input As #FileNum
    22.     TempText = Pre & StrConv(InputB(LOF(FileNum), FileNum), vbUnicode)
    23.     Else: TempText = Pre & FileOrString
    24.     End If
    25.     DoEvents
    26.     txt.Text = ""
    27.    
    28.     iret = SendMessage(txt.hWnd, WM_SETTEXT, 0&, ByVal TempText)
    29.     'iret = SendMessage(txt.hWnd, WM_GETTEXTLENGTH, 0&, ByVal 0&)
    30.     'Debug.Print "WM_GETTEXTLENGTH: " & iret
    31.     TempText = ""
    32. E:  If Not IsString Then Close #FileNum
    33. End Function
    34.  
    35. Function SelectT(txt As TextBox, SelStart As Long, SelEnd As Long)
    36.     Dim iret As Long
    37.     Res = SendMessage(txt.hWnd, EM_SETSEL, SelStart, SelEnd)
    38. End Function
    Last edited by MikiSoft; Feb 1st, 2015 at 01:35 PM.

  2. #2
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    461

    Re: [RESOLVED] TextBox API functions (for bypassing 64K limit)

    Quote Originally Posted by Gruff View Post
    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.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,486

    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.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,500

    Re: [RESOLVED] TextBox API functions (for bypassing 64K limit)

    Quote Originally Posted by MikiSoft View Post
    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VB and DPI Tutorial} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,486

    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    461

    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 05: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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.