Announcement

Collapse
No announcement yet.

How to use GRAPHIC COPY?

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

  • How to use GRAPHIC COPY?

    I'm having a problem getting graphic copy to work. I'm copying from a DDT graphic control to a bitmap created with GRAPHIC BITMAP NEW. This is in a little drawing program to create a revert point. When I copy it back I get a black graphic control.

    I created both the control and the bitmap 500x500. I'm using pixels, not graphic units. Here's the code for the "hold" and "revert" buttons:

    Code:
                 CASE %BTN_HOLD
                        CONTROL HANDLE hDlg, %IDC_GRAPHIC1 TO hCtl
                        GRAPHIC ATTACH hDlg, hBmpRevert
                        GRAPHIC COPY hCtl, %IDC_GRAPHIC1
                        GRAPHIC ATTACH hDlg, %IDC_GRAPHIC1
                         
                CASE %BTN_REVERT
                        GRAPHIC COPY hBmpRevert, 0
    I have a picture in the control when I press the hold button. When I press the revert button the control turns black.

    Does anyone have any idea what's going on? Any suggestions will be most appreciated and just might save some of what little hair I have left.

    Thanks,
    Barry

  • #2
    If you could post a small compilable example that shows the problem you'll likely get some suggestions. Maybe even helpful ones
    Rgds, Dave

    Comment


    • #3
      Code:
           CASE %BTN_HOLD
                 ....
                GRAPHIC COPY hCtl, %IDC_GRAPHIC1                    
            CASE %BTN_REVERT
                  GRAPHIC COPY hBmpRevert, 0
      This can't be right. In one case param one is a handle to the button control and param two is the ID of the control.

      In case two param one is a handle to a graphic and param two null.

      My doc says param one should be a handle to a BMP and param 2 the ID used in the CONTROL ADD GRAPHIC statement.

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

      Comment


      • #4
        Originally posted by Michael Mattias View Post
        Code:
             CASE %BTN_HOLD
                   ....
                  GRAPHIC COPY hCtl, %IDC_GRAPHIC1                    
              CASE %BTN_REVERT
                    GRAPHIC COPY hBmpRevert, 0
        This can't be right. In one case param one is a handle to the button control and param two is the ID of the control.

        In case two param one is a handle to a graphic and param two null.

        My doc says param one should be a handle to a BMP and param 2 the ID used in the CONTROL ADD GRAPHIC statement.

        MCM
        I'll surely admit to being confused about GRAPHIC COPY. I've read and re-read the documentation page on it and I don't really get it. I think it seems to say that when copying from a control I specify the control ID but when it comes from the bitmap created with GRAPHIC BITMAP NEW the second param is 0. I think this portion of the documentation is somewhat unclear and many of it's statements are ambiguous. Either that or I'm just confused.

        That's not a general complaint about PB's docs. They're very good as a rule but I can't pin down just what this page means.

        I can't really post my program since it won't compile without the accompanying resources (a lot of bitmaps) so I'm making up a small test program to illustrate my problem. I'll post it today or tomorrow.

        Thanks,
        Barry

        Comment


        • #5
          Here's an example program to illustrate what's happening.

          I'm assuming that I'm using GRAPIC COPY wrong but I've tried everything I can think of.

          Thanks,
          Barry


          Code:
          '-----------------------------------
          ' DDT Template with graphic window and buttons
          '-----------------------------------
          
           #COMPILE EXE
          #DIM ALL
          
          %USEMACROS = 1
          #INCLUDE "WIN32API.INC"
          
          %IDC_GRAPHIC   = 1001
          
          %BTN_PAINT = 2001
          %BTN_SAVE = 2002
          %BTN_REVERT = 2003
          
          %BTN_EXIT = 1099
          
          %BMPWIDE = 250
          %BMPHIGH = 190
          
          GLOBAL hDlg AS LONG
          
          GLOBAL hBmp AS LONG
          
          '---------------------------
          
          CALLBACK FUNCTION WinProc
              LOCAL hCtl AS LONG
          
              SELECT CASE AS LONG CBMSG
                  CASE %WM_INITDIALOG
                      GRAPHIC BITMAP NEW %BMPWIDE, %BMPHIGH TO hBmp
          
                  CASE %WM_NCACTIVATE
                      STATIC hWNDSaveFocus AS DWORD
                      IF ISFALSE CBWPARAM THEN
                          ' Save control focus
                          hWndSaveFocus = GetFocus()
                      ELSEIF hWndSaveFocus THEN
                          ' Restore control focus
                          SetFocus(hWndSaveFocus)
                          hWndSaveFocus = 0
                      END IF
          
                  CASE %WM_COMMAND
                      SELECT CASE AS LONG CBCTL
          
                          CASE %IDC_GRAPHIC
          
                          CASE %BTN_PAINT
                              GRAPHIC BOX (RND(20,30),RND(20,30)) - (RND(80,180),RND(40,170))
                              
                          CASE %BTN_SAVE
                              CONTROL HANDLE hDlg, %IDC_GRAPHIC TO hCtl
                              GRAPHIC ATTACH hDlg, hBmp
                              GRAPHIC COPY hCtl, %IDC_GRAPHIC
                              GRAPHIC ATTACH hDlg, %IDC_GRAPHIC
                              
                          CASE %BTN_REVERT
                              GRAPHIC COPY hBmp, 0
          
                          CASE %BTN_EXIT
                              IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                  DIALOG END CBHNDL
                              END IF
          
                      END SELECT
              END SELECT
          END FUNCTION
          
          '---------------------------
          
          FUNCTION PBMAIN () AS LONG
          
              DIALOG NEW PIXELS, 0, "Template", 10,10, 340,200, _
              %WS_SYSMENU OR %WS_DLGFRAME OR %WS_BORDER, TO hDlg
              DIALOG SET COLOR hDlg, -1, %GREEN
          
              CONTROL ADD BUTTON, hDlg, %BTN_PAINT, "Paint", 275,70, 50,20
              CONTROL ADD BUTTON, hDlg, %BTN_SAVE, "Save", 275,100, 50,20
              CONTROL ADD BUTTON, hDlg, %BTN_REVERT, "Revert", 275,130, 50,20
              CONTROL ADD BUTTON, hDlg, %BTN_EXIT, "Exit", 275,170, 50,20
          
              CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC, "", 5,5, %BMPWIDE,%BMPHIGH, _
                                  %WS_CHILD OR %WS_VISIBLE, %WS_EX_CLIENTEDGE
              GRAPHIC ATTACH hDlg, %IDC_GRAPHIC
              GRAPHIC COLOR -1, %WHITE
              'GRAPHIC PAINT BORDER (20,20), ltgray, green,0
          
              DIALOG SHOW MODAL hDlg, CALL WinProc
          
          END FUNCTION

          Comment


          • #6
            I just realized that I left out the GRAPHIC BITMAP END statement so it'll probably produce a memory leak if you run it. Here's the corrected version.

            Code:
            '-----------------------------------
            ' DDT Template with graphic window and buttons
            '-----------------------------------
            
             #COMPILE EXE
            #DIM ALL
            
            %USEMACROS = 1
            #INCLUDE "WIN32API.INC"
            
            %IDC_GRAPHIC   = 1001
            
            %BTN_PAINT = 2001
            %BTN_SAVE = 2002
            %BTN_REVERT = 2003
            
            %BTN_EXIT = 1099
            
            %BMPWIDE = 250
            %BMPHIGH = 190
            
            GLOBAL hDlg AS LONG
            
            GLOBAL hBmp AS LONG
            
            '---------------------------
            
            CALLBACK FUNCTION WinProc
                LOCAL hCtl AS LONG
            
                SELECT CASE AS LONG CBMSG
                    CASE %WM_INITDIALOG
                        GRAPHIC BITMAP NEW %BMPWIDE, %BMPHIGH TO hBmp
            
                    CASE %WM_NCACTIVATE
                        STATIC hWNDSaveFocus AS DWORD
                        IF ISFALSE CBWPARAM THEN
                            ' Save control focus
                            hWndSaveFocus = GetFocus()
                        ELSEIF hWndSaveFocus THEN
                            ' Restore control focus
                            SetFocus(hWndSaveFocus)
                            hWndSaveFocus = 0
                        END IF
            
                    CASE %WM_DESTROY
                        GRAPHIC BITMAP END
            
                    CASE %WM_COMMAND
                        SELECT CASE AS LONG CBCTL
            
                            CASE %IDC_GRAPHIC
            
                            CASE %BTN_PAINT
                                GRAPHIC BOX (RND(20,30),RND(20,30)) - (RND(80,180),RND(40,170))
                                
                            CASE %BTN_SAVE
                                CONTROL HANDLE hDlg, %IDC_GRAPHIC TO hCtl
                                GRAPHIC ATTACH hDlg, hBmp
                                GRAPHIC COPY hCtl, %IDC_GRAPHIC
                                GRAPHIC ATTACH hDlg, %IDC_GRAPHIC
                                
                            CASE %BTN_REVERT
                                GRAPHIC COPY hBmp, 0
            
                            CASE %BTN_EXIT
                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                    DIALOG END CBHNDL
                                END IF
            
                        END SELECT
                END SELECT
            END FUNCTION
            
            '---------------------------
            
            FUNCTION PBMAIN () AS LONG
            
                DIALOG NEW PIXELS, 0, "Template", 10,10, 340,200, _
                %WS_SYSMENU OR %WS_DLGFRAME OR %WS_BORDER, TO hDlg
                DIALOG SET COLOR hDlg, -1, %GREEN
            
                CONTROL ADD BUTTON, hDlg, %BTN_PAINT, "Paint", 275,70, 50,20
                CONTROL ADD BUTTON, hDlg, %BTN_SAVE, "Save", 275,100, 50,20
                CONTROL ADD BUTTON, hDlg, %BTN_REVERT, "Revert", 275,130, 50,20
                CONTROL ADD BUTTON, hDlg, %BTN_EXIT, "Exit", 275,170, 50,20
            
                CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC, "", 5,5, %BMPWIDE,%BMPHIGH, _
                                    %WS_CHILD OR %WS_VISIBLE, %WS_EX_CLIENTEDGE
                GRAPHIC ATTACH hDlg, %IDC_GRAPHIC
                GRAPHIC COLOR -1, %WHITE
                'GRAPHIC PAINT BORDER (20,20), ltgray, green,0
            
                DIALOG SHOW MODAL hDlg, CALL WinProc
            
            END FUNCTION

            Comment


            • #7
              Hi Barry,

              Code amended from your latest post:
              Code:
                              CASE %BTN_SAVE
                                  GRAPHIC ATTACH hBmp, 0
                                  GRAPHIC COPY hDlg, %IDC_GRAPHIC
                                  GRAPHIC ATTACH hDlg, %IDC_GRAPHIC
              Also, note that GRAPHIC BITMAP END works on the currently attached bitmap, so your %WM_DESTROY should be:
              Code:
              GRAPHIC ATTACH hBmp, 0
              GRAPHIC BITMAP END
              Hope that helps.

              Regards,

              Pete.
              Last edited by Peter Jinks; 24 Jul 2008, 06:45 PM. Reason: Remove redundant code

              Comment


              • #8
                That did it!

                I guess that's the combination I didn't try. I have no idea why it works but it does.

                Thanks. And thanks for pointing that out about GRAPHIC BITMAP END.

                Barry

                Comment


                • #9
                  Wow, either I have to learn how to read......
                  GRAPHIC COPY hbmpSource???, id& [, style&]
                  ...
                  The expression hbmpSource??? specifies the handle of the source bitmapor window.
                  ... or PB should have used a different variable name in the syntax diagram; "hSource" comes to mind.

                  "hbmpSource" sure fooled me!
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Originally posted by Michael Mattias View Post
                    Wow, either I have to learn how to read......


                    ... or PB should have used a different variable name in the syntax diagram; "hSource" comes to mind.

                    "hbmpSource" sure fooled me!
                    I think that whole page isn't quite up to the standards of the rest of the PB documentation. Hopefully they'll notice this discussion and mark it for improvement.

                    Barry

                    Comment


                    • #11
                      >Hopefully they'll notice this discussion and mark it for improvement.

                      Hope is not required.

                      I sent an email with subject "Documentation Improvement Suggestion." Included specific suggestions for improved text.

                      BTW, there is somewhere on this board an explicit disclaimer that this site is not an official communications channel. So hope is "officially" futile, too.


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

                      Comment

                      Working...
                      X