Jump to content

Merge two scripts [Request]


Recommended Posts

I got the script running I want to get rid of the slider gui in click me but I kept it there just so you know what it does. The server is just to show how I want the tcp to be implemented. If you could do this for me I'd be very greatfull thanks you so much autoit community!!!

(I suggest winrar for opening this file)

autoitsub.rar

Link to comment
Share on other sites

I can't help you with your request because of multiple reasons.

It doesn't become clear what it is you want to accomplish. I presume you'd want to set the state of ClickMe.au3 over FTP, rather than with the slider, but that's mostly a guess.

There is no attempt to implement the functionality in your current code. This forum is meant to help out if you get stuck somewhere, not to write code for you.

The example code does not seem to work as intended with the provided slider. Get that working properly, before adding extra code.

The code is a mess.

I can hopefully help you with the last two issues and hopefully clear up some misunderstandings, or inefficiencies in your code.

I made major changes to your code to fix the most obvious issues. Things that stood out where:

*You don't need to create a seperate GUI for each graphics object

*You don't need a seperate function for each graphics object you're trying to set. One function can do different things if you supply it with different paramenters. (For a clear example, delete all but one of the SetBitMapxxx() functions and call that each time. The script will still function as it did before)

*When you open 14 images, you need to _GDIPlus_ImageDispose all 14, not just 1. (although if the script exits it will clean up after itsself)

*When you have lots of images that are nearly identical apart from an incremental transformation (rotation, scale, etc.) you can usually just take one and modify that in your script.)

*Same as above for the red background.

*You can probably do away with all but GS.png by drawing the images in your script. This might be something that people are willing to help you with. It makes your script smaller and more portable and it will be more easy for people to run it without having to download all the images, which will result in more help!

*Instead of using GUICtrlRead() so often, you could just save it's value to a variable at the start of WM_HSCROLL and use that variable. This will give a minor speed and readability boost.

I have very limited experience with GDI+ and not enough time to really look into it, so I trial-and-errored this and it's probably not great. (especially the rotation took some testing and it's not quite centered atm) If others can clean it up further that'd be cool.

ClickMe.au3:

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>

Opt("MustDeclareVars", 1)

Global Const $AC_SRC_ALPHA = 1
Global $hGUI_Slider, $iLabelPerc, $iSlider
Global $hGUI_Graphics
Global $hImageGS, $hImageRed1, $hImageRed2, $hImageRed3, $hImagePin

$hGUI_Graphics = GUICreate("Graphics", 1280, 720, -1, -1, -1, BitOR($WS_EX_LAYERED,$WS_EX_TOPMOST))
GUISetState(@SW_SHOW)

$hGUI_Slider = GUICreate("Control", 200, 39, 192, 114, -1, $WS_EX_TOPMOST)
$iSlider = GUICtrlCreateSlider(0, 0, 136, 37)
GUICtrlSetLimit($iSlider, 255, 0)
GUICtrlSetData($iSlider, 0)
GUICtrlCreateLabel("Slider:", 138, 0, 33, 17)
$iLabelPerc = GUICtrlCreateLabel("0%", 165, 16, 30, 17)
GUISetState(@SW_SHOW)

_GDIPlus_Startup()
$hImageGS = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\gs.png")
$hImageRed1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\first.png")
$hImageRed2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\second.png")
$hImageRed3 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\third.png")
$hImagePin = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\pins\pin1.png")

GUIRegisterMsg($WM_HSCROLL  , "WM_HSCROLL"  )

Do

Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_ImageDispose($hImageGS)
_GDIPlus_ImageDispose($hImagePin)
_GDIPlus_ImageDispose($hImageRed1)
_GDIPlus_ImageDispose($hImageRed2)
_GDIPlus_ImageDispose($hImageRed3)
_GDIPlus_Shutdown()

Func WM_HSCROLL($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
    _Update()
EndFunc

Func _Update()
    Local $iSliderValue = GUICtrlRead($iSlider)
    Local $iSliderPerc = $iSliderValue/2.55
    GUICtrlSetData($iLabelPerc,Round($iSliderPerc) & "%")
    Local $hBitmap
    Switch $iSliderPerc
        Case 0 To 49
            $hBitmap = $hImageRed1
        Case 50 To 79
            $hBitmap = $hImageRed2
        Case 80 To 100
            $hBitmap = $hImageRed3
    EndSwitch
    Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsDrawImage ($hGraphic, $hImageGS, 515, 250)
    Local $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($hMatrix,615,350)
    _GDIPlus_MatrixRotate($hMatrix, ($iSliderValue*.8)+170)
    _GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_GraphicsDrawImage ($hGraphic, $hImagePin, 0, 0)
    _GDIPlus_GraphicsDispose($hGraphic)
    SetBitMap($hGUI_Graphics, $hBitmap, $iSliderValue)
    _WinAPI_DeleteObject($hBitmap)

EndFunc

Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
  $hScrDC  = _WinAPI_GetDC(0)
  $hMemDC  = _WinAPI_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
  DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _WinAPI_ReleaseDC   (0, $hScrDC)
  _WinAPI_SelectObject($hMemDC, $hOld)
  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DeleteDC  ($hMemDC)
EndFunc

As you can see it's quite a bit smaller than your script and it only requires one modified pin image in addition to the red and GS images you had in your original example. (modified pin image added to this post)

If I where you I'd continue improving on this (try getting rid of the background and pin images all together and draw them instead) and when your happy, start adding FTP functionality, come back when you're stuck.

Take some time to understand how and why the changes work and ask if you have any questions. (although GDI related questions would probably have to be answered by someone else)

post-32980-0-29758600-1310119227_thumb.p

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