Resize form to RECT

Hello all,

I'm working on a add-in to foward my AOL e-mail to another account.
What I'm trying to do is this:

I want to resize my form to the exact size of an AOL_Edit control and place my form "ontop" of it.

So I need to get the left, top, width and height of the edit control using just its Hwnd (is this possible?) and then resize my form...and place it over it. My form will just have a progress bar and should fit nicely over the keyword edit control on AOL.

Thanks
Object_shunAsked:
Who is Participating?
 
mdouganConnect With a Mentor Commented:
leojl, I have no problem sharing with the EE community, but there are often times when the source code is either so volumneous, or spread across so many files that posting it is not very helpful to the person asking the question.  

Like I said, I can post it here too, for what it's worth, but I'm happy to e-mail the working sample to anyone who posts an e-mail address. I've been a member here for 2 or 3 years and I've never heard anyone object to that before.

Object_shun, I'll send it off when I get to work today....
0
 
Richie_SimonettiIT OperationsCommented:
Unfortunatelly i haven't AOL but i think it could be done.
0
 
Object_shunAuthor Commented:
Yes, I'm sure it can be done. (not by me, yet (LOL)
Actually it doesn't have to be an AOL control...just any RECT that is elsewhere (not on my form)...and resize to whatever control size.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
lschueleCommented:
You should be able to position it using the following API call.

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

Type RECT
   left As Long
   top As Long
   right As Long
   bottom As Long
End Type


Note that the left... variables are set to pixel positions on the screen, and not on the client window.  When you are positioning the control, it will be relative to the corner of the client area of it's container.  You will have to calculate the offsets.
0
 
mdouganCommented:
Lucky you.... I created a class that allows you to take the hWnd of the thing you want to cover up, and then "hook" it, so that you intercept all of its window messages, and so you can get its coordinates and proportions, and then you can size/move your form into position over this other thing.  If the other thing is resized, your window will intercept the window paint event and then resize your window appropriately.

The code is not too big, I could post it here, but, if you'd like the sample applications (one for the application window that you're trying to cover up, one for the new window you want on top), then post an e-mail address and I'll forward it along.  It works pretty well!
0
 
Object_shunAuthor Commented:
mdougan...
aimbox@cox.net

Thanks
0
 
leojlCommented:
hi,

EE policy is to share comments with the EE comunity.

It is not fair to just email an answer to one person.

leo
0
 
Object_shunAuthor Commented:
I never got the e-mail....
0
 
Object_shunAuthor Commented:
Just what I had in mind....Thanks again.
0
 
mdouganCommented:
Thanks, let me know how it works out for you.

For those of you who are interested in how this is done, I'll post the important routines below.  Basically, you need to "hook" the window messages of the "parent" window -- which is the window that you want to cover up with your other window (call it the "child" window).  Whenever the parent window is sized or moved, you want to resize and move the child window to match.  It's very important that when you want to close either window, that you "unhook" the parent window, so that it gets its window messages directly again.  Otherwise, you are likely to GPF because of an invalid window handle.

Public Sub Hook()
' Hook the parent window to start grabbing its window messages
   lpPrevWndProc = SetWindowLong(gParentWH, GWL_WNDPROC, _
      AddressOf WindowProc)
End Sub

Public Sub Unhook()
' Unhook the parent window so that it starts getting its messages directly
   Dim temp As Long
   temp = SetWindowLong(gParentWH, GWL_WNDPROC, _
      lpPrevWndProc)
End Sub

Public Function WindowProc(ByVal hw As Long, ByVal uMsg As _
   Long, ByVal wParam As Long, ByVal lParam As Long) _
   As Long
   
' The procedure that "pre-processes the messages to the parent window"
Dim RC As Long

' any other messages we don't care about
    If uMsg = WM_WINDOWPOSCHANGED Or _
       uMsg = WM_MOVE Or _
       uMsg = WM_PAINT Or _
       uMsg = WM_WINDOWPOSCHANGING Then
       
        ' Reset the position.
        RC = GetWindowRect(hw, gRect)
        MoveWindow gChildWH, gRect.Left, gRect.Top, gRect.Right - gRect.Left, gRect.Bottom - gRect.Top, 1
    End If
   
   'Always call the original handler when done
   WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)

End Function

Public Sub SetFormTopmost(hwnd As Long)
' Makes sure that the child window is always topmost
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOZORDER + SWP_NOMOVE + SWP_NOSIZE

End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.