JohnOne Posted April 1, 2013 Posted April 1, 2013 I'm not so sure about what exactly hdc is. My question and code example might help to ask my question. #include <WinAPI.au3> $_GetPixel = _GetPixel(10, 10) ConsoleWrite($_GetPixel &@LF) Func _GetPixel($iX, $iY) $hDC = _WinAPI_GetDC(0) $aGetPixel = DllCall("Gdi32.dll", "dword", "GetPixel", "handle", $hDC, "int", $iX, "int", $iY) If @error Then Exit MsgBox(0, "DllCall Error", @error) EndIf $rtn = StringRight(Hex($aGetPixel[0]), 6) Return $rtn EndFunc ;==>_GetPixel Code returns pixel color at screen coords. Should I make the call to _WinAPI_GetDC each time my function is called or is it safe to have it called once globally, given that screen content can obviously change? I'm not after a debate on the pro's and con's of global variables, and could just as well be static. Just whether the device context remains the same throughout the life of the script I have tested this but I want to be sure. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
KaFu Posted April 1, 2013 Posted April 1, 2013 Afaik the DC stays the same as long as the hWnd stays the same, so as long as the desktop hwnd does not change, _WinAPI_GetDC(0) should stay the same and can be obtained one time globally. To free resources _WinAPI_ReleaseDC(0, $hDC) should also be called after usage, and btw., just saw in the MSDN doc comments that this will only get you the DC of the default monitor screen in a multi-monitor set-up, see said docs for a trick to get DC for whole screen in a multi-monitor set-up. JohnOne 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
JohnOne Posted April 1, 2013 Author Posted April 1, 2013 Thanks for the clarification KaFu. Do you know what the relationship between desktop dc and desktop hwnd is? For example If I try to perform a control* function on hwnd, it operates only on the desktop window. If I perform GetPixel using the DC, I get the colour of anything visible on the whole screen regardless of what the window might be. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
KaFu Posted April 1, 2013 Posted April 1, 2013 About Device Contexts, something I still have to read too ... JohnOne 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
JohnOne Posted April 1, 2013 Author Posted April 1, 2013 Thank you very kindly KaFu. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now