Jump to content

Picture not stable on my GUI


Valnurat
 Share

Recommended Posts

Hi guys.

I'm not sure why my picture is not stable on my GUI. The picture is loading just fine from Active Directory, but suddenly the picture is gone. I don't know if it is the screen is updating or something.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=FindComputer.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <ScreenCapture.au3>
#include <GuiStatusBar.au3>
#include <AD.au3>
#include <ListBoxConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

$cEnterPressed = GUICtrlCreateDummy()
Global $hGUI, $hBitmap, $hBitmap_Scaled, $hGraphics, $sUserName
Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]];x <<<<<<<<<<<<<<<<<<<<<<<<< accelerator  ON
GUISetAccelerators($aAccelKeys);x

_GDIPlus_Startup()
Local Const $iWidth = 300, $iHeight = 305, $aParts[3] = [75, 185, -1], $iBgColor = 0xFFE8FF, $ahIcons[3] = [109,131,144] ;$iBgColor format RRGGBB
Local Const $sServerName = "Servername", $sSiteCode = "PEN"
Local $oSWBEMLoc = ObjCreate("WbemScripting.SWbemLocator")
Local $oConnectSrv = $oSWBEMLoc.ConnectServer($sServerName, "root\SMS\site_" & $sSiteCode)
$hGUI = GUICreate("Find Computer", $iWidth, $iHeight, -1, -1) ;create a test gui to display the resized image
;GUISetBkColor($iBgColor, $hGUI) ;set GUI background color
GUICtrlCreateLabel("Enter shortname of user:",110, 5)
$idShortName = GUICtrlCreateInput("", 110, 20, 185, 20) ; First
GUICtrlCreateLabel("Name:",110, 42)
$idName = GUICtrlCreateInput("", 110, 55, 185, 20) ; First
GUICtrlSetState($idName,$gui_disable)
GUICtrlCreateLabel("Email:",110, 80)
$idEmail = GUICtrlCreateInput("", 110, 93, 185, 20) ; First
GUICtrlSetState($idEmail,$gui_disable)
GUICtrlCreateLabel("Manager:",110, 115)
$idManager = GUICtrlCreateInput("", 110, 130, 185, 20) ; First
GUICtrlSetState($idManager,$gui_disable)

GUICtrlCreateLabel("MODEL:",110, 160)
$ComputerModel = GUICtrlCreateLabel("",160, 160, 100,40)

GUICtrlCreateLabel("S/N:",110, 180)
$SN = GUICtrlCreateLabel("",160, 180,100,40)

GUICtrlCreateLabel("BIOS:",110, 200)
$BIOS = GUICtrlCreateLabel("",160, 200,100,40)

GUICtrlCreateLabel("MAC:",110, 220)
$MAC = GUICtrlCreateLabel("",160, 220,100,40)

GUICtrlCreateLabel("OWNER:",110, 240)
$OWNER = GUICtrlCreateLabel("",160, 240,100,40)

$idListBox = GUICtrlCreateList("", 4, 155, 101, 125)
$hWndListBox = GUICtrlGetHandle($idListBox)

$g_hStatus = _GUICtrlStatusBar_Create($hGUI)
;_GUICtrlStatusBar_SetParts($g_hStatus, 75,150,-1)
_GUICtrlStatusBar_SetParts($g_hStatus, $aParts)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)

$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
Local $hPen = _GDIPlus_PenCreate()
_GDIPlus_GraphicsDrawRect($hGraphics, 4, 4, 100, 145)
Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFF0F0F0);0xFFEE88BB
_GDIPlus_GraphicsFillRect($hGraphics, 5, 5, 99, 144, $hBrush)
$hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
$tLayout = _GDIPlus_RectFCreate(15, 70, 100, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphics, "No Image", $hFont, $tLayout, $hFormat, $hBrush)
;$tLayout = _GDIPlus_RectFCreate(110, 170, 200, 20)
;_GDIPlus_GraphicsDrawStringEx($hGraphics, "Model:", $hFont, $tLayout, $hFormat, $hBrush)
_AD_Open()
$fAction = 0
$sLastSel = ""
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $idShortName  ; Dummy
;           $sUserName = GUICtrlRead ( $idShortName )
            Local $sSamAccountNameToFQDN = _AD_SamAccountNameToFQDN(GUICtrlRead ( $idShortName ))
            Local $aResult = _AD_GetObjectAttribute($sSamAccountNameToFQDN, 'thumbnailPhoto')
            If @error Then
                Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFF0F0F0);0xFFEE88BB
                _GDIPlus_GraphicsFillRect($hGraphics, 5, 5, 99, 144, $hBrush)
                $hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
                $hFormat = _GDIPlus_StringFormatCreate()
                $hFamily = _GDIPlus_FontFamilyCreate("Arial")
                $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
                $tLayout = _GDIPlus_RectFCreate(15, 70, 100, 20)
                _GDIPlus_GraphicsDrawStringEx($hGraphics, "No Image", $hFont, $tLayout, $hFormat, $hBrush)
            Else
;               $hBitmap = _GDIPlus_BitmapCreateFromMemory(_AD_GetObjectAttribute(GUICtrlRead ( $idShortName ), 'thumbnailPhoto')) ;load binary saved GIF image and convert it to GDI+ bitmap format
                $hBitmap = _GDIPlus_BitmapCreateFromMemory($aResult) ;load binary saved GIF image and convert it to GDI+ bitmap format
                $hBitmap_Scaled = _GDIPlus_ImageResize($hBitmap, 99, 144) ;resize image
                _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, 5, 5) ;display scaled image
            EndIf
            GUICtrlSetData($idName,_AD_GetObjectAttribute($sSamAccountNameToFQDN, 'cn'))
            GUICtrlSetData($idEmail,_AD_GetObjectAttribute($sSamAccountNameToFQDN, 'mail'))
            local $sManager = _AD_GetObjectAttribute($sSamAccountNameToFQDN, 'manager')
            GUICtrlSetData($idManager,StringMid($sManager,4,StringInStr($sManager,',')-4))
            Local $aComputerOwner = _AD_GetObjectsInOU("OU=companyname,DC=AD,DC=companyname,DC=ORG","(&(objectclass=computer)(managedby=" & $sSamAccountNameToFQDN & "))",Default,"cn")
            GUICtrlSetData($SN,"")
            GUICtrlSetData($BIOS,"")
            GUICtrlSetData($ComputerModel,"")
            GUICtrlSetData($MAC,"")
            GUICtrlSetData($OWNER,"")
            If IsArray($aComputerOwner) Then
                GUICtrlSetData($idListBox, "")
                For $x = 1 to UBound($aComputerOwner)-1
                    GUICtrlSetData($idListBox, $aComputerOwner[$x])
                Next
            EndIf
    EndSwitch

    If GUICtrlRead($idListBox) <> $sLastSel Then
        $sLastSel = GUICtrlRead($idListBox)
        ; Wait to see if there is a double click
        Sleep(150)
        If $fAction = 1 Then
            if FileExists(@ProgramFilesDir & "\SolarWinds\DameWare Remote Support\DWRCC.exe") Then
                Run(@ComSpec & ' /c ' & '"' & @ProgramFilesDir & '\SolarWinds\DameWare Remote Support\DWRCC.exe -c: -m:' & GUICtrlRead($idListBox) & ' -u:' & StringUpper(@UserName) & '_SA"',"", @SW_HIDE)
            Else
                if FileExists(@WindowsDir & "\system32\msra.exe") Then
                    Run(@ComSpec & ' /c ' & 'msra /offerra ' & GUICtrlRead($idListBox) ,"", @SW_HIDE)
                Else
                    MsgBox(0, "", "You can't remote!")
                EndIf
            EndIf
            $fAction = 0
        Else
            Local $ComputerName = GUICtrlRead($idListBox)
            Local $iPing = Ping($ComputerName,250)
            If $iPing Then ; If a value greater than 0 was returned then display the following message.
                _GUICtrlStatusBar_SetText($g_hStatus, "Online")
                _GUICtrlStatusBar_SetIcon($g_hStatus, 0, _WinAPI_LoadShell32Icon($ahIcons[2]))
                $sQuery = "SELECT * FROM SMS_G_System_COMPUTER_SYSTEM Where Name='" & $ComputerName & "'"
                $oComputers = $oConnectSrv.ExecQuery($sQuery)
                GUICtrlSetData($ComputerModel,"")
                GUICtrlSetData($ComputerModel,$oComputers.itemindex(0).Model)
                $sQuery = "SELECT * FROM SMS_G_System_PC_BIOS Where RESOURCEID='" & $oComputers.itemindex(0).ResourceId & "'"
                $oBIOS = $oConnectSrv.ExecQuery($sQuery)
                GUICtrlSetData($SN,"")
                GUICtrlSetData($SN,$oBIOS.itemIndex(0).SerialNumber)
                GUICtrlSetData($BIOS,"")
                GUICtrlSetData($BIOS,$oBIOS.itemIndex(0).SMBIOSBIOSVersion)
                $sQuery = "SELECT * FROM SMS_R_System Where RESOURCEID='" & $oComputers.itemindex(0).ResourceId & "'"
                $oRSystems = $oConnectSrv.ExecQuery($sQuery)
                Local $aTmp = $oRSystems.itemindex(0).MACAddresses
                GUICtrlSetData($MAC,"")
                GUICtrlSetData($MAC,_ArrayToString ($aTmp))
                GUICtrlSetData($OWNER,"")
;                   $sManager = StringLeft($sManager,StringInStr($sManager,",")-1)

                GUICtrlSetData($OWNER,StringMid(StringLeft($oRSystems.itemindex(0).managedBy,StringInStr($oRSystems.itemindex(0).managedBy,",")-1),4))
            Else
                GUICtrlSetData($SN,"")
                GUICtrlSetData($BIOS,"")
                GUICtrlSetData($ComputerModel,"")
                GUICtrlSetData($MAC,"")
                GUICtrlSetData($OWNER,"")
                _GUICtrlStatusBar_SetText($g_hStatus, "Offline")
;               $ahIcons[1] = _WinAPI_LoadShell32Icon($ahIcons[1])
                _GUICtrlStatusBar_SetIcon($g_hStatus, 0, _WinAPI_LoadShell32Icon($ahIcons[1]))
            EndIf
        EndIf
        $fAction = 0
    Else
        If $fAction = 1 Then
            if FileExists(@ProgramFilesDir & "\SolarWinds\DameWare Remote Support\DWRCC.exe") Then
                Run(@ComSpec & ' /c ' & '"' & @ProgramFilesDir & '\SolarWinds\DameWare Remote Support\DWRCC.exe -c: -m:' & GUICtrlRead($idListBox) & ' -u:' & StringUpper(@UserName) & '_SA"',"", @SW_HIDE)
            Else
                if FileExists(@WindowsDir & "\system32\msra.exe") Then
                    Run(@ComSpec & ' /c ' & 'msra /offerra ' & GUICtrlRead($idListBox) ,"", @SW_HIDE)
                Else
                    MsgBox(0, "", "You can't remote!")
                EndIf
            EndIf
            $fAction = 0
        EndIf
    EndIf
WEnd
_AD_Close()

;cleanup resources
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BitmapDispose($hBitmap_Scaled)
_GDIPlus_Shutdown()
GUIDelete($hGUI)

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

    #forceref $hWnd, $iMsg

    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

    $hWndFrom = $lParam
    $iCode = BitShift($wParam, 16) ; Hi Word

    Switch $hWndFrom
        Case $hWndListBox
            Switch $iCode
                Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
                    $fAction = 1
            EndSwitch
    EndSwitch

EndFunc

 

Yours sincerely

Kenneth.

Link to comment
Share on other sites

Generally you have to do all drawing/painting to memory bitmap and 

in WM_PAINT event (see GUIRegisterMsg function) do Bitblt from memory bitmap to canvas of your window.

 

Search his forum for "WM_PAINT" keyword for many existing examples for this ...

 

Here is one of my old "Radar" project where I use this technique to paint red cross over image/picture

 

Edited by Zedna
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...