Solved

Resize form to RECT

Posted on 2002-04-10
10
284 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
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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now