Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetWindowRect API

Status
Not open for further replies.

GGardiner

Programmer
Aug 11, 2003
9
0
0
US
Hi All,

I have a problem, which I hope someone can help with. I am trying to sub-class the data picker control (because you cannot key 010103 as a date into it). I have written a VB6 ActiveX control that will place a textbox over the text portion of the datapicker (using the GetWindowRect API) and leave the arrow buttion visible for the user to press.

Eveything is fine on xp (my development environment), however, on Win2000, I get different results from the GetWindowRect API, which you say is to be expected. This is true, however, under XP it seems this API returns the full size of the control including borders. Under Win2000, it appears to return just the client area, minus borders!!

Can someone please tell me I am not going mad!.


Thanks

George

PS. Here is the test project I have created. It will require a combobox, command button and text box on a form to work.

Option Explicit

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) _
As Long

Private Declare Function GetWindowRect Lib "user32.dll" _
(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 tRect As RECT

Dim hwnd As Long

Dim fWidth As Single
Dim fHeight As Single
Dim fBWidth As Single
Dim sngBorderWidth As Single

Dim intSaveWidth As Integer


'get the handle to the edit portion
'of the combo control
hwnd = FindWindowEx(Combo1.hwnd, 0&, vbNullString, vbNullString)
Call GetWindowRect(hwnd, tRect)
With tRect
fWidth = (.Right - .Left) * Screen.TwipsPerPixelX
fHeight = (.Bottom - .Top) * Screen.TwipsPerPixelY
End With
Debug.Print "Width"; fWidth, "Height"; fHeight, Combo1.Width
fBWidth = Combo1.Width - fWidth

'Now get the size of the borders
intSaveWidth = Combo1.Width
Combo1.Width = 0
hwnd = FindWindowEx(Combo1.hwnd, 0&, vbNullString, vbNullString)
Call GetWindowRect(hwnd, tRect)
With tRect
sngBorderWidth = (.Right - .Left) * Screen.TwipsPerPixelX
fHeight = (.Bottom - .Top) * Screen.TwipsPerPixelY
End With
sngBorderWidth = (sngBorderWidth / 2)
Combo1.Width = intSaveWidth

'Test it
With label1
.Text = ""
.BackColor = vbRed
.Left = Combo1.Left + sngBorderWidth
.Top = Combo1.Top + sngBorderWidth
.Width = Combo1.Width - (Combo1.Width - fWidth) + (sngBorderWidth * 1.6)
.Height = Combo1.Height - (sngBorderWidth * 2)
.ZOrder 0
.Text = "13 Nov 2003"
End With

Combo1.ZOrder 1
MsgBox "Width of button should be.. " & fBWidth & " twips"

End Sub
 
Thanks for the suggestion, but, (there is always a but) it gives me the same results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top