Jump to content



Photo

Newbie requiring help


  • Please log in to reply
10 replies to this topic

#1 jameswaugh

jameswaugh

    Seeker

  • New Members
  • 6 posts

Posted 18 August 2006 - 11:21 AM

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

AutoIt         
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, 18 August 2006 - 12:36 PM.






#2 JSThePatriot

JSThePatriot

    carpe diem. vita brevis.

  • MVPs
  • 3,686 posts

Posted 18 August 2006 - 11:46 AM

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 LinksFile-String Hash Plugin Updated! 04-02-08ComputerGetInfo UDF's Updated! 11-23-06External LinksVortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

#3 jameswaugh

jameswaugh

    Seeker

  • New Members
  • 6 posts

Posted 18 August 2006 - 12:32 PM

Preview Image is this

AutoIt         
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


#4 jameswaugh

jameswaugh

    Seeker

  • New Members
  • 6 posts

Posted 18 August 2006 - 12:33 PM

Get Clipboard

AutoIt         
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


#5 jameswaugh

jameswaugh

    Seeker

  • New Members
  • 6 posts

Posted 18 August 2006 - 12:34 PM

As i said i did get this from the Autoit forum i will find where i got it and post link to it as i cant fully remember what i searched for the first time.

got it from thisa forum so i will also ask in there

http://www.autoitscript.com/forum/index.php?showtopic=29920

Edited by jameswaugh, 18 August 2006 - 12:41 PM.


#6 JSThePatriot

JSThePatriot

    carpe diem. vita brevis.

  • MVPs
  • 3,686 posts

Posted 18 August 2006 - 12:46 PM

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 LinksFile-String Hash Plugin Updated! 04-02-08ComputerGetInfo UDF's Updated! 11-23-06External LinksVortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

#7 JSThePatriot

JSThePatriot

    carpe diem. vita brevis.

  • MVPs
  • 3,686 posts

Posted 18 August 2006 - 12:50 PM

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 LinksFile-String Hash Plugin Updated! 04-02-08ComputerGetInfo UDF's Updated! 11-23-06External LinksVortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

#8 jameswaugh

jameswaugh

    Seeker

  • New Members
  • 6 posts

Posted 18 August 2006 - 12:53 PM

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

#9 JSThePatriot

JSThePatriot

    carpe diem. vita brevis.

  • MVPs
  • 3,686 posts

Posted 18 August 2006 - 01:01 PM

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 LinksFile-String Hash Plugin Updated! 04-02-08ComputerGetInfo UDF's Updated! 11-23-06External LinksVortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

#10 eltorro

eltorro

    more or less the same as the latter of the former.

  • Active Members
  • PipPipPipPipPipPip
  • 596 posts

Posted 18 August 2006 - 03:21 PM

@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

#11 i386

i386

    Wayfarer

  • Active Members
  • Pip
  • 81 posts

Posted 19 August 2006 - 02:30 AM

Try pasting it in MSPaint using the hidden window function.
"...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." -Mozart_ONLINEPosted ImageCheck out this free 1 GB FTP website at DriveHQ.com. You can control the users and even publish a website for free!!Your-Start.com - A online website that you can customize to hold all you links, news information, and other website info.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users