Jump to content
Sign in to follow this  
jebus495

GUICtrlCreatePic

Recommended Posts

jebus495

First problem is that the code is a bit sloppy lol.

This is an extremely simple game I have made to teach people how to use AutoIt. I see a lot of people coming here asking about how to write bots and all kinds of junk like that. Since 95% of those people will never read through the entire help file to sift out the information that is useful for there needs I plan on creating a few simple games that replicate common tasks AutoIt needs to perform in some games. I will give methods for accomplishing certain tasks with increasing complexity.

The game I have made is humanly impossible as far as I know. This I will use to teach people how to combine MouseMove and PixelSearch in an effective manner.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=cheese.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Timers.au3>

Global $count = 0
Global $time = 0
Global $theactualtime = 0
Global $thebait, $thecount, $Timer, $Label2, $tryagain, $Quit


$thegame = GUICreate("The Game", 250, 350, 200, 100)
GUISetCursor(3)
GUISetFont(12, 800, 2, "Arial")
GUISetBkColor(0x000000)
$startbutt = GUICtrlCreateButton("Start Playing", 75, 250, 100, 30, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "Centaur")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0000FF)
$Label1 = GUICtrlCreateLabel("Hello! Welcome to ""The Game""." & @CRLF & "This is a very difficult game." & @CRLF & "You have 10 seconds to move" & @CRLF & "your mouse cursor over the white" & @CRLF & "block 100 times! Good Luck!", 25, 50, 225, 200)
GUICtrlSetFont(-1, 12, 800, 0, "Modern")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $startbutt
            GUICtrlDelete($startbutt)
            GUICtrlDelete($Label1)
            start()
    EndSwitch
WEnd

Func start()
$thebait = GUICtrlCreateLabel("", 118, 160, 15, 15)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetCursor(-1, 7)
$thecount = GUICtrlCreateProgress(24, 316, 198, 16, $PBS_SMOOTH)
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
$Timer = GUICtrlCreateProgress(24, 284, 198, 16, $PBS_SMOOTH)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)
guiloop()
EndFunc

Func guiloop()
While 1
$naynay = MouseGetCursor()

$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $naynay = 7
            $theactualtime = _Timer_Init()
            AdlibEnable("timemove", 100)
            Do
            $naynay = MouseGetCursor()
            $nMsg = GUIGetMsg()

                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit
                EndSwitch

                    If $naynay = 7 Then
                        GUICtrlSetPos($thebait, 118 + Random(-100, 100), 160 + Random(-80, 80))
                        $count += 1
                        GUICtrlSetData($thecount, $count)
                    EndIf

            Until $count > 99 Or _Timer_Diff($theactualtime) > 10000

            AdlibDisable()
            Select
                Case _Timer_Diff($theactualtime) > 10000
                    GUICtrlDelete($thecount)
                    GUICtrlDelete($Timer)
                    GUICtrlDelete($thebait)
                    $count = 0
                    $theactualtime = 0
                    Onfail()

                Case $count > 99
                    GUICtrlDelete($thecount)
                    GUICtrlDelete($Timer)
                    GUICtrlDelete($thebait)
                    $count = 0
                    $theactualtime = 0
                    Onwin()
            EndSelect
    EndSwitch
WEnd
EndFunc

Func timemove()
    GUICtrlSetData($Timer, _Timer_Diff($theactualtime) / 100)
EndFunc

Func Onfail()
$Label2 = GUICtrlCreateLabel("You have failed! You're neither" & @CRLF & "asian or cheating which is a" & @CRLF & "recipe for failure", 25, 20, 225, 60)
GUICtrlSetFont(-1, 12, 800, 0, "Modern")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Home\Desktop\lose.jpg", 25, 100, 200, 160, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$tryagain = GUICtrlCreateButton("Try Again", 15, 300, 100, 25, $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "Centaur")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0000FF)
$Quit = GUICtrlCreateButton("Quit", 135, 300, 100, 25, $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "Centaur")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0000FF)

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Quit
            Exit

        Case $tryagain
            GUICtrlDelete($Label2)
            GUICtrlDelete($tryagain)
            GUICtrlDelete($Quit)
            GUICtrlDelete($Pic1)
            start()
    EndSwitch
WEnd
EndFunc

Func Onwin()
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Home\Desktop\win.jpg", 25, 25, 200, 206, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$playagain = GUICtrlCreateButton("Play Again", 15, 300, 100, 25, $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "Centaur")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0000FF)
$Quit2 = GUICtrlCreateButton("Quit", 135, 300, 100, 25, $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "Centaur")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0000FF)

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Quit2
            Exit

        Case $playagain
            GUICtrlDelete($Pic1)
            GUICtrlDelete($playagain)
            GUICtrlDelete($Quit2)
            start()
    EndSwitch
WEnd
EndFunc

My problem is actually quite simple. I could just .zip the two images and the program and use @scriptdir but I want the images to be "self contained" in the .exe.

I guess I can use directives to store the image? How do I use it once it's stored?

I hope to post this up in example scripts when I'm done. While I'm here can anyone think of any common questions people ask about basic game botting?

Share this post


Link to post
Share on other sites
Melba23

jebus495,

A couple of possibilities to get images into a compiled .exe:

1. FileInstall. This places a copy of a file in your .exe which you can load onto the user's machine and then use from within your script. Read the Help file carefully and search for the many forum threads.

2. Zedna's excellent Resources UDF (which you can find here). This is more complicated to use, but allows you to use files stored in your .exe without having to copy them onto the user's machine. It requires more effort from the coder to get everything into the .exe, but does have the advantage of not having to load files onto a new machine - everything is self-contained. If you want to use this you MUST read the Resources thread carefully and try out the examples - the UDF is not difficult to use, but if you do not take the trouble to learn how to use it properly, you will have problems.

I would recommend trying FileInstall first - if you can get what you want that way it is far simpler.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
jebus495

Thank you very much. I was not aware that fileinstall did that!

I was reading through that thread earlier for another reason lol.

Edit: Did you try the game? ;) Images not required :)

Edited by jebus495

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  

×