?
Solved

Resize form to RECT

Posted on 2002-04-10
10
Medium Priority
?
292 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:Object_shun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6931840
Unfortunatelly i haven't AOL but i think it could be done.
0
 

Author Comment

by:Object_shun
ID: 6932137
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
 

Expert Comment

by:lschuele
ID: 6932330
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 18

Expert Comment

by:mdougan
ID: 6932376
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
 

Author Comment

by:Object_shun
ID: 6932499
mdougan...
aimbox@cox.net

Thanks
0
 
LVL 3

Expert Comment

by:leojl
ID: 6933011
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
 

Author Comment

by:Object_shun
ID: 6933602
I never got the e-mail....
0
 
LVL 18

Accepted Solution

by:
mdougan earned 800 total points
ID: 6933710
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
 

Author Comment

by:Object_shun
ID: 6934065
Just what I had in mind....Thanks again.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6934182
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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question