Jump to content

Choose Color or Picture Background


Recommended Posts

I am having a problem trying to get my script to switch from a Picture Background to a Color Background.

I am not sure if this is possible or my logic is just flawed.

This is what I've got so far:

; Choose Color or Picture Background.au3
#include <GUIConstants.au3>
#include <Misc.au3>
Dim $Menu_Window_Color, $Menu_Window_Picture
$Color_Flag = ""
$Picture_Flag = "Y"
$Window_Color = 0xffffff; White

_Create_Main_Window(); Create Main Window
_Create_Context_Menu(); Create Right-Click Menu
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $Menu_Window_Color Then
        $Color_Flag = "Y"
        $Picture_Flag = ""
        _Create_Main_Window(); Create Main Window
    EndIf
    If $msg = $Menu_Window_Picture Then
        $Picture_Flag = "Y"
        $Color_Flag = ""
        _Create_Main_Window(); Create Main Window
    EndIf
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Exit

Func _Create_Main_Window(); Create Main Window
$Main = GUICreate( "Choose Color or Picture Background", 400, 200, -1, -1, $WS_OVERLAPPEDWINDOW)

If $Color_Flag = "Y" Then
    GUISetBkColor( $Window_Color)
EndIf

If $Picture_Flag = "Y" Then
    GUICtrlCreatePic(@Systemdir & "\oobe\images\mslogo.jpg",0,0, 400, 200)
    GUICtrlSetState(-1, $GUI_DISABLE); Disable so Buttons Work with Background Picture
EndIf

GUICtrlCreateLabel( "Right-Click to see Menu.", 100, 50, 200, 18)
EndFunc; _Create_Main_Window

Func _Create_Context_Menu(); Create Right-Click Menu
    $Menu_Window = GUICtrlCreateContextMenu()
    $Menu_Window_Color = GUICtrlCreateMenuitem("Color", $Menu_Window)
    If $Color_Flag = "Y" Then GUICtrlSetState($Menu_Window_Color, $GUI_CHECKED)
    $Menu_Window_Picture = GUICtrlCreateMenuitem("Picture", $Menu_Window)
    If $Picture_Flag = "Y" Then GUICtrlSetState($Menu_Window_Picture, $GUI_CHECKED)
EndFunc; --> _Create_Context_Menu

As always, any help is greatly appreciated.

Thanks in advance.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to comment
Share on other sites

I thought it was a logic problem, and it was.

I changed a few lines around and it works.

I was just wondering if using the

GUISetState(@SW_HIDE, $Main)

is the best approach, or if any of this could be simplified.

taurus905

; Choose Color or Picture Background.au3
#include <GUIConstants.au3>
#include <Misc.au3>
Dim $Main, $Menu_Window_Color, $Menu_Window_Picture
$Color_Flag = ""
$Picture_Flag = "Y"
$Window_Color = 0xffffff; White

_Create_Main_Window() ; Create Main Window

While 1
    $msg = GUIGetMsg()
    If $msg = $Menu_Window_Color Then
        $Color_Flag = "Y"
        $Picture_Flag = ""
        _Create_Main_Window() ; Create Main Window
    EndIf
    If $msg = $Menu_Window_Picture Then
        $Picture_Flag = "Y"
        $Color_Flag = ""
        _Create_Main_Window() ; Create Main Window
    EndIf
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Exit

Func _Create_Main_Window() ; Create Main Window
    GUISetState(@SW_HIDE, $Main)
    $Main = GUICreate( "Choose Color or Picture Background", 400, 200, -1, -1, $WS_OVERLAPPEDWINDOW)

    If $Color_Flag = "Y" Then
        GUISetBkColor( $Window_Color)
    EndIf

    If $Picture_Flag = "Y" Then
        GUICtrlCreatePic(@Systemdir & "\oobe\images\mslogo.jpg",0,0, 400, 200)
        GUICtrlSetState(-1, $GUI_DISABLE) ; Disable so Buttons Work with Background Picture
    EndIf

    GUICtrlCreateLabel( "Right-Click to see Menu.", 100, 50, 200, 18)
    _Create_Context_Menu(); Create Right-Click Menu
    GUISetState()

EndFunc ; _Create_Main_Window

Func _Create_Context_Menu(); Create Right-Click Menu
    $Menu_Window = GUICtrlCreateContextMenu()
    $Menu_Window_Color = GUICtrlCreateMenuitem("Color", $Menu_Window)
    If $Color_Flag = "Y" Then GUICtrlSetState($Menu_Window_Color, $GUI_CHECKED)
    $Menu_Window_Picture = GUICtrlCreateMenuitem("Picture", $Menu_Window)
    If $Picture_Flag = "Y" Then GUICtrlSetState($Menu_Window_Picture, $GUI_CHECKED)
EndFunc; --> _Create_Context_Menu

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

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...