[AUTOIT] Change Pic control image of external Autoit-GUI

01/25/2016 17:44 fuso98#1
Hi guys, I've a problem and maybe some one that know more than me can help me to solve it.

I've 1 gui made in autoit, It simply act in background in a game window. Cause it is fully in background I want to add preview of the window where I do actions. So I decided to make 2 autoit scripts.
The script A perform actions in the game.
The script B should get the preview of the game and edit the Pic control image (GuiCtrlCreatePic) in the script A GUI.

In the script B i've this code:

Code:
Local $hWnd = ControlGetHandle("Script A GUI","","[CLASS:Static; INSTANCE:10]")
_GDIPlus_Startup()
$himage = _GDIPlus_ImageLoadFromFile("test.bmp")
$HBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($himage)
_SendMessage($hWnd,$STM_SETIMAGE,$IMAGE_BITMAP,$HBITMAP)
Exit
But it simply don't work. At the start the pic control has a black image. After the execution of script B the control Pic seems to be empty, so I'm sure that something happened but I can't figure out to make it working :(

Thanks in advance
01/25/2016 18:12 alpines#2
Maybe _ImageLoadFromFile doesn't load the picture properly as a bitmap. Try using _GDIPlus_BitmapCreateFromFile instead.
01/25/2016 18:43 fuso98#3
I've used it too but it don't work :(
01/25/2016 22:44 Shadow992#4
I guess the problem is the memory you use.
I do not know anything exact about how to set an image but as I guess the process A cannot acces the memory allocated by process B. This may be because of the fact that SendMessage just does not support this, it could also be something AutoIt specific or just a natural thing.

I am also not sure if AutoIt handles these "bitmap-handles" correctly. As I guess (because my language follows an similar approach), whenever you pass a variable to an AutoIt-Function it only passes an object which may be called "AutoItVariable" to the function.
This "AutoItVariable" may have an attribute called "value" where the real pointer to the bitmap lies.
So theoretically it may be possible that AutoIt not copies the pointer of the bitmap but the pointer of the variableand sends this pointer of variable to the other process.

As stated earlier, these are just a few theories you could examine. I did not test it nor did I ever try something similar. So my theories may be completely wrong, just test them one by one. :D
01/25/2016 23:04 fuso98#5
I tried with GDI+ but obviusly I can use every working method. Do you have other suggestions?
01/26/2016 07:29 Moneypulation#6
If you haven't got any other options, you can do both actions in one script. Eventhough you can't use multithreading in AutoIt, there is a way to do both, botting and updating the preview "simultaneously". I figured when my bot was still written in AutoIt that you can replace the Sleep() function, which you probably use often, with an adapted version of it where you update the preview in a loop until the time you set through the parameter runs off. Of course this isn't the best way to fix your problem but it worked for me
01/26/2016 14:39 fuso98#7
Yeah but in this way, It will not update during the search loop just because there aren't sleeps in it, or at least there aren't sleep with much time as it's needed to update the preview.
01/26/2016 19:47 YatoDev#8
Quote:
Originally Posted by fuso98 View Post
much time as it's needed to update the preview.
you do not have 10ms?
01/27/2016 22:02 fuso98#9
Taking a screenshot don't take me 10ms.
01/28/2016 03:13 YatoDev#10
why not simply draw it from another process onto your window?
01/28/2016 07:27 FacePalmMan#11
What about running your second script as a child process? Works for sharing TCP Handles (example: My powerful webserver).
01/28/2016 20:13 fuso98#12
Quote:
Originally Posted by »FlutterShy™ View Post
why not simply draw it from another process onto your window?
I'm trying to do this. I want to do this, but the code that I posted in the first post don't work :(

Quote:
Originally Posted by FacePalmMan View Post
What about running your second script as a child process? Works for sharing TCP Handles (example: My powerful webserver).
How to create a child process?
01/31/2016 12:46 FacePalmMan#13
Code:
$PID = Run("Childprogram " & $TheHandleToTheGraphics, "", Default, 3)
(if graphics handle is created later, then you can do StdInWrite($PID, $TheHandleToTheGraphics))
Then you only need to copy the handle using some commands.
I am not sure what commands are needed, but it should be something like _GDIPlus_DuplicateHandle
01/31/2016 12:59 YatoDev#14
Just draw the pic onto the gui with gdi plus
01/31/2016 13:08 FacePalmMan#15
_GDIPlus_GraphicsCreateFromHWND()
_GDIPlus_ImageLoadFromFile()
_GDIPlus_GraphicsDrawImage()
^ there you have it.