[RESOLVED] Switching mouse cursor on the fly while drawing?
Plan is to switch mousepointer when drawing selection rectangle/rubber band box, as follows;
- XStart < XCurr or YStart < YCurr -> draw solid blue selection rectangle, mousepointer 99, custom 'icon overlap'
- XStart > XCurr or YStart > YCurr -> draw dashed green selection rectangle, mousepointer 99, custom 'icon inside'
Solid blue/dashed green are basic stuff, drawing with vbXorPen and bit shifting drawing color with background color (DrawColor xor BackGroundColor), but VB6 intrinsic picturebox has only one custom mouse pointer/icon.
Hence thinking of using two hidden intrinsic image controls, for the cursor icon storage and copying it two PicDraw.MouseIcon as follows;
- XStart < XCurr or YStart < YCurr -> PicDraw.MousePointer = ImageCursorStorage(0).MousePointer
- XStart > XCurr or YStart > YCurr -> PicDraw.MousePointer = ImageCursorStorage(1).MousePointer
Hence question - Method to switch between two custom mouse cursors 'on the fly' while drawing - better than that, using resource or maybe some other?
Re: Switching mouse cursor on the fly while drawing?
Tech
Don't know if this meets your purposes but ...
Components
Command2 .. CommandButton
PB1 .. PictureBox
Code:
Sub Command2_click()
'
If PB1.MousePointer < 15 Then
PB1.MousePointer = PB1.MousePointer + 1
ElseIf PB1.MousePointer = 15 Then
PB1.MousePointer = 0
End If
'
End Sub
How to construct 'proper' .cur file, which has transparent parts (other than cursor image) and hotspot in upper left corner?
Tried couple of cursor editors, but all seems 'somewhat flawed' - read -> I might have 'no knowledge' of using them properly.
For example Greenfish Icon Editor Pro - shows .cur file in it's different background color test area ok -> transparent parts are transparent, but in VB transparent parts shows as inverted colors (ie. transparent part is black on white canvas etc.) and hotspot is in middle ie. 32x32 .cur file hotspot is at 16,16.
Re: Switching mouse cursor on the fly while drawing?
Test your cursor when compiled. In IDE, cursors/icons are handled as black and white. If you post your cursor, I can take a quick peak, but try it first in a compiled app.
Edited: said cursors/icons... meant just cursors
Last edited by LaVolpe; Oct 19th, 2017 at 04:42 PM.
Insomnia is just a byproduct of, "It can't be done"
Re: Switching mouse cursor on the fly while drawing?
Interesting. Kinda leaning on another thing the IDE fails on, regarding cursors.
Assumption: The cursor does not use inverting, it is always black.
1. Loading the cursor directly into the MouseIcon property fails for these
2. Loading the cursor into a res file and then using LoadResPicture to assign it to the MouseIcon property: Success
-- however when in IDE, horrible results. But when compiled, looks correct
I didn't notice anything technically incorrect with the cursors.
Tip: To see what the compiled version will look like, without compiling, while in IDE. Use the code in post #2 in this thread
Edited: Had some time on my hands... There is something off. The color table in your cusor has no white. Typically 1 bit cursors/icons are expected to have a 2-color table: one color black and the other white. Yours has both entries as black. By changing the 2nd color table entry to white, it drew correctly in both IDE and compiled.
My guess as to why it worked (as-was) when loaded via a resource file is that VB uses the system's LoadImage/LoadCursor APIs which probably ignore color tables for 1 bit images and assume black & white entries. But when loaded directly into the MousePointer property, VB uses some other function/method (COM API maybe) that does not make that assumption?
So, I'm assuming 1 of 2 things
1. That app has a logic error when setting the color table for B&W 1-bpp images
2. You failed to set the 2nd color to White
To 'fix' your cursors, the following code can be used. This won't work in all cases, because the color table offset will be different. But with the 2 cursors your provided, this can be used. Change the path as needed. Then set fixed cursor to the MouseIcon property and see if it works.
Code:
Dim b() As Byte
Open "C:\Icon_Inside.cur" For Binary As #1
ReDim b(0 To LOF(1) - 1)
Get #1, 1, b()
Close #1
' copy fixed cursor to a new file
b(22 + 44) = 255: b(22 + 45) = 255: b(22 + 46) = 255
Open "C:\Icon_Inside2.cur" For Binary As #2
Put #2, 1, b()
Close #2
Last edited by LaVolpe; Oct 19th, 2017 at 06:45 PM.
Insomnia is just a byproduct of, "It can't be done"
Re: Switching mouse cursor on the fly while drawing?
@Tech99. See my recent 'edits' in my previous reply. Your color table in the cursor file is incorrect.
Didn't catch the hotspot? Did that fail when loading via MouseIcon property directly? Maybe VB ignores hotspot in IDE when loaded that way? If so, don't know if it would've worked compiled -- didn't test that scenario. I do see that it is set to 0,0
Insomnia is just a byproduct of, "It can't be done"
Re: Switching mouse cursor on the fly while drawing?
2. You failed to set the 2nd color to White
Second assumption could be very correct as i created cursors with Greenfish Icon Editor Pro, using 'transparent' as background.
Didn't catch the hotspot? Did that fail when loading via MouseIcon property directly? Maybe VB ignores hotspot in IDE when loaded that way? If so, don't know if it would've worked compiled -- didn't test that scenario. I do see that it is set to 0,0
Yes - it failed when loaded with mouseicon property. Clearly it was set in middle of the cursor at 16x16.
To 'fix' your cursors, the following code can be used. This won't work in all cases, because the color table offset will be different. But with the 2 cursors your provided, this can be used. Change the path as needed. Then set fixed cursor to the MouseIcon property and see if it works.
Byte patched icon works ok, is transparent and hotspot is in upper left corner.
Last edited by Tech99; Oct 19th, 2017 at 07:23 PM.