Results 1 to 9 of 9

Thread: [RESOLVED] Switching mouse cursor on the fly while drawing?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    679

    Resolved [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?

  2. #2
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: Switching mouse cursor on the fly while drawing?

    Tech

    Don't know if this meets your purposes but ...

    Components
    1. Command2 .. CommandButton
    2. 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
    Screenshot

    Name:  Mouse1.png
Views: 156
Size:  1.8 KB

    Notice anything .. oh yeah, no pointer shown ..
    Sadly, Paint doesn't capture mousepointer.

    But, if you click Command2 and move mouse to PB1, it will change.
    Repeat to see new pointer (albeit some revert to default)

    HTH

    Spoo

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    679

    Re: Switching mouse cursor on the fly while drawing?

    PicDraw.MouseIcon = ImageCursorStorage(0).MouseIcon

    Works ok.

    but...

    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.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    679

    Re: Switching mouse cursor on the fly while drawing?

    Tested cursors in compiled app, no transparency and hotspot in middle.

    See the attached zip file.
    Attached Files Attached Files

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    679

    Re: Switching mouse cursor on the fly while drawing?

    Thanks Lavolpe.

    Attached your 'post #2 in this thread code' to the project, added cursors to resource file and the following code.

    Code:
    'Load mousecursors from resource
    ImgCursorInside.MouseIcon = LoadResIconEx("ICON_INSIDE", , , , True) 'True = resource type is RT_CURSOR
    ImgCursorOverlap.MouseIcon = LoadResIconEx("ICON_OVERLAP", , , , True)
    Surprise surprise... transparency ok and hotspot in upper left corner.
    Attached Images Attached Images  

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    679

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width