'============================================= ' 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
|
|