I'm trying to draw a focus rectangle in a wxWindow
under WIN32 (only), but failed to do so.
The best approximation I got was
pen = wxPen(wxColour(0, 0, 0), 1, wxDOT)
dc.SetPen(pen)
dc.DrawRectangle(x, y, w, h)
but it looks awful under windows.
I also tried something like
pen = wxPen(wxColour(0, 0, 0), 1, wxUSER_DASH)
pen.SetDashes([0xAAAAAAAA, 0x55555555, 0, 0xFFFFFFFF])
dc.SetPen(pen)
dc.DrawRectangle(x-2, y, wt+4, wh)
but this never draws anything else than a solid line, independend
from the parameters I give to pen.SetDashes().
How is SetDashes() supposed to be used?
I would also be willing to draw the focus rectangle by a direct
call to the win32 api function DrawFocusRect() if there was a way
to retrieve the win32 HDC from a wxWindow (or a wxDC).
Is there any way to get this?
but this never draws anything else than a solid line, independend
from the parameters I give to pen.SetDashes().
How is SetDashes() supposed to be used?
I don't know, I've never gotten it to work well either. Although after
taking another look at it I think there may be a problem with the wrapper...
I would also be willing to draw the focus rectangle by a direct
call to the win32 api function DrawFocusRect() if there was a way
to retrieve the win32 HDC from a wxWindow (or a wxDC).
Is there any way to get this?
dc.GetHDC()
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
>
> I would also be willing to draw the focus rectangle by a direct
> call to the win32 api function DrawFocusRect() if there was a way
> to retrieve the win32 HDC from a wxWindow (or a wxDC).
> Is there any way to get this?
dc.GetHDC()
Great, it works. (But it's not documented at all, isn't it?)
One question remains: I get the size of the rectangle by a call to
dc.GetTextExtent(). Are the returned sizes in dialog units?
>
> dc.GetHDC()
>
Great, it works. (But it's not documented at all, isn't it?)
No. Although it is a public C++ method I don't think it was meant to be
part of the "public API." I just thought it might be useful to expose in
Python for situations like this.
One question remains: I get the size of the rectangle by a call to
dc.GetTextExtent(). Are the returned sizes in dialog units?
Pixels.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
> but this never draws anything else than a solid line, independend
> from the parameters I give to pen.SetDashes().
> How is SetDashes() supposed to be used?
I don't know, I've never gotten it to work well either. Although after
taking another look at it I think there may be a problem with the
wrapper...
I must have had another chunk of my brain get up and go for a walk. I
looked a little closer and I had already done the fix for the wrapper I
thought was needed. The values in the SetDashes list are used as described
in MSDN:
"""
The first value specifies the length of the first dash in a user-defined
style, the second value specifies the length of the first space, and so on.
"""
So something like this makes a good pen for a focus rectangle:
> >
> > dc.GetHDC()
> >
> Great, it works. (But it's not documented at all, isn't it?)
No. Although it is a public C++ method I don't think it was meant to be
part of the "public API." I just thought it might be useful to expose in
Python for situations like this.
So there are similar functions to get the window handle from
a wxWindow?
Yup, it seems GetHandle() does it.
I must have had another chunk of my brain get up and go for a walk. I
looked a little closer and I had already done the fix for the wrapper I
thought was needed. The values in the SetDashes list are used as described
in MSDN:
"""
The first value specifies the length of the first dash in a user-defined
style, the second value specifies the length of the first space, and so on.
"""
So something like this makes a good pen for a focus rectangle: