Jump to content

Auto3Lib


PaulIA
 Share

Recommended Posts

Weird. The example you posted works fine to paste into Paint, but not for MS-Word. Normally I generate a word document explaining an error message that I send to the Developers. The example above won't let me paste into Word, just Paint. Weird. Oh and I REMed out the last 4 lines and it still has the problems.

Mike

It's probably because you have other items on you clipboard. Word works with the clip board differently than Paint. Try this out:

#include <A3LScreenCap.au3>

Global Const $CF_BITMAP = 2

Global $hBMP, $aResult

$hBMP = _ScreenCap_Capture("")

$aResult = DllCall("User32.dll", "int", "OpenClipboard", "hwnd", 0)
if $aResult[0] = 0 then _Lib_ShowError("OpenClipboard failed")
$aResult = DllCall("User32.dll", "int", "EmptyClipboard")
if $aResult[0] = 0 then _Lib_ShowError("EmptyClipboard failed")
$aResult = DllCall("User32.dll", "int", "SetClipboardData", "uint", $CF_BITMAP, "hwnd", $hBMP)
if $aResult[0] = 0 then _Lib_ShowError("SetClipboardData failed")
$aResult = DllCall("User32.dll", "int", "CloseClipboard")
if $aResult[0] = 0 then _Lib_ShowError("CloseClipboard failed")

Run("C:\Program Files\Microsoft Office\OFFICE11\WinWord.exe")
WinWaitActive("Document1 - Microsoft Word")
Send("!eP")

_API_DeleteObject($hBMP)
Edited by PaulIA
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

That clipboard function works great, but in order to save as a file & send to clipboard you have to call the function twice.

I have edited your function to include the clipboard code so you can save to file & clipboard with only one call.

; #FUNCTION# ====================================================================================================================
; Description ...: Captures a region of the screen
; Parameters ....: $sFileName   - Full path and extension of the bitmap file to be saved
;                  $iLeft       - X coordinate of the upper left corner of the rectangle
;                  $iTop        - Y coordinate of the upper left corner of the rectangle
;                  $iRight      - X coordinate of the lower right corner of the rectangle.  If this is  -1,  the  current  screen
;                  +width will be used.
;                  $iBottom     - Y coordinate of the lower right corner of the rectangle.  If this is  -1,  the  current  screen
;                  +height will be used.
;                  $fCursor     - If True the cursor will be captured with the image
;                  $fClip         - If True the Captured image will be sent to the clipboard
; Return values .:
; Author ........: Paul Campbell (PaulIA)
; Remarks .......: If FileName is not blank this function will capture the screen and save it as a bitmap file.  If  FileName  is
;                  blank, this function will capture the screen and return a HBITMAP handle to the bitmap image.  In  this  case,
;                  after you are finished with the bitmap you must call _API_DeleteObject to delete the bitmap handle.
; Related .......: _API_DeleteObject, _ScreenCap_SaveBitmap
; ===============================================================================================================================
Func _ScreenCap_Capture($sFileName, $iLeft=0, $iTop=0, $iRight=-1, $iBottom=-1, $fCursor=True, $fClip=False)
  Local $iH, $iW, $hWnd, $hDDC, $hCDC, $hBMP, $aCursor, $aIcon, $hIcon, $aResult


  if $iRight  = -1 then $iRight  = _API_GetSystemMetrics($SM_CXSCREEN)
  if $iBottom = -1 then $iBottom = _API_GetSystemMetrics($SM_CYSCREEN)
  if $iLeft   < 0      then $iLeft   = 0
  if $iTop    < 0      then $iTop    = 0
  if $iRight  < $iLeft then $iRight  = $iLeft + 1
  if $iBottom < $iTop  then $iBottom = $iTop  + 1

  $iW   = $iRight  - $iLeft
  $iH   = $iBottom - $iTop
  $hWnd = _API_GetDesktopWindow()
  $hDDC = _API_GetDC($hWnd)
  $hCDC = _API_CreateCompatibleDC($hDDC)
  $hBMP = _API_CreateCompatibleBitmap($hDDC, $iW, $iH)
  _API_SelectObject($hCDC, $hBMP)
  _API_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, $SRCCOPY)

  if $fCursor then
    $aCursor = _API_GetCursorInfo()
    if $aCursor[1] then
      $hIcon = _API_CopyIcon($aCursor[2])
      $aIcon = _API_GetIconInfo($hIcon)
      _API_DrawIcon($hCDC, $aCursor[3] - $aIcon[2], $aCursor[4] - $aIcon[3], $hIcon)
    endif
  endif

  _API_ReleaseDC($hWnd, $hDDC)
  _API_DeleteDC($hCDC)
  if $fClip = True Then
     $aResult = DllCall("User32.dll", "int", "OpenClipboard", "hwnd", 0)
     if $aResult[0] = 0 then _Lib_ShowError("OpenClipboard failed")
     $aResult = DllCall("User32.dll", "int", "EmptyClipboard")
     if $aResult[0] = 0 then _Lib_ShowError("EmptyClipboard failed")
     $aResult = DllCall("User32.dll", "int", "SetClipboardData", "uint", $CF_BITMAP, "hwnd", $hBMP)
     if $aResult[0] = 0 then _Lib_ShowError("SetClipboardData failed")
     $aResult = DllCall("User32.dll", "int", "CloseClipboard")
     if $aResult[0] = 0 then _Lib_ShowError("CloseClipboard failed")
  EndIf
  if $sFileName = "" then Return $hBMP

  _ScreenCap_SaveBitmap($sFileName, $hBMP)
EndFunc
Link to comment
Share on other sites

That clipboard function works great, but in order to save as a file & send to clipboard you have to call the function twice.

I have edited your function to include the clipboard code so you can save to file & clipboard with only one call.

Just call _ScreenCap_Capture without a file name and it returns the bitmap handle. You can then use the code that I supplied to either send to the clipboard or call _ScreenCap_SaveBitmap to save the bitmap to file (or both).

As a preference, I don't like doing both at the same time as it's not obvious to the user that we're clearing the clipboard and pushing a bitmap onto the stack. I can just envision all the "it don't work" posts that I'll get. :shocked:

I have the Clipboard functions on my "to do" list, so when I get them done the code will go something like:

#include <A3LClipBoard.au3>
#include <A3LScreenCap.au3>

Global $hBMP, $aResult

$hBMP = _ScreenCap_Capture("")
_ClipBoard_PutBitmap($hBMP)
_ScreenCap_SaveToImage("C:\Pic.jpg", $hBMP)
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

This release includes the introduction of the GDI+ API calls to allow saving screen captures in formats other than BMP. The A3LScreenCap module can now save screen shots in BMP, GIF, JPG, PNG and TIF formats. The _ScreenCap_Capture parameters are the same, so this change will be transparent to existing code. To save to a format other than BMP, just change the extension of the file name passed to _ScreenCap_Capture. For example, to save the screen capture in JPG format:

_ScreenCap_Capture("C:\Pic.jpg")
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

When using the latest version and saving the Screenshot to a BMP file, the image opens fine in PAINT but when displaying that file in AutoIT it is jumbled.

Example:

#include <GUIConstants.au3>
#include <A3LScreenCap.au3>

Global Const $CF_BITMAP = 2
$SaveFile = "D:\Temp\BMPSave.BMP"

;Perform the Full Screen Capture
$hBMP = _ScreenCap_Capture($SaveFile)

$hFinished = GuiCreate("Saved as:  ", 900, 520, -1, -1, $WS_CAPTION)
GUICtrlCreatePic($SaveFile, 0, 0, 800, 500)
GuiSetState()
while 1
    sleep(10)
WEnd

Mike

Link to comment
Share on other sites

When using the latest version and saving the Screenshot to a BMP file, the image opens fine in PAINT but when displaying that file in AutoIT it is jumbled.

Example:

#include <GUIConstants.au3>
#include <A3LScreenCap.au3>

Global Const $CF_BITMAP = 2
$SaveFile = "D:\Temp\BMPSave.BMP"

;Perform the Full Screen Capture
$hBMP = _ScreenCap_Capture($SaveFile)

$hFinished = GuiCreate("Saved as:  ", 900, 520, -1, -1, $WS_CAPTION)
GUICtrlCreatePic($SaveFile, 0, 0, 800, 500)
GuiSetState()
while 1
    sleep(10)
WEndoÝ÷ ØȤ{ú®¢×«ÞmÂäyÙ®r"¶axe
Úå
·µãâqÊ'¶º%!©pk+#ºË]­¬-è¦j¬+öî´ý²È§ØZ¶+]¡ë'ßÛlq©^f zËh~+X¢éÞyÛh©²êÞ¶¬r·Æ©¶êÞ²,ÞÉm
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

I downloaded a sample .bmp file from the internet and it resizes fine.

The .bmp image resize/display through guictrlcreatepic worked fine prior to your new GDI release.

#include <GUIConstants.au3>
#include <A3LScreenCap.au3>

Global Const $CF_BITMAP = 2
$SaveFile = "C:\Sample.bmp"

;Perform the Full Screen Capture
;~ $hBMP = _ScreenCap_Capture($SaveFile)

$hFinished = GuiCreate("Saved as:  ", 900, 520, -1, -1, $WS_CAPTION)
$img = GUICtrlCreatePic($SaveFile, 0, 0, 200, 100)
GUICtrlSetImage($img, $SaveFile)
GuiSetState()
while 1
    sleep(10)
WEnd
Link to comment
Share on other sites

I downloaded a sample .bmp file from the internet and it resizes fine.

The .bmp image resize/display through guictrlcreatepic worked fine prior to your new GDI release.

#include <GUIConstants.au3>
#include <A3LScreenCap.au3>

Global Const $CF_BITMAP = 2
$SaveFile = "C:\Sample.bmp"

;Perform the Full Screen Capture
;~ $hBMP = _ScreenCap_Capture($SaveFile)

$hFinished = GuiCreate("Saved as:  ", 900, 520, -1, -1, $WS_CAPTION)
$img = GUICtrlCreatePic($SaveFile, 0, 0, 200, 100)
GUICtrlSetImage($img, $SaveFile)
GuiSetState()
while 1
    sleep(10)
WEnd
Not sure what to tell you. I can manually load/draw the captured bitmap using the LoadImage/BitBlt API calls. I can also load the bitmap in every graphics program that I have (PhotoShop, CorelDraw, Paint, etc.). In fact, the only place that I've found that it doesn't work is in AutoIt (and only if the image is larger than the control). There are different types of bitmap formats, so I'm guessing that AutoIt can't scale the type that is produced by the internal Windows codecs.

Edit: Not sure if this is the problem, but the previous version of _ScreenCap_SaveBitmap and your sample bitmap are both 24 bit images. The GDI+ version outputs a 32 bit image. Might want to see if you can find a 32 bit sample and see if it resizes in AutoIt.

Edit: After doing some testing, it appears that AutoIt can't resize certain types of 32 bit images created by GDI+. I'm working on an addition to the ScreenCap module that will allow you to specify the pixel format of the image. Should be done shortly.

Edited by PaulIA
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

I put out a new version that allows you to set the bits per pixel when saving a BMP file. It will default to 24 bpp if not explicitly set. I have tested all of the bpp settings presented in _ScreenCap_SetBMPFormat and AutoIt appears to be able to scale them all properly.

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Running this code:

#include <A3LScreenCap.au3>


_ScreenCap_Capture("c:\a.bmp", 5,10,215,80, true )

Exit

I get an error:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Autoit Scripts\test.au3"  
C:\Program Files\AutoIt3\Include\A3LWinAPI.au3 (1195) : ==> Variable must be of type "Object".: 
$tCursor.Size = $iCursor 
$tCursor^ ERROR
>Exit code: 0   Time: 0.441
Link to comment
Share on other sites

Running this code:

#include <A3LScreenCap.au3>
_ScreenCap_Capture("c:\a.bmp", 5,10,215,80, true )

Exit

I get an error:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Autoit Scripts\test.au3"  
C:\Program Files\AutoIt3\Include\A3LWinAPI.au3 (1195) : ==> Variable must be of type "Object".: 
$tCursor.Size = $iCursor 
$tCursor^ ERROR
>Exit code: 0   Time: 0.441
You don't have the latest beta version of AutoIt installed. Auto3Lib requires the new DllStruct changes.
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

This time same code paul,

Error:

_API_CreateCompatibleBitmap: The operation completed successfully.

(OK only)

After that no bitmap is created the script just closes and thats that.

I just found out a while ago that there has been some change in the latest beta version where it doesn't like formatted return results. I have removed these from all the Auto3Lib functions and put out a new version. Let me know if you spot anything else.
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Hi PailIA.

I just used your library in my large work script/program (for treeview manipulation) and it's really GREAT :shocked:

All is working fine - so no problem to report here.

Only one little cosmetic in description/comment for _Listbox_FindTextExact():

; Description ..: Find the first string in a list box that begins with the exact specified stringoÝ÷ ÚÈhºW[y«­¢+ØìÍÉ¥ÁÑ¥½¸¸¸è¥¹Ñ¡¥ÉÍÐÍÑÉ¥¹¥¸±¥ÍнàѡС̥ÐÌäíÌÑáÐáѱäѡ͵ÌÍÁ¥¥ÍÑÉ¥¹
Link to comment
Share on other sites

Hi PaulIA.

I just used your library in my large work script/program (for treeview manipulation) and it's really GREAT :shocked:

All is working fine - so no problem to report here.

Great!

Hi PauIA.

Only one little cosmetic in description/comment for _Listbox_FindTextExact():

; Description ..: Find the first string in a list box that begins with the exact specified stringoÝ÷ ÚÈhºW[y«­¢+ØìÍÉ¥ÁÑ¥½¸¸¸è¥¹Ñ¡¥ÉÍÐÍÑÉ¥¹¥¸±¥ÍнàѡС̥ÐÌäíÌÑáÐáѱäѡ͵ÌÍÁ¥¥ÍÑÉ¥¹
Right you are. Fixed for the next release. Thanks for reporting this.
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

I agree, but the TabControl is fairly limited right out of the box. You have to add a ton of code to it to do what you see in AutoIt. I will get around to deriving a control that does what you want, but just not right now. :shocked:

Thanks!

BTW: Congratulation on the sticky. Great code! I am using part of it.

I will credential your name.

Edited by lsakizada

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...