Jump to content
Sign in to follow this  
danielmohr91

Displaying multiple images on-screen simultaneously??

Recommended Posts

danielmohr91

I'm looking for a way to display a bunch of images (actually the same one multiple times) on screen. It's a little 8x8 gif. SplashImageOn() is limited to only one at a time. Anyone know of a UDF for images that I missed, or perhaps another way around this?

Something kind-of like this, only we're looking at about 25-50 of them in a grid.

for $i=0 to 20 
$x +=10
$y += 10
SplashImageOn() ; splash image here @ $x,$y
next

Share this post


Link to post
Share on other sites
Pain

Create a GUI without any menus etc. with the size you want and use GUICtrlCreatePic.

Share this post


Link to post
Share on other sites
danielmohr91

Wow! I must say, I'm impressed. I never thought of that. It took me a while to figure out how to make it work with the transparent gif OFF the GUI, but I finally got it. Unfortunately it locks up my computer and goes REALLY slow when I open up dozens of GUI's like that. Here's how it is right now, I'm calculating the grid with the for... loop, and using the coordinates to make the GUI. I make two, a parent, and a child. That's how they did it in the help file. Scroll down to my comment to skip right to where I make the images

Func _preview($x, $y, $xx, $yy, $size, $column, $row)
    Local Const $num_icons = 10
    Local Const $w = 8
    Local Const $h = 8
    Local $x_pos = $xx
    Local $y_pos = $yy
    Local $direction = 1
    Local $GUI_ICON[$num_icons]
    Local $GUI_ICON_Parent[$num_icons]


    For $i = 1 To $x
        For $j = 1 To $y
            $GUI_ICON_Parent[$i] = GUICreate("", 100, 50, -500, -500, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))




; HERE'S WHERE I'M MAKING IT:

            $GUI_ICON[$i] = GUICreate("", $w, $h, $x_pos, $y_pos, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD, $WS_EX_TOPMOST), $GUI)
            GUICtrlCreatePic($ICON_PREVIEW, 0, 0, 0, 0)
            GUISetState(@SW_SHOW, $GUI_ICON_Parent[$i])
            GUISetState(@SW_SHOW, $GUI_ICON[$i])





            ;$x_pos and $y_pos
            $x_pos += $column * $direction
            $y_pos -= -$row * $direction
            If $stop = True Then Return
        Next
        $x_pos -= $column * $direction ; Undo the very last move
        $y_pos += -$row * $direction ; Undo the very last move
        $x_pos += $column; * $size
        $y_pos -= $row; * $size
        If $direction = 1 Then
            Local $direction = -1
        Else
            Local $direction = 1
        EndIf
        If $stop = True Then Return
    Next
EndFunc   ;==>_preview
It's unusably slow. I'm thinking perhaps calling a DLL function to draw dots instead? I've never used a DLL before, but I've seen drawings done onscreen before with gdi32.dll. Something like this

$hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    $pen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0, "int", $LineWidth, "int", $LineColor)
    DllCall("gdi32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0])
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int", $Mpos_1, "int", $Mpos_2, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $Mpos_1A, "int", $Mpos_2A)
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0])
I saw it on the forums, but not realy sure how to change it into single dots. I looked for documentation on the DLL files and couldn't find out what all the parameters were for it. Do you have any suggestions where to look? Edited by danielmohr91

Share this post


Link to post
Share on other sites
Pain

I haven't tested your code, but why creating GUI's in the loop? I were more thinking about a single GUI and create the GUICtrlCreatePic's in the loop instead.

Share this post


Link to post
Share on other sites
danielmohr91

Ah, I see what you mean. I assumed we needed an individual GUI for each picture. I completely scrapped what I had and started from scratch - here's what I got so far:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$image = @ScriptDir & "\icon.gif"
$gui = GUICreate("test transparentpic", 200, 100)
$pic = GUICreate("", 68, 71, 10, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gui)
$max = 10
$w = 0
$h = 0
local $image[$max]

GUISetState(@SW_SHOW, $pic)
GUISetState(@SW_SHOW, $gui)

For $i = 0 To $max -1
;~  MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$i' & @lf & @lf & 'Return:' & @lf & $i) ;### Debug MSGBOX
    GUICtrlCreatePic($image[$i], $i * 10 + 50, $i * 10 + 50, $w, $h)
    GUISetState(@SW_SHOW, $image[$i])
Next
MsgBox(64, "Done", "")

Not sure what I'm doing wrong this time. The blank GUI shows up, but the image's aren't showing up. I've been fooling around with the width and height variables.

Share this post


Link to post
Share on other sites
Malkey

Try fooling around with the width and height variable values in this script.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $gui, $Button_1, $msg
Local $xGui = 800, $yGui = 600
Local $w = 100, $h = 50
Local $image = @ScriptDir & "\icon.gif"

$gui = GUICreate("test transparentpic", $xGui, $yGui)
;GUISetState(@SW_SHOW, $gui) ; Uncomment to view Pic control & Button control placements.

For $j = 0 To Int($yGui / $h) - 1
    For $i = 0 To Int($xGui / $w) - 1
        GUICtrlCreatePic($image, $i * $w, $j * $h, $w, $h)
        GUICtrlSetState(-1, $GUI_DISABLE)
    Next
Next

$Button_1 = GUICtrlCreateButton("Button Test", 10, 30, 100)
GUISetState(@SW_SHOW, $gui)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            MsgBox(0, 'Testing', 'Button 2 was pressed')
    EndSelect
WEnd

Share this post


Link to post
Share on other sites
danielmohr91

Thanks, so much. I was playing around with your example for a while. It works great - and it's a lot faster than mine, except now I can't get it to show off the GUI (which is the point, showing the grid on the screen). I tried what they said in the help file with the styles for transparency

, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD),
but it's still not going. Is this just not possible with only one GUI window? They've got an example in the help file that's pretty good -
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $gui, $guiPos, $pic, $picPos

Example1()
Example2()

;----- example 1 ----
Func Example1()
    Local $n, $msg
    
    GUICreate("My GUI picture", 350, 300, -1, -1, $WS_SIZEBOX + $WS_SYSMENU)  ; will create a dialog box that when displayed is centered

    GUISetBkColor(0xE0FFFF)
    $n = GUICtrlCreatePic("..\GUI\mslogo.jpg", 50, 50, 200, 50)

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd


    ; resize the control
    $n = GUICtrlSetPos($n, 50, 50, 200, 100)
    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    
    GUIDelete()
EndFunc   ;==>Example1

;----- example 2
Func Example2()
    Local $msg
    
    $gui = GUICreate("test transparentpic", 200, 100)
    $pic = GUICreate("", 68, 71, 10, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gui)
    GUICtrlCreatePic("..\GUI\merlin.gif", 0, 0, 0, 0)

    GUISetState(@SW_SHOW, $pic)
    GUISetState(@SW_SHOW, $gui)

    HotKeySet("{ESC}", "main")
    HotKeySet("{LEFT}", "left")
    HotKeySet("{RIGHT}", "right")
    HotKeySet("{DOWN}", "down")
    HotKeySet("{UP}", "up")
    $picPos = WinGetPos($pic)
    $guiPos = WinGetPos($gui)

    Do
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example2

Func main()
    $guiPos = WinGetPos($gui)
    WinMove($gui, "", $guiPos[0] + 10, $guiPos[1] + 10)
EndFunc   ;==>main

Func left()
    $picPos = WinGetPos($pic)
    WinMove($pic, "", $picPos[0] - 10, $picPos[1])
EndFunc   ;==>left

Func right()
    $picPos = WinGetPos($pic)
    WinMove($pic, "", $picPos[0] + 10, $picPos[1])
EndFunc   ;==>right

Func down()
    $picPos = WinGetPos($pic)
    WinMove($pic, "", $picPos[0], $picPos[1] + 10)
EndFunc   ;==>down

Func up()
    $picPos = WinGetPos($pic)
    WinMove($pic, "", $picPos[0], $picPos[1] - 10)
EndFunc   ;==>up

;----- example 3 PNG work araund by Zedna
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>

Global $hGUI, $hImage, $hGraphic, $hImage1

; Create GUI
$hGUI = GUICreate("Show PNG", 250, 250)

; Load PNG image
_GDIPlus_StartUp()
$hImage   = _GDIPlus_ImageLoadFromFile("..\GUI\Torus.png")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState()

; Loop until user exits
do
until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

; Draw PNG image
Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc

the second one in where they show merlin, you can move him around with the arrow keys - right off the gui. That's exactly what I need, and I can do the same thing, but I need to create an individual GUI for each separate picture - which isn't really practical, it gets REALLY slow after a few dozen. Any way to combine this with your way of only using one GUI?

Edited by danielmohr91

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  

×