LB Booster
« Using API for textboxes »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:17am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Using API for textboxes  (Read 566 times)
RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Using API for textboxes
« Thread started on: Mar 16th, 2016, 8:22pm »

I am trying to set up a small grid of textboxes using the windows api rather than using LBB's built in ones.

I am using code modified from LB's API Corner.

Code:
'=============================================
'   CREATE TEXTBOX CreateTextboxAPI.bas
'   USING WINDOWS API
'=============================================
' modified from LB Newsletter API Corner
'=============================================

NOMAINWIN

MENU #1, "&File","&Read", [readIt],_
        "E&xit", [quit]

OPEN "Password Textbox" FOR WINDOW AS #1
PRINT #1, "trapclose [quit]"

start = 20: hRow = 20
For row = 1 to 3
hPos = 20: VPos = start + row * hRow: width = 130: hRow = 20
hT = CreateTextbox(hwnd(#1),hPos,vPos,width,hRow)
next
CALL SetFocus hT
WAIT

[quit]
    CLOSE #1: END

[readIt]
    txt$ = GetWindowText$(hT)
    NOTICE txt$
    WAIT

'--------------------------------------------
'    SUBs and FUNCTIONs
'--------------------------------------------

' Set the focus in the Texbox
SUB SetFocus hWnd
    CALLDLL #user32, "SetFocus", hWnd AS LONG,_
    result AS LONG
END SUB

'Get the text entered into the Textbox
FUNCTION GetWindowText$(hWnd)
    total = GetWindowTextLength(hWnd)
    Title$ = SPACE$(total) + CHR$(0): l= LEN(Title$)

    CALLDLL #user32, "GetWindowTextA", hWnd AS LONG,_
    Title$ AS PTR, l AS LONG, result AS LONG
    GetWindowText$ = TRIM$(Title$)
END FUNCTION

'Get the length of the text entered into Textbox
FUNCTION GetWindowTextLength(hW)
    CALLDLL #user32, "GetWindowTextLengthA",_
    hW AS LONG,_
    GetWindowTextLength AS LONG
END FUNCTION

' Function to create Textbox
FUNCTION CreateTextbox(hW, x, y, w, h)
    style = _WS_CHILDWINDOW OR _WS_BORDER _
    OR _WS_VISIBLE
    hInst = GetWindowLong(hW, _GWL_HINSTANCE)

    CALLDLL #user32, "CreateWindowExA",_
        0 AS LONG,"EDIT" AS PTR,_
        "" AS PTR, style AS LONG,_
        x AS LONG,y AS LONG,w AS LONG,h AS LONG,_
        hW AS LONG, 0 AS LONG, hInst AS LONG,_
        0 AS LONG, CreateTextbox AS LONG
END FUNCTION

FUNCTION GetWindowLong(hW, type)
    CALLDLL #user32, "GetWindowLongA", _
    hW AS LONG, type AS LONG,_
    GetWindowLong AS LONG
END FUNCTION
 


Any help will be appreciated.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Using API for textboxes
« Reply #1 on: Mar 16th, 2016, 9:33pm »

on Mar 16th, 2016, 8:22pm, RNBW wrote:
Any help will be appreciated.

You don't say what you want help with! There's a typo (VPos in one place, vPos in another) but apart from that I can't see any particular problems, and the code appears to run the same in LBB and LB 4.04.

I do wonder why you are using the Windows API at all. The window title is "Password Textbox", but you don't need to use the API to create an ES_PASSWORD style box (using a regular TEXTBOX with STYLEBITS works fine; Alyce has an example).

Richard.
« Last Edit: Mar 16th, 2016, 9:34pm by Richard Russell » User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Re: Using API for textboxes
« Reply #2 on: Mar 16th, 2016, 9:52pm »

Richard

Thanks for your response.

I said I'd modified code from API Corner. other than the heading, I've taken all the Password info out of Alyce's code. I was too lazy to change the heading!

Your eagle eye caught my typo and that solved the problem.

The reason for my using APIs is that I'm playing around with them to try to get to know them better.

By the way, some time ago you gave me some LBB code for a grid and got rid of the thick lines between textboxes by adding 1 to the textbox width and to the textbox height. That doesn't appear to work with the API solution, but using -1 instead does.

Next step is to develop a multi-column grid.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Using API for textboxes
« Reply #3 on: Mar 16th, 2016, 10:40pm »

on Mar 16th, 2016, 9:52pm, RNBW wrote:
Next step is to develop a multi-column grid.

Would it not be better to learn the Windows API by doing something which it is genuinely better at? For example rather than creating a grid of textboxes create a ListView (report style), which is superficially similar but for which there is no native equivalent.

Richard.
« Last Edit: Mar 16th, 2016, 10:40pm by Richard Russell » User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Re: Using API for textboxes
« Reply #4 on: Mar 17th, 2016, 3:07pm »

Richard
I hear what you are saying but I have my reasons.

The reason I posted the code for a grid of textboxes was because I had developed code in liberty basic (with help from your goodself) and trying to develop the same result but using the Windows API enables me to check along the way the correctness and accuracy off the code. Much the same way if you had developed some code in Pascal butt now wanted to do it in Basic. It is simply a means to an end.

If I maintain an interest in this, I shall continue to try different things, including, possibly, a ListView.

I have no doubt that I shall have to return to the forum in three weeks to come for help. I do sometimes have difficulty getting my head around things sometimes. Old age, I'm afraid.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls