NELyon Posted July 20, 2007 Share Posted July 20, 2007 (edited) This is a small UDF i whipped up because the DLLCall for SetParent was something i needed on hand, and didn't want to type out all the time, so i made a small wrapper. expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.4.9 Author: Senton-Bomb $TitleP: The title of the parent window $TitleC: The title of the child window If a window doesn't exist, It returns -1, otherwise it returns 1 Script Function: Wrapper for the "SetParent" dllcall + Example. #ce ---------------------------------------------------------------------------- ; Script Stizzle - Add your codeizzle Func _SetParent($TitleP, $TitleC) If WinExists($TitleP) Then If WinExists($TitleC) Then $HwndP = WinGetHandle($TitleP) $HwndC = WinGetHandle($TitleC) $user32 = DllOpen("user32.dll") DllCall($user32, "str", "SetParent", "HWnd", $HwndP, "HWnd", $HwndC) Return 1 Else Return -1 EndIf Else Return -1 EndIf EndFunc ;==>_SetParentƒoÝŠ÷ Ù@ÅjëhŠ×6Opt("WinTitleMatchMode", 2) $p = _SetParent("- SciTE", "Mozilla Firefox") If $p = -1 Then MsgBox(0, "", "One or more windows don't exist") EndIf ^^Example: Open SciTe and Firefox to see the effect. Comments? Questions? Insults? Anybody?? Edited October 22, 2007 by Senton-Bomb Link to comment Share on other sites More sharing options...
NELyon Posted July 21, 2007 Author Share Posted July 21, 2007 Nobody uh-like my wuurk? Link to comment Share on other sites More sharing options...
RazerM Posted August 19, 2007 Share Posted August 19, 2007 (edited) Just found this.. Good UDF but in the SetParent func the first parameter is the child, but you pass $hwndP Edit: I'm not sure but shouldn't DllClose be called? Edited August 19, 2007 by RazerM My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
Celeri Posted August 19, 2007 Share Posted August 19, 2007 Nobody uh-like my wuurk?Good timing!I was looking for something like this!I'll test it this week and come back to you.P.S.: A lot of people here just download and go, they don't bother to comment. Don't despair there's still a few good guys (and gals) around to help you out and comment. I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!) Link to comment Share on other sites More sharing options...
Celeri Posted August 19, 2007 Share Posted August 19, 2007 (edited) Allright just a fast reply ... since I read the code (didn't run it yet).You should declare all variables LocalLocal $HwndP, $HwndC, $user32For quickness and standardisation, on error you should return 1, on no error you should return 0Why? If _SetParent("- SciTE", "Mozilla Firefox") Then MsgBox(0,,"","Big ERROR")You save a few lines of code also. If NOT _SetParent(... will do something if there is no error BTW. Edited August 19, 2007 by Celeri I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!) Link to comment Share on other sites More sharing options...
Celeri Posted August 19, 2007 Share Posted August 19, 2007 (edited) I'd also combine both verifications: If WinExists($TitleP) And WinExists($TitleC) Then And add Opt("WinTitleMatchMode", 2) into the function Now it's looking good too Edited August 19, 2007 by Celeri I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!) Link to comment Share on other sites More sharing options...
cppman Posted August 19, 2007 Share Posted August 19, 2007 (edited) Nice little function Just found this.. Good UDF but in the SetParent func the first parameter is the child, but you pass $hwndP Edit: I'm not sure but shouldn't DllClose be called?eh, DLLOpen() shouldn't have even been called inside the function. #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.4.9 Author: Senton-Bomb $TitleP: The title of the parent window $TitleC: The title of the child window If a window doesn't exist, It returns -1, otherwise it returns 1 Script Function: Wrapper for the "SetParent" dllcall + Example. #ce ---------------------------------------------------------------------------- ; Script Stizzle - Add your codeizzle Func _SetParent($TitleP, $TitleC) If WinExists($TitleP) Then If WinExists($TitleC) Then $HwndP = WinGetHandle($TitleP) $HwndC = WinGetHandle($TitleC) DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $HwndC, "hwnd", $HwndP) Return 1 Else Return -1 EndIf Else Return -1 EndIf EndFunc ;==>_SetParent Edited August 19, 2007 by chris95219 Miva OS Project Link to comment Share on other sites More sharing options...
cppman Posted August 19, 2007 Share Posted August 19, 2007 For quickness and standardisation, on error you should return 1, on no error you should return 0 Why? If _SetParent("- SciTE", "Mozilla Firefox") Then MsgBox(0,,"","Big ERROR") You save a few lines of code also. If NOT _SetParent(... will do something if there is no error BTW. If you return 1 when there is an error, than this will happen: if (_SetParent(...)) Then ;an error occurred EndIf Usually it should return 0(false) if an error occurred and a non-zero (true) value if an error didn't occurr. Miva OS Project Link to comment Share on other sites More sharing options...
NELyon Posted August 20, 2007 Author Share Posted August 20, 2007 I'm re-writing the function now. Thanks for everything you guys pointed out. I just took a 5 mile bike ride and am thinking clearer now! Link to comment Share on other sites More sharing options...
NELyon Posted August 20, 2007 Author Share Posted August 20, 2007 {Post reserved for release of code} Link to comment Share on other sites More sharing options...
Celeri Posted August 20, 2007 Share Posted August 20, 2007 Usually it should return 0(false) if an error occurred and a non-zero (true) value if an error didn't occurr. Not sure. Let me quote the help file for Set Error:RETURN VALUE: By default, none, however if the optional return value argument is passed, then the function will return that value.SO unless I read wrong, no error, no returned value. If error, than a value that correspond to a specific error. Per example, error 1 would be "One of the windows does not exist".Error 2 could be error returned by RunDll, the extended code could be that error #.BTW I'm a complete dork with DllCalls so you got me there I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!) Link to comment Share on other sites More sharing options...
cppman Posted August 20, 2007 Share Posted August 20, 2007 (edited) Not sure. Let me quote the help file for Set Error: SO unless I read wrong, no error, no returned value. If error, than a value that correspond to a specific error. Per example, error 1 would be "One of the windows does not exist". Error 2 could be error returned by RunDll, the extended code could be that error #. BTW I'm a complete dork with DllCalls so you got me there You can call SetError before you return, and call @Error if the function failed if (not _SetParent(...)) Then MsgBox(0, "", @error) endif This is just my personal opinion though It makes it easier when calling a function because you can simply have a 1 liner.. if (not _SetParent(...)) Then blah... Edited August 20, 2007 by chris95219 Miva OS Project Link to comment Share on other sites More sharing options...
Celeri Posted August 20, 2007 Share Posted August 20, 2007 You can call SetError before you return, and call @Error if the function failed if (not _SetParent(...)) Then MsgBox(0, "", @error) endif This is just my personal opinion though It makes it easier when calling a function because you can simply have a 1 liner.. if (not _SetParent(...)) Then blah... Ok, I don't want to pick a fight (ahahahah) Anyways we almost agree So here's my take on this. Take a smal program that checks a filename (hey I'm working on that!) Here's what can go wrong: 1. Does it contain illegal characters? 2. Is it null ""? 3. Is it too long? 4. Does it contain too many wildcards? ("*" and "?") So in fact there are at least 4 different types of error here. There is only one instance where there is no error and that's when all the four previous checks are ok. So it makes more sense if the returned values are: 0. No problemo 1. Invalid characters 2. Null string 3. String too long 4. Too many wildcards. In any case we usually check to see if there is an error rather than the reverse. So ... If _CheckMyFilename("Celeri_?????_with_his_RunDLL_Calls.bak") Then ConsoleWrite("I made a boo-boo")makes perfect sense. However If _CheckMyFilename("Celeri_?????_with_his_RunDLL_Calls.bak") Then ConsoleWrite("Wow you made it!")is not quite as practical. Oh well, to each is own I guess I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!) Link to comment Share on other sites More sharing options...
DirtDBaK Posted October 21, 2007 Share Posted October 21, 2007 (edited) i think this is what i have been looking for forever!! glad to find it ever noticed the cpu power this needs?? Edited October 21, 2007 by DBak [center][/center] Link to comment Share on other sites More sharing options...
NELyon Posted November 30, 2007 Author Share Posted November 30, 2007 Func _SetParent($TitleC, $TitleP) If WinExists($TitleC) And WinExists($TitleP) Then $HwndC = WinGetHandle($TitleC) $HwndP = WinGetHandle($TitleP) DLLCall("user32.dll", "str", "SetParent", "HWnd", $HWndP, "HWnd", $HWndC) If @error then return 0 EndIf Return 1 EndIf EndFunc New version, no DLLopen, slimmed down, returns 0 on failure, 1 on execution, and switched the Parent and Child windows around. I ask for someone to test, because i cannot. Link to comment Share on other sites More sharing options...
DirtDBaK Posted November 30, 2007 Share Posted November 30, 2007 ok cool hope it works faster ill test it out for you in a few hours when i get home Thanks for all the great work! [center][/center] Link to comment Share on other sites More sharing options...
James Posted November 30, 2007 Share Posted November 30, 2007 Very good. But I lost my window. Anyway of fixing this? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
DirtDBaK Posted November 30, 2007 Share Posted November 30, 2007 (edited) Orignal was tested and works fine I dont know about the new one Show the code, maybe i can help, i use this function a lot... Check my sig for an example Edited November 30, 2007 by DBak [center][/center] Link to comment Share on other sites More sharing options...
grham Posted December 31, 2007 Share Posted December 31, 2007 (edited) very good!!!! I have this because of my curiosity. I'm still looking for the scite window after minimizing it within the firefox window. jaja Edited December 31, 2007 by grham Link to comment Share on other sites More sharing options...
James Posted December 31, 2007 Share Posted December 31, 2007 I lost my window the first time I ran this. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ 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