Author |
Topic: Removing focus from a bitmap button. (Read 1359 times) |
|
net2014
New Member
member is offline
Posts: 37
|
|
Removing focus from a bitmap button.
« Thread started on: Dec 10th, 2013, 8:20pm » |
|
I use bmpbuttons to represent LEDs in lots of my LB programs. Usually the buttons act as a toggle switch to set or reset a hardware port and the LED changes colour. To avoid a clicked button remaining in focus, I setfocus to the application window and the 'LED' displays normally. However when compiled with LBB, the last clicked LED bmpbutton is always left with a surrounding box after moving focus to the window, by the api setfocus method. Is there a way round this?
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Removing focus from a bitmap button.
« Reply #1 on: Dec 10th, 2013, 10:13pm » |
|
on Dec 10th, 2013, 8:20pm, net2014 wrote:Is there a way round this? |
|
According to MSDN the WM_KILLFOCUS message "Removes the focus rectangle from a button" so I'm not too sure whether what you're describing really is the focus rectangle or not:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775941.aspx Can you list some code which illustrates the issue?
Richard.
|
|
Logged
|
|
|
|
net2014
New Member
member is offline
Posts: 37
|
|
Re: Removing focus from a bitmap button.
« Reply #2 on: Dec 11th, 2013, 11:02am » |
|
on Dec 10th, 2013, 10:13pm, Richard Russell wrote: Can you list some code which illustrates the issue?
|
|
Code:
nomainwin ' open no main window
button #1.1, "B1", [b1], UL, 30, 10
button #1.2, "B2", [b2], UL, 30, 40
button #1.3, "B3", [b3], UL, 30, 70
open "Button Focus" for window as #1
print #1, "trapclose [quit]"
wait
[b1]
h=hwnd(#1.3)
calldll #user32, "SetFocus", h as ulong, result as long
wait
[b2]
wait
[b3]
wait
[quit]
close #1
end
Thanks Richard, here's an example.
This does not use bmpbuttons but exhibits the same effect. Run in LB4, clicking button B1 moves focus to B3 and button B1 displays normally, B3 shows focus.
Run In LBB, focus moves to B3 but the focus rectangle remains around B1 and B3.
This is under winXP and Linux/WINE 1.4 I can't test any other OS, sorry.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Removing focus from a bitmap button.
« Reply #3 on: Dec 11th, 2013, 1:50pm » |
|
on Dec 11th, 2013, 11:02am, net2014 wrote:Run In LBB, focus moves to B3 but the focus rectangle remains around B1 and B3. |
|
Right, here is the explanation. Microsoft says you are not supposed to move focus between controls using SetFocus, but instead by sending the WM_NEXTDLGCTL message:
http://blogs.msdn.com/b/oldnewthing/archive/2004/08/02/205624.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms645432.aspx
If you do that your program will work as expected in LBB:
Code:nomainwin ' open no main window
button #1.1, "B1", [b1], UL, 30, 10
button #1.2, "B2", [b2], UL, 30, 40
button #1.3, "B3", [b3], UL, 30, 70
open "Button Focus" for window as #1
hw = hwnd(#1)
print #1, "trapclose [quit]"
wait
[b1]
h=hwnd(#1.3)
calldll #user32, "SendMessageA", hw as ulong, _
_WM_NEXTDLGCTL as long, h as ulong, 1 as long, _
result as long
wait
[b2]
wait
[b3]
wait
[quit]
close #1
end For maximum compatibility I should probably arrange that the "!setfocus" command also sends a WM_NEXTDLGCTL message. I will make a note of that for a future version of LBB.
Richard.
|
|
Logged
|
|
|
|
net2014
New Member
member is offline
Posts: 37
|
|
Re: Removing focus from a bitmap button.
« Reply #4 on: Dec 11th, 2013, 3:49pm » |
|
on Dec 11th, 2013, 1:50pm, Richard Russell wrote:Right, here is the explanation. Microsoft says you are not supposed to move focus between controls using SetFocus, but instead by sending the WM_NEXTDLGCTL message:
If you do that your program will work as expected in LBB:
For maximum compatibility I should probably arrange that the "!setfocus" command also sends a WM_NEXTDLGCTL message. I will make a note of that for a future version of LBB.
Richard. |
|
Thank you Richard, superb result, the fix works brilliantly and I've noted it for further use (which will be redundant if you incorporate it into a future LBB release.)
Wish you and Carl could make a team.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Removing focus from a bitmap button.
« Reply #5 on: Mar 15th, 2014, 4:30pm » |
|
on Dec 11th, 2013, 3:49pm, net2014 wrote:Thank you Richard, superb result, the fix works brilliantly and I've noted it for further use (which will be redundant if you incorporate it into a future LBB release.) |
|
Now incorporated in LBB v2.50 and later.
Richard.
|
|
Logged
|
|
|
|
|