Jump to content

Recommended Posts

Posted (edited)

In relation to:

 

 

 @argumentum and @Nine could you be so nice and check mine modification from:

https://github.com/ioa747/NetWebView2Lib/pull/104/changes

Func __NetWebView2_freezer($oWebV2M, ByRef $idPic)
    Local $hWindow_WebView2 = WinGetHandle($oWebV2M.BrowserWindowHandle)
    #Region ; if $idPic is given then it means you already have it and want to delete it - unfreeze - show WebView2 content
    If $idPic Then
        WinSetState($hWindow_WebView2, '', @SW_SHOW)
        GUICtrlDelete($idPic)
        $idPic = 0
        Return
    EndIf
    #EndRegion ; if $idPic is given then it means you already have it and want to delete it - unfreeze - show WebView2 content

    #Region ; freeze $hWindow_WebView2

    #Region ; add PIC to parent window
    Local $hWindow_Parent = WinGetHandle($oWebV2M.ParentWindowHandle)
    Local $aPos = WinGetPos($hWindow_WebView2)
    Local $hPrev = GUISwitch($hWindow_Parent)
    $idPic = GUICtrlCreatePic('', 0, 0, $aPos[2], $aPos[3])
    Local $hPic = GUICtrlGetHandle($idPic)
    GUISwitch($hPrev)
    #EndRegion ; add PIC to parent window

    Local $hPictureDC = _WinAPI_GetDC($hPic)

    ; Create Dest bitmap
    Local $hDestination_DC = _WinAPI_CreateCompatibleDC($hPictureDC) ; Creates a memory device context compatible with the specified device
    Local $hDestination_Bitmap = _WinAPI_CreateCompatibleBitmap($hPictureDC, $aPos[2], $aPos[3]) ; Creates a bitmap compatible with the specified device context
    Local $hDestination_Sv = _WinAPI_SelectObject($hDestination_DC, $hDestination_Bitmap) ; Selects an object into the specified device context
    _WinAPI_PrintWindow($hWindow_WebView2, $hDestination_DC, 2)

    _WinAPI_ReleaseDC($hPic, $hPictureDC)
    _WinAPI_SelectObject($hDestination_DC, $hDestination_Sv)
    _WinAPI_DeleteDC($hDestination_DC)

    ; Set bitmap to control
    _SendMessage($hPic, $STM_SETIMAGE, 0, $hDestination_Bitmap)
    _WinAPI_DeleteObject($hDestination_Bitmap)

    WinSetState($hWindow_WebView2, '', @SW_HIDE)
    Return $idPic
    #EndRegion ; freeze $hWindow_WebView2
EndFunc   ;==>__NetWebView2_freezer

I reduced the code by 11 lines.

I wonder why the earlier version uses two bitmaps?
Can someone enlighten me?

EDIT:

Earlier version:

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>
#include <WindowsConstants.au3>

_Example()

Func _Example()
    ShellExecute(@SystemDir & '\calc.exe')
    Local $hWnd = WinWaitActive("[REGEXPCLASS:CalcFrame|ApplicationFrameWindow]", '', 3)
    If Not $hWnd Then
        Exit
    EndIf
    Sleep(500) ; give it time to draw - let the window draw completely - skip the window animation

    ; Create GUI
    Local $aSize = WinGetPos($hWnd)
    GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), $aSize[2] + 80, $aSize[3] + 80)
    Local $idPic = GUICtrlCreatePic('', 40, 40, $aSize[2], $aSize[3])
    Local $hPic = GUICtrlGetHandle($idPic)

    ; Create bitmap
    Local $hDC = _WinAPI_GetDC($hPic)
    Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $aSize[2], $aSize[3])
    Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
    Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $aSize[2], $aSize[3])
    Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp)
    Local Const $PW_RENDERFULLCONTENT = 0x2 ; this will go to where it should  =)
    _WinAPI_PrintWindow($hWnd, $hSrcDC, $PW_RENDERFULLCONTENT)
    _WinAPI_BitBlt($hDestDC, 0, 0, $aSize[2], $aSize[3], $hSrcDC, 0, 0, $MERGECOPY)

    _WinAPI_ReleaseDC($hPic, $hDC)
    _WinAPI_SelectObject($hDestDC, $hDestSv)
    _WinAPI_SelectObject($hSrcDC, $hSrcSv)
    _WinAPI_DeleteDC($hDestDC)
    _WinAPI_DeleteDC($hSrcDC)
    _WinAPI_DeleteObject($hBmp)

    ; Set bitmap to control
    _SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
    Local $hObj = _SendMessage($hPic, $STM_GETIMAGE)
    If $hObj <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf

    GUISetState(@SW_SHOW)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    WinClose($hWnd, "")
EndFunc   ;==>_Example

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted
2 minutes ago, argumentum said:

Did run 014-pdfJS-Static_PDF_Viewer.au3 with your mods and it all woks as it should.

yeap

 

btw.
Why _WinAPI_BitBlt() was used - and in my scenario it is not needed ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted
4 minutes ago, argumentum said:

I can copy and paste, but reasoning is not my forte :D
I don't know anything about GDI 🤷‍♂️

It's almost like me ;)

Maybe the GDI master could answer... let's see if @UEZ knows the answers ?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)

btw.
Here is modified _WinAPI_PrintWindow.au3 example:

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>
#include <WindowsConstants.au3>

_Example()

Func _Example()
    ShellExecute(@SystemDir & '\calc.exe')
    Local $hWnd = WinWaitActive("[REGEXPCLASS:CalcFrame|ApplicationFrameWindow]", '', 3)
    If Not $hWnd Then
        Exit
    EndIf
    Sleep(500) ; give it time to draw - let the window draw completely - skip the window animation

    ; Create GUI
    Local $aSize = WinGetPos($hWnd)
    GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), $aSize[2] + 80, $aSize[3] + 80)
    Local $idPic = GUICtrlCreatePic('', 40, 40, $aSize[2], $aSize[3])
    Local $hPicture_Control = GUICtrlGetHandle($idPic)

    Local $hPicture_DC = _WinAPI_GetDC($hPicture_Control)

    ; Create destination bitmap
    Local $hDestination_Bitmap = _WinAPI_CreateCompatibleBitmap($hPicture_DC, $aSize[2], $aSize[3])
    Local $hDestination_DC = _WinAPI_CreateCompatibleDC($hPicture_DC)
    Local $hDestination_Sv = _WinAPI_SelectObject($hDestination_DC, $hDestination_Bitmap)

    ; Create source bitmap
    Local $hSource_Bitmap = _WinAPI_CreateCompatibleBitmap($hPicture_DC, $aSize[2], $aSize[3])
    Local $hSource_DC = _WinAPI_CreateCompatibleDC($hPicture_DC)
    Local $hSource_Sv = _WinAPI_SelectObject($hSource_DC, $hSource_Bitmap)

    Local Const $PW_RENDERFULLCONTENT = 0x2 ; this will go to where it should  =)
    _WinAPI_PrintWindow($hWnd, $hSource_DC, $PW_RENDERFULLCONTENT)
    _WinAPI_BitBlt($hDestination_DC, 0, 0, $aSize[2], $aSize[3], $hSource_DC, 0, 0, $MERGECOPY)

    _WinAPI_ReleaseDC($hPicture_Control, $hPicture_DC)

    #Region ; CleanUp
    _WinAPI_SelectObject($hDestination_DC, $hDestination_Sv)
    _WinAPI_DeleteDC($hDestination_DC)

    _WinAPI_SelectObject($hSource_DC, $hSource_Sv)
    _WinAPI_DeleteDC($hSource_DC)

    _WinAPI_DeleteObject($hSource_Bitmap)
    #EndRegion ; CleanUp

    ; Set bitmap to control
    _SendMessage($hPicture_Control, $STM_SETIMAGE, 0, $hDestination_Bitmap)
    Local $hObj = _SendMessage($hPicture_Control, $STM_GETIMAGE)
    If $hObj <> $hDestination_Bitmap Then
        _WinAPI_DeleteObject($hDestination_Bitmap)
    EndIf

    GUISetState(@SW_SHOW)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    WinClose($hWnd, "")
EndFunc   ;==>_Example

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted
7 minutes ago, mLipok said:

Here is modified _WinAPI_PrintWindow.au3 example:

@UEZ 

Would you be so kind as to take a look at this code, perhaps improve it or add comments?

Perhaps this will allow us to create a better example or improve the HelpFile.
Anyway, thanks.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted
2 minutes ago, argumentum said:

That'll be good to have in an example given todays monitors

Speaking of this, it would be better to have some sort of DPI enablement script in with the official UDFs that are supplied with the AutoIt installer.

When we search the forum, there are many options for DPI with varying results. Some easy, some complex. Having something built-in or at least supplied with installer would be necessary these days.

Posted (edited)

Here my suggestion:

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>
#include <WindowsConstants.au3>

Const $PW_RENDERFULLCONTENT = 2

_Example()

Func _Example()
    ; Launch Calculator and wait for it to finish opening
    ShellExecuteWait(@SystemDir & "\calc.exe")
    Local $hWnd = WinWaitActive("[REGEXPCLASS:CalcFrame|ApplicationFrameWindow]", "", 3)
    If Not $hWnd Then Exit ; Abort if the window didn't appear in time

    Sleep(500) ; Wait for the window to fully render and skip the open animation

    ; Create a GUI slightly larger than the Calculator window
    Local $aSize = WinGetPos($hWnd)
    Local $hGUI = GUICreate("Test " & StringReplace(@ScriptName, ".au3", "()"), $aSize[2] + 80, $aSize[3] + 80)
    GUISetBkColor(0x404040, $hGUI) ; Dark gray background
    Local $idPic = GUICtrlCreatePic("", 48, 48, $aSize[2], $aSize[3]) ; Placeholder for the captured bitmap
    GUISetState(@SW_SHOW)

   ; Capture the Calculator window as a GDI bitmap (cropped, client area, GDI-compatible)
    Local $hGDIBitmap = _WinAPI_CreateBitmapFromPrintWindow($hWnd, True, $PW_RENDERFULLCONTENT, True)

    ; Assign the bitmap to the picture control, delete any previously set bitmap
    Local $hHBmp = GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBitmap)
    If $hHBmp Then _WinAPI_DeleteObject($hHBmp)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Cleanup
    _WinAPI_DeleteObject($hGDIBitmap)
    WinClose($hWnd, "")
    GUIDelete($hGUI)
EndFunc   ;==>_Example

; Captures a window's content using PrintWindow and returns a GDI+ or GDI bitmap.
; $bCrop        - Crop the bitmap to the visible frame using DWM (removes window shadow/frame margins)
; $iClientMode  - PrintWindow flags passed directly to PrintWindow (1 = PW_CLIENTONLY). PW_RENDERFULLCONTENT (required for UWP/DX windows)
; $bBmpGDI      - Return a GDI HBITMAP instead of a GDI+ bitmap handle
Func _WinAPI_CreateBitmapFromPrintWindow($hWnd, $bCrop = True, $iClientMode = 1, $bBmpGDI = False)
    Local $aWinSize = WinGetPos($hWnd)
    If @error Then Return SetError(1, 0, 0)

    ; Set up a memory DC with a compatible bitmap to draw into
    Local Const $hDC_Capture = _WinAPI_GetDC($hWnd)
    If @error Then Return SetError(2, 0, 0)
    Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
    Local Const $hHBmp = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $aWinSize[2], $aWinSize[3])
    Local Const $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBmp)

    ; Use HALFTONE for better quality when stretching/scaling during capture
    _WinAPI_SetStretchBltMode($hDC_Capture, $HALFTONE)
    
    ; Capture the window content using the specified PrintWindow flags
    _WinAPI_PrintWindow($hWnd, $hMemDC, $iClientMode)

    ; Restore and release DC resources
    _WinAPI_SelectObject($hMemDC, $hObjectOld)
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_ReleaseDC($hWnd, $hDC_Capture)
    
    ; Skip GDI+ conversion if no cropping is needed and a raw HBITMAP (GDI) was requested
    If $bCrop = False And $bBmpGDI = True Then Return $hHBmp
    
     _GDIPlus_Startup()
    ; Convert the HBITMAP to a GDI+ bitmap
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp)
    _WinAPI_DeleteObject($hHBmp)

    ; Optionally crop the bitmap to the visible window area, excluding shadow/frame margins
    If $bCrop Then
        Local $iLeft, $iTop, $iRight, $iBottom, $pX, $pY
        ; Query the actual visible frame bounds via DWM to get the exact shadow margins
        Local $tRECT = _WinAPI_DwmGetWindowAttribute($hWnd, $DWMWA_EXTENDED_FRAME_BOUNDS)
        ; Calculate the margin on each side
        $iLeft   = $tRECT.left - $aWinSize[0]
        $iTop    = $tRECT.top  - $aWinSize[1]
        $iRight  = $aWinSize[0] + $aWinSize[2] - $tRECT.right
        $iBottom = $aWinSize[1] + $aWinSize[3] - $tRECT.bottom
        Local $hBitmap_Cropped = _GDIPlus_BitmapCloneArea($hBitmap, $iLeft, $iTop, $aWinSize[2] - $iLeft - $iRight, $aWinSize[3] - $iTop - $iBottom)
        _GDIPlus_BitmapDispose($hBitmap)
        $hBitmap = $hBitmap_Cropped
    EndIf

    ; Optionally convert to a GDI HBITMAP (needed for use with STM_SETIMAGE etc.)
    If $bBmpGDI Then
        Local $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_Shutdown()
        Return $hBitmap_GDI
    EndIf
    _GDIPlus_Shutdown()
    Return $hBitmap
EndFunc   ;==>_WinAPI_CreateBitmapFromPrintWindow

 

_WinAPI_CreateBitmapFromPrintWindow is from here:

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

Thank you very much.
I will have few questions.

1.

Is this following part not required when the source and destination size will be the same ?

; Use HALFTONE for better quality when stretching/scaling during capture
    _WinAPI_SetStretchBltMode($hDC_Capture, $HALFTONE)

 

2.
Why after using:

Local Const $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBmp)

there is a need to use it as a kind of revert

_WinAPI_SelectObject($hMemDC, $hObjectOld)

I understand it's about restoring/freeing/wiping, but reverting seems a bit odd to me.

 

3.
about the cropping feature

; Optionally crop the bitmap to the visible window area, excluding shadow/frame margins
    If $bCrop Then
        Local $iLeft, $iTop, $iRight, $iBottom, $pX, $pY
        #forceref $pX, $pY
        ; Query the actual visible frame bounds via DWM to get the exact shadow margins
        Local $tRECT = _WinAPI_DwmGetWindowAttribute($hWnd, $DWMWA_EXTENDED_FRAME_BOUNDS)
        ; Calculate the margin on each side
        $iLeft   = $tRECT.left - $aWinSize[0]
        $iTop    = $tRECT.top  - $aWinSize[1]
        $iRight  = $aWinSize[0] + $aWinSize[2] - $tRECT.right
        $iBottom = $aWinSize[1] + $aWinSize[3] - $tRECT.bottom
        Local $hBitmap_Cropped = _GDIPlus_BitmapCloneArea($hBitmap, $iLeft, $iTop, $aWinSize[2] - $iLeft - $iRight, $aWinSize[3] - $iTop - $iBottom)
        _GDIPlus_BitmapDispose($hBitmap)
        $hBitmap = $hBitmap_Cropped
    EndIf

If I have a window that contains an embedded IE control, WebView, DebenuViewer, or even simpler _WinAPI_CreateWindowEx(),
that is, not the window created using GuiCreate()

Then ... was it a case that the cropping is not needed ? I mean when will this be the case when user should to crop entire window ?

 

btw.
Question 1 and 3 are quite similar or even the same case.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

1) This is not necessary, as it is only relevant for scaling purposes

2) This is a Windows GDI requirement. SelectObject always returns the previously selected object, and you must restore it before deleting the DC. If you don't, you're deleting a DC that still "owns" your bitmap, which can cause resource leaks or undefined behavior.

3) The shadow margins from DWM only apply to top-level windows with a drop shadow (the typical WS_OVERLAPPEDWINDOW style). In these cases:

  • Cropping needed: Standard top-level windows (GUICreate, CreateWindowEx with default styles) — they have DWM shadow margins, so the captured bitmap is slightly larger than the visible content.
  • Cropping not needed / potentially harmful: Borderless windows, child windows, embedded controls (WebView, IE, DebenuViewer), or windows with WS_POPUP and no shadow. Here DWMWA_EXTENDED_FRAME_BOUNDS equals the window rect, so all margins would be 0 anyway — but it's worth checking, since forcing a crop on such windows could cut off actual content.

So your observation is correct: questions 1 and 3 are essentially the same issue — both assume scaling or size differences that may not actually exist.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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
×
×
  • Create New...