Author |
Topic: Using API for textboxes (Read 567 times) |
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
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.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
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.
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
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.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
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.
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
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.
|
|
Logged
|
|
|
|
|