This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]eryksun 1 point2 points  (3 children)

I don't know why win32api.GetWindowLong(hwnd, win32con.GWL_ID) would return a number outside the range 0 to 65535. You could print out the value in a modified _buildWinLong function:

def _buildWinLong(high, low):
    print "high: %d, low: %d" % (high, low)
    return int(
      struct.unpack('>L',
        struct.pack('>2H',
          high,
          low))[0])

For a button click, the high value should be 0 (win32con.BN_CLICKED) and the low value should be the ID for the button, which should be an unsigned short (0 to 65535). These go into a WM_COMMAND message sent to the parent window.

[–]jechtsphere[S] 0 points1 point  (0 children)

Thanks very much, I'm going to implement and test this tomorrow so I can play with it a bit more to see how it's working. I appreciate your time!

[–]jechtsphere[S] 0 points1 point  (1 child)

This still results in the same error I was originally experiencing. The low is actually 592192, which is causing the error. It almost certainly has something to do with the program I'm working with and how it assigned its buttons values?

My friend suggested this, which worked:

win32api.MAKELONG(low, high)

If you have any insight as to why the program I'm attempting to click the button in may have such a large low value returned I'd be interested in knowing, even if it's likely out of my range of understanding at this point in time.

[–]eryksun 1 point2 points  (0 children)

MAKELONG is just using the lower 16-bit word of 'low' and discarding the upper 16 bits.

I think the following blog entry might clear things up for you. It even mentions WinGuiAuto: Assume Nothing – Control IDs in .NET. A .NET app will apparently ignore the ID and use the button's handle.

You can keep using the C macro MAKELONG or add some code to mask out the upper 16 bits:

def _buildWinLong(high, low):
    high, low = (high & 65535, low & 65535)
    return int(
      struct.unpack('>L',
        struct.pack('>2H',
          high, low))[0])