Changing border type on string and text gadgets
Changing border type on string and text gadgets
I need to draw text in rectangles and expected that one or both of the string or text gadgets would do the job. Alas, no -- they provide 3D borders only!
Can an API (Windows) call change the border type of these gadgets and, if so, would anyone care to volunteer a code snippet?
I don't think it can, at least I've never come across it before.
If you have to 'roll your own' then it shouldn't be too hard. One way would be to place a borderless text gadget within some kind of container, e.g. an image gadget, and then draw your own border within the container etc. There's all sorts of possibilities.
If you have to 'roll your own' then it shouldn't be too hard. One way would be to place a borderless text gadget within some kind of container, e.g. an image gadget, and then draw your own border within the container etc. There's all sorts of possibilities.
I may look like a mule, but I'm not a complete ass.
Code: Select all
If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
TextGadget(1, 10, 100, 250, 20, "TextGadget Border")
SetWindowLong_(GadgetID(1), #GWL_STYLE, GetWindowLong_(GadgetID(1), #GWL_STYLE) |#WS_BORDER)
SetWindowPos_(GadgetID(1), 0, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
I may look like a mule, but I'm not a complete ass.
And for the StringGadget...
Code: Select all
If OpenWindow(0, 0, 0, 270, 160, "StringGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
StringGadget(2, 10, 130, 250, 20, "StringGadget Flat Border")
SetWindowLong_(GadgetID(2), #GWL_EXSTYLE, GetWindowLong_(GadgetID(2), #GWL_EXSTYLE) &(~#WS_EX_CLIENTEDGE))
SetWindowLong_(GadgetID(2), #GWL_STYLE, GetWindowLong_(GadgetID(2), #GWL_STYLE) | #WS_BORDER)
SetWindowPos_(GadgetID(2), 0, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
Excellent! My thanks to srod and Sparkie for the code snippets.
Now let us extend the problem a little.
Given, say, a square TextGadget (or StringGadget, Sparkie
) of an arbitrary size, we need to centre the text both horizontally and vertically. The horizontal positioning is a piece of cake: simply specify the #PB_Text_Center flag. Vertically we need to set the text's "leading" value, which requires a bit of arithmetic on the size of the square and text/font attributes, and then make another API call.
Any of you experts care to provide a code snippet for that one?
Given, say, a square TextGadget (or StringGadget, Sparkie
Any of you experts care to provide a code snippet for that one?
You can also try this :
Dri
Code: Select all
If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
TextGadget(1, 10, 100, 250, 20, "TextGadget Border", #WS_BORDER)
StringGadget(2, 10, 130, 250, 20, "StringGadget Flat Border", #WS_EX_STATICEDGE | #WS_BORDER)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIfRight, we can drop the API call by using its flag directly in the gadget. Nice one, Dr. Dri! So why isn't this documented (in the PB gadget documentation), Fred?Dr. Dri wrote:You can also try this :DriCode: Select all
If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) TextGadget(1, 10, 100, 250, 20, "TextGadget Border", #WS_BORDER) StringGadget(2, 10, 130, 250, 20, "StringGadget Flat Border", #WS_EX_STATICEDGE | #WS_BORDER) Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow EndIf
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Flags like this are Windows Only, and the PureBasic language is designed to be cross-platform. As a rule, you won't find any OS-specific flags or commands documented or really supported but many will nonetheless work. For example, this note can be found in the MessageRequester doc:So why isn't this documented (in the PB gadget documentation), Fred?
Note: In PureBasic you can also use many more constants of the WindowsAPI. But be aware, that these constants are not cross-platform compatible! An overview you will find in the MSDN Library at the function MessageBox.
BERESHEIT
That's not the same problem, srod. An EditGadget gives me arbitrary multiple lines, not an arbitrary height,. Anyway, I don't think it can be done because -- as I understand it -- it requires access to the font metrics, just like you have in 2D drawing. No, I think we've got just about all we can out of the PB text/string gadgets, they simply aren't designed to be manipulated beyond their basic functionality.
That's a fair enough retort (and rebuke), netmaestro, point taken!netmaestro wrote:Flags like this are Windows Only, and the PureBasic language is designed to be cross-platform. As a rule, you won't find any OS-specific flags or commands documented or really supported but many will nonetheless work. For example, this note can be found in the MessageRequester doc:So why isn't this documented (in the PB gadget documentation), Fred?Note: In PureBasic you can also use many more constants of the WindowsAPI. But be aware, that these constants are not cross-platform compatible! An overview you will find in the MSDN Library at the function MessageBox.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada


