Page 1 of 1

ButtonGadget() border

Posted: Thu Feb 14, 2013 4:44 pm
by SFSxOI
Not really a coding question, but related.

Take a look at the below pic below showing the ButtonGadget() buttons created for this post:

Image

Notice the slight white border around the button and contrasting against the blue'ish background in the button at the top? This button was created with 'Enable XP Skin Support' enabled in the compiler options.

Now, take a look at the bottom pic. Notice there is no white border around the button and contrasting against the blue'ish background? This is the same button as the top button in the pic above only without 'Enable XP Skin Support' enabled in the compiler options.

Is there an easy way to get rid of the white border (around the top button in the pic) so the somewhat 'rounded corner' view of the button can be used? The white border detracts from the look of the button. (I assume 'XP Skin Support' is the only way to get the look of the 'rounded corners' natively in PureBasic.)

Is this really even theme support or simply adding and subtracting 'shadow' ? Notice also in the bottom button the font used on the button has slightly changed from the top button even though the font its self did not change.

if it matters any, this is with PB 5.10 Beta 8 in Windows 7.

Re: ButtonGadget() border

Posted: Thu Feb 14, 2013 5:19 pm
by Inf0Byt3
I have no idea if this is the right way to do it, but here's something that seems to work on XP:

Code: Select all

Global hBrush = CreateSolidBrush_(RGB(255,0,0))

Procedure Callback(hWnd, msg, wParam, lParam)
  Ret = #PB_ProcessPureBasicEvents
  Select Msg

    Case #WM_CTLCOLORBTN ;see http://msdn.microsoft.com/en-us/library/windows/desktop/bb761849%28v=vs.85%29.aspx
      If lParam = GadgetID(0)
        ProcedureReturn hBrush
      EndIf

  EndSelect
  ProcedureReturn Ret
EndProcedure

If OpenWindow(0, 0, 0, 220, 70, "Button gadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  SetWindowCallback(@Callback(), 0)
  
  SetWindowColor(0, RGB(255,0,0))
  
  ButtonGadget(0, 10, 10, 200, 20, "Transparent button")
  ButtonGadget(1, 10, 40, 200, 20, "Normal button")
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  
  DeleteObject_(hBrush)
  
EndIf

Re: ButtonGadget() border

Posted: Thu Feb 14, 2013 5:36 pm
by SFSxOI
Thanks InfoByte, that works here on Windows 7. Doesn't remove the white but colors it the same color as the window color which visually accomplishes the goal, and thats Ok in this case so it works for its use and makes the buttons look more attractive than the white border did. :)

Re: ButtonGadget() border

Posted: Thu Feb 14, 2013 5:48 pm
by Inf0Byt3
Great! Unless you will use gradient colors on the window, it will probably look ok. I think that Uxtheme.dll (activated when XP theme support is enabled) uses bitmaps to draw the states of the controls. These bitmaps seem to lack the alpha channel but they have a color used as a transparency mask which can be changed at will. Might be talking out of my hat though.

Re: ButtonGadget() border

Posted: Fri Sep 30, 2016 3:47 am
by VB6_to_PBx

Code: Select all

;-< Top >
;-
;-       Transparent_Button__v3.pb
;-
;-       Link : http://www.purebasic.fr/english/viewtopic.php?p=404516#p404516
;-       
;-< Start Program >------------------------------------------------------------
;-
;
Global hBrush = CreateSolidBrush_(RGB(255,0,0))
Global hBrushGreen = CreateSolidBrush_(RGB(0,255,0))


Procedure Callback(hWnd, msg, wParam, lParam)
    Ret = #PB_ProcessPureBasicEvents
    Select Msg
    Case #WM_CTLCOLORBTN
        Select lParam
        Case GadgetID(0), GadgetID(3)
              ProcedureReturn hBrush
        Case GadgetID(1)
              ProcedureReturn hBrushGreen
        EndSelect
    EndSelect

    ProcedureReturn Ret
EndProcedure

If OpenWindow(0, 0, 0, 220, 130, "Button gadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SetWindowCallback(@Callback(), 0)
    SetWindowColor(0, RGB(255,0,0))
 
    ButtonGadget(0, 10, 10, 200, 20, "Transparent Border button 0")
    ButtonGadget(1, 10, 40, 200, 20, "Normal button • Green Border 1")
    ButtonGadget(2, 10, 70, 200, 20, "Normal button • Normal Border 2")  ;<--- Normal Border = RGB(240,240,240)
    ButtonGadget(3, 10, 100, 200, 20, "Transparent Border button 3")

    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
 
    DeleteObject_(hBrush)
    DeleteObject_(hBrushGreen)
EndIf

;-
;-< End Program >--------------------------------------------------------------

Re: ButtonGadget() border

Posted: Fri May 05, 2017 5:05 am
by VB6_to_PBx

Code: Select all

;-< Top >
;-
;-       Colored_Text_ButtonGadget_without_Border_Edge__v2.pb
;-
;-       Link : http://www.purebasic.fr/english/viewtopic.php?p=404516#p404516
;-       Post Subject/Date : 
;-       Compiler : PB 5.31
;-      
;-< Start Program >------------------------------------------------------------
;
LoadFont (0, "Verdana", 8)

Procedure ColoredButtonGadget(GadgetNumber, X, Y, Width, Height, Text.S, TextColor = $000000)
    Protected ImageNr

    If GadgetNumber = #PB_Any 
         ProcedureReturn -1
    EndIf
         
    ImageNr = CreateImage(#PB_Any, Width, Height, 32, #PB_Image_Transparent)
         
    If ImageNr
         StartDrawing(ImageOutput(ImageNr))
         DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
         DrawingFont(FontID(0))
         DrawText((Width - TextWidth(Text)) / 2, (Height - TextHeight(Text)) / 2, Text, TextColor | $FF000000)
         StopDrawing()
         ButtonImageGadget(GadgetNumber, X, Y, Width, Height, ImageID(ImageNr))
    EndIf

    ProcedureReturn ImageNr
EndProcedure


Global hBrush = CreateSolidBrush_(RGB(200,200,200))

Procedure Callback(hWnd, msg, wParam, lParam)
    Ret = #PB_ProcessPureBasicEvents
    Select Msg
    Case #WM_CTLCOLORBTN     ;~~~~~ see http://msdn.microsoft.com/en-us/library/windows/desktop/bb761849%28v=vs.85%29.aspx
         Select lParam
         Case GadgetID(1),GadgetID(2):ProcedureReturn hBrush
         EndSelect
    EndSelect

    ProcedureReturn Ret
EndProcedure


If OpenWindow(0, 0, 0, 220, 70, "Button gadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SetWindowColor(0, RGB(200,200,200))

    SetWindowCallback(@Callback(), 0)

    ButtonGadget(1, 10, 10, 200, 20, "Text Color Button 1")
    ColoredButtonGadget(1, 10, 10, 200, 20, "Text Color Button 1", RGB(0,0,140))

    ButtonGadget(2, 10, 40, 200, 20, "Text Color Button 2")
    ColoredButtonGadget(2, 10, 40, 200, 20, "Text Color Button 2", RGB(0,140,0))

    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

;-
;-< End Program >--------------------------------------------------------------