Jump to content

Newbie requiring help


Recommended Posts

Hi

This is my first request for help so please be nice, i have only just started using Autoit and i need to capture a screen shot and save it with the file neam of machine number , user, date and time on a network drive.

I have used scripts that i have found on this forum and have got to the point where i press printscreen and it copies the screen to clipboard and previews it. This is where i get stuck as i can do a file save as but then that requires user input which is what i want to avoid. I know the text for the $filename is correct but i dont understand how to get it to put it as the file name and save it automatically. If that makes sense.

Thanks in advance :P

Func ContentHandler()
    Local $buffer
    Local $clipbmp = GetClipBoard($buffer)
    If $DEBUG Then
        _FileWriteLog($LOG, ";----------------------------------------------------------" & @LF)
        _FileWriteLog($LOG, "Begin Process: " & @error & @LF)
    EndIf
    If $DEBUG Then _FileWriteLog($LOG, "Getting Clipboard>" & @error & @LF)
    If $clipbmp Then
        If $DEBUG Then _FileWriteLog($LOG, "Captured Screen>" & @error & @LF)
        PreviewImage($buffer, $wide, $tall)
        
        FileSaveDialog ( "Save As" , "\\Wyjs_pdc\Flare\JWaugh" , "Images (*.jpg;*.bmp)")
        
        $filename = @UserName & " on " & @ComputerName & " at " & @HOUR & "." & @MIN & "." & @SEC & " on " & @MON & "-" & @MDAY & "-" & @YEAR & ".jpg"

    
    If $DEBUG Then _FileWriteLog($LOG, "Return Error Status: " & @error & @LF)
    EndIf
    If $DEBUG Then
        _FileWriteLog($LOG, "Exiting Now.  Bye." & @LF)
        _FileWriteLog($LOG, ";----------------------------------------------------------" & @LF & @LF)
    EndIf
    DeleteObject($clipbmp)
    $buffer = 0
EndFunc   ;==>ContentHandler
Edited by jameswaugh
Link to comment
Share on other sites

Welcome to the AutoIt community. Thank you for posting code and not just an open-ended question.

1. You forgot your closing [/autoit] tag.

2. There are some functions in your script that do not exist in AutoIt so to better underdstand what your script is doing at each location it would be required that I see these functions to further assist (GetClipBoard(), PreviewImage()).

Again thank you for posting your question. I hope to be able to help.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Preview Image is this

Func PreviewImage(ByRef $byteStruct, $wid, $hgt)
    ; Local Const $DIB_RGB_COLORS = 0
    ; Local Const $SRCCOPY = 0xCC0020
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    
    Local $preview = GUICreate("Preview", 500, 400, (@DesktopWidth - 500) / 2, (@DesktopHeight - 400) / 2)
    Local $pic = GUICtrlCreatePic("", 0, 0, $wid, $hgt)
    Local $pic_hWnd = DllCall("user32.dll", "hwnd", "GetDlgItem", "hwnd", $preview, "int", $pic)
    $pic_hWnd = $pic_hWnd[0]
    GUISetState()
    Local $lpInfo = DllStructCreate($tagBITMAPINFOHEADER & ";" & $tagBITS)
    
    DllStructSetData($lpInfo, 1, 40)
    DllStructSetData($lpInfo, 2, $wid)
    DllStructSetData($lpInfo, 3, $hgt)
    DllStructSetData($lpInfo, 4, 1)
    DllStructSetData($lpInfo, 5, $bpp)
    Local $dc = GetDC($pic_hWnd)
    if ($dc) Then
        ConsoleWrite("Dc>" & $dc & @LF)
        Local $hBitmap = CreateCompatibleBitmap($dc, $wid, $hgt)
        If $hBitmap Then
            ConsoleWrite("$hBitmap>" & $hBitmap & @LF)
            Local $v_ret = SetDIBits($dc, $hBitmap, 0, $hgt, DllStructGetPtr($byteStruct), DllStructGetPtr($lpInfo), $DIB_RGB_COLORS)
            if ($v_ret) Then
                ConsoleWrite("$v_ret>" & $v_ret & @LF)
                Local $vret = DllCall("user32.dll", "int", "SendMessage", "hwnd", $pic_hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "hwnd", $hBitmap)
                If $vret[0] Then ConsoleWrite("SendMessage>" & $v_ret[0] & @LF)
                
            EndIf
        EndIf
        Sleep(3000)
        GUIDelete($preview)
        ReleaseDC($pic_hWnd, $dc)
    EndIf
    $lpInfo = 0
EndFunc   ;==>PreviewImage
Link to comment
Share on other sites

Get Clipboard

Func GetClipBoard(ByRef $pbuf)
    Local $hBitmap;
    Local $hMyDC
    Local $bmBitmap = DllStructCreate($tagBITMAP)
    If $DEBUG Then _FileWriteLog($LOG, "DllStructCreate Error>" & $StructError[@error] & @LF)
    Local $Me = DllCall("user32.dll", "hwnd", "GetDesktopWindow")
    If IsArray($Me) Then
        OpenClipboard($Me[0])
        If (IsClipboardFormatAvailable($CF_BITMAP)) Then
            $hBitmap = GetClipboardData($CF_BITMAP)
            If ($hBitmap) Then
                GetObject($hBitmap, DllStructGetSize($bmBitmap), DllStructGetPtr($bmBitmap))
                For $x = 1 To 7
                    ConsoleWrite("BMP>" & $x & ">" & DllStructGetData($bmBitmap, $x) & @LF)
                Next
                
                $hMyDC = GetDC(0)
                If ($hMyDC) Then
                    Local $width = DllStructGetData($bmBitmap, 2)
                    Local $height = DllStructGetData($bmBitmap, 3)
                    Local $DIBHead = DllStructCreate($tagBITMAPINFOHEADER & ";" & $tagBITS)
                    DllStructSetData($DIBHead, 1, 40)
                    DllStructSetData($DIBHead, 2, $width)
                    DllStructSetData($DIBHead, 3, $height)
                    DllStructSetData($DIBHead, 4, 1)
                    $bpp = DllStructGetData($bmBitmap, 6)
                    If $bpp > 16 Then $bpp = 24
                    ConsoleWrite(">>$bbp>" & $bpp & @LF)
                    DllStructSetData($DIBHead, 5, $bpp)
                    
                    Local $iBitmap = CreateDIBSection($hMyDC, $DIBHead, $DIB_RGB_COLORS, 0, 0, 0)
                    Local $iSrc = CreateCompatibleDC(0)
                    Local $hOldObj = SelectObject($iSrc, $hBitmap)
                    Local $iDest = CreateCompatibleDC(0)
                    Local $hNewObj = SelectObject($iDest, $iBitmap)
                    if (DllStructGetData($DIBHead, 5) <= 8) Then
                        ;take the DFB's palette and set it to our DIB
                        ;not working with clipboard yet.
                        Local $hPalette = GetCurrentObject($iSrc, $OBJ_PAL);
                        if ($hPalette) Then
                            Local $pal = DllStructCreate("byte[1024]")
                            Local $nEntries = GetPaletteEntries($hPalette, 0, 256, DllStructGetPtr($pal));
                            if ($nEntries) Then
                                If $DEBUG Then ConsoleWrite("$nEntries:" & $nEntries & @LF)
                                For $x = 1 to ($nEntries * 4) Step 4
                                    DllStructSetData($pal, 1, 0, $x)
                                Next
                                ConsoleWrite(SetDIBColorTable($iDest, 0, $nEntries * 4, DllStructGetPtr($pal)) & @LF)
                            EndIf
                        EndIf
                    EndIf
                    BitBlt($iDest, 0, 0, $width, $height, $iSrc, 0, 0, $SRCCOPY)
                    $wide = DllStructGetData($DIBHead, 2)
                    $tall = DllStructGetData($DIBHead, 3)
                    Local $size = (((($wide * 32) + 31) / 32) * 4) * Abs($tall)
                    DllStructSetData($DIBHead, 7, $size)
                    ;                       $bmInfoHeader = DllStructCreate($tagBITMAPINFOHEADER, DllStructGetPtr($DIBHead, 1))
                    ConsoleWrite("byte[" & DllStructGetData($DIBHead, 7) & "]" & @LF)
                    $pbuf = DllStructCreate("byte[" & DllStructGetData($DIBHead, 7) & "]")
                    GetDIBits($iDest, $iBitmap, 0, $tall, DllStructGetPtr($pbuf), DllStructGetPtr($DIBHead), 0)
                Else
                    If $DEBUG Then _FileWriteLog($LOG, "Error retrieving Bitmap" & @LF)
                EndIf
                
                ; Release struct.
                CloseClipboard()
                ReleaseDC(0, $iSrc)
                DeleteDC($iSrc)
                ReleaseDC(0, $iDest)
                DeleteDC($iDest)
                DeleteObject($hBitmap)
                $hBitmap = $iBitmap
                DeleteObject($hOldObj)
                DeleteObject($hNewObj)
                ReleaseDC(0, $hMyDC)
                DeleteDC($hMyDC)
                $bmBitmap = 0
                $pal = 0
                $DIBHead = 0
                
                If $DEBUG Then _FileWriteLog($LOG, "Bitmap Retrieved" & @LF)
            Else
                If $DEBUG Then _FileWriteLog($LOG, "Error creating DC" & @LF)
            EndIf
            ;Return $iBitmap
            Return $hBitmap
        Else
            If $DEBUG Then _FileWriteLog($LOG, "No bitmap's in clipboard" & @LF)
        EndIf
    EndIf
    
EndFunc   ;==>GetClipBoard
Link to comment
Share on other sites

Hrm...Okay.

I am unsure how you are supposed to take it from that point and save it. Maybe a FileSaveAs() dialog box isnt the way to go.

Could you FileOpen() FileWrite() FileClose() using the binary data? That way it wouldnt require any intervention at all?

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Okay, I would recommend that you use the functions that are available in that thread. It already has where you can save it directly to a file.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Thankyou for that i will try it and look through the other post as i may have missed something that has been posted there.

You shouldnt need the PreviewImage() since you arent wanting user interaction. Just use the other functions. I think it is CreateDib() and SaveDibToFile().

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

@jameswaugh

please see this in your other post here.

eltorro.

You can comment these lines:

About line 94:

MsgBox($MB_OK + $MB_SYSTEMMODAL + $MB_TOPMOST, "Clipboard UDF", "The Clipboard has changed.",3)
oÝ÷ Ù©Ýiº.¶X§{]ºjëh×6
PreviewImage($buffer, $wide, $tall)

eltorro

Link to comment
Share on other sites

Try pasting it in MSPaint using the hidden window function.

Spoiler

 

"...Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like.My crime is that of outsmarting you, something that you will never forgive me for." --The Mentor

"Mess with the best, die like the rest!!" -Hackers

"This above all to thine own self be true." -William Shakespeare

"Corruption is only as corrupted as the individual makes it out to be." -i386

 

style7,AutoIt.png

 

 

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