Jump to content

How to setup WM_PAINT, etc in Event Mode?


Mbee
 Share

Recommended Posts

I'm using trancexx's GifAnimation UDF in an Event Mode GUI, and every image type is being correctly displayed except animated gifs!

After reading and re-reading the UDF code and the examples, the only thing I can see that could well be causing that failure is that in trancexx's examples, the two following Message Mode calls are made:

; Additional processing of some windows messages (for example)
GUIRegisterMsg(133, "_Refresh") ; WM_NCPAINT
GUIRegisterMsg(15, "_ValidateGIFs") ; WM_PAINT

But everything I've read says you cannot / should not combine Message Modes and Event Modes.  So how do I perform the equivalent in Event Mode?

Thanks!

Link to comment
Share on other sites

maybe :

; Additional processing of some windows messages (for example)
GUIRegisterMsg(133, "_Refresh") ; WM_NCPAINT
GUIRegisterMsg(15, "_ValidateGIFs") ; WM_PAINT

; Additional processing of some windows messages (for example)
GUISetOnEvent($WM_NCPAINT, "_Refresh")
GUISetOnEvent($WM_PAINT, "_ValidateGIFs")

i'm not sure...

 

edit : don't forget #include <WindowsConstants.au3> for use $WM_PAINT, $WM_NCPAINT, ...

Edited by Synapsee
edit
Link to comment
Share on other sites

3 minutes ago, Synapsee said:

maybe :

; Additional processing of some windows messages (for example)
GUIRegisterMsg(133, "_Refresh") ; WM_NCPAINT
GUIRegisterMsg(15, "_ValidateGIFs") ; WM_PAINT

; Additional processing of some windows messages (for example)
GUISetOnEvent($WM_NCPAINT, "_Refresh")
GUISetOnEvent($WM_PAINT, "_ValidateGIFs")

i'm not sure...

Thanks!  I'll give it a try and report back...

Link to comment
Share on other sites

Quote

Unfortunately, the two GUISetOnEvent calls failed.  So a solution is still needed, I'm afraid...

that no help, any console message ?

anyway...

i have use that sample :

 

 

the adapt give :

Opt("GUIOnEventMode", 1) ;<================================ set mode


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

Opt("MustDeclareVars", 1)

; Start by choosing GIF to display
Global $sFile = FileOpenDialog("Choose Image", "", "(*.gif;*.png;*.jpg;*.tiff;*.bmp;*.jpeg)", -1, "")
If @error Then Exit

; Make GUI
Global $hGui = GUICreate("GIF Animation", 500, 500, -1, -1, $WS_OVERLAPPEDWINDOW)

; Add some buttons
Global $hButton = GUICtrlCreateButton("&Pause animation", 50, 450, 100, 25)
Global $hButton1 = GUICtrlCreateButton("&Delete Control", 200, 450, 100, 25)
Global $hButton2 = GUICtrlCreateButton("&Open Image", 350, 450, 100, 25)

; Make GIF Control
Global $hGIF = _GUICtrlCreateGIF($sFile, "", 10, 10)
If @extended Then GUICtrlSetState($hButton, $GUI_DISABLE)
GUICtrlSetTip($hGIF, "Image")

; Additional processing of some windows messages (for example) ;<================================ comment that part
;~ GUIRegisterMsg(133, "_Refresh") ; WM_NCPAINT
;~ GUIRegisterMsg(15, "_ValidateGIFs") ; WM_PAINT

GUISetOnEvent($WM_NCPAINT, "_Refresh") ;<================================ add that part
GUISetOnEvent($WM_PAINT, "_ValidateGIFs")

Opt("GUIOnEventMode", 0) ;<================================ return to default mode for the untouched while part


Global $iPlay = 1

; Show it
GUISetState()

; Loop till end
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $hButton
            If $iPlay Then
                If _GIF_PauseAnimation($hGIF) Then
                    $iPlay = 0
                    GUICtrlSetData($hButton, "Resume animation")
                EndIf
            Else
                If _GIF_ResumeAnimation($hGIF) Then
                    $iPlay = 1
                    GUICtrlSetData($hButton, "Pause animation")
                EndIf
            EndIf
        Case $hButton1
            _GIF_DeleteGIF($hGIF)
        Case $hButton2
            $sFile = FileOpenDialog("Choose gif", "", "(*.gif;*.png;*.jpg;*.tiff;*.bmp;*.jpeg)", -1, "", $hGui)
            If Not @error Then
                _GIF_DeleteGIF($hGIF); delete previous
                $hGIF = _GUICtrlCreateGIF($sFile, "", 10, 10)
                If @extended Then
                    GUICtrlSetState($hButton, $GUI_DISABLE)
                Else
                    GUICtrlSetState($hButton, $GUI_ENABLE)
                EndIf
                GUICtrlSetTip($hGIF, "Image")
                $iPlay = 1
                GUICtrlSetData($hButton, "Pause animation")
            EndIf
    EndSwitch
WEnd


Func _Refresh() ;<================================ remove var here
;~     #forceref $hWnd, $iMsg, $wParam, $lParam ;<================================ comment that
    _GIF_RefreshGIF($hGIF)
EndFunc ;==>_Refresh

Func _ValidateGIFs() ;<================================ remove var here
;~     #forceref $hWnd, $iMsg, $wParam, $lParam ;<================================ comment that
    _GIF_ValidateGIF($hGIF)
EndFunc ;==>_ValidateGIFs

 

Link to comment
Share on other sites

Thanks for your reply, Synapsee.

In reply to your first question about my previous reply not being helpful, what I meant was that the GUISetOnEvent() call returns only 1 or 0, and does not set @error or @extended with any additional info. All it returns is 0, so I have no detailed explanation for the  failure. No console messages were issued.

My guess is that calling it with the first parameter set ro $WM_NCPAINT is simply an invalid value (it's not listed as an acceptable value in the help file for GuiSetOnEvent() ).

As for your advice to remove all paramters from the event handlers, I had already done that -- it would'nt compile otherwise.

Any other suggestions instead of GUISetOnEvent(), or whatever?

Edited by Mbee
Link to comment
Share on other sites

Quote

In reply to your first question about my previous reply not being helpful, what I meant was that the GUISetOnEvent() call returns only 1 or 0, and does not set @error or @extended with any additional info. All it returns is 0, so I have no detailed explanation for the  failure. No console messages were issued.

mmm, ok. so $WM_NCPAINT  is not the problem. for test u can try :

#include <WindowsConstants.au3>
msgbox(0, "$WM_NCPAINT", $WM_NCPAINT)
msgbox(0, "$WM_PAINT", $WM_PAINT)

after some test, if you try my previous post script without the 2 lines, the gif is correctly animated :

;~ GUISetOnEvent($WM_NCPAINT, "_Refresh") ;<================================ add that part
;~ GUISetOnEvent($WM_PAINT, "_ValidateGIFs")

so maybe your gif problem is not located arround WM_PAINT

Link to comment
Share on other sites

9 minutes ago, Synapsee said:

so maybe your gif problem is not located arround WM_PAINT

I'm now sure you're right!  Instead, my problem relates to the face that I don't understand a key aspect of the internal code of trancexx's UDF related to animated GIFs and theire display. I've been reading her/his code for several days, and due to the very understandable fact that the internal functions are minimally commented/documented, I still don't understand the essentials relating to animating GIFs.

I'll just have to keep reading and re-reading the UDF's code in hopes of figuring it out.  I sure wish trancexx would respond to my queries and email, but that's not happening.  Oh, well...

Thanks for your reply!

Link to comment
Share on other sites

My bad :

 

Quote

In my admittedly limited knowledge and experience, I was informed that you could not call GUIRegisterMsg for an Event Mode GUI, but only in Message Loop mode.  Is that incorrect?

That it's not correct. I think that could help :

https://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm

Quote

If the GUIOnEventMode option is set to 1 then the return from GUIGetMsg is always 0 and the @error is set to 1.

so GUIOnEventMode set to 1 is compatible with GUIRegisterMsg but not with GUIGetMsg  :

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case
            ...
    EndSwitch
WEnd
Link to comment
Share on other sites

22 minutes ago, Synapsee said:

My bad :

 

That it's not correct. I think that could help :

https://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm

so GUIOnEventMode set to 1 is compatible with GUIRegisterMsg but not with GUIGetMsg  :

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case
            ...
    EndSwitch
WEnd

I see!  Thank you most kindly, Synapsee!

Link to comment
Share on other sites

This:

GUISetOnEvent($WM_NCPAINT, "_Refresh") ;<================================ add that part
GUISetOnEvent($WM_PAINT, "_ValidateGIFs")

together with

; Additional processing of some windows messages (for example) ;<================================ comment that part
GUIRegisterMsg(133, "_Refresh") ; WM_NCPAINT
GUIRegisterMsg(15, "_ValidateGIFs") ; WM_PAINT

Funcs registered to aMsgCodes using GuiRegisterMSG musn't Set with GuiSetOnEvent nor GUICtrlSetOnEvent. So this code: 

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

Opt("GUIOnEventMode", 1) ;<================================ set mode
Opt("MustDeclareVars", 1)

; Start by choosing GIF to display
Global $sFile = FileOpenDialog("Choose Image", "", "(*.gif;*.png;*.jpg;*.tiff;*.bmp;*.jpeg)", -1, "")
If @error Then Exit

; Make GUI
Global $hGui = GUICreate("GIF Animation", 500, 500, -1, -1, $WS_OVERLAPPEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
; Add some buttons
Global $hButton = GUICtrlCreateButton("&Pause animation", 50, 450, 100, 25)
GUICtrlSetOnEvent(-1, '_CheckPausePlay')
Global $hButton1 = GUICtrlCreateButton("&Delete Control", 200, 450, 100, 25)
GUICtrlSetOnEvent(-1, '_GIF_Delete')
Global $hButton2 = GUICtrlCreateButton("&Open Image", 350, 450, 100, 25)
GUICtrlSetOnEvent(-1, '_OpenImage')

; Make GIF Control
Global $hGIF = _GUICtrlCreateGIF($sFile, "", 10, 10)
If @extended Then GUICtrlSetState($hButton, $GUI_DISABLE)
GUICtrlSetTip($hGIF, "Image")

; Additional processing of some windows messages (for example) ;<================================ comment that part
GUIRegisterMsg($WM_NCPAINT, "_Refresh") ; 133
GUIRegisterMsg($WM_PAINT, "_ValidateGIFs") ;15


Global $iPlay = 1

; Show it
GUISetState()

; Loop till end
While 1
    Sleep(1000)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _OpenImage()
    $sFile = FileOpenDialog("Choose gif", "", "(*.gif;*.png;*.jpg;*.tiff;*.bmp;*.jpeg)", -1, "", $hGui)
    If Not @error Then
        _GIF_DeleteGIF($hGIF); delete previous
        $hGIF = _GUICtrlCreateGIF($sFile, "", 10, 10)
        If @extended Then
            GUICtrlSetState($hButton, $GUI_DISABLE)
        Else
            GUICtrlSetState($hButton, $GUI_ENABLE)
        EndIf
        GUICtrlSetTip($hGIF, "Image")
        $iPlay = 1
        GUICtrlSetData($hButton, "Pause animation")
    EndIf
EndFunc   ;==>_OpenImage

Func _GIF_Delete()
    _GIF_DeleteGIF($hGIF)
EndFunc   ;==>_GIF_Delete

Func _CheckPausePlay()
    If $iPlay Then
        If _GIF_PauseAnimation($hGIF) Then
            $iPlay = 0
            GUICtrlSetData($hButton, "Resume animation")
        EndIf
    Else
        If _GIF_ResumeAnimation($hGIF) Then
            $iPlay = 1
            GUICtrlSetData($hButton, "Pause animation")
        EndIf
    EndIf
EndFunc   ;==>_CheckPausePlay

Func _Refresh($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam 
    _GIF_RefreshGIF($hGIF)
EndFunc   ;==>_Refresh

Func _ValidateGIFs($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam 
    _GIF_ValidateGIF($hGIF)
EndFunc   ;==>_ValidateGIFs

script (complete in GUIOnEventMode) should work.

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