Announcement

Collapse
No announcement yet.

Cursor Update Question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Barry Marks
    replied
    I missed that with LoadCursor and now it's working when I move the cursor over the dialog. Next step is to make it change over the graphics control. Thanks for pointing out what I missed.

    I think the problem is that I don't really understand what's going on with all this yet. I need to play with it some more and read more about it, I guess.

    Barry

    Leave a comment:


  • Michael Mattias
    replied
    LoadCursor:
    Code:
    HCURSOR LoadCursor(          HINSTANCE hInstance,
        LPCTSTR lpCursorName
    );
    Parameters

    hInstance
    [in] Handle to an instance of the module whose executable file contains the cursor to be loaded.
    lpCursorName
    [in] Pointer to a null-terminated string that contains the name of the cursor resource to be loaded....
    Last edited by Michael Mattias; 16 Sep 2008, 09:59 AM.

    Leave a comment:


  • Charles Dietz
    replied
    Barry, You're not calling LoadCursor the same way I did. I guess you don't really need the sz variable I used, however. Try this... it works for me.

    hCursor = LoadCursor(GetModuleHandle(BYVAL %NULL), "CUR_CROSS")

    Leave a comment:


  • Barry Marks
    replied
    I tried changing mine to look like yours but it's still not showing the cursor. I'm mystified.

    Here's my code now:
    Code:
    '------------------------------------------
    ' Template with subclassed graphic window
    '------------------------------------------
    
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "WIN32API.INC"
    #RESOURCE "curtest.pbr"
    
    %IDC_GRAPHIC1 = 1001
    
    GLOBAL OldGrProc AS LONG
    
    '----------------------------------------------------------------------
    CALLBACK FUNCTION GrProc
        LOCAL s AS STRING
        LOCAL x,y AS WORD
        STATIC oldx,oldy AS WORD
        STATIC btn AS LONG
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_RBUTTONDOWN
            s = "Right Button Down at "
            GOTO DisplayAction
    
            CASE %WM_LBUTTONDOWN
                btn = 1
                s = "Left button Down at "
                GOTO DisplayAction
    
            CASE %WM_LBUTTONUP
                btn = 0
            s = "Right Button Down at "
            GOTO DisplayAction
    
            CASE %WM_MOUSEMOVE
                IF btn = 1 THEN
                    x = LO(WORD, CBLPARAM)
                    y = HI(WORD, CBLPARAM)
                    GRAPHIC LINE (x,y)-(oldx,oldy), %RED
                    oldx = x
                    oldy = y
                ELSE
                    oldx = LO(WORD, CBLPARAM)
                    oldy = HI(WORD, CBLPARAM)
                END IF
                s = "Mouse move at "
                GOTO DisplayAction
    
        END SELECT
    
        FUNCTION = CallWindowProc(OldGrProc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
        EXIT FUNCTION
    
      DisplayAction:
        DIALOG SET TEXT GetParent(CBHNDL), s+FORMAT$(LO(WORD, CBLPARAM))+","+FORMAT$(HI(WORD, CBLPARAM))
    END FUNCTION
    
    '==================================================================================
    CALLBACK FUNCTION DlgProc
        LOCAL p AS POINTAPI
        STATIC hCursor, hOrigCursor AS DWORD
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                OldGrProc = SetWindowLong(GetDlgItem(CB.HNDL, %IDC_GRAPHIC1), %GWL_WNDPROC, CODEPTR(GrProc))
                hCursor = LoadCursor(BYVAL %NULL,"CUR_CROSS")
                hOrigCursor = SetClassLong(CB.HNDL, %GCL_HCURSOR, hCursor)
    
            CASE %WM_DESTROY
                SetWindowLong(GetDlgItem(CB.HNDL, %IDC_GRAPHIC1), %GWL_WNDPROC, OldGrProc)
                DestroyCursor hCursor
    
            CASE %WM_SETCURSOR
                SetCursor hCursor
                ShowCursor 1
                FUNCTION = 1 'Will prevent window to reset cursor to default arrow  END SELECT
    
        END SELECT
    
    END FUNCTION
    
    '====================================================================================
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg  AS DWORD
    
      DIALOG NEW PIXELS, 0, "Dialog1", 40, 40, 601, 600, %WS_MINIMIZEBOX OR %WS_SYSMENU TO hDlg
      DIALOG SET COLOR hDlg, -1&, RGB(183, 180, 133)
    
      CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC1, "", 15, 15, 500, 500, %SS_NOTIFY
    
      GRAPHIC ATTACH hDlg, %IDC_GRAPHIC1
      GRAPHIC CLEAR %WHITE
    
      DIALOG SHOW MODAL hDlg, CALL DlgProc
    
    END FUNCTION

    Leave a comment:


  • Michael Mattias
    replied
    >Barry, I'm not sure how to tell if the mouse is over the graphic control

    GetCursorPos => point
    ChildWindowFromPoint

    Leave a comment:


  • Charles Dietz
    replied
    Barry, I'm not sure how to tell if the mouse is over the graphic control, but the cross at least shows, so maybe this will get you back on the road.

    Code:
    CALLBACK FUNCTION DlgProc
        LOCAL p AS POINTAPI, sz AS ASCIIZ*32
        STATIC hCursor, hOrigCursor AS DWORD
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                OldGrProc = SetWindowLong(GetDlgItem(CBHNDL, %IDC_GRAPHIC1), %GWL_WNDPROC, CODEPTR(GrProc))
                sz = "CUR_CROSS"
                hCursor = LoadCursor(GetModuleHandle(BYVAL %NULL), sz)
                hOrigCursor = SetClassLong(CB.HNDL, %GCL_HCURSOR, hCursor)
    
            CASE %WM_DESTROY
                SetWindowLong(GetDlgItem(CB.HNDL, %IDC_GRAPHIC1), %GWL_WNDPROC, OldGrProc)
                DestroyCursor hCursor
    
            CASE %WM_SETCURSOR
                SetCursor hCursor
                'SetCursor hOrigCursor
                ShowCursor 1
                FUNCTION = 1 'Will prevent window to reset cursor to default arrow  END SELECT
    
        END SELECT
    
    END FUNCTION

    Leave a comment:


  • james klutho
    replied
    I solved my problem by using the SetCursorPos call and moving the cursor position only 1 pixel when the cursor is changed. This forced the cursor to be updated without fail.

    Thanks to everyone for their replies.

    Jim

    Leave a comment:


  • Barry Marks
    replied
    I tried some time ago to change to a custom cursor within a DDT program. The code follows this text. I wasn't able to make it work and put it aside till later.

    My intention is to have the cursor change to a custom cursor just over the graphic control but I think in this code I was trying to get a controlled change at all. The cursor goes away and I don't know why.

    Any suggestions?

    Thanks,
    Barry

    The cursor is in the attachement. I hope that worked. It's my first attachement in this forum.

    The program:

    Code:
    '------------------------------------------
    ' Template with subclassed graphic window
    '------------------------------------------
    
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "WIN32API.INC"
    #RESOURCE "curtest.pbr"
    
    %IDC_GRAPHIC1 = 1001
    
    GLOBAL OldGrProc AS LONG
    
    '----------------------------------------------------------------------
    CALLBACK FUNCTION GrProc
        LOCAL s AS STRING
        LOCAL x,y AS WORD
        STATIC oldx,oldy AS WORD
        STATIC btn AS LONG
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_RBUTTONDOWN
            s = "Right Button Down at "
            GOTO DisplayAction
    
            CASE %WM_LBUTTONDOWN
                btn = 1
                s = "Left button Down at "
                GOTO DisplayAction
    
            CASE %WM_LBUTTONUP
                btn = 0
            s = "Right Button Down at "
            GOTO DisplayAction
    
            CASE %WM_MOUSEMOVE
                IF btn = 1 THEN
                    x = LO(WORD, CBLPARAM)
                    y = HI(WORD, CBLPARAM)
                    GRAPHIC LINE (x,y)-(oldx,oldy), %RED
                    oldx = x
                    oldy = y
                ELSE
                    oldx = LO(WORD, CBLPARAM)
                    oldy = HI(WORD, CBLPARAM)
                END IF
                s = "Mouse move at "
                GOTO DisplayAction
    
        END SELECT
    
        FUNCTION = CallWindowProc(OldGrProc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
        EXIT FUNCTION
    
      DisplayAction:
        DIALOG SET TEXT GetParent(CBHNDL), s+FORMAT$(LO(WORD, CBLPARAM))+","+FORMAT$(HI(WORD, CBLPARAM))
    END FUNCTION
    
    '==================================================================================
    CALLBACK FUNCTION DlgProc
        LOCAL p AS POINTAPI
        STATIC hCursor AS DWORD
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                OldGrProc = SetWindowLong(GetDlgItem(CBHNDL, %IDC_GRAPHIC1), %GWL_WNDPROC, CODEPTR(GrProc))
    
            CASE %WM_DESTROY
                SetWindowLong(GetDlgItem(CB.HNDL, %IDC_GRAPHIC1), %GWL_WNDPROC, OldGrProc)
                DestroyCursor hCursor
    
            CASE %WM_SETCURSOR
                'hCursor = LoadCursor(0,"CUR_CROSS")
                SetClassLong CB.HNDL, %GCL_HCURSOR, LoadCursor (%NULL, BYVAL hCursor)
                SetCursor hCursor
                ShowCursor 0
                ShowCursor 1
                FUNCTION = 1 'Will prevent window to reset cursor to default arrow  END SELECT
    
        END SELECT
    
    END FUNCTION
    
    '====================================================================================
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg  AS DWORD
    
      DIALOG NEW PIXELS, 0, "Dialog1", 40, 40, 601, 600, %WS_MINIMIZEBOX OR %WS_SYSMENU TO hDlg
      DIALOG SET COLOR hDlg, -1&, RGB(183, 180, 133)
    
      CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC1, "", 15, 15, 500, 500, %SS_NOTIFY
    
      GRAPHIC ATTACH hDlg, %IDC_GRAPHIC1
      GRAPHIC CLEAR %WHITE
    
      DIALOG SHOW MODAL hDlg, CALL DlgProc
    
    END FUNCTION
    The .rc file:

    Code:
    #include "resource.h"
    
    CUR_CROSS CURSOR "Cross.cur"
    Attached Files

    Leave a comment:


  • Michael Mattias
    replied
    Code:
    LoadCursor (......)
    SetCursor (...) 
    (Or SetClasslong) 
    ShowCursor %FALSE   ' <<< TRUE, FALSE must be used in matched pairs
    ShowCursor %TRUE
    OR,
    Code:
    GetCursorPos  pt 
    SetCursorPos  pt    " The DECLARE IN WIN32API probably wants X & Y "
    so .......SetCursorPos  pt.x, pt.y

    Leave a comment:


  • Peter Lameijn
    replied
    Works normally overhere. Maybe some other problem in your code?

    Leave a comment:


  • james klutho
    started a topic Cursor Update Question

    Cursor Update Question

    I have been setting the cursor shape with a call such as

    SetClassLong hWnd, %GCL_HCURSOR, LoadCursor (%NULL, BYVAL %IDC_ARROW)

    I notice that the cursor does not change shape until the mouse is moved. Since I am changing cursor shapes while the mouse is sometimes stationary, I have an annoying problem. Is there a way to force the cursor to visually change without moving the mouse?

    Thanks

    Jim
Working...
X