Sign in to follow this  
Followers 0

Gui buttons

19 posts in this topic

Posted · Report post

Ok im trying to create a button in a gui which looks like an icon !

Heres my code !

$Gui = GUICreate("Gui", 250, 500, -1, -1, $WS_POPUP)
$Background = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\Menu.bmp", 0, 0, 250, 500)
GUISetBkColor(000000)

$Button1 = GUICtrlCreateButton ( "", 75, 200 ,100 ,200 $BS_ICON) 
GUICtrlSetImage ( $Button1, C:\Icons\itunes.ico )
GUISetState()

Ive never used GUICtrlCreateButton can anyone tell me why the above wont work ?

Share this post


Link to post
Share on other sites



Posted · Report post

C:\Icons\itunes.ico needs to be in quotes

and you were missing a comma before $BS_ICON

(and you were missing an #include or declaration for $WS_POPUP)

#include <GuiConstants.au3>

$Gui = GUICreate("Gui", 250, 500, -1, -1, $WS_POPUP)
$Background = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\Menu.bmp", 0, 0, 250, 500)
GUISetBkColor(000000)

$Button1 = GUICtrlCreateButton ( "", 75, 200 ,100 ,200,  $BS_ICON)
GUICtrlSetImage ( $Button1, "C:\Icons\itunes.ico" )
GUISetState()

sleep(5000)

Share this post


Link to post
Share on other sites

Posted · Report post

and with double quotes around the filename?

GUICtrlSetImage ( $Button1, "C:\Icons\itunes.ico" )

Share this post


Link to post
Share on other sites

Posted · Report post

C:\Icons\itunes.ico needs to be in quotes

[Reply]CrapI hate when its something sosimple that I overlook[/Reply]

and you were missing a comma before $BS_ICON

[Reply]Damit !!![/Reply]

and you were missing an #include or declaration for $WS_POPUP

[Reply]Well that one I account for I only posted a smallsection of the code imworking on ! #include was in the original![/Reply]

Share this post


Link to post
Share on other sites

Posted · Report post

How come nothing happens when I click button 1 ?

#include <GuiConstants.au3>

$Gui = GUICreate("Gui", 250, 500, -1, -1, $WS_POPUP)
$Background = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\Menu.bmp", 0, 0, 250, 500)
GUISetBkColor(000000)

$Button1 = GUICtrlCreateButton ( "OK", 75, 125 ,100 ,50 ,$BS_ICON) 
GUICtrlSetImage ($Button1, "C:\Icons\itunes.ico" )
GUICtrlSetOnEvent($Button1, "OKPressed")
GUISetState()

Func OKPressed()
   MsgBox(4096,"", "Ok pressed")
EndFunc

While 1
   Sleep (10)
Wend

Share this post


Link to post
Share on other sites

Posted · Report post

Add Opt("GuiOnEventMode", 1) to your script ... :)

Share this post


Link to post
Share on other sites

Posted · Report post

How come nothing happens when I click button 1 ?

<{POST_SNAPBACK}>

You need include this line at startup.

Opt("GUIOnEventMode", 1)

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

Opss! (Double answer above). :">

From Helpfile:

GUIOnEventMode Enable/disable OnEvent functions notifications.

0 = (default) disable.

1 = enable.

Return previous mode.

@Devs: I believe that the helpfile would to have more info about this. :)

Edited by josbe

Share this post


Link to post
Share on other sites

Posted · Report post

Still not working 4 sum reason ! :)

#include <GUIConstants.au3>
Opt("GuiOnEventMode", 1) 

$GuiWidth = 250
$GuiHeight = 500
$xPos = (@DesktopWidth - 250) 
$yPos = (@DesktopHeight - $GuiHeight) / 2

;Main Gui
$Gui = GUICreate("Gui", 250, 500, $xPos, $yPos, $WS_POPUP)
$Background = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\Menu.bmp", 0, 0, 250, 500)
GUISetBkColor(000000)

$Button1 = GUICtrlCreateButton ( "OK", 75, 125 ,100 ,50 ,$BS_ICON) 
GUICtrlSetImage ($Button1, "C:\Dev-Cpp\Icons\Console.ico" )
GUICtrlSetOnEvent($Button1, "OKPressed")
GUISetState()

Func OKPressed()
   MsgBox(4096,"", "Ok pressed")
EndFunc

While 1
   Sleep(10)
WEnd

Share this post


Link to post
Share on other sites

Posted · Report post

Still not working 4 sum reason !  :)

Your code works fine for me... shows the msgbox when button is pressed.

Share this post


Link to post
Share on other sites

Posted · Report post

Still not working 4 sum reason !  :)

:) Are you sure?

Works fine here.

What about this code:

#include <GUIConstants.au3>
Opt("GuiOnEventMode", 1)

GUICreate("Gui", 150, 150)
GuiSetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$Button1 = GUICtrlCreateButton ( "OK", 50, 50)
GUICtrlSetOnEvent(-1, "OKPressed")

GUISetState()

While 1
  Sleep(10)
WEnd
Exit

Func OKPressed()
  MsgBox(4096,"", "Ok pressed")
EndFunc

Func SpecialEvents()
   If @GUI_CTRLID = $GUI_EVENT_CLOSE Then Exit
EndFunc

Share this post


Link to post
Share on other sites

Posted · Report post

It seems that the picture being displayed by GUICtrlCreatePic is stoping the button from working !

If the following line of code is removed it works !

$Background = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\Menu.bmp", 0, 0, 250, 500)

I need that line of code !!!!!

Why is it causing this error ?

Share this post


Link to post
Share on other sites

Posted · Report post

It seems that the picture being displayed by GUICtrlCreatePic is stoping the button from working !

If the following line of code is removed it works !

$Background = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\Menu.bmp", 0, 0, 250, 500)

But I need that line of code !!!!!

Why is it causing this error ? Is this a bug ?

Example

#include <GUIConstants.au3>
Opt("GuiOnEventMode", 1) 

$Gui = GUICreate("Gui", 250, 500, -1, -1, $WS_POPUP)

GUISetBkColor(000000)

$Button1 = GUICtrlCreateButton ( "OK", 75, 125 ,100 ,50 ) 
GUICtrlSetOnEvent($Button1, "OKPressed")
GUISetState()

While 1
 Sleep(10)
WEnd

Func OKPressed()
 MsgBox(4096,"", "Ok pressed")
EndFunc

Above works

#include <GUIConstants.au3>
Opt("GuiOnEventMode", 1) 

$Gui = GUICreate("Gui", 250, 500, -1, -1, $WS_POPUP)
$Background = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\Menu.bmp", 0, 0, 250, 500)
GUISetBkColor(000000)

$Button1 = GUICtrlCreateButton ( "OK", 75, 125 ,100 ,50 ) 
GUICtrlSetOnEvent($Button1, "OKPressed")
GUISetState()

While 1
 Sleep(10)
WEnd

Func OKPressed()
 MsgBox(4096,"", "Ok pressed")
EndFunc

Above dosent work

Share this post


Link to post
Share on other sites

Posted · Report post

This probably has to do with the fact that controls are overlapping and that the picture control is "hiding" the button control.....

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

Shouldnt this keep the button on top ?

$Button1 = GUICtrlCreateButton ( "OK", 75, 125 ,100 ,50 ,$WS_EX_TOPMOST) 
GUICtrlSetOnEvent($Button1, "OKPressed")
GUISetState()

GUICtrlSetState($Button1, $GUI_FOCUS)

Neither work to solve this little problem by the way :)

Any ideas ? :)

Edited by nova

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

Shouldnt this keep the button on top ?

$Button1 = GUICtrlCreateButton ( "OK", 75, 125 ,100 ,50 , $WS_EX_TOPMOST) 
GUICtrlSetOnEvent($Button1, "OKPressed")
GUISetState()

It dosent by the way  :)

Any ideas ?

<{POST_SNAPBACK}>

just been playing with this a bit and the button responds ok when you first create the button and then the picture. but the strange thing i see is that the button initially isn't shown, but when clicked the msgbox pops up and the button is shown......:) Edited by JdeB

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

$Background = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\Menu.bmp", 0, 0, 250, 500, $GUI_DISABLE)

I had to do stuff like that in AutoBuilder....

Edited by CyberSlug

Share this post


Link to post
Share on other sites

Posted · Report post

$Background = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\Menu.bmp", 0, 0, 250, 500,  $GUI_DISABLE)

I had to do stuff like that in AutoBuilder....

<{POST_SNAPBACK}>

ok. that works... :)

still the behaviour described is at least confusion........

Share this post


Link to post
Share on other sites

Posted · Report post

Tnx a million josbe, JdeB and CyberSlug its workin perfect now !

One last thing is there anyway of stopping a gui from showing up in the taskbar?

I have a one or two scripts which start multiple GUI's sometimes as many as 8 and I dont like the taskbar being flooded with gui window titles !

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  
Followers 0