1 Attachment(s)
GetWindowRect make me headeache
Hi,
I'm trying to make popup object.
When Command1 get clicked, Text1 should show up exactly under Command1.
But it didn't.
I take a look on every sample on VBForum. It's should work.
Strangely When i try it with two FORM (Another Form show up under Command1, when command1 get clicked), it succeed.
Please help :)
PS: attached the fail sample
Re: GetWindowRect make me headeache
I can't look at your sample right now.
What are you passing to GetWindowRect()?
Re: GetWindowRect make me headeache
Here my "fail" code
VB Code:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Sub Command1_Click()
Dim tR As RECT
GetWindowRect Command1.hwnd, tR
Text1.Visible = True
Text1.Move tR.Left * Screen.TwipsPerPixelX, (tR.Bottom + 1) * Screen.TwipsPerPixelY
End Sub
Re: GetWindowRect make me headeache
Change your form's ScaleMode property to Pixels. That gets rid of the Twips issue.
And you need to subtract the form's on-screen position from the values returned by GetWindowRect. Remember the coordinates for form controls are relative to the 0,0 position of the Form. The coordinates for a hWnd are all returned relative to 0,0 on the screen.
Re: GetWindowRect make me headeache
Hi,
No, sample i attched only an "EXAMPLE". My application are big :). and it include many control position and form resize which is already on twip. I can't change baack to pixel.
Btw, as i mention before. i try it with two FORM and it work flawlesly. I just don't want using two FORM for this part of code, since it will make so many form.
Re: GetWindowRect make me headeache
Well like I said I can't look at your sample and the Twips thing was only a suggestion. The rest of my post still applies, just add in the appropriate pixels -> twips conversions.
Re: GetWindowRect make me headeache
Ok.
Hope i hear good news from you in shorten time :)
Thanks penagate
Re: GetWindowRect make me headeache
Look at this thread, they manage to do it.
And i try to mimic only the part when it showing popup
http://vbforums.com/showthread.php?t...=getwindowrect
Anyone please help....
Re: GetWindowRect make me headeache
What's the problem now? Did what I suggest not work? What in fact happens when you run the code?
Like Cluedo, you have to give us some clues before we can work out who assaulted who in the dining room with the plastic McDonalds fork.
Re: GetWindowRect make me headeache
in my post above, from the first time i already make pixel - twip conversion, it didn't work.
VB Code:
Text1.Move tR.Left * Screen.TwipsPerPixelX, (tR.Bottom + 1) * Screen.TwipsPerPixelY
Re: GetWindowRect make me headeache
Quote:
Originally Posted by me
you need to subtract the form's on-screen position from the values returned by GetWindowRect. Remember the coordinates for form controls are relative to the 0,0 position of the Form. The coordinates for a hWnd are all returned relative to 0,0 on the screen.
:afrog:
Re: GetWindowRect make me headeache
Hi penagate
Sorry i can cath up with you.
Can you make me liltle sample how to do it with form scalemode set to twip? please.
Re: GetWindowRect make me headeache
Actually, why can't you just use the command buttons's Top and Height property to work out the position? Would be a darn sight quicker than calling API functions.
VB Code:
Private Sub Command1_Click()
Text1.Move Command1.Left, Command1.Top + Command1.Height + Screen.TwipsPerPixelY
Text1.Visible = True
End Sub
Re: GetWindowRect make me headeache
You genius, it work.
But will it work, when using with mdi child form?
Where tje main form toolbar can have one toolbar, two toolbar, so on. Depend on user setting to the appplication?
Sorry to keep ask you :(
1 Attachment(s)
Re: GetWindowRect make me headeache
Try it with MDI CHild Form and Codejock Tabworkdpace control. Position was not exactly where i want it.
Please see attach picture. It should exactly under FAKTUR combobox
Re: GetWindowRect make me headeache
Nice UI, I love the name too :p
It should show in the correct position as long as it is placed within the same form as the combo box. If it's not in the same form, or floating in the MDI client area, you have another difficulty. Can you confirm where it's located?
Re: GetWindowRect make me headeache
it's in the same FORM. It's just another object on FORM
Re: GetWindowRect make me headeache
That's odd, I can't think of a reason why it would be wrong then :confused:
Try this instead. Uses the related API function to get the screen coords of the form's client area.
VB Code:
Private Declare Function GetClientRect Lib "user32" ( _
ByVal hWnd As Long, _
ByRef lpRect As RECT _
) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Command1_Click()
Dim clientRect As RECT
If (GetClientRect(me.hWnd, clientRect)) Then
Text1.Move _
Command1.Left - (clientRect.Left * Screen.TwipsPerPixelX), _
Command1.Top + Command1.Height - ((clientRect.Top - 1) * Screen.TwipsPerPixelY)
End If
End Sub
Re: GetWindowRect make me headeache
Actually when i add left with 120 and bottom 235, it achieve with i want.
When i remove all toolbar or change screen resolution, it's still work.
VB Code:
ofrBantuan.Move myCmbFaktur.Left + 120, myCmbFaktur.Top + myCmbFaktur.Height + Screen.TwipsPerPixelY + 235
But i will give a try your code
Re: GetWindowRect make me headeache
No, It didn't work penagate.
It's position the same as my picture attachment
Re: GetWindowRect make me headeache
Re: GetWindowRect make me headeache