Jump to content

Help with COM object


Recommended Posts

The issue of previewing images into a GUI was raised many times - however none of the topics gave me a solution. I wanted to have an image displayed into a GUI and resized automatically (tried first using a Splash Image - it was good but ... if the user decide to move the window ... problem starts).

So, I found that I can use Windows Preview for doing this and it has an extra - it allows the image to be rotated; the result doesn't look too good but it does whatever I need - or almost...

Anyway - I was able so far only to create the object and to make it to display a picture ... I'm affraid I can't get more by myself..

So far what I got is:

$Obj1 = ObjCreate("Preview.Preview.1")  
$Obj1_ctrl = GUICtrlCreateObj($Obj1, 280, 32, 401, 433)
$Obj1.ShowFile ("c:\image.jpg", 1)

There are not many things in EventViewer and I couldn't understand what synthax I need to use.

My question is:

It is possible to add something like zoom buttons to this object?

What other options are for this type of object?

Thank you,

EDIT:

I'm thinking that I could use a dll call.

Unfortunately I was not able to find on the Internet a list of the functions included in shimgvw.dll ... the fact is, in 2005 a big vulnerability involving this dll was discovered in WinXP and there is alot of info about how to unregister this dll (not very helpful for me).

I know I can't ask for a list of functions to be posted here but ... if someone could help me (by sending me a PM) I will really appreciate it.

Thanks again,

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

  • Moderators

Here is a small example...

#include <GUIConstants.au3>

Opt("GUIOnEventMode", True)

HotKeySet("`", "_LoadPicture")
HotKeySet("=", "_Zoom")
HotKeySet("-", "_Zoom")

$oPreview = ObjCreate("Preview.Preview.1")

GUICreate("Preview Test")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$GUI_OBJ = GUICtrlCreateObj($oPreview, 10, 10, 380, 380)
GUISetState()

While 1
    Sleep(100)
WEnd

Func _LoadPicture()
    $sFile = FileOpenDialog("Open Image", @MyDocumentsDir & "\My Pictures", "Image files (*.bmp;*.jpg;*.jpeg)", 1)
    If @error Then Return
    $oPreview.ShowFile ($sFile, 1)
EndFunc   ;==>_LoadPicture

Func _Zoom()
    Switch @HotKeyPressed
        Case "-"
            $oPreview.Zoom (-1)
        Case "="
            $oPreview.Zoom (1)
    EndSwitch
EndFunc   ;==>_Zoom

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

That is fantastic :whistle:

Thank you gazillion times big_daddy :lmao:

May I ask for a favor please?

Can you tell me how did you find about this Zoom? and the synthax?

Sorry for asking but I would like to learn how to do this myself; I'm sure it will come in handy in the future.

Thank you.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Sorry for posting again ...

I tried to make something like a button inside the preview area in order to provide some buttons to do the zoom (instead of hotkeys). This works but ... the button won't show until the preview is clicked. How can I make them to show by default? I tried using GUICtrlSetState with $GUI_SHOW, $GUI_ONTOP, $GUI_FOCUS but nothing worked.

here is the code:

#include <GUIConstants.au3>

Opt("GUIOnEventMode", True)

HotKeySet("`", "_LoadPicture")
HotKeySet("=", "_Zoom")
HotKeySet("-", "_Zoom")

$oPreview = ObjCreate("Preview.Preview.1")

GUICreate("Preview Test")

$test = GUICtrlCreateButton ("+", 270,355, 20, 20)      ;this is the button I want to be seen
GUICtrlSetOnEvent(-1, "test")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$GUI_OBJ = GUICtrlCreateObj($oPreview, 10, 10, 380, 380)
GUISetState()

While 1
    Sleep(100)
WEnd

Func test ()
    MsgBox (0, "", "")
EndFunc

Func _LoadPicture()
    $sFile = FileOpenDialog("Open Image", @MyDocumentsDir & "\My Pictures", "Image files (*.bmp;*.jpg;*.jpeg)", 1)
    If @error Then Return
    $oPreview.ShowFile ($sFile, 1)
EndFunc  ;==>_LoadPicture

Func _Zoom()
    Switch @HotKeyPressed
        Case "-"
            $oPreview.Zoom (-1)
        Case "="
            $oPreview.Zoom (1)
    EndSwitch
EndFunc  ;==>_Zoom

Func _Exit()
    Exit
EndFunc  ;

Thank you,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

  • Moderators

I tried everything I could think of, but couldn't figure it out either.

#include <GUIConstants.au3>

Opt("GUIOnEventMode", True)

$oPreview = ObjCreate("Preview.Preview.1")

$GUI = GUICreate("Preview Test")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Button1 = GUICtrlCreateButton("Load", 50, 355, 40, 20)
GUICtrlSetOnEvent(-1, "_LoadPicture")
$Button2 = GUICtrlCreateButton("-", 100, 355, 20, 20)
GUICtrlSetOnEvent(-1, "_Zoom")
$Button3 = GUICtrlCreateButton("+", 280, 355, 20, 20)
GUICtrlSetOnEvent(-1, "_Zoom")

$GUI_OBJ = GUICtrlCreateObj($oPreview, 10, 10, 380, 380)
GUICtrlSetState($GUI_OBJ, $GUI_NOFOCUS)

GUISetState()

While 1
    Sleep(100)
WEnd

Func _LoadPicture()
    $sFile = FileOpenDialog("Open Image", @MyDocumentsDir & "\My Pictures", "Image files (*.bmp;*.jpg;*.jpeg)", 1)
    If @error Then Return
    $oPreview.ShowFile ($sFile, 1)
EndFunc   ;==>_LoadPicture

Func _Zoom()
    Switch @GUI_CtrlId
        Case $Button2
            $oPreview.Zoom (-1)
        Case $Button3
            $oPreview.Zoom (1)
    EndSwitch
EndFunc   ;==>_Zoom

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

Thank you for your time big_daddy :whistle:

What I discovered is: the controls will show after an event occured so I will put the Load button outside the preview window and that will generate the needed event.

Another thing: if the buttons are created AFTER this line:

$GUI_OBJ = GUICtrlCreateObj($oPreview, 10, 10, 380, 380)

they will always show but they aren't clickable.

Unfortunately I can't understand this behaviour :lmao:

If someone could explain, it would be great.

Thanks,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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