Jump to content

GuiCtrlCreateButton with BS_FLAT set shows ugly 3D button on Windows XP


AcidUser
 Share

Recommended Posts

Hello All!

I wanted to create simple looking two-dimensional Gui.

On Windows 7 it looks awesome and the button is looking like expected based on Autoit Manual using "$BS_FLAT" style.

However, running the same code on Windows XP (Classic Theme) shows that Gui Window is two dimensional, but a Button is with ugly border.

I found a thread describing the same problem here:

So I added this string: DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)

to my project, but result is the same.

Is there anything I can do to make button look like it is expected with "$BS_FLAT" style on Windows XP?

I tried messing with GuiCtrlCreateLabel, but it is not usable, since if you enable black square, the text of lable will become not visible.

Looking forward for advice from experienced AutoIt users.

Thanks in advance.

Here is a code:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
#include <date.au3>

Opt("GUIOnEventMode", 1)
Global $afksleep, $lasth, $lastm, $lasts
Global $begin = 1000 * 60 * 60 * 2 ; 2 Hours
$afksleep = $begin
Global $start = TimerInit()
Global $WINDOW_WIDTH = @DesktopWidth/5
Global $WINDOW_HEIGHT = @DesktopHeight/8
Global $WINDOW_STYLE = $WS_POPUP
Global $WINDOW_EX_STYLE = $WS_EX_TOPMOST
Global $WINDOW_BG_COLOR = 0xADD8E6
Global $WINDOW_TITLE_ID
Global $WINDOW_TITLE_WIDTH  = $WINDOW_WIDTH-10
Global $WINDOW_TITLE_HEIGHT = $WINDOW_HEIGHT/6
Global $WINDOW_TITLE_STYLE  = $SS_LEFT
Global $WINDOW_TITLE_BG_COLOR = 0xADD8E6
Global $WINDOW_TITLE_TXT_COLOR = 0x000000
Global $WINDOW_TITLE_TXT = "  Adobe Reader 10.1.1 installation:"
Global $CANCEL_BUTTON_ID
Global $CANCEL_BUTTON_TITLE  = "Cancel"
Global $CANCEL_BUTTON_WIDTH  = $WINDOW_WIDTH/3
Global $CANCEL_BUTTON_HEIGHT = -1
Global $CANCEL_BUTTON_LEFT   = ($WINDOW_WIDTH-$CANCEL_BUTTON_WIDTH)/2
Global $CANCEL_BUTTON_TOP    = $WINDOW_HEIGHT-($WINDOW_HEIGHT/4)
Global $CANCEL_BUTTON_STYLE  = BitOR($BS_CENTER,$BS_VCENTER,$BS_FLAT,$GUI_ONTOP)
$CANCEL_BUTTON_COLOR = 0xADD8E6
Global $FAKE_BUTTON_ID
Global $FAKE_BUTTON_STYLE = BitOR($BS_FLAT,$GUI_FOCUS)
Global $PROCESS_1 = "iexplore.exe"
Global $PROCESS_1_APP = "Internet Explorer"
Global $PROCESS_2 = "Firefox.exe"
Global $PROCESS_1_APP = "Firefox"
Global $PROCESS_3 = "Adrd32.exe"
Global $PROCESS_1_APP = "Adobe Reader"
Global $CD_TIMER_ID
Global $CD_TIMER_LEFT = 5
Global $CD_TIMER_TOP = $WINDOW_TITLE_WIDTH
Global $CD_TIMER_WIDTH = $WINDOW_WIDTH-(2*$CD_TIMER_LEFT)
Global $CD_TIMER_HEIGHT = -1
Global $CD_TIMER_STYLE = $SS_CENTERIMAGE
$Form1 = GUICreate("", $WINDOW_WIDTH, $WINDOW_HEIGHT, -1, -1, $WINDOW_STYLE, $WINDOW_EX_STYLE)
;$size = WinGetClientSize($Form1)
;$iTitle_Height = 20
$WINDOW_TITLE_ID = GUICtrlCreateLabel($WINDOW_TITLE_TXT, 5, 5, $WINDOW_TITLE_WIDTH, 30, $WINDOW_TITLE_STYLE) ;
GUICtrlSetResizing($WINDOW_TITLE_ID,$GUI_DOCKALL)
MsgBox(64,"",$WINDOW_TITLE_HEIGHT)
;$WINDOW_TITLE_SIZES = WinGetPos(GuiCtrlGetHandle($WINDOW_TITLE_ID))
;GUICtrlSetPos($WINDOW_TITLE_ID, 0, 0, $WINDOW_TITLE_WIDTH, $WINDOW_TITLE_SIZES[3]+5)
; $WINDOW_TITLE_ID = GUICtrlCreateLabel($WINDOW_TITLE_TXT, 0, 0, -1, -1, $WINDOW_TITLE_STYLE) ;
 
GUICtrlSetBkColor($WINDOW_TITLE_ID, $WINDOW_TITLE_BG_COLOR)
GUICtrlSetColor($WINDOW_TITLE_ID, $WINDOW_TITLE_TXT_COLOR)
GUICtrlSetFont($WINDOW_TITLE_ID, Default, 600)
;$CD_TIMER_ID = GUICtrlCreateLabel("", $CD_TIMER_LEFT, $CD_TIMER_TOP, $CD_TIMER_WIDTH , $CD_TIMER_HEIGHT, $CD_TIMER_STYLE)
;GUICtrlSetFont($CD_TIMER_ID, Default, 600)
;GUICtrlSetBkColor($CD_TIMER_LABLE,0xCD3700)
$CANCEL_BUTTON_ID = GUICtrlCreateButton($CANCEL_BUTTON_TITLE, $CANCEL_BUTTON_LEFT, $CANCEL_BUTTON_TOP, $CANCEL_BUTTON_WIDTH, $CANCEL_BUTTON_HEIGHT, $CANCEL_BUTTON_STYLE)
$FAKE_BUTTON_ID = GUICtrlCreateButton("", 1, 1,1, 1,$FAKE_BUTTON_STYLE)
;GUICtrlCreateLabel("",5,25,$size[0],2,$SS_SUNKEN)
;GUICtrlCreateGraphic(5,25,390,2,$SS_SUNKEN)

GUICtrlSetState($CANCEL_BUTTON_ID,$GUI_NOFOCUS)
GUICtrlSetState($FAKE_BUTTON_ID,$GUI_FOCUS)
GUICtrlSetState($FAKE_BUTTON_ID,@SW_HIDE)
GUICtrlSetBkColor($CANCEL_BUTTON_ID, $CANCEL_BUTTON_COLOR)
GUISetBkColor($WINDOW_BG_COLOR)
GUICtrlSetResizing($CANCEL_BUTTON_ID,$GUI_DOCKALL)
GUICtrlSetResizing($FAKE_BUTTON_ID,$GUI_DOCKALL)
GUICtrlSetResizing($CD_TIMER_ID,$GUI_DOCKALL)
GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND")
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0) ;Don't Use WinXP Theme
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($CANCEL_BUTTON_ID, "CancelButtonPressed")
While ($afksleep > 0) AND (ProcessExists("iexplore.exe") OR ProcessExists("Firefox.exe"))
   $afksleep = $begin - TimerDiff($start)
   GoToBathroom()
   Sleep(1000)
  
WEnd
CheckProcess()

Func CancelButtonPressed()
CheckProcess()
EndFunc
Func CheckProcess()
If Not (ProcessExists("iexplore.exe") OR ProcessExists("Firefox.exe")) Then
  Exit(0)
Else
  Exit(1)
EndIf
EndFunc
Func On_WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    If BitAND($wParam, 0xFFF0) = $SC_MOVE Then Return False
    Return $GUI_RUNDEFMSG
EndFunc
Func GoToBathroom()
    Local $iHours, $iMins, $iSecs, $CD_TIMER
    _TicksToTime($afksleep, $iHours, $iMins, $iSecs)
    If $lasth <> $iHours Or $lastm <> $iMins Or $lasts <> $iSecs Then
 
  $CD_TIMER = "Estimated wait time: " & $iHours & ":" & StringFormat("%02d",$iMins) & ":" & StringFormat("%02d",$iSecs)
 
  GUICtrlSetData($CD_TIMER_ID,$CD_TIMER)
        ;ToolTip("Please close all open Internet Browsers (IE, FireFox) and Adobe Reader" & @CR & "Estimated wait time: " & $iHours & ":" & StringFormat("%02d",$iMins) & ":" & StringFormat("%02d",$iSecs), @DesktopWidth/2, @DesktopHeight/2, "Adobe Reader X Installation:", 2, 6)
 
  $lasth = $iHours
        $lastm = $iMins
        $lasts = $iSecs
    EndIf
EndFunc  ;==>GoToBathroom
Link to comment
Share on other sites

  • Moderators

AcidUser,

Please do not bump your own posts within 24 hours. :D

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 6 months later...

I am also interested in getting this to work in XP. Are there any updates to getting this to display correctly??

At last, after two thousand years of research, the illudium Q-36 explosive space modulator.Well, back to the old drawing board.

Link to comment
Share on other sites

See this example:

#include <guiconstantsex.au3>
#include <windowsconstants.au3>
#include <buttonconstants.au3>

_Example()

; example
Func _Example()
    Local $iMsg, $iButton1

    GUICreate("My GUI", 320, 240) ; will create a dialog box that when displayed is centered
    $iButton1 = GUICtrlCreateButton("Start", 105, 100, 100, -1, $BS_FLAT)

    ; Disable Win Theme in button...
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($iButton1), "wstr", 0, "wstr", 0)

    GUISetState(@SW_SHOW) ; will display an empty dialog box

    ; Run the GUI until the dialog is closed
    While 1
        $iMsg = GUIGetMsg()

        If $iMsg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    GUIDelete()
EndFunc   ;==>_Example

Regards,

João Carlos.

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...