PSet and Mouse Position

jerbear
01-13-2005, 10:39 PM
A part of a program I'm making needs to be able to put a dot where the user clicks. I'm not very familiar with pointapi and am looking for a simple way to do it. I tried pointapi and the dots were appearing at the topleft of the screen, when I was clicking in the middle.

I'm still willing to learn about pointapi though. I haven't quite figured it out yet.

MikeJ
01-13-2005, 11:01 PM
The trick with the API is that they deal with pixels, while VB by default uses Twips. Set the scalemode of the form to vbPixels, and the API method should work correctly.

jerbear
01-14-2005, 08:22 AM
The trick with the API is that they deal with pixels, while VB by default uses Twips. Set the scalemode of the form to vbPixels, and the API method should work correctly.

how do i do that? i'm sort of a beginner at programming.

Kalkran
01-14-2005, 08:38 AM
Form.ScaleType I think... It could be ScaleMode too ... I dunno don't have VB installed just yet

jerbear
01-14-2005, 09:20 AM
it's almost working. only now instead of being a few hundred pixels away on the top left corner, they're appearing on the bottom right corner, only less grouped together. here's my code:


Private Sub Form_Click()
Dim MousePos As POINTAPI

If blnWaypoint = True Then
'changes measurement to pixels and thickness to 5
Me.ScaleMode = 3
Me.DrawWidth = 5
Call GetCursorPos(MousePos)
Me.PSet (MousePos.x, MousePos.y), vbRed
End If
End Sub

noi_max
01-14-2005, 09:56 AM
Dots on your form... the easy way:


Option Explicit

Private MouseX As Single, MouseY As Single

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Me.PSet (MouseX, MouseY), vbRed

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

MouseX = X
MouseY = Y

End Sub

I looked up the GetCurPos in the API guide and found this description:
The GetCursorPos function retrieves the cursorís position, in screen coordinates.

I figure since the GetCursorPos is using the screen's coordinates, it won't offset correctly on your form. mAybe some other API is needed to do it that way.

jerbear
01-14-2005, 10:53 AM
wow thanks. that worked really well! how come i didn't think of that? oh well.

jerbear
01-14-2005, 02:50 PM
is there a way to prevent things printed on the screen from disappearing when i minimize the form? like pset and line. they always get cleared.

jerbear
01-14-2005, 03:42 PM
nvm. i figured it out. autoredraw. oops

tomc2506
01-14-2005, 04:36 PM
Autoredraw will work but it shouldn't be used the whole time for memory reasons :)

Kalkran
01-17-2005, 12:33 PM
Yeah it lags your computer like hell!

noi_max
01-17-2005, 01:47 PM
is there a way to prevent things printed on the screen from disappearing when i minimize the form? like pset and line. they always get cleared.
A little trick I picked up from passel:

Me.AutoRedraw = True

'Draw a box (or point or whatever else...)
Me.Line (500, 500)-(1000, 1000), vbBlue, BF

Me.AutoRedraw = False

passel
01-17-2005, 11:52 PM
Without AutoRedraw being set True, you are drawing directly to the screen, so what
you draw can be wiped out by other windows, or by minimizing your window since the
"screen" is the memory, and if you don't see it on the screen, it no longer exists.

With AutoRedraw set True, memory is allocated and your drawing goes in that memory,
and then the Screen is AUTOmatically REDRAWn with the contents of that memory
when necessary.

So it is true that you use more memory. For a Sizable Form, a full Screen worth of
memory is allocated, even if the form is not the full size of the screen. This allows you
to resize the form and not loose any of your drawing. It also allows drawing beyond
the left and bottom of the form (as long as it is not more than a screen width or height
beyond the origin of the form), and then revealing what was drawn by resizing the form.

Once this memory has been allocated, setting AutoRedraw back to False does not save
you any memory. The memory is maintained.

All that AutoRedraw controls at that point is whether you are drawing to the .Image (set True),
or to the Screen (set False).

Since it won't save you any memory, what reason would you have for changing AutoRedraw on the fly?
Well, you could set it True, and then draw something that you want to keep as a background.
You could then set it False, and then draw something "on top" of your background.
If you use Cls to clear the Form, then (with AutoRedraw False), only the stuff you
drew "on top" is cleared, the "background" is unaffected.

To clear the "background", set AutoRedraw to True, then issue the Cls.

With AutoRedraw set True, it is also true that the normal VB drawing commands are
slower than when AutoRedraw is False. The is because, when it is False, it is a one
step process, writing directly to the screen. If AutoRedraw is True, then it is a two
step process, writing first to memory, and then refreshing to the screen.
The advantage is, you won't have to worry about having to redraw the form yourself
if something wipes out part of your drawing (or you minimize, or resize your form). It
will be refreshed from the .Image buffer automatically.
If speed is a concern, then you will need to turn to the API (but you will still probably
want AutoRedraw set True (if not using some other Memory DC to hold the drawing)
so that the drawing will be maintained if you minimize or resize your form).

As far as the simple Dot Drawing goes, since the X and Y are passed to the Sub, you
don't need to maintain code in the MouseMove and use Module Level variables.

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Me.PSet (X, Y), vbRed

End Sub

would have worked fine.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum