Page 1 sur 1

[R] faire signer les personnes sur tablette

Posté : sam. 15 oct. 2016 10:38
par yasen
Bonjour,

J'ai un projet ou je doit fait signer des personnes sur des tablettes windows.

J'aimerai savoir si il est possible de faire signer ces personnes sur une interface autoit, et d'enregistrer cette signature dans un fichier images temporaire. Je sais que le peut contrôler le point, mais j'aimerai l'intégrer directement dans cette interface.

Si ce n'est pas possible, auriez vous des pistes pour contourner cette difficulté.

Je vous en remercie par avance.

Yasen

Re: faire signer les personnes sur tablette

Posté : sam. 15 oct. 2016 17:42
par walkson
Quelque chose comme ça ?
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#Include <Misc.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
ToolTip(" Exit => Alt + x "  ,50,100,"EXIT",1)
_GDIPlus_Startup()
$iWidth = @DesktopWidth
$iHeight = @DesktopHeight
$hGUI = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 0x60)
GUISetState()

Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight,$hGraphic)
$g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
;~ _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
;_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
HotKeySet ( "!x" , "_Exit");alt x
OnAutoItExitRegister("_Exit")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI)

Global $om = MouseGetCursor()
GUISetCursor(3, 1, $hGUI)

While Sleep(100000)
WEnd

Func Draw()
   ToolTip("")
    Local Const $w = 8, $h = 8
    Local Const $w2 = $w / 2, $h2 = $h / 2
    Local $aMC
    Do
        ;GUISetCursor(5, 1, $hGUI)
        $aMPos = MouseGetPos()
        _GDIPlus_GraphicsFillRect($g_hGfxCtxt, $aMPos[0] - $w2, $aMPos[1] - $h2, $w, $h, $hBrush)
      _GDIPlus_GraphicsDrawImage($hGraphic,$hBitmap,0,0)
        $aMC = GUIGetCursorInfo($hGUI)
    Until Not $aMC[2]

EndFunc

Func _Exit()
   ;_GDIPlus_GetBitmapFromGraphic($hGUI, $iWidth, $iHeight)
   GUISetCursor($om, 1, $hGUI)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "")
   _GDIPlus_ImageSaveToFile($hBitmap,@DesktopDir & '\ESSAI_1.png')
   _GDIPlus_BitmapDispose($hBitmap)
   _GDIPlus_GraphicsDispose($g_hGfxCtxt)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc
    Func _GDIPlus_GetBitmapFromGraphic($hWnd, $iWidth, $iHeight)
        ;récupère l'image mais sur fond opaque
      Local Const $hDC = _WinAPI_GetDC($hWnd)
        Local Const $memDC = _WinAPI_CreateCompatibleDC($hDC)
        Local Const $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
        _WinAPI_SelectObject ($memDC, $memBmp)
        _WinAPI_BitBlt($memDC, 0, 0, $iWidth, $iHeight, $hDC, 0, 0, 0x00CC0020) ;  0x00CC0020 = $SRCCOPY
        Local Const $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp)
        _WinAPI_ReleaseDC($hWnd, $hDC)
        _WinAPI_DeleteDC($memDC)
        _WinAPI_DeleteObject($memBmp)
        _GDIPlus_ImageSaveToFile($hBitmap,@DesktopDir & '\ESSAI.png')
    EndFunc

Re: faire signer les personnes sur tablette

Posté : sam. 15 oct. 2016 19:38
par yasen
Bonsoir,

Merci pour votre réponse, test ça au plus vite et je reviens vers pour vous tenir au courant si c'est bon.

Re: faire signer les personnes sur tablette

Posté : dim. 16 oct. 2016 01:13
par orax
J'ai remplacé les rectangles par des lignes, sinon ça fait des pointillés.
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
ToolTip(" Exit => Alt + x ", 50, 100, "EXIT", 1)
_GDIPlus_Startup()
$iWidth = @DesktopWidth
$iHeight = @DesktopHeight
;~ $hGUI = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED)
$hGUI = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP)
GUISetBkColor(0xABCDEF)
;~ _WinAPI_SetLayeredWindowAttributes($hGUI, 0xFFFFFF, 0x60)

GUISetState()

Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
$g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
Global $hPen = _GDIPlus_PenCreate(0xFF000000, 4)

HotKeySet("!x", "_Exit");alt x
OnAutoItExitRegister("_Exit")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI)

Global $om = MouseGetCursor()
GUISetCursor(3, 1, $hGUI)

While Sleep(100000)
WEnd

Func Draw()
;~         ToolTip("")
   Local Const $w = 8, $h = 8
   Local Const $w2 = $w / 2, $h2 = $h / 2
   Local $aMC
   Local $aMPosOld = MouseGetPos()
   Do
      $aMC = GUIGetCursorInfo($hGUI)
      _GDIPlus_GraphicsDrawLine($g_hGfxCtxt, $aMPosOld[0], $aMPosOld[1], $aMC[0], $aMC[1], $hPen)
      _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
      $aMPosOld = $aMC
   Until Not $aMC[2]
EndFunc   ;==>Draw

Func _Exit()
   GUISetCursor($om, 1, $hGUI)
   GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "")
   _GDIPlus_ImageSaveToFile($hBitmap, @DesktopDir & '\ESSAI_1.png')
   _GDIPlus_BitmapDispose($hBitmap)
   _GDIPlus_GraphicsDispose($g_hGfxCtxt)
   _GDIPlus_PenDispose($hPen)
   _GDIPlus_GraphicsDispose($hGraphic)
   _GDIPlus_Shutdown()
   GUIDelete($hGUI)
   Exit
EndFunc   ;==>_Exit

Re: faire signer les personnes sur tablette

Posté : dim. 16 oct. 2016 11:25
par walkson
Bonjour,
En effet, le code ainsi est beaucoup plus véloce !
Petite précision: le code de base est du sieur Uez (forum us) modifié pour sauvegarder l'image

[Edit] l'ajout de
_GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
sous la variable $g_hGfxCtxt donne un trait beaucoup plus régulier

Re: faire signer les personnes sur tablette

Posté : dim. 16 oct. 2016 14:14
par orax
Oui, le trait est en effet de meilleur qualité avec GraphicsSetSmoothingMode (je l'ai ajouté dans le code).

Dans les modifications que j'avais apportées, j'avais retiré $WS_EX_LAYERED et _WinAPI_SetLayeredWindowAttributes parce que la GUI ne s'affichait pas (testé sur Windows 8.1) ; j'ai laissé ces lignes en commentaire.

Re: faire signer les personnes sur tablette

Posté : dim. 16 oct. 2016 16:38
par walkson
Dans les modifications que j'avais apportées, j'avais retiré $WS_EX_LAYERED et _WinAPI_SetLayeredWindowAttributes parce que la GUI ne s'affichait pas (testé sur Windows 8.1) ; j'ai laissé ces lignes en commentaire.
Je suis étonné car la semaine dernière, j'ai lancé, sur un Win 10, une gui sous cette forme (mon PC est sous win 7)
Global $hGUI = GUICreate("GDI+", $width, $height, 50, 5, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW)
sans aucun problème...
As tu essayé l'exemple de la fonction _WinAPI_SetLayeredWindowAttributes() ?

Re: faire signer les personnes sur tablette

Posté : dim. 16 oct. 2016 17:46
par orax
Je viens d'essayer sur un Windows 10, mais j'ai le même problème. Le curseur en forme de croix et la GUI (de couleur bleutée) ne s'affichent pas. Mais j'ai quand même essayé de dessiner quelque chose... ESSAI_1.png est créé sur le bureau, mais l'image est toute blanche.

Pour que la GUI s'affiche chez moi, j'ai besoin de changer la ligne _WinAPI_SetLayeredWindowAttributes. Quand je remplace 0xABCDEF par 0x010101 (par exemple), ça marche pour moi :
_WinAPI_SetLayeredWindowAttributes($hGUI, 0x010101, 0x60)
Je pense que l'exemple de la fonction _WinAPI_SetLayeredWindowAttributes fonctionne correctement.
Quand j'exécute le script d'exemple, si je clique sur "Transparent color 0xABCDEF (Checked) Or 0x010101", alors la GUI (sauf les contours) devient totalement transparente. Si je clique sur la zone transparente, ça ne clique pas sur la GUI mais sur la fenêtre en arrière plan.

Re: [R]faire signer les personnes sur tablette

Posté : lun. 17 oct. 2016 10:46
par yasen
Bonjour,

Je viens de tester et cela fonctionne à merveille, cela me permet un temps considérable sur mon projet.

Je vous en remercie énormément.

Yasen

Re: [..] faire signer les personnes sur tablette

Posté : lun. 17 oct. 2016 16:11
par yasen
Dernière petite question, j'essaye de mettre un bouton (jusque la, aucun problème), mais le bouton ne fonctionne pas.
je chercher sur le net, mais les exemples ressemble à ce que j'ai mis en place.
#include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <Misc.au3>
   #include <GuiToolTip.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    Opt("GUIOnEventMode", 1)

    ToolTip(" Exit => Alt + x ", 50, 100, "EXIT", 1)
    _GDIPlus_Startup()
    $iWidth = @DesktopWidth
    $iHeight = @DesktopHeight
    ;~ $hGUI = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED)
    $hGUI = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP)
    GUISetBkColor(0xABCDEF)
    ;~ _WinAPI_SetLayeredWindowAttributes($hGUI, 0xFFFFFF, 0x60)
    Local $idVal = GUICtrlCreateButton("Valider signature", (@DesktopWidth - 150), (@DesktopHeight - 80), 110, 30, $WS_GROUP)
    GUISetState(@SW_SHOW)

    Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
    Global $hPen = _GDIPlus_PenCreate(0xFF000000, 4)

    HotKeySet("!x", "_Exit");alt x
    OnAutoItExitRegister("_Exit")
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI)

    Global $om = MouseGetCursor()
    GUISetCursor(3, 1, $hGUI)

    Local $msg
    While 1
      $msg = GUIGetMsg()
      Switch $msg
      Case $idVal
         _Exit()
      EndSwitch
    WEnd

    Func Draw()
    ;~         ToolTip("")
        Local Const $w = 8, $h = 8
        Local Const $w2 = $w / 2, $h2 = $h / 2
        Local $aMC
        Local $aMPosOld = MouseGetPos()
        Do
            $aMC = GUIGetCursorInfo($hGUI)
            _GDIPlus_GraphicsDrawLine($g_hGfxCtxt, $aMPosOld[0], $aMPosOld[1], $aMC[0], $aMC[1], $hPen)
            _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
            $aMPosOld = $aMC
        Until Not $aMC[2]
    EndFunc   ;==>Draw

    Func _Exit()
        GUISetCursor($om, 1, $hGUI)
        GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "")
      _GDIPlus_ImageSaveToFile($hBitmap, 'system\tmp\_tmp_sig.bmp')
        _GDIPlus_ImageSaveToFile($hBitmap, 'system\tmp\_tmp_sig.png')
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_GraphicsDispose($g_hGfxCtxt)
        _GDIPlus_PenDispose($hPen)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
        GUIDelete($hGUI)
        Exit
    EndFunc   ;==>_Exit
Auriez vous une petite idée d'où pourrais provenir le problème ?

Re: [..] faire signer les personnes sur tablette

Posté : lun. 17 oct. 2016 16:21
par yasen
Oublié ma question c'est bon, j'ai ajouter
GUIRegisterMsg($WM_COMMAND, "_Exit")

Re: [..] faire signer les personnes sur tablette

Posté : lun. 17 oct. 2016 17:04
par orax
J'ai supprimé OnAutoItExitRegister("_Exit") parce que la fonction _Exit() est exécutée deux fois lors de la fermeture du script.
GUIGetMsg() ne fonctionne pas avec le mode GUIOnEventMode. Il faut utiliser GUICtrlSetOnEvent().
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <GuiToolTip.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

ToolTip(" Exit => Alt + x ", 50, 100, "EXIT", 1)
_GDIPlus_Startup()
$iWidth = @DesktopWidth
$iHeight = @DesktopHeight
;~ $hGUI = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED)
$hGUI = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP)
GUISetBkColor(0xABCDEF)
;~ _WinAPI_SetLayeredWindowAttributes($hGUI, 0xFFFFFF, 0x60)
Local $idVal = GUICtrlCreateButton("Valider signature", (@DesktopWidth - 150), (@DesktopHeight - 80), 110, 30, $WS_GROUP)
GUISetState(@SW_SHOW)

Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
$g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
Global $hPen = _GDIPlus_PenCreate(0xFF000000, 4)

HotKeySet("!x", "_Exit");alt x
GUICtrlSetOnEvent($idVal, "_Exit")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw")

Global $om = MouseGetCursor()
GUISetCursor(3, 1, $hGUI)

While 1
   Sleep(10000)
WEnd

Func Draw()
;~  ToolTip("")
   If @GUI_CtrlId = $idVal Then _Exit()

   Local Const $w = 8, $h = 8
   Local Const $w2 = $w / 2, $h2 = $h / 2
   Local $aMC
   Local $aMPosOld = MouseGetPos()
   Do
      $aMC = GUIGetCursorInfo($hGUI)
      _GDIPlus_GraphicsDrawLine($g_hGfxCtxt, $aMPosOld[0], $aMPosOld[1], $aMC[0], $aMC[1], $hPen)
      _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
      $aMPosOld = $aMC
   Until Not $aMC[2]
EndFunc   ;==>Draw

Func _Exit()
   GUISetCursor($om, 1, $hGUI)
   GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "")
   _GDIPlus_ImageSaveToFile($hBitmap, 'system\tmp\_tmp_sig.bmp')
   _GDIPlus_ImageSaveToFile($hBitmap, 'system\tmp\_tmp_sig.png')
   _GDIPlus_BitmapDispose($hBitmap)
   _GDIPlus_GraphicsDispose($g_hGfxCtxt)
   _GDIPlus_PenDispose($hPen)
   _GDIPlus_GraphicsDispose($hGraphic)
   _GDIPlus_Shutdown()
   GUIDelete($hGUI)
   Exit
EndFunc   ;==>_Exit

Re: [..] faire signer les personnes sur tablette

Posté : ven. 21 oct. 2016 09:58
par yasen
Bonjour,

J'ai effectué des tests sur une tablette sous windows 8, et la signature ne se fait pas fluidement et s'effectue avec des lignes.
J'ai réduit la taille de la fenêtre, cela améliore la fluidité et le dessin de la signature, mais j'aimerai savoir si on peut améliorer.

J'ai testé sur paint, aucun problème.

Merci pour vos lumières

Yasen