 |
Bay Six Software Beyond the Basics
|
View previous topic :: View next topic |
Author |
Message |
snoopy11 Guest
|
Posted: May 19th, 2010, 7:08pm Post subject: subclassing an edit box with WmLiberty |
|
|
How can I subclass an edit box using wmliberty so that it catches the rtuen key and moves it to the next editbox
I can do this in c++ but am struggling to achieve the same in LB and I dont know why.
Code: |
Open "WMLiberty" For DLL As #wmlib
WindowWidth = 300
WindowHeight = 350
UpperLeftX = Int((DisplayWidth - WindowWidth)/2)
UpperLeftY = Int((DisplayHeight - WindowHeight)/2)
Textbox #main.tbx1, 150, 50, 120, 30
Textbox #main.tbx2, 150, 100, 120, 30
Open "editbox demo" for Window as #main
#main, "Trapclose EndDemo"
#main.tbx1, "!Setfocus"
hWnd = HWND(#main.tbx1)
Callback lpfn, OnCommand (ULong,ULong,ULong,ULong),Long
CallDLL #wmlib, "SetWMHandler", _
hWnd As ULong, _
_WM_COMMAND As ULong, _
lpfn As ULong, _
-1 As Long, _
ret As Long
Call DoEvents
Wait
' mwliberty requires this loop to stop using all of the system resources.
Sub DoEvents
[localLoop]
Scan
CallDLL #kernel32, "Sleep", 50 As Long, ret As Void
GoTo [localLoop]
End Sub
Sub EndDemo handle$
close #wmlib
Close #main
End
End Sub
Function OnCommand( hWnd, uMsg, wParam, lParam )
Select Case ULong (uMsg)
Case _WM_GETDLGCODE
OnCommand = _DLGC_WANTALLKEYS
Case _WM_CHAR
OnCommand = 0
Case _WM_KEYDOWN
if wParam = _VK_RETURN then #main.tbx2, "!Setfocus"
OnCommand = 0
End Select
End Function
|
If you could point me in the right direction that would be great. |
|
Back to top |
|
 |
STPendl Full Member
Joined: 20 Aug 2007 Posts: 161 Location: Austria
|
Posted: May 19th, 2010, 8:32pm Post subject: Re: subclassing an edit box with WmLiberty |
|
|
The following is working.
Code: |
Open "WMLiberty" For DLL As #wmlib
nomainwin
WindowWidth = 300
WindowHeight = 350
UpperLeftX = Int((DisplayWidth - WindowWidth)/2)
UpperLeftY = Int((DisplayHeight - WindowHeight)/2)
Textbox #main.tbx1, 150, 50, 120, 30
Textbox #main.tbx2, 150, 100, 120, 30
Open "editbox demo" for Window as #main
#main "Trapclose EndDemo"
#main.tbx1 "!Setfocus"
hWnd = HWND(#main.tbx1)
Callback lpfn, OnKeyUP(ULong,ULong,ULong,ULong),Long
lSuccess = 0 or -1
CallDLL #wmlib, "SetWMHandler", _
hWnd As ULong, _
_WM_KEYUP As ULong, _
lpfn As ULong, _
lSuccess As Long, _
ret As Long
Call DoEvents
Wait
' mwliberty requires this loop to stop using all of the system resources.
Sub DoEvents
[localLoop]
Scan
CallDLL #kernel32, "Sleep", 50 As Long, ret As Void
GoTo [localLoop]
End Sub
Sub EndDemo handle$
Close #handle$
close #wmlib
End
End Sub
Function OnKeyUP( hWnd, uMsg, wParam, lParam )
if wParam = _VK_RETURN then
#main.tbx2 "!Setfocus"
OnKeyUP = 0
End If
End Function
|
_________________ Stefan
Any code I post can be freely used, just give credit. |
|
Back to top |
|
 |
snoopy11 Guest
|
Posted: May 20th, 2010, 3:38pm Post subject: Re: subclassing an edit box with WmLiberty |
|
|
thanks stefan never thought of using WM_KEYUP like that.
if you dont mind i will post this answer in liberrty forum i will tell them its your code though. it might help some one. |
|
Back to top |
|
 |
STPendl Full Member
Joined: 20 Aug 2007 Posts: 161 Location: Austria
|
Posted: May 20th, 2010, 10:15pm Post subject: Re: subclassing an edit box with WmLiberty |
|
|
I have posted the code to help you, so you can do whatever you like with it.
I followed the discussion on the LB community forum, so there would be other ways to get this going too.
I have done similar things using BS_DEFPUSHBUTTON and GetFocus to advance to the next control, without the need to use an additional DLL. _________________ Stefan
Any code I post can be freely used, just give credit. |
|
Back to top |
|
 |
snoopy11 Guest
|
Posted: May 21st, 2010, 5:41am Post subject: Re: subclassing an edit box with WmLiberty |
|
|
Hi again stefan perhaps you can explain why this code gives out a protection violation when you close it. Is there any way round this or am I calling wmliberty one too many times ?
Code: |
Open "WMLiberty" For DLL As #wmlib
Open "WMLiberty" For DLL As #wmlib2
nomainwin
WindowWidth = 300
WindowHeight = 350
UpperLeftX = Int((DisplayWidth - WindowWidth)/2)
UpperLeftY = Int((DisplayHeight - WindowHeight)/2)
Textbox #main.tbx1, 150, 50, 120, 30
Textbox #main.tbx2, 150, 100, 120, 30
Textbox #main.tbx3, 150, 150, 120, 30
Open "editbox demo" for Window as #main
#main "Trapclose EndDemo #main"
#main.tbx1 "!Setfocus"
hWnd = HWND(#main.tbx1)
hWnd2 = HWND(#main.tbx2)
hWnd3 = HWND(#main.tbx3)
Callback lpfn, OnKeyUP(ULong,ULong,ULong,ULong),Long
lSuccess = 0
CallDLL #wmlib, "SetWMHandler", _
hWnd As ULong, _
_WM_KEYUP As ULong, _
lpfn As ULong, _
lSuccess As Long, _
ret As Long
Callback lpfn2, OnKeyUP2(ULong,ULong,ULong,ULong),Long
lSuccess = 0
CallDLL #wmlib2, "SetWMHandler", _
hWnd2 As ULong, _
_WM_KEYUP As ULong, _
lpfn2 As ULong, _
lSuccess As Long, _
ret As Long
Call DoEvents
Wait
' mwliberty requires this loop to stop using all of the system resources.
Sub DoEvents
[localLoop]
Scan
CallDLL #kernel32, "Sleep", 50 As Long, ret As Void
GoTo [localLoop]
End Sub
Sub EndDemo handle$
close #wmlib
close #wmlib2
close #main
End
End Sub
Function OnKeyUP( hWnd, uMsg, wParam, lParam )
if wParam = _VK_RETURN then
' do something here in this case set the focus of textbox2
#main.tbx2 "!Setfocus"
OnKeyUP = 0
End If
End Function
Function OnKeyUP2( hWnd2, uMsg, wParam, lParam )
if wParam = _VK_RETURN then
' do something here in this case set the focus of textbox3
#main.tbx3 "!Setfocus"
OnKeyUP2 = 0
End If
End Function
|
|
|
Back to top |
|
 |
STPendl Full Member
Joined: 20 Aug 2007 Posts: 161 Location: Austria
|
Posted: May 21st, 2010, 7:48am Post subject: Re: subclassing an edit box with WmLiberty |
|
|
All the examples posted by Brent include a hint to close the window before the DLL, which you don't.
I have never had a need to open a DLL twice and it is easy to create one callback, which handles all text boxes. _________________ Stefan
Any code I post can be freely used, just give credit. |
|
Back to top |
|
 |
STPendl Full Member
Joined: 20 Aug 2007 Posts: 161 Location: Austria
|
Posted: May 21st, 2010, 8:10am Post subject: Re: subclassing an edit box with WmLiberty |
|
|
Below find a working solution.
Code: |
Open "WMLiberty" For DLL As #wmlib
nomainwin
' globalize the text box handles to be visible in the callback
global hWnd1, hWnd2, hWnd3
WindowWidth = 300
WindowHeight = 350
UpperLeftX = Int((DisplayWidth - WindowWidth)/2)
UpperLeftY = Int((DisplayHeight - WindowHeight)/2)
Textbox #main.tbx1, 150, 50, 120, 30
Textbox #main.tbx2, 150, 100, 120, 30
Textbox #main.tbx3, 150, 150, 120, 30
Open "editbox demo" for Window as #main
#main "Trapclose EndDemo #main"
#main.tbx1 "!Setfocus"
hWnd1 = HWND(#main.tbx1)
hWnd2 = HWND(#main.tbx2)
hWnd3 = HWND(#main.tbx3)
Callback lpfn, OnKeyUP(ULong,ULong,ULong,ULong),Long
lSuccess = 0 or -1
CallDLL #wmlib, "SetWMHandler", _
hWnd1 As ULong, _
_WM_KEYUP As ULong, _
lpfn As ULong, _
lSuccess As Long, _
ret As Long
CallDLL #wmlib, "SetWMHandler", _
hWnd2 As ULong, _
_WM_KEYUP As ULong, _
lpfn As ULong, _
lSuccess As Long, _
ret As Long
CallDLL #wmlib, "SetWMHandler", _
hWnd3 As ULong, _
_WM_KEYUP As ULong, _
lpfn As ULong, _
lSuccess As Long, _
ret As Long
Call DoEvents
Wait
' mwliberty requires this loop to stop using all of the system resources.
Sub DoEvents
[localLoop]
Scan
CallDLL #kernel32, "Sleep", 50 As Long, ret As Void
GoTo [localLoop]
End Sub
Sub EndDemo handle$
close #handle$
close #wmlib
End
End Sub
Function OnKeyUP( hWnd, uMsg, wParam, lParam )
if wParam = _VK_RETURN then
' do something here in this case set the focus of textbox2
select case hWnd
case hWnd1
handle$ = "#main.tbx2"
case hWnd2
handle$ = "#main.tbx3"
case hWnd3
handle$ = "#main.tbx1"
end select
#handle$ "!Setfocus"
OnKeyUP = 0
End If
End Function
|
_________________ Stefan
Any code I post can be freely used, just give credit. |
|
Back to top |
|
 |
snoopy11 Guest
|
Posted: May 21st, 2010, 9:18am Post subject: Re: subclassing an edit box with WmLiberty |
|
|
Hi Stefan thanks for the code it unfortunately still persists with the runtime error Protection Violation when you close the window.
Annoying but your code was neater....
I thought you surely had cracked it, still dont know why exactly there is the Protection Violation.
Thanks for all your help once again. |
|
Back to top |
|
 |
snoopy11 Guest
|
Posted: May 21st, 2010, 9:25am Post subject: Re: subclassing an edit box with WmLiberty |
|
|
Ok found a solution but dont know why it works
Code: |
Open "WMLiberty" For DLL As #wmlib
nomainwin
' globalize the text box handles to be visible in the callback
global hWnd1, hWnd2, hWnd3
WindowWidth = 300
WindowHeight = 350
UpperLeftX = Int((DisplayWidth - WindowWidth)/2)
UpperLeftY = Int((DisplayHeight - WindowHeight)/2)
Textbox #main.tbx1, 150, 50, 120, 30
Textbox #main.tbx2, 150, 100, 120, 30
Textbox #main.tbx3, 150, 150, 120, 30
Open "editbox demo" for Window as #main
#main "Trapclose EndDemo #main"
#main.tbx1 "!Setfocus"
hWnd1 = HWND(#main.tbx1)
hWnd2 = HWND(#main.tbx2)
hWnd3 = HWND(#main.tbx3)
handle = HWND(#main)
Callback lpfn, OnKeyUP(ULong,ULong,ULong,ULong),Long
lSuccess = 0 or -1
CallDLL #wmlib, "SetWMHandler", _
handle As ULong, _
_WM_KEYDOWN As ULong, _
lpfn As ULong, _
lSuccess As Long, _
ret As Long
CallDLL #wmlib, "SetWMHandler", _
hWnd1 As ULong, _
_WM_KEYDOWN As ULong, _
lpfn As ULong, _
lSuccess As Long, _
ret As Long
CallDLL #wmlib, "SetWMHandler", _
hWnd2 As ULong, _
_WM_KEYDOWN As ULong, _
lpfn As ULong, _
lSuccess As Long, _
ret As Long
CallDLL #wmlib, "SetWMHandler", _
hWnd3 As ULong, _
_WM_KEYDOWN As ULong, _
lpfn As ULong, _
lSuccess As Long, _
ret As Long
Call DoEvents
Wait
' mwliberty requires this loop to stop using all of the system resources.
Sub DoEvents
[localLoop]
Scan
CallDLL #kernel32, "Sleep", 50 As Long, ret As Void
GoTo [localLoop]
End Sub
Sub EndDemo handle$
close #handle$
close #wmlib
End
End Sub
Function OnKeyUP( hWnd, uMsg, wParam, lParam )
if wParam = _VK_RETURN then
' do something here in this case set the focus of textbox's
select case hWnd
case hWnd1
handle$ = "#main.tbx2"
case hWnd2
handle$ = "#main.tbx3"
case hWnd3
handle$ = "#main.tbx1"
end select
#handle$, "!Setfocus"
OnKeyUP = 0
End If
End Function
|
This causes no protection violations
but if you could tell me why. including the main window in the callback
works that would be extra special.
Thanking you again. |
|
Back to top |
|
 |
Brent Site Admin
Joined: 01 Jul 2005 Posts: 793
|
Posted: May 22nd, 2010, 2:09am Post subject: Re: subclassing an edit box with WmLiberty |
|
|
WMLiberty does seem to have a few assumptions built into it. One of these could be that the hwnd being passed is that of a top-level window. People have had problems subclassing controls only. In many cases, they could have subclassed the parent window and been able to determine the originating control because many messages bubble up. However, the key-press messages don't bubble. You may have found a work-around for the control-only problem. _________________ Brent |
|
Back to top |
|
 |
snoopy11 Guest
|
Posted: May 22nd, 2010, 5:29am Post subject: Re: subclassing an edit box with WmLiberty |
|
|
Quote: |
You may have found a work-around for the control-only problem.
|
Well it works just fine as it is...
So hopefully I have Brent.
I was thinking that WMLiberty needs to close the window your working in so thats why you have to include it before the child window controls.
But no matter how it works it definitely works  |
|
Back to top |
|
 |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|
|