hWnd_to_hBmp() : Capture full screen, Window, Control or user defined area of these

Post your working scripts, libraries and tools for AHK v1.1 and older
Turisas
Posts: 6
Joined: 04 Jul 2020, 15:21

Re: hWnd_to_hBmp() : Capture full screen, Window, Control or user defined area of these

Post by Turisas » 04 Jul 2020, 15:27

Does this function support that the cursor is also drawn?
Thanks for your help

MFG

Turisas

User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: hWnd_to_hBmp() : Capture full screen, Window, Control or user defined area of these

Post by SKAN » 05 Jul 2020, 08:43

Turisas wrote:Does this function support that the cursor is also drawn?
Hi Turisas,

Yes. But this feature is dependent on additional function DrawCursor()
The fourth parameter of hWnd_to_hBmp() requires a 3 element array consisting: IDC constant, X, Y
For example: hWnd_to_hBmp(,,, [0, X, Y]) where 0 will use the current cursor.
If you want to draw a different cursor say IDC_HAND, you may call like: hWnd_to_hBmp(,,, [32649, X, Y])
To determine X and Y you have to call MouseGetPos after setting CoordMode correctly.
List of IDC constants
 
 
 
...and you will also have to include the following function with your code

Code: Select all

DrawCursor( hDC, C:="" ) {                               ; By SKAN C/M on D295|D299 @ bit.ly/2lyG0sN
  C := IsObject(C) ? C : StrLen(C) ? StrSplit( C, ",", A_Space ) : {},   C.Res := 0
  C.1 := Round(C.1),  C.2 := Round(C.2),  C.3 := Round(C.3)
  
  If ! ( C.hCurs := C.1 ? DllCall( "LoadCursor", "Ptr",0, "Int",C.1, "Ptr" ) : 0 )
    {
        C.SetCapacity( "CURSORINFO", 24 ), C.Ptr := C.GetAddress( "CURSORINFO" )
        NumPut( A_PtrSize+16, C.Ptr, "UInt" )
        DllCall( "GetCursorInfo", "Ptr",C.Ptr )
        C.hCurs := NumGet(C.Ptr,8) 
    }
  
  If ( C.hIcon := C.hCurs ? DllCall( "CopyIcon", "Ptr",C.hCurs, "Ptr" ) : 0  )
    {
        C.SetCapacity( "ICONINFO", 32 ),  C.Ptr := C.GetAddress( "ICONINFO" ) 
        DllCall( "GetIconInfo", "Ptr",C.hIcon, "Ptr",C.Ptr )
        C.xHot := NumGet( C.Ptr+4, "UInt" ),   C.hbmMask  := NumGet( C.Ptr, A_PtrSize=8 ? 16:12 )   
        C.yHot := NumGet( C.Ptr+8, "UInt" ),   C.hbmColor := NumGet( C.Ptr, A_PtrSize=8 ? 24:16 )

	      C.Res  := DllCall( "DrawIcon", "Ptr",hDC, "Int",C.2-C.xHot, "Int", C.3-C.yHot, "Ptr",C.hCurs )  

	      DllCall( "DestroyIcon",  "Ptr", C.hCurs )
	      DllCall( "DeleteObject", "Ptr", C.hbmMask )
	      DllCall( "DeleteObject", "Ptr", C.hbmColor )
     }
Return C.Res              
}
My Scripts and Functions: V1  V2

Turisas
Posts: 6
Joined: 04 Jul 2020, 15:21

Re: hWnd_to_hBmp() : Capture full screen, Window, Control or user defined area of these

Post by Turisas » 05 Jul 2020, 09:26

I thank you it worked. :D


MFG
Turisas.

User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: hWnd_to_hBmp() : Capture full screen, Window, Control or user defined area of these

Post by SKAN » 05 Jul 2020, 15:22

Turisas wrote:
05 Jul 2020, 09:26
I thank you it worked. :D
Thanks for the feedback. :)
My Scripts and Functions: V1  V2

Post Reply

Return to “Scripts and Functions (v1)”