Jump to content

Recommended Posts

Posted (edited)

$dll = DLLOpen("user32.dll")
$hwnd = DllCall("user32.dll", "hwnd", "GetTopWindow")
dim $String
DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hwnd, "str", $string, "int", 80)
MsgBox(0, "LOSER", $string)
$hwnd = DLLCall("user32.dll", "hwnd", "GetNextWindow", "hwnd", "NULL", "int", "GW_HWNDNEXT")
DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hwnd, "str", $string, "int", 80)
MsgBox(0, "LOSER", $string)
DLLClose($dll)

Any specific reason it isn't working. Its compiling, just no message in text box.

Edited by Encryption
Posted

A few quick points:

  • $hwnd is not being set which means that your remaining calls will also fail. Here is the related MSDN page. It sounds like you need to pass a 'null' handle as a parameter to GetTopWindow but I don't know how you might do that.
  • Since you're opening user32.dll you should use the handle in your DLLCall() lines instead of "user32.dll".
Posted (edited)

$dll = DLLOpen("user32.dll")
$hwnd = DllCall($dll, "hwnd", "GetTopWindow", "hwnd", 0)
dim $String
DllCall($dll, "int", "GetWindowText", "hwnd", $hwnd, "str", $string, "int", 80)
MsgBox(0, "LOSER", $string)

Tried this, but still no text in the message box. ;)

Edited by Encryption
Posted

Some more points:

  • Check how DLLCall() returns information (hint: array).
  • MSDN says a couple interesting things about GetWindowText, including that it 'cannot retrieve the text of a control in another application'. So is this a function that you want to be using?
I'll keep fiddling with your code and see what I can do though. I think we might need DLLStructs to access said text if it turns out to be possible.
Posted

Well, here's my best attempt:

Global Const $GW_HWNDNEXT = 2

; Variable to hold DLLCall() responses
Local $Response

; Open the DLL for multiple calls
Local $DLL = DLLOpen("User32.dll")

; Find the handle of the topmost window in the Z order
$Response = DLLCall($DLL, "HWnd", "GetTopWindow", "HWnd", "")
Local $HWnd = $Response[0]
MsgBox(0x40, "Window handle", $HWnd)

; Receive the window text
Local $WinText
$Response = DLLCall($DLL, "Int", "GetWindowText", "HWnd", $HWnd, "Str", $WinText, "Int", 80)

; Display the received text
MsgBox(0x40, "Window text", $WinText)

; Get the next window down in the Z order
$Response = DLLCall($DLL, "HWnd", "GetNextWindow", "HWnd", $HWnd, "Int", $GW_HWNDNEXT)
$HWnd = $Response[0]

; Display the handle
MsgBox(0x40, "Next window handle", $HWnd)

; Release the DLL
DLLClose($DLL)

It errors out on the final DLLCall() with @Error stating that it's 'unable to use the DLL file', so I don't know. MSDN seems to think that it's a valid user32.dll function.

Posted

The logic of your script (if it were working) seems to be: 'get the text of the topmost window and the handle of the next one down'. Is it definitely meant to be that and not 'get the text of the window immediately under the topmost one'?

Posted

Thats just testing for the DllCalling...I have a complete other function that I have in C++ that I am going to port to AutoIt after I figure out these DlCalls.

int GetNumberofWindows()
{
    HWND hWnd;
    hWnd = GetTopWindow(NULL);//Get highest window

    if(hWnd == NULL)//If there are no windows
        return 0;

    int numberOfWindows = 1;//count the window i found

    while(GetNextWindow(hWnd, GW_HWNDNEXT) != NULL)//loop until there are no windows
    {
        hWnd = GetNextWindow(hWnd, GW_HWNDNEXT);//get next window for me to count
        numberOfWindows++;//add onto the list
    }
    return numberOfWindows;//return the number of windows found.
}

void SendWindowList()
{
    HWND hWnd = GetTopWindow(NULL);//Mm get top window
    char buffer[80];//OMG! Buffer for text ima send

    while(hWnd != NULL)
    {
        GetWindowText(hWnd, buffer, sizeof(buffer));//get current windows title
        send(s, buffer, sizeof(buffer), 0);//send the text to me
        hWnd = GetNextWindow(hWnd, GW_HWNDNEXT);//get the next window
    }

Yes, that is my code...sorry for wierd comments.

Posted

Well, here's my best attempt:

Global Const $GW_HWNDNEXT = 2

; Variable to hold DLLCall() responses
Local $Response

; Open the DLL for multiple calls
Local $DLL = DLLOpen("User32.dll")

; Find the handle of the topmost window in the Z order
$Response = DLLCall($DLL, "HWnd", "GetTopWindow", "HWnd", "")
Local $HWnd = $Response[0]
MsgBox(0x40, "Window handle", $HWnd)

; Receive the window text
Local $WinText
$Response = DLLCall($DLL, "Int", "GetWindowText", "HWnd", $HWnd, "Str", $WinText, "Int", 80)

; Display the received text
MsgBox(0x40, "Window text", $WinText)

; Get the next window down in the Z order
$Response = DLLCall($DLL, "HWnd", "GetNextWindow", "HWnd", $HWnd, "Int", $GW_HWNDNEXT)
$HWnd = $Response[0]

; Display the handle
MsgBox(0x40, "Next window handle", $HWnd)

; Release the DLL
DLLClose($DLL)

It errors out on the final DLLCall() with @Error stating that it's 'unable to use the DLL file', so I don't know. MSDN seems to think that it's a valid user32.dll function.

MSDN is leaving out one crucial bit of information. GetNextWindow() is just a C pre-processor macro which wraps GetWindow(). Replace "GetNextWindow" in your code with "GetWindow" and it will work. I had to look the function up in the header file to determine this.
Posted

Thanks Valik -- that definitely makes more sense. It seemed kind of redundant to need to specify a GW_HWNDNEXT flag in a GetNextWindow() call.

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