Jump to content
Sign in to follow this  
trancexx

Vista style buttons on XP

Recommended Posts

trancexx

Vista style buttons are definitely more attractive than XP and below, and I kind of miss that on XP.

So, I was thinking, why not try to do something about that?

I was struggling mostly about the way how could that be done, was missing the idea. But, eventually it came to me.

The idea is to make image list and asign it to a button control (what's new? lol), every now and then replace some image from the image list with the new one and assign it again.

So simple, but would it work? Yes it probably would :)

It can all be done by means of classic AutoIt scripting but then there is a problem with the UDF format. In that case it would be very hard to make UDF that would support non-OnEvent mode. This is because main loop would have to have part that deals with image list and that's just overkill. OnEvent mode is more suitable for the job.

But pushing things in another thread is almost ideal solution for the task and is a winner for me. Since we can't access (execute in) another thread by default I used assembly generated on the fly to do the job.

I think that technique needs spreading because of the whole new exiting possibilities it offers. And what better way than giving examples. This is a new example of 'assembly' exploit.

Back to rendering...

GIF is used to carry the drawn frames. Out of frames icons are made. That icons are used to populate image list. Image list is then assigned to a button. You can use default GIF. It's in form of variable inside attached RenderLikeVista.au3.

If you would like to use custom GIF it should look like this:

- frames 1-27 is set of images that are rotated to make an animation

- frame 28 is used for 'no focus' state of button

- frame 29 is used for 'mouse hover'

- frame 30 is used for 'left click'

- frame 31 is used for 'button disabled' state

So you would need 31 frame GIF to fully customize the rendering.

Btw, I'm using gif in dimensions 1x21 - just for the record.

GDI+ is used too.

The whole script is heavily commented and I think it shouldn't be too hard to get the grip of it.

Animation will be done only if two main conditions are met. Written in AutoIt those are:

If GUICtrlSendMsg($hButton, $BM_GETSTATE, 0, 0)= 8 And BitAND(_GetWindowStyle(GUICtrlGetHandle($hButton)), $WM_SETFOCUS) Then
; Animate
EndIf

This means you can have as much buttons as you like and with no more imposition than it's needed for just one.

Three examples. Nothing much, just to show the rendering.

#include <GUIConstantsEx.au3>
#include "RenderLikeVista.au3"


Opt('MustDeclareVars', 1)


; Create GUI
GUICreate("Vista-like Buttons")


; Create first button:
Global $hButton_1 = GUICtrlCreateButton("Run Notepad", 40, 70, 120, 30)
; Rendering:
Global $aIconHandles
Global $tImageList1
_VistaLikeRenderButton($hButton_1, $tImageList1, $aIconHandles)


; Create second button:
Global $hButton_2 = GUICtrlCreateButton("Button Test", 220, 70, 120, 30)
; Rendering (will use the same $aIconHandles):
Global $tImageList2
_VistaLikeRenderButton($hButton_2, $tImageList2, $aIconHandles)


; Create third button:
Global $hButton_3 = GUICtrlCreateButton("Run Notepad", 40, 170, 120, 30)

; Create fourth button:
Global $hButton_4 = GUICtrlCreateButton("Button Test", 220, 170, 120, 30)


; Give focus to e.g. $hButton_1
GUICtrlSetState($hButton_1, $GUI_FOCUS)

; Show GUI
GUISetState()

; Handle events
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton_1, $hButton_3
            Run('Notepad.exe')
        Case $hButton_2, $hButton_4
            MsgBox(0, 'Testing', 'Button was pressed')
    EndSwitch

WEnd

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "RenderLikeVista.au3"

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

; Create GUI
Global $hGui = GUICreate("Vista-like Buttons", 510, 400, -1, -1, $WS_OVERLAPPEDWINDOW)


; Create button
Global $hButton1 = GUICtrlCreateButton("Button 1", 100, 100, 172, 40)
; Set font to it
GUICtrlSetFont(-1, 14, 700, 2)
; If clicked _DoSomething()
GUICtrlSetOnEvent(-1, "_DoSomething")
; Make it beautiful
Global $aIconHandles
Global $tImageList1
_VistaLikeRenderButton(-1, $tImageList1, $aIconHandles)


; Create another button
Global $hButton2 = GUICtrlCreateButton("Button 2", 100, 200, 110, 30)
; Set font
GUICtrlSetFont(-1, 12, 700)
; Vista like:
Global $tImageList2
_VistaLikeRenderButton(-1, $tImageList2, $aIconHandles)


; Create third button:
Global $hButton3 = GUICtrlCreateButton("Button 3", 100, 300, 70, 25)
; Again take care of appearance:
Global $tImageList3
_VistaLikeRenderButton(-1, $tImageList3, $aIconHandles)
; If that button is clicked then _UndoSomething()
GUICtrlSetOnEvent(-1, "_UndoSomething")

; Give focus to e.g. $hButton1
GUICtrlSetState($hButton1, $GUI_FOCUS)

; Deal with Exit
GUISetOnEvent(-3, "_Quit")

; Show GUI
GUISetState()


; Wait for the end
While 1

    Sleep(100)

WEnd



; FUNCTIONS:


Func _UndoSomething()

    GUICtrlSetState($hButton2, $GUI_ENABLE)
    MsgBox(0, "Title", "Button 2 enabled", 0, $hGui)

EndFunc;==>_UndoSomething


Func _DoSomething()

    GUICtrlSetState($hButton2, $GUI_DISABLE)
    MsgBox(0, "Title", "Button 2 disabled", 0, $hGui)

EndFunc;==>_DoSomething


Func _Quit()
    Exit
EndFunc;==>_Quit

#include <GUIConstantsEx.au3>
#include "RenderLikeVista.au3"

Opt('MustDeclareVars', 1)


; Create GUI
GUICreate("Vista-like Buttons")


Global $aIconHandles; handles here
Global $aImageList[14]; there will be 14 buttons

; Create buttons
For $i = 1 To 14
    If $i <= 7 Then
    GUICtrlCreateButton("Button Test " & $i, 40, 20 + 40*$i, 120, 30)
    _VistaLikeRenderButton(-1, $aImageList[$i-1], $aIconHandles)
Else
    GUICtrlCreateButton("Button Test " & $i, 220, 20 + 40*($i-7), 120, 30)
    _VistaLikeRenderButton(-1, $aImageList[$i-1], $aIconHandles)
    EndIf
Next

; Give focus to last one
GUICtrlSetState(-1, $GUI_FOCUS)

; Show GUI
GUISetState()

; Handle events
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

And the main script (yea I know, it's a stupid name):

Sorry, had to remove it. No more space in my attachments folder.

It's pretty much obvious that you don't use it on Vista+, but on systems prior that. Maybe to check what system the script is running on and act upon that.

It's not the same as Vista button, but still... it's a good start IMHO.

I had something else to said, but I forgot... if I remember I will edit or something like that.

edit:

Removed another script to make space in my attachments folder

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
WideBoyDixon

I'm not sure what I'm doing wrong. I definitely have gdiplus.dll installed. However, both your examples make no change to the button controls :-/

WBD

Share this post


Link to post
Share on other sites
trancexx

I'm not sure what I'm doing wrong. I definitely have gdiplus.dll installed. However, both your examples make no change to the button controls :-/

WBD

You almost can't do anything wrong. If something is wrong it's on me.

What system?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Valuater

It worked for me, just noticed on the second demo, "Button1" would fade from silver-gray to blue in the center, however the top and bottom edges stayed blue... then reversed... continually

I tested and retesting and that color changing ( kind neat actually ) continues

8)

Win Xp sp3 Autoit 3.3.0.0

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
Skrip

Didn't work for me. Windows Vista Home Premium SP2

Edited by Firestorm

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites
trancexx

I really don't know should I say "Excellent!" or "wtf!?!".

Now I'm starting to wonder is it really me?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
WideBoyDixon

You almost can't do anything wrong. If something is wrong it's on me.

What system?

I tried it at work also. No changes. Both are running XP SP2. The function returns zero (success?) but the buttons look the same.

WBD

Share this post


Link to post
Share on other sites
trancexx

I tried it at work also. No changes. Both are running XP SP2. The function returns zero (success?) but the buttons look the same.

WBD

Could you check @eror value after the function.

I've gone throuh* the code again and there is just one case of error that I didn't check and maybe an issue with freeing memory too soon. Both are very remote but possible.

Please check error and do what I tell you afterwards.

edit:

* through

edit2:

Ok, I did modifications regardless of your answer. New script is in the first post. I hope I got it now.

Could you run this script to see what's wrong (if it's wrong):

CODE
#include <GUIConstantsEx.au3>
#include "RenderLikeVista.au3"

Opt('MustDeclareVars', 1)


; Create GUI
GUICreate("Vista-like Buttons")


Global $aIconHandles; handles here
Global $aImageList[14]; there would be 14 buttons

; Create buttons
For $i = 1 To 14
    If $i <= 7 Then
    GUICtrlCreateButton("Button Test " & $i, 40, 20 + 40*$i, 120, 30)
    _VistaLikeRenderButton(-1, $aImageList[$i-1], $aIconHandles)
    ConsoleWrite("Button " & $i & ", error = " & @error & " @extended = " & @extended & @CRLF);<- for debug
Else
    GUICtrlCreateButton("Button Test " & $i, 220, 20 + 40*($i-7), 120, 30)
    _VistaLikeRenderButton(-1, $aImageList[$i-1], $aIconHandles)
    ConsoleWrite("Button " & $i & ", error: " & @error & " @extended: " & @extended & @CRLF);<- for debug
    EndIf
Next

; Give focus to last one
GUICtrlSetState(-1, $GUI_FOCUS)

; Show GUI
GUISetState()

; Handle events
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd
Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
trancexx

Screenshot?

Picture file containing an image of the on-screen display.

Rendering?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
dantay9

I tried both scripts on my computer (Windows XP SP3) and the buttons faded in and out with a blue tint. Great work trancexx!


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
trancexx

Yeah, thanks man.

I tested on, like, dozen of systems and didn't encounter any problems.

I'm really puzzled about why it fails (or was failing) with WideBoyDixon and on more than one system.

Anyway I hope It's foolproof now. Will see what he says.

I will explain the difference between scripts in a few lines when it's confirmed that it works.

Btw, Firestorm's remark is vainness. He's running it on Windows Vista Home Premium SP2 and says it didn't work. I mean, just think of it...


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
WideBoyDixon

It's working with the new example. I have no idea why it wasn't working before. As I said, the function was returning @error = 0.

WBD

Share this post


Link to post
Share on other sites
trancexx

Huh? I can't run it as I'm on Seven. I was asking if you had a screen shot.

And I was asking if it was working with you.

You can run it on Win7.

Firestorm was runing it on Vista. But buttons there are already 'Vista style'. If you don't see the difference between buttons in first row and second one in the first example that means that I did excellent job.

First two buttons are 'my buttons', other two are unmodified. If you look closer (obviously much) you will see the difference, that is intentional btw.

And you are asking me a screenshot.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
trancexx

It's working with the new example. I have no idea why it wasn't working before. As I said, the function was returning @error = 0.

WBD

No, you said "function returns zero". You didn't mention error vlue.

The problem is obviously too soon released memory with 'stream' job on binary.

Thanks for the feedbacks. Much appreciated. I'm gonna edit first post (If I manage - looks like Jon is breaking something with new modifications on the forum).


♡♡♡

.

eMyvnE

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.