What is the reason that the button for both code examples ends up in a different location on the form?.
This piece of code sets the button in the correct location on the form.
hCtle = CreateWindowEx(xStyle, "Button", cText, WS_CHILD Or WS_VISIBLE Or WS_TABSTOP Or cStyle, _
hctl.rect.left, _ ' // horizontal position
hctl.rect.top, _ ' // vertical position
hctl.rect.right - hctl.rect.left, _ ' // window width
hctl.rect.bottom - hctl.rect.top, _ ' // window height
hwndOwner, Cast(HMENU,id), _
GetModuleHandle(NULL), _
NULL)
I would like to use AFX, but then my button location is no longer correct.
DIM pWindow AS CWindow PTR = AfxCWindowOwnerPtr(hwndOwner)
hCtle = pWindow->AddControl ( "Button", _
hwndOwner, _
id, _
cText, _
hctl.rect.left, _ ' // Horizontal position
hctl.rect.top, _ ' // Vertical position
hctl.rect.right - hctl.rect.left, _ ' // Control width
hctl.rect.bottom - hctl.rect.top, _ ' // Control height
WS_CHILD Or WS_VISIBLE Or WS_TABSTOP Or cStyle, _
xStyle, _
0, _
Null, _
&HFFFFFFFF, _
Null )
can I calculate the correct coordinates with a function?
The Afx routine does the scaling based on the passed in position values. You would need to unscale those values prior to passing in the value because Afx will scale it up.
, _
pWindow->UnScaleX(hctl.rect.left), _
pWindow->UnScaleY(hctl.rect.top), _
etc
Thanks for the effort.
Already thought there would be a function for it