Announcement

Collapse
No announcement yet.

How to paint background of animated cursor

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

  • How to paint background of animated cursor

    Hi All, I gotten the program that could be used to draw a circular spinner but the background of the animated cursor
    isn't good. How do I paint its background ?

    Click image for larger version

Name:	Capture.PNG
Views:	150
Size:	11.4 KB
ID:	802281


    Code:
    ' Animate Image Dialog.bas
    
    #COMPILE EXE
    #DIM ALL
    #INCLUDE  "Win32API.inc"
    
    
    
       #RESOURCE RES,"Aimg.res"
    
    'Equates
     %Btn_Start      = 1001
     %LBL_LABEL1     = 1002
     %IDC_Image      = 1010
    
    
    
    FUNCTION PBMAIN()
     LOCAL hDlg,hFONTb  AS DWORD
    
      ' Bold font for the labels
        FONT END hFONTb
        FONT NEW "Arial",9,1 TO hFONTb
    
    
      DIALOG NEW PIXELS ,0, "Animated Image", , , _
                  300, 200, %WS_OVERLAPPEDWINDOW, TO hDlg
    
      DIALOG SET COLOR hDlg, -1, RGB(255,248,220)
    
      CONTROL ADD LABEL,     hDlg, %LBL_LABEL1,_
                "Click 'Start' to start processing", 70, 15, 190, 18
      CONTROL SET FONT hDlg, %LBL_LABEL1 , hFONTb
      CONTROL SET COLOR hDlg, %LBL_LABEL1, %RGB_MEDIUMBLUE  , -2
    
      CONTROL ADD BUTTON, hDlg, %Btn_Start, "Start", 75, 45, 40, 18
    
       CONTROL ADD IMAGEX, hdlg, %IDC_Image, "", _
                   80, 100, 80, 80, %WS_CHILD OR %WS_VISIBLE OR %SS_ICON , %WS_EX_TRANSPARENT
       CONTROL HIDE HDlg,%IDC_Image
    
      DIALOG SHOW MODAL hDlg, CALL DlgProc
    
       FONT END hFONTb
    
    END FUNCTION
    
    
    
    
    CALLBACK FUNCTION DlgProc()
     LOCAL hIcon AS DWORD
      SELECT CASE AS LONG CB.MSG
        CASE %WM_INITDIALOG
            ' DIALOG REDRAW CB.HNDL
    
    
        CASE %WM_COMMAND
          SELECT CASE AS LONG CB.CTL
            CASE %Btn_Start
             ' display the animated image
              IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
    
                 CONTROL NORMALIZE CB.HNDL,%IDC_Image
    
                ' Load from .ani file
                 ' hIcon = LoadImage(%NULL, "C:\Windows\Cursors\aero_busy_xl.ani", _
                         '   %IMAGE_ICON, 80, 80, %LR_LOADFROMFILE)
    
                '  Load from animated icon in resource
                   hIcon = LoadImage(GetModuleHandle(""), "#100", %IMAGE_ICON, 80, 80, 0)
    
                  CONTROL SEND CB.HNDL, %IDC_Image, %STM_SETIMAGE, %IMAGE_ICON, hIcon
              END IF
          END SELECT
    
    
        CASE %WM_SYSCOMMAND
          IF (CB.WPARAM AND &HFFF0) = %SC_CLOSE THEN
            DIALOG END CB.HNDL
          END IF
    
        CASE %WM_CLOSE
    
        CASE %WM_DESTROY
          DestroyIcon hIcon
      END SELECT
    END FUNCTION

    and its rc file for you to compile to Aimg.res
    Code:
    #include "resource.h"
    #define RT_ANIICON 22
    100  22  C:\Windows\Cursors\aero_busy_xl.ani

  • #2
    Control Set Color hDlg, %IDC_Image, -1, RGB(255,248,220)
    Rgds, Dave

    Comment


    • #3
      Why DIALOG END under %WM_SYSCOMMAND / %SC_CLOSE?
      MS speaks, "A window receives this message when the user chooses a command from the window menu"
      Like Close (Alt F4) or clicking the X. In other words, the program is already ending when you send another DIALOG END. Rem out and see it ends whithout the extra DIALOG END.

      Comment


      • #4
        Thank you Sir Dave Biggs, that was a quick fix!

        Thank you Sir Borje, I have rem out out these codes and it works fine, maybe these came from some old programs I cobbled up from

        Code:
        CASE %WM_SYSCOMMAND
        IF (CB.WPARAM AND &HFFF0) = %SC_CLOSE THEN
              DIALOG END CB.HNDL
        END IF
        
        CASE %WM_CLOSE

        Comment


        • #5
          Why DIALOG END under %WM_SYSCOMMAND / %SC_CLOSE?
          MS speaks, "A window receives this message when the user chooses a command from the window menu"
          Like Close (Alt F4) or clicking the X. In other words, the program is already ending when you send another DIALOG END. Rem out and see it ends whithout the extra DIALOG END.
          The window is closing (being destroyed) which may or may not end the program only because the default processing of the DDT engine or defWindowProc/DefDlgProc wlll carry out the system menu command.
          ===>
          An application can carry out any system command at any time by passing a WM_SYSCOMMAND message to DefWindowProc. Any WM_SYSCOMMAND messages not handled by the application must be passed to DefWindowProc. Any command values added by an application must be processed by the application and cannot be passed to DefWindowProc.
          Note the default closing or other system menu action may be preempted by returning non-zero to a dialog or simply skipping the call to DefWindowProc() when using a non-dialog window.

          In this case, you are correct it is redundant. However, "surfers" should not assume that because that is what happens in this example, that is what will happen in all cases.

          This is one of the reasons I returned to posting here... just like twenty+ years ago there are answers given which work in a particular case but should not be assumed to work in all cases.

          Besides... I *Think* funky stuff can happen if no DIALOG END is issued and the program continues. (I am not a DDT Guy).
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Now for everyone, here's the code for an elliptical spinner

            Code:
            ' Animate Image Dialog.bas
            
            '  uses a resource file to store up the animated cursor
             ' display an elliptical shape spinner
            
            #COMPILE EXE
            #DIM ALL
            #INCLUDE  "Win32API.inc"
            
            
            
               #RESOURCE RES,"Aimg.res"
            
            'Equates
             %Btn_Start      = 1001
             %LBL_LABEL1     = 1002
             %IDC_Image      = 1010
            
            
            
            FUNCTION PBMAIN()
             LOCAL hDlg,hFONTb  AS DWORD
            
              ' Bold font for the labels
                FONT END hFONTb
                FONT NEW "Arial",9,1 TO hFONTb
            
            
              DIALOG NEW PIXELS ,0, "Animated Image", , , _
                          300, 200, %WS_OVERLAPPEDWINDOW, TO hDlg
            
              DIALOG SET COLOR hDlg, -1, RGB(255,248,220)
            
              CONTROL ADD LABEL,     hDlg, %LBL_LABEL1,_
                        "Click 'Start' to start processing", 70, 15, 190, 18
            
              CONTROL SET FONT hDlg, %LBL_LABEL1 , hFONTb
              CONTROL SET COLOR hDlg, %LBL_LABEL1, %RGB_MEDIUMBLUE  , -2
            
              CONTROL ADD BUTTON, hDlg, %Btn_Start, "Start", 75, 45, 40, 18
            
               ' display an elliptical shape spinner
               CONTROL ADD IMAGEX, hdlg, %IDC_Image, "", _
                           80, 100, 120, 50, %WS_CHILD OR %WS_VISIBLE OR %SS_ICON , %WS_EX_TRANSPARENT
               CONTROL SET COLOR hDlg, %IDC_Image, -1, RGB(255,248,220)
               CONTROL HIDE HDlg,%IDC_Image
            
              DIALOG SHOW MODAL hDlg, CALL DlgProc
            
               FONT END hFONTb
            
            END FUNCTION
            
            
            
            
            CALLBACK FUNCTION DlgProc()
             LOCAL hIcon AS DWORD
              SELECT CASE AS LONG CB.MSG
                CASE %WM_INITDIALOG
            
            
                CASE %WM_COMMAND
                  SELECT CASE AS LONG CB.CTL
                    CASE %Btn_Start
                     ' display the animated image
                      IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
            
                         CONTROL NORMALIZE CB.HNDL,%IDC_Image
            
                        ' Load from .ani file
                         ' hIcon = LoadImage(%NULL, "C:\Windows\Cursors\aero_busy_xl.ani", _
                                 '   %IMAGE_ICON, 120, 80, %LR_LOADFROMFILE)
            
                        '  Load from animated icon in resource
                           hIcon = LoadImage(GetModuleHandle(""), "#100", %IMAGE_ICON, 120, 50, 0)
            
                          CONTROL SEND CB.HNDL, %IDC_Image, %STM_SETIMAGE, %IMAGE_ICON, hIcon
                      END IF
                  END SELECT
            
            
            
                CASE %WM_DESTROY
                  DestroyIcon hIcon
              END SELECT
            END FUNCTION
            Attached Files

            Comment


            • #7
              This is one of the reasons I returned to posting here... just like twenty+ years ago there are answers given which work in a particular case but should not be assumed to work in all cases.
              Are you saying a dialog might not close without a redundant DIALOG END after %WM_SYSCOMMAND/%SC_CLOSE (with no other action) ? (in the post containing quoted line)
              Dale

              Comment


              • #8
                Are you saying a dialog might not close without a redundant DIALOG END after %WM_SYSCOMMAND/%SC_CLOSE (with no other action) ? (in the post containing quoted line)
                With no action, dialogs close.. or at least they vanish from the screen. .

                HOWEVER... I seem to recall multiple occasions here where not issuing a DIALOG END can cause issues if you want to keep the program running without the closed dialog.

                Not being a DDT guy I have no real experience to draw on and the documentation is, well, less just say it's not on anyone's short list for any of the Pulitzer Prizes.

                Best bet might be to contact PB support and ask for more clarification, eg "DIALOG END is not required if the dialog is modal and the user closes the dialog from the system menu" IF THAT IS TRUE.

                There probably should be some kind of explanation in the "Remarks" for the doc of the DIALOG END statement.. My doc (PB Win 10.0.4) don't say squat about it.

                MCM
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Best bet might be to contact PB support and ask for more clarification, eg "DIALOG END is not required if the dialog is modal and the user closes the dialog from the system menu" IF THAT IS TRUE.
                  I don't have to. But perhaps you should hold your opinion till you become a "DDT guy".

                  And it is not just DDT anyway, and and (intentional) MSDN is not unclear; so no need (in this case) to add to PB Help.

                  This is one of the reasons I returned to posting here...
                  What is another reason you returned? This one isn't working.

                  ((Is the question "polite" enough?))
                  Dale

                  Comment


                  • #10
                    What is another reason you returned? This one isn't working.
                    Dale, you can only say that for yourself. FWIW, I'm glad he(and others(which includes you, Dale)) puts their thoughts in here, whether right or wrong, for if I can't tell which, I end up finding out which.
                    On this off topic matter, my experience is that if you have the %WS_SYSMENU style included(and it is included when using %WS_OVERLAPPEDWINDOW as the original poster does) then you don't need to include DIALOG END unless you want additional program exit capability.
                    Rod
                    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                    Comment


                    • #11
                      Rod,

                      A. I stand on what I asked in the quote.

                      B. Purposely spreading manure confuses others, so I disagree with your "right or wrong".

                      C. When Windows sends %WM_SYSCOMMAND/%SC_CLOSE, dialog closing is under way unless callback returns non-zero. A DIALOG END at that point is completely redundant, and would not be a cure for unwanted program close when dialog ends.

                      Just in case I'll say "bye" now because maybe I won't be able to later. I've been warned to be polite. (This is polite compared to what I'm thinking!)

                      Adam, I've ignored MCM's less serious driftings for months since you let him back in again. Keep the leash tighter. (And you don't have time for distractions (tax season, then PBWin 11/PBCC7 (64 bit or clean last 32 bit))
                      Dale

                      Comment


                      • #12
                        Hi all,
                        I'm very confused now, is this below statement constitute the "Gospel truth" when dealing with or without DIALOG END scenarios ? please comment

                        C. When Windows sends %WM_SYSCOMMAND/%SC_CLOSE, dialog closing is under way unless callback returns non-zero. A DIALOG END at that point is completely redundant, and would not be a cure for unwanted program close when dialog ends.
                        What I need to know is that I need to be able to exit a program cleanly without remnants of it still hovering in the memory. Can Dialog End statement
                        does this securely? at least speak from your experience as the original author of the compiler has passed.

                        Comment


                        • #13
                          Originally posted by Michael Mattias View Post
                          This is one of the reasons I returned to posting here... just like twenty+ years ago there are answers given which work in a particular case but should not be assumed to work in all cases.

                          Besides... I *Think* funky stuff can happen if no DIALOG END is issued and the program continues. (I am not a DDT Guy).
                          It is good that you are back.
                          But try not to respond to inappropriate animosity. (It's all a pun if you are a word guy.)
                          A manual command to end the program, when the system is already doing so, is only necessary within a loop that maintains processing without the dialog present.
                          This is a common occurrence in GRAPHIC windows or in console applications. I suppose also in TXT windows?
                          In that case, an iswin() to determine if the window had been shut down.
                          The world is strange and wonderful.*
                          I reserve the right to be horrifically wrong.
                          Please maintain a safe following distance.
                          *wonderful sold separately.

                          Comment


                          • #14
                            Hello Kurt, does your statement implies that we should check whether the window is shut down for good by something kinda
                            Code:
                                  if iswin(hdlg) then
                                     DIALOG END hdlg
                                  end if
                            I have seen some programs here uses DESTROY windows statement?

                            Comment


                            • #15
                              I have seen some programs here uses DESTROY windows statement?
                              The DestroyWindow() WinAPI function is called if you created the window with either the CreateWndowEx() or the CreateDialog() WinAPI functions. It does not apply to windows created with the PB DIALOG NEW statement.

                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #16
                                This [program running after window is destroyed] is a common occurrence in GRAPHIC windows or in console applications
                                Maybe that is the situation I have been encountering here.

                                Regardless, the doc for DIALOG END is in need of expansion to include "when it should be used" and "when it should not be used" For now it would be good to get that info into the Online Help and Commentary" forum under DIALOG END. (Maybe someone who is really good at DDT /Graphics will do that?)
                                Michael Mattias
                                Tal Systems (retired)
                                Port Washington WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  I think Tim was referring to the %WM_DESTROY message which is handy for killing handles to various creations such as brushes, fonts, bitmaps, icons, etc. just as Tim did in the code in the first post of this thread. According to the docs, that message is handled after the window is closed.

                                  In post #10 I mentioned that if a dialog had the %WS_SYSMENU style that DIALOG END was not needed. There may be more than I know to this issue, but DIALOG END seems to be appropriate when some user event such as a button click or a time period lapse triggers the end of the process. There may be things I'm unaware of. FWIW, PBFORMS includes it on buttons with the %IDCANCEL identifier.

                                  With regard to GRAPHIC windows, I have found that if a GRAPHIC WAITKEY$ has been invoked then one needs to include the GRAPHIC WINDOW END or the program will still be running after closing with the system menu. This may or may not apply to GRAPHIC INSTAT as well.
                                  Rod
                                  I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                  Comment


                                  • #18
                                    Originally posted by Tim Lakinir View Post
                                    What I need to know is that I need to be able to exit a program cleanly without remnants of it still hovering in the memory. Can Dialog End statement
                                    does this securely? at least speak from your experience as the original author of the compiler has passed.
                                    The WM_Close message is sent to a dialog's callback when a dialog is closing. It has nothing to do with exiting an application.

                                    Closing a Dialog does not end an application any more than closing a message box does. It's up to you to ensure that there is no code still running (loops, threads, long running functions/subs) when you close your the last visible dialog.

                                    Comment


                                    • #19
                                      Originally posted by Tim Lakinir View Post
                                      Hello Kurt, does your statement implies that we should check whether the window is shut down for good by something kinda
                                      Code:
                                      if iswin(hdlg) then
                                      DIALOG END hdlg
                                      end if
                                      No,that is completely unnecessary to close a DDT window. if you are using DDT, DIALOG/TXT/GRAPHIC WINDOW END is all you need to close a "window". It's up to you however to ensure that you don't leave code running which is not associated with any visible window.

                                      Comment


                                      • #20
                                        Originally posted by Michael Mattias View Post

                                        Maybe that is the situation I have been encountering here.

                                        Regardless, the doc for DIALOG END is in need of expansion to include "when it should be used" and "when it should not be used" For now it would be good to get that info into the Online Help and Commentary" forum under DIALOG END. (Maybe someone who is really good at DDT /Graphics will do that?)
                                        I disagree. The current Help covers all that is necessary:

                                        DIALOG END destroys a dialog.
                                        (It should be used when you want to destroy a DDT dialog)

                                        It should not be used when you don't want to destroy a DDT dialog, the dialog is in a different thread or the application is still processing the %WM_INITDIALOG callback for the dialog.

                                        What else needs to be said?


                                        Comment

                                        Working...
                                        X