Jump to content

Recommended Posts

Posted (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.

#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 by Senton-Bomb
  • 5 weeks later...
Posted (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 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.
Posted

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!)

Posted (edited)

Allright just a fast reply ... since I read the code (didn't run it yet).

You should declare all variables Local

Local $HwndP, $HwndC, $user32

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. Edited 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!)

Posted (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 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!)

Posted (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 by chris95219
Posted

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.

:)

Posted

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!

Posted

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!)

Posted (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 by chris95219
Posted

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!)

  • 2 months later...
Posted (edited)

i think this is what i have been looking for forever!! glad to find it

ever noticed the cpu power this needs??

Edited by DBak

[center][/center]

  • 1 month later...
Posted

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.

Posted (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 by DBak

[center][/center]

  • 1 month later...
Posted (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 by grham

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...