Announcement

Collapse
No announcement yet.

Logo in program using graphics routines - no bitmaps

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

  • Logo in program using graphics routines - no bitmaps

    Does anyone have any source (or if bored (and kind!) enough willing to hack some up) of an example (the simpler the better) of putting a logo (eg. for your company or your name, re-usable in every program kind of thing) <U>using graphics routines</U> such as line API's? My only graphics experience is with Visual Basic, so, for all intensive purposes I have no graphics experience
    Itd just be nice to add 2-10kb per exe rather than a 20-500kb worth of bitmap
    Thanks


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

  • #2
    Not sure this will help, but following is copy&pasted from some test
    code I have done to learn more about GDI stuff myself. It builds a
    simple roundrect logotype with some text and lines. Maybe can serve
    as base for your own routine.
    Code:
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
     
    DECLARE CALLBACK FUNCTION DlgProc() AS LONG
    DECLARE SUB PaintLogo(BYVAL hWnd AS LONG)
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create dialog and controls, etc
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg AS LONG
      DIALOG NEW 0, "Simple logotype demo",,, 195, 50, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
      DIALOG SHOW MODAL hDlg CALL DlgProc
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main callback procedure (dialog's message handler)
    ' WM_PAINT is called each time dialog needs repainting,
    ' so it is good place to put code for drawing routines.
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgProc() AS LONG
      IF CBMSG = %WM_PAINT THEN PaintLogo CBHNDL
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Paint logotype - demonstrates some basic GDI stuff
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    SUB PaintLogo(BYVAL hWnd AS LONG)
      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
     
      rc.nLeft   = 8   : rc.nTop    = 8              'position and size of logotype
      rc.nRight  = 178 : rc.nBottom = 48
     
      hDC = GetDc(hWnd)                              'get dialog's device context
     
      'DRAW RECTANGLE WITH ROUNDED CORNERS
      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
      RoundRect hDC, rc.nLeft, rc.nTop, rc.nRight, rc.nBottom, 12, 12 'draw roundrect
      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 DIAGONAL LINES IN UPPER, LEFT AND LOWER, RIGHT CORNER
      hPen = CreatePen(%PS_SOLID, 1, RGB(0,0,255)) 'create thin pen for diagonal lines
      hPen = SelectObject(hDC, hPen)
      FOR I = 6 TO 18 step 3
         MoveTo hDC, rc.nLeft + 1, rc.nTop + I         'move into position, upper left
         LineTo hDC, rc.nLeft + 1 + I, rc.nTop         'draw diagonal line
         MoveTo hDC, rc.nRight - 3, rc.nBottom - I - 1 'move into position, lower right
         LineTo hDC, rc.nRight - 2 - I, rc.nBottom - 2 'draw diagonal line
      NEXT
      DeleteObject SelectObject(hDC, hPen)
     
      'DRAW TEXT
      lf.lfFaceName = "Times New Roman"              'initialize logfont structure
      lf.lfHeight = 30
      lf.lfWeight = %FW_BOLD
      lf.lfItalic = 1
      lf.lfUnderline = 1
      hFont = CreateFontIndirect(lf)                 'create font
      hFont = SelectObject(hDC, hFont)               'select font into DC, original is returned
      zTxt = "PowerBasic"                            '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 hWnd, hDC                            'release dialog's device context
     
    END SUB

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

    Comment


    • #3
      Geeeez, it's even commented - bonus! That is exactly what I'm after Borje, I should be able to get a handle on simple graphics routines just from going on that code now
      Thankyou kind sir!


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

      Comment


      • #4
        When I do training code, I always try to add as many comments I can.
        Have found that the few minutes it takes to do it can save me hours
        next time I have to use this or that command. Especially since my
        memory is only a few lazy bytes nowadays..

        A tip is to experiment with last two members of RoundRect, which decides
        the corners. I like RoundRect. Actually possible to anything from sharp
        cornered square or rectangle, to perfect oval and circle with it. With
        some work, one can create quite stunning 3-D effects too - first draw
        text and/or background in shadow color, move 2 steps up/left and draw
        in highlight color, and finally move one step down/right and draw actual
        text/background. Once carefully coded, one can have a beautiful routine
        to copy&paste in all future projects, and one learns a lot on the way.

        Another tip is to start MS resource monitor and keep an eye on it. It's
        easy to do mistakes with Windows GDI and start loosing resources. I try
        to think of it as a plain toolbox. When a tool is picked up to be used,
        same tool must also be returned, otherwise one finally will run out of
        tools. (If I only could learn do this in real life too - have two fine
        toolboxes in the garage. Both are usually empty..


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

        Comment


        • #5
          wayne,

          try timm's tsunami example :-
          http://www.powerbasic.com/support/pb...ad.php?t=25830

          he does the logo tsunami the way you want.

          david

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

          Comment

          Working...
          X