Loc Posted August 10, 2021 Share Posted August 10, 2021 (edited) I'm making a program to get digital images, all the color points of that number have been obtained. I don't know how to get that number out from within the function. For example, if the image is 008, it will be output in msgbox as 008 instead of being displayed multiple times as msgbox 0 _ msgbox 0 _ msgbox 8. Here is my code expandcollapse popup#include <WinAPIShPath.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Array.au3> Global $handle = WinGetHandle('NumberApp') Global $OX1[3] = [32, 35, 39], $OX2[3] = [45, 48, 52], _ $OX3[3] = [58, 61, 65], $OY[5] = [69, 71, 73, 75, 77] _RoomNumber($handle, $OX1, $OY) _RoomNumber($handle, $OX2, $OY) _RoomNumber($handle, $OX3, $OY) Func _RoomNumber($hwnd, $OX, $OY) If _GetColor($hwnd, $OX[0], $OY[0]) <> 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[0]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[1]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[1]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[2]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[2]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[3]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[3]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[1], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[2], $OY[4]) = 0xFFB400 Then MsgBox(0, '', 'Number 0'); Number 0 ElseIf _GetColor($hwnd, $OX[0], $OY[0]) <> 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[0]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[1]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[1]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[2]) <> 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[2]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[3]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[3]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[4]) <> 0xFFB400 And _GetColor($hwnd, $OX[1], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[2], $OY[4]) <> 0xFFB400 Then MsgBox(0, '', 'Number 1'); Number 1 ElseIf _GetColor($hwnd, $OX[0], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[0]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[1]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[1]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[2]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[3]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[3]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[1], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[2], $OY[4]) = 0xFFB400 Then MsgBox(0, '', 'Number 2'); Number 2 ElseIf _GetColor($hwnd, $OX[0], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[0]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[1]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[1]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[2]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[3]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[3]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[1], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[2], $OY[4]) = 0xFFB400 Then MsgBox(0, '', 'Number 3'); Number 3 ElseIf _GetColor($hwnd, $OX[0], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[0]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[0]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[1]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[1]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[2]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[3]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[3]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[4]) <> 0xFFB400 And _GetColor($hwnd, $OX[1], $OY[4]) <> 0xFFB400 And _GetColor($hwnd, $OX[2], $OY[4]) = 0xFFB400 Then MsgBox(0, '', 'Number 4'); Number 4 ElseIf _GetColor($hwnd, $OX[0], $OY[0]) <> 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[0]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[1]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[1]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[2]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[3]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[3]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[1], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[2], $OY[4]) = 0xFFB400 Then MsgBox(0, '', 'Number 5'); Number 5 ElseIf _GetColor($hwnd, $OX[0], $OY[0]) <> 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[0]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[1]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[1]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[2]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[3]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[3]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[1], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[2], $OY[4]) = 0xFFB400 Then MsgBox(0, '', 'Number 6'); Number 6 ElseIf _GetColor($hwnd, $OX[0], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[0]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[1]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[1]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[2]) <> 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[2]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[2]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[3]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[3]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[4]) <> 0xFFB400 And _GetColor($hwnd, $OX[1], $OY[4]) <> 0xFFB400 And _GetColor($hwnd, $OX[2], $OY[4]) = 0xFFB400 Then MsgBox(0, '', 'Number 7'); Number 7 ElseIf _GetColor($hwnd, $OX[0], $OY[0]) <> 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[0]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[1]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[1]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[2]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[3]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[3]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[1], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[2], $OY[4]) = 0xFFB400 Then MsgBox(0, '', 'Number 8'); Number 8 ElseIf _GetColor($hwnd, $OX[0], $OY[0]) <> 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[0]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[0]) <> 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[1]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[1]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[1], $OY[2]) = 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[2]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[3]) <> 0xFFFF00 And _GetColor($hwnd, $OX[2], $OY[3]) = 0xFFFF00 And _ _GetColor($hwnd, $OX[0], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[1], $OY[4]) = 0xFFB400 And _GetColor($hwnd, $OX[2], $OY[4]) = 0xFFB400 Then MsgBox(0, '', 'Number 9'); Number 9 ElseIf _GetColor($hwnd, $OX[0], $OY[0]) = 0xFFFFFF And _GetColor($hwnd, $OX[1], $OY[0]) = 0xFFFFBD And _GetColor($hwnd, $OX[2], $OY[0]) = 0xFFFFAF And _ _GetColor($hwnd, $OX[0], $OY[4]) = 0x00DB00 And _GetColor($hwnd, $OX[1], $OY[4]) = 0x00DB00 And _GetColor($hwnd, $OX[2], $OY[4]) = 0x00B500 Then MsgBox(0, '', 'String S');Chữ S EndIf; Number 0 ô đầu EndFunc Func _GetColor($title, $iX, $iY) If Not _WinAPI_DwmIsCompositionEnabled() Then MsgBox(0x30,"Error","Error") Else Local $WinHandle = WinGetHandle($title) _GDIPlus_Startup() Local $aPos = WinGetPos($WinHandle) $iWidth = $aPos[2] $iHeight = $aPos[3] Local $hDDC = _WinAPI_GetDC($WinHandle) Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC,$iWidth,$iHeight) _WinAPI_SelectObject($hCDC, $hBMP) DllCall("User32.dll","int","PrintWindow","hwnd",$WinHandle,"hwnd",$hCDC,"int",0) _WinAPI_BitBlt($hCDC,0,0,$iWidth,$iHeight,$hDDC,0,0,0x00CC0020) $BMP = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) Local $aPixelColor = _GDIPlus_BitmapGetPixel($BMP,$iX,$iY) _WinAPI_ReleaseDC($WinHandle,$hDDC) _WinAPI_DeleteDC($hCDC) _WinAPI_DeleteObject($hBMP) _GDIPlus_ImageDispose($BMP) _GDIPlus_Shutdown() Return "0x"&Hex($aPixelColor, 6) EndIf EndFunc Edited August 11, 2021 by Loc Link to comment Share on other sites More sharing options...
Nine Posted August 10, 2021 Share Posted August 10, 2021 Replace MsgBox(0, '', 'Number X') with Return 'X' Where X is the number found. And then : Local $RoomNumber = _RoomNumber($handle, $OX1, $OY) & _RoomNumber($handle, $OX2, $OY) & _RoomNumber($handle, $OX3, $OY) MsgBox (0, "", $RoomNumber) Error handling should be added (of course). BTW, you should only read the screen once, and put it in an array (or structure). Then you can get the colors from the array, would be a lot faster this way... Loc 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Loc Posted August 10, 2021 Author Share Posted August 10, 2021 Thanks. Because my knowledge is not enough, I post here to see how to shorten the code and search faster Link to comment Share on other sites More sharing options...
Nine Posted August 10, 2021 Share Posted August 10, 2021 Look example of _GDIPlus_BitmapLockBits to get an idea how to parse your $BMP into a 2D array. Earthshine and Loc 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
636C65616E Posted August 10, 2021 Share Posted August 10, 2021 (edited) As stated by @Nine, i guess what's making your script slow is the fact that you are calling your functions on each condtions test (i looked realy quickly the code, but as far as i saw you're fetching the same colors each time). Just fetch the data/colors/we once, and then check/compare them. In a more general way, and that's valid in nearly any programming case and based on some elementary logic: if the data you want to test are constant on some period of time, compute them once. For instance : we suppose we get some function called PredictWeather (self explenatory) that takes a fair 5h computation time if PredictWeather() == 'Tempest' then ; do some stuff elseif PredictWeather() == 'Sunny' then ; do some other stuff endif If the prediction is "Sunny" it will take 10h to run (because you call the function 2 times), instead compute once and check : local $prediction = PredictWeather() if $predition == 'Tempest' then ; do some stuff elseif $prediction == 'Sunny' then ; do some stuff endif ; an other way: because switch evaluate once switch PredictWeather() case 'Tempest' ; ... case 'Sunny' ; ... endswitch EDIT: Futhermore: On each call you are Allocating and Releasing lot of memory that doesn't need to be done that many time: GDI_StartUp should be called one at start, and ShuDown once at end, CreateYour objects onces, etc, etc expandcollapse popupif not _WinAPI_DwmIsCompositionEnabled() then MsgBox(0x30,"Error","Error") endif _GDIPlus_Startup() func FetchColors() local $aPos = WinGetPos($WinHandle) $iWidth = $aPos[2] $iHeight = $aPos[3] local $hDDC = _WinAPI_GetDC($WinHandle) local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC,$iWidth,$iHeight) _WinAPI_SelectObject($hCDC, $hBMP) DllCall("User32.dll","int","PrintWindow","hwnd",$WinHandle,"hwnd",$hCDC,"int",0) _WinAPI_BitBlt($hCDC,0,0,$iWidth,$iHeight,$hDDC,0,0,0x00CC0020) $BMP = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) ; local $aPixelColor = _GDIPlus_BitmapGetPixel($BMP,$iX,$iY) ; HERE FETCH EVERYTHING ONCE ; one dirty trick: haha local $ret = ObjCreate('scripting.dictionary') for $x in $OX for $y in $OY $ret.Add($x & ':' & $y, _GDIPlus_BitmapGetPixel($BMP,$x,$y)) next next _WinAPI_ReleaseDC($WinHandle,$hDDC) _WinAPI_DeleteDC($hCDC) _WinAPI_DeleteObject($hBMP) _GDIPlus_ImageDispose($BMP) return $ret endfunc local $cols = FetchColors() ; you can access each coords likes that ; _GetColor($hwnd, $OX[0], $OY[1]) = $cols.Item($OX[0] & ':' & $OY[1]) ; anyway that's not the 'good' way to do it, accessing any of the dictionary items takes something like log(n) operations ; and you need to compute a string key, etc ; also accessing an unknown key will return an empty string so you need to take that in consideration ; so just for example purpose _GDIPlus_Shutdown() EDIT2: fetching the raw pixel array + some sidenotes might be one of the best solution ... (note: idk why _WinAPI_CopyStruct "fail") expandcollapse popup#include <GDIPlus.au3> #include <GDIPlusConstants.au3> #include <WinAPIMisc.au3> ; just for testing purpose, you shouldn't deploy with this kind of stuff ; when ragequiting the script, windows should release the process mem and allocated handles (thanks Microsoft) func assert($check, $line = @SCRIPTLINENUMBER) if not $check then MsgBox(0x10, 'ERROR', 'Assert failed at line ' & $line) Exit endif endfunc func GetBPP($type) switch $type ; $GDIP_PXF01INDEXED ; 1 bpp, indexed ; $GDIP_PXF04INDEXED ; 4 bpp, indexed case $GDIP_PXF08INDEXED return 'BYTE' case $GDIP_PXF16GRAYSCALE, $GDIP_PXF16RGB555, $GDIP_PXF16RGB565, $GDIP_PXF16ARGB1555 return 'WORD' ; $GDIP_PXF24RGB ; 24 bpp - 8 bits for each RGB case $GDIP_PXF32RGB, $GDIP_PXF32ARGB, $GDIP_PXF32PARGB return 'DWORD' case else MsgBox(0x10, 'ERROR', 'Unsupported bpp') Exit endswitch endfunc func GetRawBitmap($aWinHandle, $type = $GDIP_PXF32RGB) local $str = GetBPP($type) local $tmp = WinGetPos($aWinHandle) assert(@ERROR = 0) local $width = $tmp[2] local $height = $tmp[3] local $hDDC = _WinAPI_GetDC($aWinHandle) assert($hDDC <> 0) local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) assert($hCDC <> 0) local $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $width, $height) assert($hBMP <> 0) $tmp = _WinAPI_SelectObject($hCDC, $hBMP) assert($tmp <> 0) $tmp = _WinAPI_PrintWindow($aWinHandle, $hCDC) assert($tmp = True) $tmp = _WinAPI_BitBlt($hCDC, 0, 0, $width, $height, $hDDC, 0, 0, 0x00CC0020) assert($tmp = True) local $BMP = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) assert(@ERROR = 0) local $data = _GDIPlus_BitmapLockBits($BMP, 0, 0, $width, $height, $GDIP_ILMREAD, $type) assert(@ERROR = 0) $str &= '[' & ($width * $height) & ']' $tmp = DllStructCreate($str, $data.Scan0) ; weirdly zero memory ; local $raw = _WinAPI_CopyStruct($tmp, $str) ; assert(@ERROR = 0) local $raw = DllStructCreate($str) DllStructSetData($raw, 1, Binary(DllStructGetData($tmp, 1))) _GDIPlus_BitmapUnlockBits($BMP, $data) assert(@ERROR = 0) ; a good practice: dispose/release/free objects in reverse order of instantiation/allocation, as it is common one may rely on a precedent ; no assert on release because w/e _GDIPlus_BitmapDispose($BMP) _WinAPI_DeleteObject($hBMP) _WinAPI_DeleteDC($hCDC) _WinAPI_ReleaseDC($aWinHandle, $hDDC) ; to keep ref and prevent deallocation of the raw buffer local $ret = [$width,$height,$raw] return $ret endfunc func GetPixel(byref $raw, $x, $y) ; , $line = @SCRIPTLINENUMBER) ; assert(0 <= $y and $y < $raw[1], $line) ; assert(0 <= $x and $x < $raw[0], $line) local $ind = $y * $raw[0] + $x ; this is a normalized/flattened array return DllStructGetData($raw[2], 1, 1 + $ind) endfunc if not _WinAPI_DwmIsCompositionEnabled() then MsgBox(0x10, 'ERROR', 'DWM not enabled') Exit endif _GDIPlus_Startup() local $pid = Run('notepad.exe', '') local $hwnd = WinWait('[CLASS:Notepad]', '', 10) local $time = TimerInit() local $raw = GetRawBitmap($hwnd) ConsoleWrite('GetRawBitmap exec time: ' & Round(TimerDiff($time)) & ' ms' & @CRLF) MsgBox(0, 'Info', '[0,0] = 0x' & hex(GetPixel($raw,0,0),6)) ProcessClose($pid) _GDIPlus_Shutdown() Edited August 11, 2021 by 636C65616E FrancescoDiMuro and Loc 1 1 Link to comment Share on other sites More sharing options...
Loc Posted August 11, 2021 Author Share Posted August 11, 2021 Thank you so much for your humorous help. I will try to learn to solve my problem 😑 Link to comment Share on other sites More sharing options...
636C65616E Posted August 11, 2021 Share Posted August 11, 2021 3 hours ago, Loc said: Thank you so much for your humorous help. I will try to learn to solve my problem 😑 Hey, I don't know if this is ironic, but i've posted 2 ways to solve your problem in the EDITs ^^ Link to comment Share on other sites More sharing options...
Loc Posted August 11, 2021 Author Share Posted August 11, 2021 (edited) ; local $aPixelColor = _GDIPlus_BitmapGetPixel($BMP,$iX,$iY) ; HERE FETCH EVERYTHING ONCE ; one dirty trick: haha That's not what I mean. I see in your code there is a funny comment so I find it funny 😰 Edited August 11, 2021 by Loc Link to comment Share on other sites More sharing options...
636C65616E Posted August 11, 2021 Share Posted August 11, 2021 ho ok ^^ Link to comment Share on other sites More sharing options...
Nine Posted August 11, 2021 Share Posted August 11, 2021 @636C65616EAre you sure your second example works ? I highly doubt it should, as DllStructGetData($tmp, 1) would only return the first DWORD. Unless you use a Struct with BYTE, it will make a bad copy... Loc 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
636C65616E Posted August 11, 2021 Share Posted August 11, 2021 no as it is an array it returns the whole binary data if you don't specify an index Loc 1 Link to comment Share on other sites More sharing options...
Nine Posted August 11, 2021 Share Posted August 11, 2021 Not for me. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
636C65616E Posted August 11, 2021 Share Posted August 11, 2021 well ok, didnt tested intensively, so just copy with byte and then recast as dword Link to comment Share on other sites More sharing options...
Nine Posted August 11, 2021 Share Posted August 11, 2021 Just for the record : if not _WinAPI_DwmIsCompositionEnabled() then MsgBox(0x30,"Error","Error") endif is useless as it is working with or without Aero. One of my Win7 has Aero disabled and it is working fine... Also : $tmp = _WinAPI_BitBlt($hCDC, 0, 0, $width, $height, $hDDC, 0, 0, 0x00CC0020) should be removed as it will has bad side effect when window is in background Finally : #include <WinAPIMem.au3> $t1 = DllStructCreate("dword arr[10]") $t2 = DllStructCreate("dword arr[10]") _WinAPI_FillMemory(DllStructGetPtr($t1), 10 * 4, 0x01) ConsoleWrite($t1.arr(2) & @CRLF) DllStructSetData($t2, 1, DllStructGetData($t1, 1)) ; failed attempt to copy ConsoleWrite($t2.arr(2) & @CRLF) ConsoleWrite($t2.arr(1) & @CRLF) ; only one element is copied Not working aside from BYTE structures... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
636C65616E Posted August 11, 2021 Share Posted August 11, 2021 yep that's what im looking for, and anyway _WinAPI_CopyStruct doesnt work ... Link to comment Share on other sites More sharing options...
Nine Posted August 11, 2021 Share Posted August 11, 2021 (edited) 1 minute ago, 636C65616E said: _WinAPI_CopyStruct doesnt work ... It works well when using BYTE array structures ! Edited August 11, 2021 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
636C65616E Posted August 11, 2021 Share Posted August 11, 2021 so what's the point of casting a specific struct ? Link to comment Share on other sites More sharing options...
Nine Posted August 11, 2021 Share Posted August 11, 2021 You can simply double declare your structures one like you really want it, the second (with the same address) in byte array. Then you can use _WinAPI_CopyStruct successfully. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
636C65616E Posted August 11, 2021 Share Posted August 11, 2021 that was what i was testing, but it didn't worked, if you have some code Link to comment Share on other sites More sharing options...
Loc Posted August 11, 2021 Author Share Posted August 11, 2021 I'm glad my topic is of interest. The _Getcolor function I have shared by others and I only know its use can find pixels when the window is obscured. I don't even know how the functions in it work 😭 I hope it is improved from the masters 😘 Link to comment Share on other sites More sharing options...
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