| Home | Ruff-In | MTutor | GradientFill | FB code | FBLoan | TW-Form | JaxGUI | Other DownLoads | PBCC Code | GW Code | Fix 2000/ XP | Text Screen Shots | QB code

GradientFill

ConASCII

JaxGUI Generated Gradient Fill

Horizontal & Vertical Gradient Fills using JaxGUI, compiled by PBCC.

gradient-fill.jpeg

The above window is what you see when you Click on Preveiw below.

program-grid.jpeg

 
Text you would see when you click on CodeView
 
 
 
 #CONSOLE OFF ' Delete if using older than PBCC4.03
 #COMPILE EXE
 #DIM ALL
 #INCLUDE "C:\PBCC40\WINAPI\WIN32API.INC"
 GLOBAL hInstance, hwnd AS LONG
 
 SUB GradientFills (BYVAL hdlg AS DWORD, BYVAL dr AS LONG, _
        BYVAL R AS LONG, BYVAL G AS LONG, BYVAL B AS LONG, _
        BYVAL R1 AS LONG, BYVAL G1 AS LONG, BYVAL B1 AS LONG, _
        BYVAL x1 AS LONG, BYVAL y1 AS LONG, BYVAL x2 AS LONG, BYVAL y2 AS LONG)
   LOCAL hDC AS DWORD
   LOCAL gRect AS GRADIENT_RECT
   DIM vert(1) AS TRIVERTEX
   hDC = GetDC(hdlg)
   vert(0).x      = x1
   vert(0).y      = y1
   vert(0).Red    = VAL("&H" + HEX$(R) + "00")
   vert(0).Green  = VAL("&H" + HEX$(G) + "00")    '1st color
   vert(0).Blue   = VAL("&H" + HEX$(B) + "00")
   vert(0).Alpha  = &H0000
   vert(1).x      = x2
   vert(1).y      = y2
   vert(1).Red    = VAL("&H" + HEX$(R1) + "00")
   vert(1).Green  = VAL("&H" + HEX$(G1) + "00")    '2nd color
   vert(1).Blue   = VAL("&H" + HEX$(B1) + "00")
   vert(1).Alpha  = &H0000
   gRect.UpperLeft  = 0
   gRect.LowerRight = 1
   IF dr = 1 THEN        ' dr is horizontal/vertical fill (1/0)
      GradientFill hDC, vert(0), 2, gRect, 1, %GRADIENT_FILL_RECT_H
   ELSEIF dr = 2 THEN
      GradientFill hDC, vert(0), 2, gRect, 1, %GRADIENT_FILL_RECT_V
   END IF
   ReleaseDC(hdlg, hDC)
 END SUB

  FUNCTION EnumCharSet(elf AS ENUMLOGFONT,ntm AS NEWTEXTMETRIC, _
             BYVAL FontType AS LONG, BYVAL CharSet AS LONG) AS LONG
      CharSet = elf.elfLogFont.lfCharSet
  END FUNCTION

  FUNCTION MakeFontEx(sFont AS STRING, BYVAL PointSize AS LONG, _
         BYVAL fBold AS LONG, BYVAL fItalic AS LONG, BYVAL fUnderline AS LONG, _
         BYVAL StrikeThru AS LONG) AS LONG
      LOCAL hDC AS LONG, CharSet AS LONG, CyPixels AS LONG
      hDC = GetDC(%HWND_DESKTOP)
      CyPixels  = GetDeviceCaps(hDC, %LOGPIXELSY)
      EnumFontFamilies hDC, BYVAL STRPTR(sFont), CODEPTR(EnumCharSet) , BYVAL VARPTR(CharSet)
      ReleaseDC %HWND_DESKTOP, hDC
      PointSize = 0 - (PointSize * CyPixels) \ 72
      FUNCTION = CreateFont(PointSize,0,0,0, fBold, _
                           fItalic,fUnderline,StrikeThru,CharSet, _
                           %OUT_TT_PRECIS, %CLIP_DEFAULT_PRECIS, _
                           %DEFAULT_QUALITY, %FF_DONTCARE, _
                           BYCOPY sFont)
  END FUNCTION
 
 FUNCTION ProcessWindow (BYVAL hDlg AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam _
                  AS DWORD, BYVAL lParam AS LONG) AS LONG
   STATIC hStBrush1 AS LONG
   STATIC hStBrush2 AS LONG
   LOCAL wmID AS LONG, wmEvent AS LONG
   LOCAL ps AS PAINTSTRUCT
   LOCAL StBgColor1 AS LONG, StFgColor1 AS LONG
   LOCAL Lt1 AS STRING
   LOCAL StBgColor2 AS LONG, StFgColor2 AS LONG
   LOCAL Lt2 AS STRING
   LOCAL hfont AS LONG
   LOCAL hHand AS LONG
    STbgColor1 = &H800080     ' Selected background color for a Static control
    STfgColor1 = &HFFFFFF     ' Selected foreground color for a Static control
    STbgColor2 = &H800080     ' Selected background color for a Static control
    STfgColor2 = &HFFFFFF     ' Selected foreground color for a Static control
  SELECT CASE wMSG
     CASE %WM_CREATE         'Create and initialize Controls
     hSTbrush1  =  CreateSolidBrush(STbgColor1)' Create a logical brush with selected color for a Static/Label control
     hSTbrush2  =  CreateSolidBrush(STbgColor2)' Create a logical brush with selected color for a Static/Label control
        Lt1=Lt1 + "After Selecting an Area and Right clicking on Parent "
        Lt1=Lt1 + "Button, I selected Vertical Gradient to fill it."
         CreateWindowEx(0, "static", BYVAL STRPTR( LT1 ), _
             %WS_CHILD OR %WS_VISIBLE, _
            20,  0,  690,  19, _
            hdlg,  100, hInstance, BYVAL %NULL)
        Lt2=Lt2 + "To fill a Horizontal and Vertical bars like the ones "
        Lt2=Lt2 + "showing here, it takes two steps for each bar. The first "
        Lt2=Lt2 + "step does a gradient fill on the first half and the 2nd "
        Lt2=Lt2 + "step does a fill on the next half. To do this Horizontal "
        Lt2=Lt2 + "bar, I selected one row on the Grid and Right clicked on "
        Lt2=Lt2 + "Rectangle. I then clicked on Vertical Gradient. When the "
        Lt2=Lt2 + "color picker showed, I clicked on my dark color first and "
        Lt2=Lt2 + "click on Ok and when the it came back, I clicked on my "
        Lt2=Lt2 + "light color which was white. Then I clicked on Finished at "
        Lt2=Lt2 + "the bottom of the menu and that completed the 1st "
        Lt2=Lt2 + "half.....2nd half.... On the Grid, I selected the next row "
        Lt2=Lt2 + "and right clicked on Rectangle again. Next I clicked "
        Lt2=Lt2 + "Vertical Gradient and when the Color picker came up, this "
        Lt2=Lt2 + "time I clicked on my lighter color first, which was white. "
        Lt2=Lt2 + "When the color picker came back for its next color, I "
        Lt2=Lt2 + "clicked on my darker color............The vertical bars "
        Lt2=Lt2 + "are done the same way except I selected two vertical "
        Lt2=Lt2 + "columns on the Grid for each half, and in the Rectangle "
        Lt2=Lt2 + "menu, I selected Horizontal Gradient since it filled from "
        Lt2=Lt2 + "side to side."
         CreateWindowEx(0, "static", BYVAL STRPTR( LT2 ), _
             %WS_CHILD OR %WS_VISIBLE, _
            120,  114,  490,  209, _
            hdlg,  102, hInstance, BYVAL %NULL)
        CreateWindowEx(%WS_EX_CLIENTEDGE, "Button", "&Close", _
           %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR  %BS_PUSHBUTTON, _
           520,  361,  50,  19, _
           hdlg,  101, hInstance, BYVAL %NULL)
        hFont = MakeFontEx("Tahoma", -11,  400,  0,  0,  0)   ' Get a Handle for this Font
        hHand = GetDlgItem(hDlg,  100)                                      ' Get Handle for a Control using its ID nr and its Parent Handle
        SendMessage hHand, %WM_SETFONT, hfont, %TRUE              ' Change font in Control using its handle and Font handle
        hFont = MakeFontEx("Tahoma", -11,  400,  0,  0,  0)   ' Get a Handle for this Font
        hHand = GetDlgItem(hDlg,  102)                                      ' Get Handle for a Control using its ID nr and its Parent Handle
        SendMessage hHand, %WM_SETFONT, hfont, %TRUE              ' Change font in Control using its handle and Font handle
        SetWindowPos hDlg, %HWND_TOP, 0, 0, 0, 0, %SWP_NoSize OR %SWP_NoMove
     CASE %WM_CTLCOLORSTATIC
        IF GetDlgCtrlId(lParam) =  100 THEN      '  Check for Static controls ID number
           SetTextColor Wparam, STfgColor1       '  Set the foreground colors for a Static control
           SetBkColor Wparam, STbgColor1         '  Set the background colors for a Static control
           ProcessWindow = hStBrush1 : EXIT FUNCTION  '  Apply the colors for a Static control
        ELSEIF GetDlgCtrlId(lParam) =  102 THEN  '  Check for Static controls ID number
           SetTextColor Wparam, STfgColor2       '  Set the foreground colors for a Static control
           SetBkColor Wparam, STbgColor2         '  Set the background colors for a Static control
           ProcessWindow = hStBrush2 : EXIT FUNCTION  '  Apply the colors for a Static control
        END IF
     CASE %WM_DESTROY
        DeleteObject hStBrush1                '  Frees all system resources associated with this brush
        DeleteObject hStBrush2                '  Frees all system resources associated with this brush
     CASE %WM_COMMAND        ' Messages sent for Command Items
        wmID = LOWRD(wparam)            ' Control ID
        wmEvent = HIWRD(wparam)         ' Window Event
        SELECT CASE wmID
           CASE  101 AND wmEVENT = %BN_CLICKED  ' Close Button
              PostQuitMessage 0
           END SELECT
     CASE %WM_PAINT    ' dialog is to be redrawn
        BeginPaint hDlg, ps  ' get device context to draw in
           GradientFills hdlg,  2, 128, 000, 128, 255, 255, 255, 0, 0,  739,  507
           GradientFills hdlg,  2, 125, 000, 125, 255, 255, 255,  40,  38,  690,  57
           GradientFills hdlg,  2, 255, 255, 255, 119, 000, 119,  40,  57,  690,  76
           GradientFills hdlg,  2, 128, 000, 128, 255, 255, 255,  40,  418,  690,  437
           GradientFills hdlg,  2, 255, 255, 255, 128, 000, 128,  40,  437,  690,  456
           GradientFills hdlg,  1, 128, 000, 128, 255, 255, 255,  40,  76,  60,  418
           GradientFills hdlg,  1, 255, 255, 255, 128, 000, 128,  60,  76,  80,  418
           GradientFills hdlg,  1, 128, 000, 128, 255, 255, 255,  650,  76,  670,  418
           GradientFills hdlg,  1, 255, 255, 255, 128, 000, 128,  670,  76,  690,  418
           GradientFills hdlg,  2, 128, 000, 128, 255, 255, 255,  120,  342,  250,  380
           GradientFills hdlg,  2, 255, 255, 255, 119, 000, 119,  120,  380,  250,  399
           GradientFills hdlg,  2, 128, 000, 128, 255, 255, 255,  480,  342,  610,  361
           GradientFills hdlg,  2, 255, 255, 255, 128, 000, 128,  480,  361,  610,  399
        EndPaint hDlg, ps
     CASE %WM_CLOSE     ' Message from Clicking on system close Icon
        PostQuitMessage 0
  END SELECT
  ProcessWindow = DefWindowProc(hdlg, wMsg, wParam, lParam)
END FUNCTION

FUNCTION WINMAIN (BYVAL hInstance     AS LONG, _
                  BYVAL hPrevInstance AS LONG, _
                  BYVAL szCmdLine     AS ASCIIZ PTR, _
                  BYVAL iCmdShow      AS LONG) AS LONG
    LOCAL wMsg       AS tagMsg, hMenu AS LONG
    LOCAL WindClass AS wndclassex
    DIM szpgmname AS ASCIIZ * 20, STYLE AS LONG
    'ShowWindow CONSHNDL, %SW_Hide ' Use for older PBCC
    szpgmname = "SDK Samples"
    windclass.cbSize        = SIZEOF(windclass)
    windclass.lpfnWndProc   = CODEPTR(ProcessWindow)  'point to callback
    windclass.hInstance     = hInstance
    windclass.hIcon         = LoadIcon( hInstance, "MAINICON" )
    windclass.hCursor       = LoadCursor( %NULL, BYVAL %IDC_ARROW )
    windclass.hbrBackground = %COLOR_MENU +1
    windclass.lpszClassName = VARPTR(szpgmname)
     RegisterClassEX windclass
          STYLE =   %WS_VISIBLE OR %WS_OVERLAPPEDWINDOW OR %WS_CLIPCHILDREN
        CreateWindowEx(0, szpgmname, "JaxGUI Example", _
                      STYLE,  40,  38,  739,  507, _
                      %HWND_DESKTOP, hMenu, hInstance, BYVAL %NULL)
     ShowWindow hWnd, iCmdShow
     UpdateWindow hWnd
     WHILE (GetMessage(wMsg, %NULL, 0, 0) <> %false )
        IF IsDialogMessage(hWnd, wMsg) = %FALSE THEN 'For TabKey,  Comment out if using WM_KEYDOWN
           TranslateMessage wMsg
           DispatchMessage  wMsg
        END IF                                       'For TabKey,  Comment out if using WM_KEYDOWN
     WEND
     WINMAIN = wMsg.wParam
END FUNCTION