Announcement

Collapse
No announcement yet.

Shape Control (Circle)

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

  • Shape Control (Circle)

    Anyone using VB has likely run across the Shape control. I have used this to create circles which can be colorized so as to give feedback (i.e. Green = Good; Red = Bad).

    Has anyone done something like this with PB/DLL? I have no used DDT and am working on my first app with it.

    Thanks,
    Ron

  • #2
    Could create a custom "shape" control, but also easy to draw directly
    on dialog or controls. To make it hollow, use hollow brush. Simple sample:
    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' DDT TEMPLARE
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
     
    DECLARE CALLBACK FUNCTION DlgCallback()
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' PBMAIN - build dialog and controls
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN
      LOCAL hDlg AS LONG
     
      DIALOG NEW 0, "Circle",,, 78, 72, %WS_CAPTION OR %WS_SYSMENU TO hDlg
      CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Ok", 14, 29, 50, 14
     
      DIALOG SHOW MODAL hDlg CALL DlgCallback
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' MAIN DIALOG'S CALLBACK PROCEDURE
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgCallback()
       SELECT CASE CBMSG
          CASE %WM_COMMAND
             IF CBCTLMSG = %BN_CLICKED AND CBCTL = %IDCANCEL THEN DIALOG END CBHNDL
     
          CASE %WM_PAINT
             LOCAL hPen AS LONG, hBrush AS LONG, ps AS PAINTSTRUCT
     
             BeginPaint CBHNDL, ps                                      'draw a hollow shape - here circle
             hPen   = CreatePen(%PS_SOLID, 1, RGB(255, 0, 0))           'create (red) pen for frame
             hPen   = SelectObject(ps.hDC, hPen)                        'Select pen into DC, original pen is returned
             hBrush = SelectObject(ps.hDC, GetStockObject(%NULL_BRUSH)) 'Select a hollow brush into DC, original brush..etc.
             Ellipse ps.hDC, 8, 8, 110, 110                             'draw circle
             DeleteObject SelectObject(ps.hDC, hPen)                    'Delete pen
             SelectObject ps.hDC, hBrush                                'Select original brush back
             EndPaint CBHNDL, ps
     
       END SELECT
    END FUNCTION

    ------------------

    Comment


    • #3
      Quickly extracted from one of Borje samples to get you started...

      Code:
      #COMPILE EXE
      #INCLUDE  "WIN32API.INC"
       
      '------------------------------------------------------------------------------
      ' General Dialog Callback Code:
      '
      '------------------------------------------------------------------------------
      CALLBACK FUNCTION DialogCallback
      
      LOCAL I AS LONG, hDC AS LONG, hPen AS LONG, hBrush AS LONG, hFont AS LONG
      LOCAL lf AS LOGFONT, rc AS RECT, zTxt AS ASCIIZ * 100
          
      
      SELECT CASE CBMSG
                 
          CASE %WM_PAINT
        
              SetRect rc, 10,10,80,80
         
              hDC = GetDc(CBHNDL)                            'get dialog's device context
      
              hBrush = CreateSolidBrush(RGB(255,255,0))      'create yellow background brush
              hBrush  = SelectObject(hDC, hBrush)            'select brush into hDC, original brush is returned
              hPen = CreatePen(%PS_SOLID, 2, RGB(255,0,0))   'create red, thick pen for border
              hPen = SelectObject(hDC, hPen)                 'select pen into hDC, old pen is returned
              
              CALL Ellipse(hdc,rc.nLeft, rc.nTop,rc.nRight,rc.nBottom)
              
              DeleteObject SelectObject(hDC, hPen)           'select old pen back and delete new that is returned
              DeleteObject SelectObject(hDC, hBrush)         'select old brush back and delete new..
      
         
      
              'DRAW TEXT
              lf.lfFaceName = "Times New Roman"              'initialize logfont structure
              lf.lfHeight = 30
              lf.lfWeight = %FW_BOLD
              lf.lfItalic = 1
              lf.lfUnderline = 0
              hFont = CreateFontIndirect(lf)                 'create font
              hFont = SelectObject(hDC, hFont)               'select font into DC, original is returned
              zTxt = "On"                                    'text to draw
              SetTextColor hDC, RGB(0, 0, 255)               'set text color
              SetBkMode hDC, %TRANSPARENT                    'transparent text background
              CALL DrawText(hDC, zTxt, LEN(zTxt), rc, %DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER)
      
              DeleteObject SelectObject(hDC, hFont)          'select old font back, new is returned - delete new
              ReleaseDc CBHNDL, hDC
        
              FUNCTION = 0 :EXIT FUNCTION
               
          CASE %WM_COMMAND
              SELECT CASE  LOWRD(CBWPARAM)
                  CASE %IDCANCEL
                      DIALOG END CBHNDL, %TRUE
                  END SELECT
          END SELECT
      END FUNCTION
      
      
      '------------------------------------------------------------------------------
      '  Main entry point when program starts:
      '
      '------------------------------------------------------------------------------
      FUNCTION PBMAIN() AS LONG
          LOCAL hDlg AS LONG, dx AS LONG, dy AS LONG, Rct AS RECT
          DIALOG NEW %HWND_DESKTOP, "Draw Circle", 0, 0, _
              250, 200, %WS_MAXIMIZEBOX OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR _
              %WS_THICKFRAME OR %WS_CLIPCHILDREN OR %WS_CLIPSIBLINGS OR %DS_CENTER _
              TO hDlg
          DIALOG SHOW MODAL hDlg CALL DialogCallback
      END FUNCTION
      Best regards
      Jules
      www.rpmarchildon.com

      Comment


      • #4
        Thanks, Borje and Jules! I appreciate your help!
        Ron

        Comment


        • #5
          Ron,

          Yea, that Borje is just too quick...

          One other thing I used for Red/Green/Yellow LEDS ON/OFF were
          Icons from a resource file. That would probably be your smallest
          effort.

          Regards,
          Jules

          Best regards
          Jules
          www.rpmarchildon.com

          Comment


          • #6
            Ron --

            I agree with Jules. The easiest way to do this would be to use Microsoft Paint to create a couple of small bitmaps (circles or whatever), embed them with #RESOURCE, and then use the DDT IMAGE functions.

            -- Eric


            ------------------
            Perfect Sync Development Tools
            Perfect Sync Web Site
            Contact Us: mailto:[email protected][email protected]</A>

            [This message has been edited by Eric Pearson (edited October 11, 2001).]
            "Not my circus, not my monkeys."

            Comment


            • #7
              Thanks for the suggestions, Jules and Eric. I will give that a shot. I am probably going to have about 32 of these across a dialog to represent serial ports and some status. I wish I had not waited forever to use PB/DLL with a GUI!!!

              At least this is something I can "play" with a little without any deadline to meet.

              All you guys have been superb help!
              Ron

              Comment


              • #8
                On my site i have a very old VB example (Regions.exe)


                ------------------
                http://www.hellobasic.com
                hellobasic

                Comment


                • #9
                  Edwin, I checked out "Regions".
                  It's k00l!
                  thanks,
                  Ron

                  Comment


                  • #10
                    Ron,

                    I made a couple of bitmaps a while ago for the same sort of thing.
                    If you want them, just email me at [email protected] & I'll send them
                    over.

                    Russ Srole

                    ------------------
                    "There are two novels that can change a bookish fourteen-year old's life: The Lord of the Rings and Atlas Shrugged. One is a childish fantasy that often engenders a lifelong obsession with its unbelievable heroes, leading to an emotionally stunted, socially crippled adulthood, unable to deal with the real world. The other, of course, involves orcs." - John Rogers

                    Comment

                    Working...
                    X