Sign in to follow this  
Followers 0
Rat

GuiRegisterMsg not Working for $WM_LBUTTONDBLCLK

18 posts in this topic

Dear AutoIt People,

I have a script where I am attempting to create an event handler for the left mouse button double click event. I have confirmed that the "GuiRegisterMsg" call is successful, but the event handler is never called?

The event handler is registered as follows:

GuiRegisterMsg($WM_LBUTTONDBLCLK, "doLButtonDblClk")  ; Register an event handler for the Left Mouse Button Double-Click message

And the actual event handler looks like this:

Func doLButtonDblClk($hWnd, $Msg, $WParam, $LParam)
    $X = BitShift($LParam, 16)
    $Y = BitAND($LParam, 0xFFFF)
MsgBox(0, 'Debug', 'X = ' & $X & @CRLF & 'Y = ' & $Y)

    If $X >= $LogoLeft And $X <= $LogoLeft + $LogoWidth And $Y >= $LogoTop And $Y <= $LogoTop + $LogoHeight Then
MsgBox(0, 'Debug', 'Hit In Logo')
        WinSetOnTop($LongName, '', 0)  ; Un-Pin the Window from the top of the Z-Order (Technician can do this after remoting in)
        $PinWindow = False
        Return 0  ; Disable any further event handling of this message
    EndIf
EndFunc

Cheers,

Rat ^^>//o

Share this post


Link to post
Share on other sites



Rat,

Welcome to the AutoIt forum. :mellow:

There is a major problem with your message handler - it contains a couple of blocking functions. :P

As the Help file says:

"Warning: blocking of running user functions which executes window messages with commands such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!"

So it is hardly unexpected that you are not getting what you want. Try replacing the MsgBoxes with ConsoleWrites - this works fine for me: :party:

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

Global $LogoLeft = 0, $LogoWidth = 100, $LogoTop = 0, $LogoHeight = 100

$hGUI = GUICreate("Test", 500, 500)

GUISetState()

GUIRegisterMsg($WM_LBUTTONDBLCLK, "doLButtonDblClk") ; Register an event handler for the Left Mouse Button Double-Click message

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func doLButtonDblClk($hWnd, $iMsg, $wParam, $lParam)

    $X = BitShift($LParam, 16)
    $Y = BitAND($LParam, 0xFFFF)
    ConsoleWrite('X = ' & $X & @CRLF & 'Y = ' & $Y & @CRLF)

    If $X >= $LogoLeft And $X <= $LogoLeft + $LogoWidth And $Y >= $LogoTop And $Y <= $LogoTop + $LogoHeight Then
        ConsoleWrite("Hit in Logo" & @CRLF)
        ;WinSetOnTop($LongName, '', 0) ; Un-Pin the Window from the top of the Z-Order (Technician can do this after remoting in)
        ;$PinWindow = False
        Return 0 ; Disable any further event handling of this message
    EndIf

EndFunc   ;==>doLButtonDblClk

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi M23,

Thanks for you prompt reply. I did notice that bit about blocking functions in the help doc... but ony added the MsgBox() calls for debugging when I didn't appear to be handling the double click event. I took them back out but I am still not handling the event, (ie. the window isn't becoming un-pinned).

I've included the entire script below:

;***************************
;  Include External Files  *
;*******************************************************************************
#include 'Aut2Exe\Include\GUIConstantsEx.au3'
#include 'Aut2Exe\Include\StaticConstants.au3'
#include 'Aut2Exe\Include\EditConstants.au3'
#include 'Aut2Exe\Include\WindowsConstants.au3'
#Include 'Aut2Exe\Include\WinAPI.au3'
#Include 'Aut2Exe\Include\GDIPlus.au3'
#include 'Aut2Exe\Include\Misc.au3'

; include our re-branding info and other global variables
#include 'InstantSupportDefs.au3'


; Allow only one instance to run
if _Singleton($LongName, 1) = 0 Then
    Msgbox(0, 'Warning', $LongName & ' is already running')
    Exit
EndIf


;***********************************
;  Global Constants and Variables  *
;*******************************************************************************
$TempConnectId = $ConnectId  ; Initial value in Connection ID input dialog
$ConnectId = Number($ConnectId)  ; Ignore any non-numeric ID's

$TempPath = @TempDir & '\' & $ShortName & '_Temp_Files'  ; Set our temp working directory.

$ServerStarted = False  ; Global Flag to indicate VNC Server state, (used in doGuiClose() and the background loop)


;*********************************
;  Functions and Event Handlers  *
;*******************************************************************************
Func _DeleteTemp($iDelay = 5)
    Local $sCmdFile

    FileDelete(@TempDir & '\scratch.bat')

    $sCmdFile = 'PING -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\cad.exe"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\logo.jpg"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\' & $ShortName & 'Server.exe"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\' & $ShortName & 'ServiceInstaller.exe"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\schook.dll"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\rc4.key"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\MSRC4Plugin.dsm"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\ultravnc.ini"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\chunkvnc.ini"' & @CRLF _
            & 'RMDIR /Q "' & $TempPath & '"' & @CRLF _
            & 'DEL "' & @TempDir & '\scratch.bat"'

    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)

    Run( @TempDir & "\scratch.bat", @TempDir, @SW_HIDE )
EndFunc

Func DrawConnectionId()  ; Show Connection ID
    Local $hDC, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo

    If Not $ShowID Then Return

    If $ConnectId = 0 Then Return

    ; Get DC of GUI
    $hDC  = _WinAPI_GetWindowDC($InstantSupport)

    ; Start up GDI+ library
    _GDIPlus_Startup()

    $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000 + $IdFontColor)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate($IdFont)
    $hFont = _GDIPlus_FontCreate($hFamily, $IdFontSize, $IdFontStyle, 2)

    $tLayout = _GDIPlus_RectFCreate(0, 0, $GuiWidth, $IdHeight)

    $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, 'ID = ' & $ConnectId, $hFont, $tLayout, $hFormat)
    $tLayout = $aInfo[0]

    $W = DllStructGetData($tLayout, 3)
    $H = DllStructGetData($tLayout, 4)
    DllStructSetData($tLayout, 1, ($GuiWidth - $W)/2)
    DllStructSetData($tLayout, 2,  $LogoHeight + ($GuiHeight - $LogoHeight - $H)/2 + $IdFontSize/2)

    _GDIPlus_GraphicsDrawStringEx($hGraphic, 'ID = ' & $ConnectId, $hFont, $tLayout, $hFormat, $hBrush)

    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)

    ; Shut down GDI+ library
    _GDIPlus_ShutDown()
EndFunc

Func doLButtonDblClk($hWnd, $Msg, $WParam, $LParam)
    $X = BitShift($LParam, 16)
    $Y = BitAND($LParam, 0xFFFF)
;MsgBox(0, 'Debug', 'X = ' & $X & @CRLF & 'Y = ' & $Y)
;ConsoleWrite('X = ' & $X & @CRLF & 'Y = ' & $Y & @CRLF)

    If $X >= $LogoLeft And $X <= $LogoLeft + $LogoWidth And $Y >= $LogoTop And $Y <= $LogoTop + $LogoHeight Then
;MsgBox(0, 'Debug', 'Hit In Logo')
        WinSetOnTop($LongName, '', 0)  ; Un-Pin the Window from the top of the Z-Order (Technician can do this after remoting in)
        $PinWindow = False
        Return 0  ; Disable any further event handling of this message
    EndIf
EndFunc

Func doPaintText($hWnd, $Msg)
    DrawConnectionId()
    Return $GUI_RUNDEFMSG  ; Proceed the default Autoit3 internal message commands
EndFunc

Func doGuiClose()
    If $PinWindow Then WinSetOnTop($LongName, '', 0)  ; Un-Pin Window from top of Z-Order (to allow message boxes to display)

    If MsgBox(4, 'Close ' & $LongName, 'Are you sure you want to close ' & $LongName & '?' & @CRLF & 'If you do, no one will be able to connect to you.') = 6 Then

        ; Kill the server
        if $ServerStarted Then
            ; Allow viewer to disconnect to prevent schook.dll locking.
            MsgBox(0, 'Information', 'Please click OK and wait 15 seconds to allow ' & $LongName & ' to close correctly.' & @CRLF & 'Any currently connected Remote Support technicians should also close their Viewer now.', 15)

            ShellExecute($TempPath & '\' & $ShortName & 'Server.exe', '-kill')
            ; Remove files after server closes.
            ProcessWaitClose($ShortName & 'Server.exe', 30)
        EndIf

        _DeleteTemp()

        DisableUAC(False)  ; Restore the UAC prompt dialog setting

        Exit
    Else
        If $PinWindow Then WinSetOnTop($LongName, '', 1)  ; Re-Pin Window to the top of the Z-Order
    EndIf
EndFunc   ;==>doGuiClose

Func doLogoClicked()
    ShellExecute('http://' & $WebURL)
EndFunc   ;==>doLogoClicked

Func doServiceInstall()
    If IsNumber($ConnectId) Then
        If MsgBox(4, $LongName & ' Service Installation','The currently running ' & $LongName & ' session must first be closed.' & @CRLF & 'Are you sure you want to close ' & $LongName & '?') = 6 Then

            ; Allow viewer to disconnect to prevent schook.dll locking.
            MsgBox(0, 'Information', 'Please click OK and wait 15 seconds to allow ' & $LongName & ' to close correctly.' & @CRLF & 'Any currently connected Remote Support technicians should also close their Viewer now.', 15)

            ; Configure ultravnc.ini
            IniWrite($TempPath & "\ultravnc.ini", "admin", "service_commandline", '-autoreconnect ID:' & $ConnectId & ' -connect ' & $RepeaterAddress)

            ; Configure chunkvnc.ini
            IniWrite($TempPath & '\chunkvnc.ini', 'ChunkVNC', 'Path', @ProgramFilesDir & '\' & $LongName)
            IniWrite($TempPath & '\chunkvnc.ini', 'ChunkVNC', 'ID', $ConnectId)

            ; Exit the server.
            ShellExecute($TempPath & '\' & $ShortName & 'Server.exe', '-kill')

            ; Run installer after the server exits.
            ProcessWaitClose($ShortName & 'Server.exe', 30)

            ShellExecute($TempPath & '\' & $ShortName & 'ServiceInstaller.exe')

            DisableUAC(False)  ; Restore the UAC prompt dialog setting

            Exit
        EndIf
    Else
        MsgBox(0, 'Information', 'Invalid ID entered, service installation cancelled')
    EndIf
EndFunc     ;==>doServiceInstall

Func DisableUAC($Disable)  ; Disable/Restore UAC prompt dialog setting
    $Result = 1

    $Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
    $Value = "ConsentPromptBehaviorAdmin"
    $Type = "REG_DWORD"

    $RegData = RegRead($Key, $Value)
    If @Error Then Return False ; Key doesn't exist, (probably not Vista or Windows 7)

    If $Disable Then
        $Result = IniWrite($TempPath & '\chunkvnc.ini', 'UAC', 'Prompt', $RegData)        ; Store original UAC setting, (so that it can be restored later)
        If $Result = 1 And $RegData <> 0 Then $Result = RegWrite($Key, $Value, $Type, 0)  ; Disable the UAC prompt dialog, (if were able to store original UAC setting and it requires changing)
    Else
        $RestoreData = IniRead($TempPath & '\chunkvnc.ini', 'UAC', 'Prompt', '')
        If $RestoreData = '' Then Return False  ; Ini value doesn't exist and therefore has never been previously disabled
        If $RestoreData <> $RegData Then $Result = RegWrite($Key, $Value, $Type, $RestoreData)  ; Restore the UAC prompt dialog setting, (if it requires changing)
    EndIf

    If $Result = 0 Then Return False  ; Error: failed to do task
    Return True
EndFunc     ;==>DisableUAC


;**********************
;  Extract the Files  *
;*******************************************************************************
; Remove any leftovers.
DirRemove($TempPath, 1)

; Extract everything. (Note: Files need to be extracted before creating the GUI so that the Logo image can be added)
DirCreate($TempPath)
FileInstall('InstantSupport_Files\cad.exe', $TempPath & '\cad.exe', 1)
FileInstall('InstantSupport_Files\logo.jpg', $TempPath & '\logo.jpg', 1)
FileInstall('InstantSupport_Files\winvnc.exe', $TempPath & '\' & $ShortName & 'Server.exe', 1)
FileInstall('InstantSupport_Files\InstantSupportServiceInstaller.exe', $TempPath & '\' & $ShortName & 'ServiceInstaller.exe', 1)
FileInstall('InstantSupport_Files\schook.dll', $TempPath & '\schook.dll', 1)
FileInstall('InstantSupport_Files\rc4.key', $TempPath & '\rc4.key', 1)
FileInstall('InstantSupport_Files\MSRC4Plugin.dsm', $TempPath & '\MSRC4Plugin.dsm', 1)
FileInstall('InstantSupport_Files\ultravnc.ini', $TempPath & '\ultravnc.ini', 1)
FileInstall('InstantSupport_Files\chunkvnc.ini', $TempPath & '\chunkvnc.ini', 1)


;*************************************
;  Enable and Create Event Handlers  *
;*******************************************************************************
Opt('GUIOnEventMode', 1)  ; Enable our event handlers


;*******************
;  Create the GUI  *
;*******************************************************************************
$InstantSupport = GUICreate($LongName, $GuiWidth, $GuiHeight, -1, -1, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS,$WS_MINIMIZEBOX))

GUISetBkColor($BackgroundColor)
GUISetOnEvent($GUI_EVENT_CLOSE, 'doGuiClose')

; Show Logo Image
$LogoPic = GUICtrlCreatePic($TempPath & '\logo.jpg', $LogoLeft, $LogoTop, $LogoWidth, $LogoHeight , BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))

If $AllowLogoClick And $WebURL <> '' Then
 GUICtrlSetOnEvent(-1, 'doLogoClicked')
 GUICtrlSetCursor(-1, 0)
 GUICtrlSetTip(-1, 'Click here to open the ' & $BrandName & ' website')
EndIf

; Show Connection ID
;$ConnectIdLabel = GUICtrlCreateLabel('ID = ' & $ConnectId, 0, $LogoHeight, $GuiWidth, $IdHeight, $SS_CENTER)
;GUICtrlSetFont(-1, $IdFontSize, 800, 0, 'Arial Black', 2)
;GUICtrlSetColor(-1, $IdFontColor)
;GUICtrlSetBkColor(-1, $IdBackgroundColor)

GUISetState(@SW_SHOW)  ; Show the GUI

If $ConnectId <> 0 Then DrawConnectionId()  ; Display the Connection ID text, (must do this after showing GUI)

If $PinWindow Then
    WinSetOnTop($LongName, '', 1)  ; Pin the Window to the top of the Z-Order
    GUIRegisterMsg($WM_LBUTTONDBLCLK, "doLButtonDblClk")  ; Register an event handler for the Left Mouse Button Double-Click message
EndIf


;*************************
;  Create the Tray Menu  *
;*******************************************************************************
Opt('TrayOnEventMode', 1)  ; Enable our event handlers
Opt('TrayMenuMode', 1)   ;Create the tray icon, Default tray menu items (Script Paused/Exit) will not be shown.

TraySetClick(16)    ; Only secondary mouse button will show the tray menu.

$InstallItem = TrayCreateItem('Install ' & $LongName & ' Service')
TrayItemSetOnEvent(-1, 'doServiceInstall')

TrayCreateItem('')  ; Menu divider

$ExitItem = TrayCreateItem('Exit')
TrayItemSetOnEvent(-1, 'doGuiClose')

TraySetState()  ; Show the tray icon

; Register the Windows Paint message, (to repaint the Connection ID text)
GUIRegisterMsg($WM_PAINT, "doPaintText")


;*****************************************
;  Main Application and Background Loop  *
;*******************************************************************************
; Read the address of the repeater from our settings file.
$RepeaterAddress = IniRead($TempPath & '\chunkvnc.ini', 'Repeater', 'Address', '')

DisableUAC(True)  ; Disable the UAC prompt dialog

; Background Loop
While True
    ; Close any windows firewall messages that popup. The windows firewall doesn't block outgoing connections anyways.
    if WinExists('Windows Security Alert') then WinClose('Windows Security Alert')

    If $ConnectId = 0 Then
        $TempConnectId = InputBox('Enter Your Connection ID', 'Connection ID:', $TempConnectId, '', 220, 40)

        if (@Error) Then doGuiClose()  ; Close the app if user cancels

        $ConnectId = Number($TempConnectId)
        If $ConnectId = 0 Or $ConnectId < $LowerLimit Or $ConnectId > $UpperLimit Then
            $ConnectId = 0
            MsgBox(0, 'Error', 'You must enter a numeric Connection ID between ' & $LowerLimit & ' and ' & $UpperLimit)
        EndIf

;       If $ConnectId <> 0 Then GUICtrlSetData($ConnectIdLabel, 'ID = ' & $ConnectId)
        If $ConnectId <> 0 Then DrawConnectionId()  ; Display the  Connection ID text
    EndIf

    ; Start the server and make a reverse connection to the repeater.
    If Not $ServerStarted And $ConnectId <> 0 And $ConnectId <> '' Then
        ShellExecute($TempPath & '\' & $ShortName & 'Server.exe', '-autoreconnect ID:' & $ConnectId & ' -connect ' & $RepeaterAddress & ' -run')
        If Not @error Then $ServerStarted = True
    EndIf

    Sleep(100)
WEnd

Cheers,

Rat.

Share this post


Link to post
Share on other sites

If $PinWindow Then
    WinSetOnTop($LongName, '', 1)  ; Pin the Window to the top of the Z-Order
    GUIRegisterMsg($WM_LBUTTONDBLCLK, "doLButtonDblClk")  ; Register an event handler for the Left Mouse Button Double-Click message
EndIf

I fail to see where and how $PinWindow resolves to True in your code. It's not GUIRegisterMsg and $WM_LBUTTONSBLCLK that don't work, it's something about how you use them.

Share this post


Link to post
Share on other sites

Rat,

In a similar vein, I cannot find where you declare $LongName. You create a GUI using that as the title and have numerous references to it, but you never declare it. When you try running your script, do you not get multiple warnings about undeclared variables? :mellow:

Or are they all stored in your InstantSupportDefs.au3 include file?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Yep its all in that Defs file... see below:

I left it out because I thought it may obscure the issue... sorry.

; Select wether to use encryption with Viewer, (Mac InstantSupport doesn't use encryption)
$EncryptViewer = True

; VNC Server and Repeater ports
$ServerPort = 5900    ; External port of the VNC Server
$RepeaterPort = 5500  ; External port of the VNC Repeater Server

; Select Connection ID Type, (1 = Fixed, 2 = User-Selected, 3 = Random)
Const $ConnectIdFixed = 1, $ConnectIdUser = 2, $ConnectIdRandom = 3
Const $LowerLimit = 100000, $UpperLimit = 999999

$ConnectIdType = $ConnectIdRandom

; Define a Unique Connection ID number
Switch $ConnectIdType
    Case $ConnectIdFixed
        $ConnectId = 123456
    Case $ConnectIdUser
        $ConnectId = 'Enter a Connection ID'
    Case $ConnectIdRandom
        $ConnectId = Random($LowerLimit, $UpperLimit, 1)  ; Generate a random Connection ID number
    Case Else
        $ConnectId = 'Enter a Connection ID'
        $ConnectIdType = $ConnectIdUser
EndSwitch

; Display Code, (ignored except for $ConnectIdFixed)
$ShowID = True
If $ConnectIdType <> $ConnectIdFixed Then $ShowId = True

; Define some Re-branding Strings
$BrandName = 'ChunkVNC'                ; Used for tooltip when clicking on the logo
$LongName = 'ChunkVNC Remote Support'
$ShortName = 'ChunkVNCRemote'

; URLs
$RepeaterUrl = 'repeater.chunkvnc.com'
$WebURL = 'www.chunkvnc.com'

; Display a message box prompt if an RC4 encryption file already exists during compilation
$KeepExistingRc4 = False

; Pin the Window to the top of the Z-Order
$PinWindow = True  ; If $PinWindow is True then double-clicking the logo image will Un-Pin the window

; Enable Click on Logo to load $WebURL
$AllowLogoClick = False

; GUI Background Colour
$BackgroundColor = 0x2B2EA5

; Exe Icons
$InstallerIcon = 'InstallerIcon.chunkvnc'
$ServerIcon = 'ServerIcon.chunkvnc'
$ViewerIcon = 'ViewerIcon.chunkvnc'

; Top/Left coordinates and Width and Height of clickable Logo image
$LogoLeft = 0
$LogoTop = 0
$LogoWidth = 480
$LogoHeight = 170

; Height, Font and Colour of Connection ID text
$IdHeight = 66
$IdFont = 'Arial Black'
$IdFontStyle = 0  ;0 - Normal, 2 - Bold, 3 - Italic, 4 - Underline, 8 - Strikethrough
$IdFontSize = 50  ; in pixels
$IdFontColor = 0x00C000

; Width and Height of Dialog client viewport area, (in this case same as the Logo since it covers the entire form client area)
$GuiWidth = $LogoWidth
$GuiHeight = $LogoHeight

If $ShowId Then $GuiHeight = $GuiHeight + $IdHeight

Share this post


Link to post
Share on other sites

Rat,

When I run your script (after commenting out a fair bit of code so that it actually runs on my system :P ) I get the handler to run when I click in the correct place and the TOPMOST flag is definitely removed from the $LongName GUI. So I am at a loss to understand why it does not work for you.

Sorry. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks for your efforts M23,

Could you post your "modified" working code here...it may provide some clues for me?

Cheers,

Rat.

Share this post


Link to post
Share on other sites

Rat,

Sorry, already overwritten by another script. I run forum help scripts under a series of "scratch" names and yours has gone to the great recycle bin in the sky. :mellow:

All I did was comment out the lines which caused errors when I ran the script on my system (such as FileInstall, ShellExecute, IniWrite, RegWrite, etc).

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Well thats a bit of a shame...

I'm afraid I have reached the end of the road with this script. I will have to release it to the ChunkVNC fraternity without this final feature and hope that someone else can resolve the problem.

Thanks again for your help.

Cheers,

Rat.

Share this post


Link to post
Share on other sites

Rat,

I will try and do better next time! :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

There is always a hope *)

You can be sure that nothing is wrong with either GUIRegisterMsg or $WM_LBUTTONDBLCLK. I think that somehow, some controls take the entire GUI area so you won't be notified about double click events through the GUI event handlers. Check to see where.

Edited by Authenticity

Share this post


Link to post
Share on other sites

Hi Authenticity,

Well if the parameter $ShowId = False then the clickable logo image will be the only control on the window... however I have just discovered that if $ShowId = True then double-clicking the (now visible) ID Code displayed below the logo will call the event handler, (and un-pin the window, even though its outside the logo bounding rect?).

This looks a lot like a CLUE but I haven't been able to progress much past this point :mellow:

I have included the latest versions of both the Definitions script file and the Window script file below for anybody will to take on the challenge :P

Cheers,

Rat.

[DEFINITIONS SCRIPT]

; Select wether to use encryption with Viewer, (Mac InstantSupport doesn't use encryption)
$EncryptViewer = True

; VNC Server and Repeater ports
$ServerPort = 5901    ; External port of the VNC Server
$RepeaterPort = 5501  ; External port of the VNC Repeater Server

; Select Connection ID Type, (1 = Fixed, 2 = User-Selected, 3 = Random)
Const $ConnectIdFixed = 1, $ConnectIdUser = 2, $ConnectIdRandom = 3
Const $LowerLimit = 100000, $UpperLimit = 999999

$ConnectIdType = $ConnectIdFixed

; Define a Unique Connection ID number
Switch $ConnectIdType
    Case $ConnectIdFixed
        $ConnectId = 131160
    Case $ConnectIdUser
        $ConnectId = 'Enter a Connection ID'
    Case $ConnectIdRandom
        $ConnectId = Random($LowerLimit, $UpperLimit, 1)  ; Generate a random Connection ID number
    Case Else
        $ConnectId = 'Enter a Connection ID'
        $ConnectIdType = $ConnectIdUser
EndSwitch

; Display Code, (ignored except for $ConnectIdFixed)
$ShowID = True ;False
If $ConnectIdType <> $ConnectIdFixed Then $ShowId = True

; Define some Re-branding Strings
$BrandName = 'vuWare'                ; Used for tooltip when clicking on the logo
$LongName = 'vuWare Remote Support'
$ShortName = 'vuWareRemote'

; URLs
$RepeaterUrl = 'netsoft.com.au'
$WebURL = 'www.vuware.com'

; Display a message box prompt if an RC4 encryption file already exists during compilation
$KeepExistingRc4 = True

; Pin the Window to the top of the Z-Order
$PinWindow = True  ; If $PinWindow is True then double-clicking the logo image will Un-Pin the window

; Enable Click on Logo to load $WebURL
$AllowLogoClick = False

; GUI Background Colour
$BackgroundColor = 0x707E89

; Exe Icons
$InstallerIcon = 'InstallerIcon.vuware'
$ServerIcon = 'ServerIcon.vuware'
$ViewerIcon = 'ViewerIcon.vuware'

; Top/Left coordinates and Width and Height of clickable Logo image
$LogoLeft = 0
$LogoTop = 0
$LogoWidth = 349
$LogoHeight = 141

; Height, Font and Colour of Connection ID text
$IdHeight = 61
$IdFont = 'Arial Black'
$IdFontStyle = 0  ;0 - Normal, 2 - Bold, 3 - Italic, 4 - Underline, 8 - Strikethrough
$IdFontSize = 45  ; in pixels
$IdFontColor = 0xFFFFFF

; Width and Height of Dialog client viewport area, (in this case same as the Logo since it covers the entire form client area)
$GuiWidth = $LogoWidth
$GuiHeight = $LogoHeight

If $ShowId Then $GuiHeight = $GuiHeight + $IdHeight

[WINDOW SCRIPT]

;***************************
;  Include External Files  *
;*******************************************************************************
#include 'Aut2Exe\Include\GUIConstantsEx.au3'
#include 'Aut2Exe\Include\StaticConstants.au3'
#include 'Aut2Exe\Include\EditConstants.au3'
#include 'Aut2Exe\Include\WindowsConstants.au3'
#Include 'Aut2Exe\Include\WinAPI.au3'
#Include 'Aut2Exe\Include\GDIPlus.au3'
#include 'Aut2Exe\Include\Misc.au3'

; include our re-branding info and other global variables
#include 'InstantSupportDefs.au3'


;***********************
;  Set Script Options  *
;*******************************************************************************
Opt('GUIOnEventMode', 1)     ; Enable our event handlers
Opt("WinTitleMatchMode", 3)  ; Exact Window Title Match only
Opt('TrayOnEventMode', 1)    ; Enable our Tray event handlers
Opt('TrayMenuMode', 1)       ; Create the Tray icon, Default tray menu items (Script Paused/Exit) will not be shown.


;******************************
;  Check for Other Instances  *
;*******************************************************************************
If $PinWindow Then
 If _Singleton($LongName, 0) = 0 Then Exit  ; Exit without a warning dialog if pinned, (so that the warning dialog won't be hidden behind the previous instance's pinned window)
Else
    If _Singleton($LongName, 1) = 0 Then
        Msgbox(0, 'Warning', $LongName & ' is already running')  ; Display a warning dialog if not pinned, (warning dialog won't be hidden behind the previous instance's pinned window)
        Exit
    EndIf
EndIf


;***********************************
;  Global Constants and Variables  *
;*******************************************************************************
$TempConnectId = $ConnectId  ; Initial value in Connection ID input dialog
$ConnectId = Number($ConnectId)  ; Ignore any non-numeric ID's

$TempPath = @TempDir & '\' & $ShortName & '_Temp_Files'  ; Set our temp working directory.

$ServerStarted = False  ; Global Flag to indicate VNC Server state, (used in doGuiClose() and the background loop)


;********************************************
;  Register Windows Message Event Handlers  *
;*******************************************************************************
If $ShowID Then GUIRegisterMsg($WM_PAINT, "doPaintText")  ; Register the Windows Paint message, (to repaint the Connection ID text)
If $PinWindow Then GUIRegisterMsg($WM_LBUTTONDBLCLK, 'doLButtonDblClk')  ; Register an event handler for the Left Mouse Button Double-Click message


;**************
;  Functions  *
;*******************************************************************************
Func _DeleteTemp($iDelay = 5)
    Local $sCmdFile

    FileDelete(@TempDir & '\scratch.bat')

    $sCmdFile = 'PING -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\cad.exe"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\logo.jpg"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\' & $ShortName & 'Server.exe"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\' & $ShortName & 'ServiceInstaller.exe"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\schook.dll"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\rc4.key"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\MSRC4Plugin.dsm"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\ultravnc.ini"' & @CRLF _
            & 'DEL /F /Q "' & $TempPath & '\chunkvnc.ini"' & @CRLF _
            & 'RMDIR /Q "' & $TempPath & '"' & @CRLF _
            & 'DEL "' & @TempDir & '\scratch.bat"'

    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)

    Run( @TempDir & "\scratch.bat", @TempDir, @SW_HIDE )
EndFunc

Func DrawConnectionId()  ; Show Connection ID
    Local $hDC, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo

    If Not $ShowID Then Return

    If $ConnectId = 0 Then Return

    ; Get DC of GUI
    $hDC  = _WinAPI_GetWindowDC($InstantSupport)

    ; Start up GDI+ library
    _GDIPlus_Startup()

    $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000 + $IdFontColor)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate($IdFont)
    $hFont = _GDIPlus_FontCreate($hFamily, $IdFontSize, $IdFontStyle, 2)

    $tLayout = _GDIPlus_RectFCreate(0, 0, $GuiWidth, $IdHeight)

    $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, 'ID = ' & $ConnectId, $hFont, $tLayout, $hFormat)
    $tLayout = $aInfo[0]

    $W = DllStructGetData($tLayout, 3)
    $H = DllStructGetData($tLayout, 4)
    DllStructSetData($tLayout, 1, ($GuiWidth - $W)/2)
    DllStructSetData($tLayout, 2,  $LogoHeight + ($GuiHeight - $LogoHeight - $H)/2 + $IdFontSize/2)

    _GDIPlus_GraphicsDrawStringEx($hGraphic, 'ID = ' & $ConnectId, $hFont, $tLayout, $hFormat, $hBrush)

    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)

    ; Shut down GDI+ library
    _GDIPlus_ShutDown()
EndFunc

Func DisableUAC($Disable)  ; Disable/Restore UAC prompt dialog setting
    $Result = 1

    $Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
    $Value = "ConsentPromptBehaviorAdmin"
    $Type = "REG_DWORD"

    $RegData = RegRead($Key, $Value)
    If @Error Then Return False ; Key doesn't exist, (probably not Vista or Windows 7)

    If $Disable Then
        $Result = IniWrite($TempPath & '\chunkvnc.ini', 'UAC', 'Prompt', $RegData)        ; Store original UAC setting, (so that it can be restored later)
        If $Result = 1 And $RegData <> 0 Then $Result = RegWrite($Key, $Value, $Type, 0)  ; Disable the UAC prompt dialog, (if were able to store original UAC setting and it requires changing)
    Else
        $RestoreData = IniRead($TempPath & '\chunkvnc.ini', 'UAC', 'Prompt', '')
        If $RestoreData = '' Then Return False  ; Ini value doesn't exist and therefore has never been previously disabled
        If $RestoreData <> $RegData Then $Result = RegWrite($Key, $Value, $Type, $RestoreData)  ; Restore the UAC prompt dialog setting, (if it requires changing)
    EndIf

    If $Result = 0 Then Return False  ; Error: failed to do task
    Return True
EndFunc     ;==>DisableUAC


;*******************
;  Event Handlers  *
;*******************************************************************************

Func doLButtonDblClk($hWnd, $Msg, $WParam, $LParam)
    $X = BitShift($LParam, 16)
    $Y = BitAND($LParam, 0xFFFF)

    If $X >= $LogoLeft And $X <= $LogoLeft + $LogoWidth And $Y >= $LogoTop And $Y <= $LogoTop + $LogoHeight Then
        WinSetOnTop($LongName, '', 0)  ; Un-Pin the Window from the top of the Z-Order (Technician can do this after remoting in)
        $PinWindow = False
        Return 0  ; Disable any further event handling of this message
    EndIf
EndFunc

Func doPaintText($hWnd, $Msg)
    DrawConnectionId()
    Return $GUI_RUNDEFMSG  ; Proceed the default Autoit3 internal message commands
EndFunc

Func doGuiClose()
    If $PinWindow Then WinSetOnTop($LongName, '', 0)  ; Un-Pin Window from top of Z-Order (to allow message boxes to display)

    If MsgBox(4, 'Close ' & $LongName, 'Are you sure you want to close ' & $LongName & '?' & @CRLF & 'If you do, no one will be able to connect to you.') = 6 Then

        ; Kill the server
        if $ServerStarted Then
            ; Allow viewer to disconnect to prevent schook.dll locking.
            MsgBox(0, 'Information', 'Please click OK and wait 15 seconds to allow ' & $LongName & ' to close correctly.' & @CRLF & 'Any currently connected Remote Support technicians should also close their Viewer now.', 15)

            ShellExecute($TempPath & '\' & $ShortName & 'Server.exe', '-kill')
            ; Remove files after server closes.
            ProcessWaitClose($ShortName & 'Server.exe', 30)
        EndIf

        _DeleteTemp()

        DisableUAC(False)  ; Restore the UAC prompt dialog setting

        Exit
    Else
        If $PinWindow Then WinSetOnTop($LongName, '', 1)  ; Re-Pin Window to the top of the Z-Order
    EndIf
EndFunc   ;==>doGuiClose

Func doLogoClicked()
    ShellExecute('http://' & $WebURL)
EndFunc   ;==>doLogoClicked

Func doServiceInstall()
    If IsNumber($ConnectId) Then
        If MsgBox(4, $LongName & ' Service Installation','The currently running ' & $LongName & ' session must first be closed.' & @CRLF & 'Are you sure you want to close ' & $LongName & '?') = 6 Then

            ; Allow viewer to disconnect to prevent schook.dll locking.
            MsgBox(0, 'Information', 'Please click OK and wait 15 seconds to allow ' & $LongName & ' to close correctly.' & @CRLF & 'Any currently connected Remote Support technicians should also close their Viewer now.', 15)

            ; Configure ultravnc.ini
            IniWrite($TempPath & "\ultravnc.ini", "admin", "service_commandline", '-autoreconnect ID:' & $ConnectId & ' -connect ' & $RepeaterAddress)

            ; Configure chunkvnc.ini
            IniWrite($TempPath & '\chunkvnc.ini', 'ChunkVNC', 'Path', @ProgramFilesDir & '\' & $LongName)
            IniWrite($TempPath & '\chunkvnc.ini', 'ChunkVNC', 'ID', $ConnectId)

            ; Exit the server.
            ShellExecute($TempPath & '\' & $ShortName & 'Server.exe', '-kill')

            ; Run installer after the server exits.
            ProcessWaitClose($ShortName & 'Server.exe', 30)

            ShellExecute($TempPath & '\' & $ShortName & 'ServiceInstaller.exe')

            DisableUAC(False)  ; Restore the UAC prompt dialog setting

            Exit
        EndIf
    Else
        MsgBox(0, 'Information', 'Invalid ID entered, service installation cancelled')
    EndIf
EndFunc     ;==>doServiceInstall


;**********************
;  Extract the Files  *
;*******************************************************************************
; Remove any leftovers.
DirRemove($TempPath, 1)

; Extract everything. (Note: Files need to be extracted before creating the GUI so that the Logo image can be added)
DirCreate($TempPath)
FileInstall('InstantSupport_Files\cad.exe', $TempPath & '\cad.exe', 1)
FileInstall('InstantSupport_Files\logo.jpg', $TempPath & '\logo.jpg', 1)
FileInstall('InstantSupport_Files\winvnc.exe', $TempPath & '\' & $ShortName & 'Server.exe', 1)
FileInstall('InstantSupport_Files\InstantSupportServiceInstaller.exe', $TempPath & '\' & $ShortName & 'ServiceInstaller.exe', 1)
FileInstall('InstantSupport_Files\schook.dll', $TempPath & '\schook.dll', 1)
FileInstall('InstantSupport_Files\rc4.key', $TempPath & '\rc4.key', 1)
FileInstall('InstantSupport_Files\MSRC4Plugin.dsm', $TempPath & '\MSRC4Plugin.dsm', 1)
FileInstall('InstantSupport_Files\ultravnc.ini', $TempPath & '\ultravnc.ini', 1)
FileInstall('InstantSupport_Files\chunkvnc.ini', $TempPath & '\chunkvnc.ini', 1)


;*******************
;  Create the GUI  *
;*******************************************************************************
$InstantSupport = GUICreate($LongName, $GuiWidth, $GuiHeight, -1, -1, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))

GUISetBkColor($BackgroundColor)

; Show Logo Image
$LogoPic = GUICtrlCreatePic($TempPath & '\logo.jpg', $LogoLeft, $LogoTop, $LogoWidth, $LogoHeight) ; , BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))

If $AllowLogoClick And $WebURL <> '' Then
    GUICtrlSetOnEvent(-1, 'doLogoClicked')
    GUICtrlSetCursor(-1, 0)
    GUICtrlSetTip(-1, 'Click here to open the ' & $BrandName & ' website')
EndIf

; Show Connection ID
;$ConnectIdLabel = GUICtrlCreateLabel('ID = ' & $ConnectId, 0, $LogoHeight, $GuiWidth, $IdHeight, $SS_CENTER)
;GUICtrlSetFont(-1, $IdFontSize, 800, 0, 'Arial Black', 2)
;GUICtrlSetColor(-1, $IdFontColor)
;GUICtrlSetBkColor(-1, $IdBackgroundColor)

GUISetState(@SW_SHOW)  ; Show the GUI

If $ConnectId <> 0 Then DrawConnectionId()  ; Display the Connection ID text, (must do this after showing GUI)

If $PinWindow Then WinSetOnTop($LongName, '', 1)  ; Pin the Window to the top of the Z-Order

GUISetOnEvent($GUI_EVENT_CLOSE, 'doGuiClose')


;*************************
;  Create the Tray Menu  *
;*******************************************************************************
TraySetClick(16)    ; Only secondary mouse button will show the tray menu.

$InstallItem = TrayCreateItem('Install ' & $LongName & ' Service')
TrayItemSetOnEvent($InstallItem, 'doServiceInstall')

TrayCreateItem('')  ; Menu divider

$ExitItem = TrayCreateItem('Exit')
TrayItemSetOnEvent($ExitItem, 'doGuiClose')

TraySetState()  ; Show the tray icon


;*****************************************
;  Main Application and Background Loop  *
;*******************************************************************************
; Read the address of the repeater from our settings file.
$RepeaterAddress = IniRead($TempPath & '\chunkvnc.ini', 'Repeater', 'Address', '')

DisableUAC(True)  ; Disable the UAC prompt dialog, (should only work if you have administrator privileges, but should save you clicking some buttons if you do)

; Background Loop
While True
    ; Close any windows firewall messages that popup. The windows firewall doesn't block outgoing connections anyways.
    if WinExists('Windows Security Alert') then WinClose('Windows Security Alert')

    If $ConnectId = 0 Then
        $TempConnectId = InputBox('Enter Your Connection ID', 'Connection ID:', $TempConnectId, '', 220, 40)

        if (@Error) Then doGuiClose()  ; Close the app if user cancels

        $ConnectId = Number($TempConnectId)
        If $ConnectId = 0 Or $ConnectId < $LowerLimit Or $ConnectId > $UpperLimit Then
            $ConnectId = 0
            MsgBox(0, 'Error', 'You must enter a numeric Connection ID between ' & $LowerLimit & ' and ' & $UpperLimit)
        EndIf

;       If $ConnectId <> 0 Then GUICtrlSetData($ConnectIdLabel, 'ID = ' & $ConnectId)
        If $ConnectId <> 0 Then DrawConnectionId()  ; Display the  Connection ID text
    EndIf

    ; Start the server and make a reverse connection to the repeater.
    If Not $ServerStarted And $ConnectId <> 0 And $ConnectId <> '' Then
        ShellExecute($TempPath & '\' & $ShortName & 'Server.exe', '-autoreconnect ID:' & $ConnectId & ' -connect ' & $RepeaterAddress & ' -run')
        If Not @error Then $ServerStarted = True
    EndIf

    Sleep(100)
WEnd

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I've also noticed that the LParam message cracking for the mouse X and Y coordinates is probably incorrect. I believe it should be:

;   $Y = BitShift($LParam, 16)
;   $X = BitAND($LParam, 0xFFFF)

However this then prevents the double-clicking on the ID Code from working, as described previously... another CLUE no doubt.

In fact it indicates that the logo image will not accept double-click messages, since the (incorrectly) calculated X-Y coordinates fortuitously happened to fall within the Logo bounding Rect thus triggering the code to un-pin the window.

This image was added with the following command:

$LogoPic = GUICtrlCreatePic($TempPath & '\logo.jpg', $LogoLeft, $LogoTop, $LogoWidth, $LogoHeight) ; , BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))

So perhaps something about that call to "GUICtrlCreatePic()" is causing the problem?

Edited by Rat

Share this post


Link to post
Share on other sites

Rat,

I may have the answer!

Firstly, you are reading the coordinates from your doLButtonDblClk handler the wrong way round! :party: Reversing them gives valid returns for doubleclicks both in and outside the logo area - as long as the logo is absent. This might well explain the apparently random nature of the handler firing!

However, if you create the logo you lose all the double clicks within the logo area - GUICtrlSetOnEvent obviously eats the second click as it fires on the first. :P So as your unpin code is only fired when the double click is within the logo area it never runs.

The problem is solved if you disable the pic control, but then you do not get the doLogoClicked function to fire. :party:

How about reversing the logic of the doLButtonDblClk code and unpinning the GUI when you click outside of the logo area? Then you could simplify the handler enormously (any doubleclick would fire the code as it woudl not refgister if on the logo) and you could still have the doLogoClickedfunction activated.

Over to you! :mellow:

M23

Edit:

I see we cross posted and you have realised the first part!


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi M23,

I had actually considered the possibility that the single click event may "mask" the double-click event so I had disabled the single-click event altogether during testing, (ie. $AllowLogoClick = False).

In hindsight however I suspect that even if I did manage to get the double-click event handling working successfully, then this may still interfere with single-clicking. This inspired me to attempt the following work-around where I used a timer in the single-click event to simulate double-click handling, (see code snippet below). Unfortunately, this didn't work... Windows still knows that a double-click has occurred and will not call the single-click event. I could possibly do this by setting a handler for the mouse down/up windows messages, but I am starting to consider code readability issues here, (since this is an open-source project), and may simply set a Hot Key instead.

Please feel free to investigate the whole double-clicking on images issue further, i suspect it could do with some closer inspection by the AutoIt community.

> How about reversing the logic of the doLButtonDblClk code and unpinning the GUI when you click outside of the logo area?

> Then you could simplify the handler enormously (any doubleclick would fire the code as it woudl not refgister if on the logo)

> and you could still have the doLogoClickedfunction activated.

In many cases the logo occupies the entire client area of the window so this isn't an option. :mellow:

ps. I also didn't want end-users to disable pinning with a single-click because in my experience the first thing that users tend to do is click the image, (its true... everyone does it!)

Cheers,

Rat.

[DOUBLE/SINGLE CLICK EVENT HANDLER]

Func doLogoClicked()
    If $PinWindow Then ; Only enable single-click handling if window is un-pinned
        $LogoClicked = Not $LogoClicked  ; Toggle double-click flag

        If $LogoClicked Then
            $DoubleClickTimer = TimerInit()
        Else
            $DoubleClickInterval = TimerDiff($DoubleClickTimer)
MsgBox(0, 'Debug', '$DoubleClickInterval = ' & $DoubleClickInterval)
            If $DoubleClickInterval <= 500 Then
                WinSetOnTop($LongName, '', 0)  ; Un-Pin the Window from the top of the Z-Order (Technician can do this after remoting in)
                $PinWindow = False
            Else
                $LogoClicked = False  ; Reset Double-Click handling
            EndIf
        EndIf
    ElseIf $AllowLogoClick And $WebURL <> '' Then
        ShellExecute('http://' & $WebURL)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

Rat,

This code recognises single and double clicks on a picture:

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

Global Const $iDoubleClickTime = _GetDoubleClickTime()

Global $iDoubleClicked = 0, $iClicked = 0

$hGUI = GUICreate("Test", 500, 500)

$hPic = GUICtrlCreatePic("Your_Pic_Path", 0, 0, 500, 250)
ConsoleWrite("CID = " & $hPic & @CRLF)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    Switch $iClicked
        Case $hPic
            $Begin = TimerInit()
            Do
                Switch $iDoubleClicked
                    Case $hPic
                        MsgBox(0, "", "DBLCLK on Pic")
                        $iDoubleClicked = 0
                        $iClicked = 0
                EndSwitch
            Until TimerDiff($Begin) > $iDoubleClickTime
            If $iClicked Then MsgBox(0, "", "CLK on Pic")
            $iClicked = 0
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    Local $nID = BitAND($wParam, 0xFFFF)

    Switch BitShift($wParam, 16) ; message code
        Case 0 ; $STN_CLICKED
            $iClicked = $nID
        Case 1 ; $STN_DBLCLK
            $iDoubleClicked = $nID
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc ;==>WM_COMMAND

Func _GetDoubleClickTime()
    Local $aResult = DllCall("user32.dll", "uint", "GetDoubleClickTime")
    If @error Then Return SetError(1,0,100)
    Return $aResult[0]
EndFunc

I hope it helps. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi Melba23,

Thanks for the code... I'm sorry I didn't reply earlier, I was called away for a couple of weeks and didn't notice the reply until today.

Before I left I did a quick fix using a Hot Key combination approach instead, and that seemed to cause no complaints. I have stored your code snippet away for future reference though :blink:

Cheers,

Rat.

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  
Followers 0