Link to home
Start Free TrialLog in
Avatar of Kagehi
Kagehi

asked on

Getting the size of another applications window..

I am having two issues here. The first one involve the data returned by GetWindowRect, it is flat out wrong. I have my desktop at 1280x1024 and the window I tried to get the info from takes up the full size top to bottom and 3/4 of the width of the entire available space, but it returns Top = 0, Bottom = 0, Left = 3, Right = 0, of which only the Left coordinate is right according to information about the window retrieved by Spy++, or for that matter, just basic common sense. The other issue is that when I close the small test program, it causes an exception in Kernel32. :p The following is the code, sans all the form layout etc.:

EnumDeclares.bas>>

Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal ccs As Long) As Long

Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Type RECT
    Left As Integer
    Top As Integer
    Right As Integer
    Bottom As Integer
End Type

Public Myhandle As Long
Public WinName As String

Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
  Dim sSave As String, Ret As Long
  Dim TestWin As String
  TestWin = "MUSHclient" 'Change to whichever window is being looked for.
  Ret = GetWindowTextLength(hwnd)
  sSave = Space(Ret)
  GetWindowText hwnd, sSave, Ret + 1
  TestEnumWin.RichTextBox1.Text = TestEnumWin.RichTextBox1.Text + vbCrLf + Hex(hwnd) + " " + sSave + " " + Str$(InStr(sSave, TestWin))
  If InStr(sSave, TestWin) Then 'Replace with key word to look for.
    Myhandle = hwnd
    WinName = sSave
  End If
  EnumWindowsProc = True
End Function

Code from the form>>

Private Sub Form_Load()
  Dim WinRect As RECT
  EnumWindows AddressOf EnumWindowsProc, ByVal 0&
  GetWindowRect Myhandle, WinRect
  'GetWindowRect TestEnumWin.hwnd, WinRect
  TestEnumWin.TopText = WinRect.Top
  TestEnumWin.BottomText = WinRect.Bottom
  TestEnumWin.LeftText = WinRect.Left
  TestEnumWin.RightText = WinRect.Right
  TestEnumWin.NameText = WinName
End Sub

This is annoyingly the last critical piece in a small animated firework gadget I want to 'dock' to a program called MUSHclient. The idea is to get the windows current size and position, then when ever it gets resized, also move and resize the firework display. Eventually, I want to use the same code in other tools that can be attached to the client as well, like a form for a database, a map displayer and other stuff like the firework gadget that is problematic at best, since it requires code execution that is in a seperate thread from the clients scripting, which would hang the client during execution if used to perform the same task. Without being able to get the above to work right, let alone reliably, I am pretty much sunk... :p

Oh yeah.. I am using VB6 on Windows 98se.
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Please maintain this old open question:

https://www.experts-exchange.com/questions/20564440/PC-Terminal-font.html

Thanks,
Anthony
ASKER CERTIFIED SOLUTION
Avatar of zzzzzooc
zzzzzooc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kagehi
Kagehi

ASKER

I found a resolution for this on another forum (now that it stopped bloody goind awol ever five minutes..). Turns out the key was in the structure for RECT. Many of the online examples I checked had the structure using integers. :p

As for your comment Anthony.. The font one isn't an open issue any more, I found a solution myself, so it wasn't exactly possible for me to accept anyone elses answer, nor does there appear to be an option for terminating a question that you have resolved yourself on here. Seems like the only option is to hand you points to someone else for not actually solving the problem or... Can you even delete things here? The first option isn't acceptable imho and the second is almost as bad, because it would also delete any information posted about how the person asking the question managed to solve it for themselves. I don't think that is a grand option either. :( So how exactly do I close that thread, without having to give credit for a solution that didn't actually help me?
>>The font one isn't an open issue any more, I found a solution myself, so it wasn't exactly possible for me to accept anyone elses answer<<
I was not suggesting you accept anyone's solution.  In fact, I would encourage you not to, we have enough bogus solutions in the PAQ, as it is.  If you feel no one answered your question than follow the EE Guidelines:
Nobody answered my question. What do I do?
https://www.experts-exchange.com/help/closing.jsp#5

>>nor does there appear to be an option for terminating a question that you have resolved yourself on here.<<
Again, if you took the time to re-read the EE Guidelines you would have read this:
I answered my question myself. What do I do?
https://www.experts-exchange.com/help/closing.jsp#5

>>Can you even delete things here? <<
I think I just answered that question.

>>So how exactly do I close that thread, without having to give credit for a solution that didn't actually help me?<<
Again, RTFM

Anthony
Avatar of Kagehi

ASKER

Thanks I found it myself, but either forgot, glossed over or assumed a more direct 'thread' option that would do it. This is the only forum I have posted to that requires a somewhat conveluted way to end something yourself. But then it is also the only one that uses a point system. It wasn't exactly what I was expecting, and yes I really was expecting a big red button labelled 'Close Me!' or the like. ;) lol