-
my program snaps to the sides of the screen (like winamp), and the user has the option of changing the # of twips that the screen snaps from (so if the window is closer than X twips, it snaps to the side). anyway, since most people aren't very familiar with twips, i was wondering how to convert twips to pixels, or possibly just use pixels as the default measurement. here is the code from my sub:
'The Form is the form
'Dist is the # of twips that it snaps from
ReleaseCapture
Call SendMessage(TheForm.hwnd, &HA1, 2, 0&)
If TheForm.Left <= Dist Then TheForm.Left = 0
If TheForm.Top <= Dist Then TheForm.Top = 0
If TheForm.Left >= (Screen.Width - (TheForm.Width + Dist)) Then TheForm.Left = Screen.Width - TheForm.Width
If TheForm.Top >= (Screen.Height - (TheForm.Height + Dist)) Then TheForm.Top = Screen.Height - TheForm.Height
------------------
-cxs
[email protected]
-
Use the ScaleX/ScaleY Methods to Convert between Scale Modes, ie.
lValueInPixels = ScaleX(lValueInTwips, vbTwips, vbPixels)
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Certified AllExperts Expert
-
i still couldn't get it. i tried messing around with a few things, but it always ended up not snapping to the sides properly. here is my original sub:
Sub MoveFormSnap(TheForm As Form, Dist As Single)
ReleaseCapture
Call SendMessage(TheForm.hwnd, &HA1, 2, 0&)
If TheForm.Left <= Dist Then TheForm.Left = 0
If TheForm.Top <= Dist Then TheForm.Top = 0
If TheForm.Left >= (Screen.Width - (TheForm.Width + Dist)) Then TheForm.Left = Screen.Width - TheForm.Width
If TheForm.Top >= (Screen.Height - (TheForm.Height + Dist)) Then TheForm.Top = Screen.Height - TheForm.Height
End Sub
[This message has been edited by cxs (edited 02-07-2000).]
-
Never posted here before, so please bear with me if I screw something up.
Easiest way that I know of would be to let the user post in pixels and use Screen.TwipsPerPixelX and/or Screen.TwipsPerPixelY to make the conversion:
User enters 5 pixels. 5 * Screen.TwipsPerPixelX would be your "dist". I'd guess both ...PixelX and ...PixelY are always the same, but I don't know.
Hope this helps!
-
i tested it with winamp using the same number of pixels and it worked perfectly....thanks a lot. here's the final sub, just in case you are interested.
_______________
Sub MoveFormSnap(TheForm As Form, NumOfPixels)
Dim TwipsPerX
TwipsPerX = Screen.TwipsPerPixelX
NumOfPixels = NumOfPixels * TwipsPerX
ReleaseCapture
Call SendMessage(TheForm.hwnd, &HA1, 2, 0&)
If TheForm.Left <= NumOfPixels Then TheForm.Left = 0
If TheForm.Top <= NumOfPixels Then TheForm.Top = 0
If TheForm.Left >= (Screen.Width - (TheForm.Width + NumOfPixels)) Then TheForm.Left = Screen.Width - TheForm.Width
If TheForm.Top >= (Screen.Height - (TheForm.Height + NumOfPixels)) Then TheForm.Top = Screen.Height - TheForm.Height
End Sub
_______________
------------------
-cxs
[email protected]