Results 1 to 22 of 22

Thread: GetWindowRect make me headeache

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    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
    Attached Files Attached Files

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: GetWindowRect make me headeache

    I can't look at your sample right now.

    What are you passing to GetWindowRect()?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: GetWindowRect make me headeache

    Here my "fail" code

    VB Code:
    1. Option Explicit
    2. Private Type RECT
    3.    Left As Long
    4.    Top As Long
    5.    Right As Long
    6.    Bottom As Long
    7. End Type
    8. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    9.  
    10. Private Sub Command1_Click()
    11.     Dim tR As RECT
    12.     GetWindowRect Command1.hwnd, tR
    13.     Text1.Visible = True
    14.     Text1.Move tR.Left * Screen.TwipsPerPixelX, (tR.Bottom + 1) * Screen.TwipsPerPixelY
    15. End Sub

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    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.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: GetWindowRect make me headeache

    Ok.

    Hope i hear good news from you in shorten time

    Thanks penagate

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

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

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.
    Last edited by penagate; Jul 19th, 2006 at 02:46 AM.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    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:
    1. Text1.Move tR.Left * Screen.TwipsPerPixelX, (tR.Bottom + 1) * Screen.TwipsPerPixelY

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    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.

  13. #13
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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:
    1. Private Sub Command1_Click()
    2.     Text1.Move Command1.Left, Command1.Top + Command1.Height + Screen.TwipsPerPixelY
    3.     Text1.Visible = True
    4. End Sub

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    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

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    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
    Attached Images Attached Images  

  16. #16
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: GetWindowRect make me headeache

    Nice UI, I love the name too

    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?

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: GetWindowRect make me headeache

    it's in the same FORM. It's just another object on FORM

  18. #18
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: GetWindowRect make me headeache

    That's odd, I can't think of a reason why it would be wrong then

    Try this instead. Uses the related API function to get the screen coords of the form's client area.

    VB Code:
    1. Private Declare Function GetClientRect Lib "user32" ( _
    2.   ByVal hWnd As Long, _
    3.   ByRef lpRect As RECT _
    4. ) As Long
    5.  
    6. Private Type RECT
    7.   Left    As Long
    8.   Top     As Long
    9.   Right   As Long
    10.   Bottom  As Long
    11. End Type
    12.  
    13. Private Sub Command1_Click()
    14.   Dim clientRect As RECT
    15.  
    16.   If (GetClientRect(me.hWnd, clientRect)) Then
    17.     Text1.Move _
    18.       Command1.Left - (clientRect.Left * Screen.TwipsPerPixelX), _
    19.       Command1.Top + Command1.Height - ((clientRect.Top - 1) * Screen.TwipsPerPixelY)
    20.   End If
    21. End Sub

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    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:
    1. ofrBantuan.Move myCmbFaktur.Left + 120, myCmbFaktur.Top + myCmbFaktur.Height + Screen.TwipsPerPixelY + 235

    But i will give a try your code

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: GetWindowRect make me headeache

    No, It didn't work penagate.
    It's position the same as my picture attachment

  21. #21
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: GetWindowRect make me headeache

    use your method then.

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: GetWindowRect make me headeache

    Ok then

    Thnks penagate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width