home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_2 / VBRDOBTN / VBRDOBTN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-22  |  23.3 KB  |  722 lines

  1. #include "windows.h"
  2. #include "vbapi.h"
  3.  
  4. /********************************************************************************************************************************
  5.  
  6.                               Custom 3-D buttons for Visual Basic  by Mark Gamber, March 1992
  7.  
  8.               This code may be freely distributed and modified. Because of this, it is not supported by the author.
  9.  
  10. ********************************************************************************************************************************/
  11.  
  12.  
  13. LONG FAR PASCAL _export MainWndProc( HCTL, HWND, WORD, WORD, LONG );                                  /*  Function prototypes  */
  14. void PaintControl( HCTL, HWND );
  15. void AutoCheck( HCTL, HWND );
  16. BOOL _export FAR PASCAL SetColor( HWND, WORD, WORD, LONG );
  17. LONG _export FAR PASCAL PopupWndProc( HWND, WORD, WORD, LONG );
  18.  
  19. typedef struct {                                                                                 /*  Structure passed by hCtl  */
  20.    long Color;
  21.    long CheckBorderColor;
  22.    long ShadowColor;
  23.    int Shadow;
  24.    int Xsize, Ysize;
  25.    int Selected;
  26.    int ButtonDown;
  27.    HFONT hFont;
  28.    char Caption[ 129 ];
  29. } BTNSTRUCT;
  30.  
  31. #define DEREF(hctl)  ((BTNSTRUCT far *)VBDerefControl(hctl))                  /*  Method to access above structure using hCtl  */
  32.  
  33.  
  34. /*******************************************        Control Properties        **************************************************/
  35.  
  36. char ValueList[] = "0 - Unchecked\0"\
  37.                    "1 - Checked\0"\
  38.                    "";
  39.  
  40. char *CLASSPOPUP = "CPopup";
  41.  
  42. PROPINFO piValue =
  43. {
  44.    "Value",
  45.    DT_ENUM | PF_fSetMsg | PF_fGetMsg | PF_fSaveData,
  46.    0, 0, 0, ValueList, 1
  47. };
  48.  
  49. PROPINFO piCheckColor =
  50. {
  51.    "CheckColor",
  52.    DT_COLOR | PF_fSetMsg | PF_fGetMsg | PF_fSaveData | PF_fEditable,
  53.    0, 0, NULL, 0
  54. };
  55.  
  56. PROPINFO piCheckBorderColor =
  57. {
  58.    "ChkBrdColor",
  59.    DT_COLOR | PF_fSetMsg | PF_fGetMsg | PF_fSaveData | PF_fEditable,
  60.    0, 0, NULL, 0
  61. };
  62.  
  63. PROPINFO piShadow =
  64. {
  65.    "TextShadow",
  66.    DT_BOOL | PF_fSetMsg | PF_fGetMsg | PF_fSaveData,
  67.    0, 0, NULL, 0
  68. };
  69.  
  70. PROPINFO piShadowColor =
  71. {
  72.    "TextShadowCol",
  73.    DT_COLOR | PF_fSetMsg | PF_fGetMsg | PF_fSaveData,
  74.    0, 0, NULL, 0
  75. };
  76.  
  77. PROPINFO piVersion =
  78. {
  79.    "Version",
  80.    DT_SHORT | PF_fGetMsg,
  81.    0, 0, NULL, 0
  82. };
  83.  
  84. PPROPINFO proplistBtn[] =                                                     /*  Properties supported by this control module  */
  85. {                                                                         /*  Note: Does not have to be in a particular order  */
  86.    PPROPINFO_STD_CTLNAME,
  87.    PPROPINFO_STD_CAPTION,
  88.    PPROPINFO_STD_BACKCOLOR,
  89.    PPROPINFO_STD_FORECOLOR,
  90.    PPROPINFO_STD_LEFT,
  91.    PPROPINFO_STD_TOP,
  92.    PPROPINFO_STD_HEIGHT,
  93.    PPROPINFO_STD_WIDTH,
  94.    PPROPINFO_STD_INDEX,
  95.    PPROPINFO_STD_FONTNAME,
  96.    PPROPINFO_STD_FONTBOLD,
  97.    PPROPINFO_STD_FONTITALIC,
  98.    PPROPINFO_STD_FONTSTRIKE,
  99.    PPROPINFO_STD_FONTUNDER,
  100.    PPROPINFO_STD_FONTSIZE,
  101.    PPROPINFO_STD_ENABLED,
  102.    PPROPINFO_STD_MOUSEPOINTER,
  103.    PPROPINFO_STD_TABINDEX,
  104.    PPROPINFO_STD_TABSTOP,
  105.    PPROPINFO_STD_DRAGICON,
  106.    PPROPINFO_STD_DRAGMODE,
  107.    &piValue,
  108.    &piCheckColor,
  109.    &piCheckBorderColor,
  110.    &piShadow,
  111.    &piShadowColor,
  112.    &piVersion,
  113.    NULL,
  114. };
  115.  
  116. #define PROP_BASE          21                                                  /*  Definitions for easier property management  */
  117. #define PROP_VALUE         PROP_BASE
  118. #define PROP_COLOR         (PROP_BASE+1)
  119. #define PROP_CHKBRDCOLOR   (PROP_BASE+2)
  120. #define PROP_SHADOW        (PROP_BASE+3)
  121. #define PROP_SHADOWCOLOR   (PROP_BASE+4)
  122. #define PROP_VERSION       (PROP_BASE+5)
  123.  
  124. /***********************************************        Control Events        **************************************************/
  125.  
  126. EVENTINFO peClick =                                                                          /*  Description of "Click" event  */
  127. {
  128.    "Click",
  129.    0, 0, NULL, NULL
  130. };
  131.  
  132. PEVENTINFO eventlistBtn[] =                                                      /*  List of events supported by this control  */
  133. {                                                                                /*  Note: This MUST be in alphabetical order  */
  134.    &peClick,
  135.    PEVENTINFO_STD_DBLCLICK,
  136.    PEVENTINFO_STD_GOTFOCUS,
  137.    PEVENTINFO_STD_KEYDOWN,
  138.    PEVENTINFO_STD_KEYPRESS,
  139.    PEVENTINFO_STD_KEYUP,
  140.    PEVENTINFO_STD_LOSTFOCUS,
  141.    NULL
  142. };
  143.  
  144. #define EVENT_CLICK          0
  145.  
  146. char CONTROLNAME[] = "Radio3D";
  147.  
  148. MODEL modelBtn =                                                                        /*  Model for custom checkbox control  */
  149. {                                                                       /*  This is similar to registering a class in Windows  */
  150.    VB_VERSION,
  151.    MODEL_fFocusOk | MODEL_fMnemonic,                                                         /*  Ok to accept focus from form  */
  152.    (PCTLPROC)MainWndProc,
  153.    NULL,
  154.    WS_CHILD | BS_OWNERDRAW,                                                                              /*  Ownerdraw button  */
  155.    sizeof(BTNSTRUCT),                                                           /*  Size of user-defined structure from above  */
  156.    8000,                                                                           /*  Number of first bitmap used in toolbox  */
  157.    CONTROLNAME,
  158.    CONTROLNAME,                                                                                              /*  Control name  */
  159.    "button",                                                                       /*  Subclassing a Windows "button" control  */
  160.    proplistBtn,
  161.    eventlistBtn                                                                  /*  Include property and event support lists  */
  162. };
  163.  
  164.  
  165. /*********************************************  Standard VB DLL Code sections  *************************************************/
  166.  
  167. HANDLE hmodDLL;
  168. HCTL ColorHctl;
  169. HWND ColorHwnd;
  170. WORD ColorID;
  171.  
  172.  
  173. BOOL FAR PASCAL LibMain( HANDLE hmod, HANDLE segDS, USHORT cbHeapSize )                 /*  Called when Windows loads the DLL  */
  174. {
  175.    hmodDLL = hmod;                                                                  /*  Save data selector in global variable  */
  176.    UnlockData( 0 );                                                    /*  Unlock the default data segment (Make it moveable)  */
  177.  
  178.    return( TRUE );
  179. }
  180.  
  181.  
  182. BOOL FAR PASCAL _export VBINITCC( USHORT usVersion, BOOL fRunTime )                      /*  Called when VB loads the control  */
  183. {
  184.    if( ! fRunTime )
  185.    {
  186.       WNDCLASS wc;
  187.  
  188.       wc.style = 0;
  189.       wc.lpfnWndProc = (WNDPROC)PopupWndProc;
  190.       wc.cbClsExtra = 0;
  191.       wc.cbWndExtra = 0;
  192.       wc.hInstance = hmodDLL;
  193.       wc.hIcon = NULL;
  194.       wc.hCursor = NULL;
  195.       wc.hbrBackground = NULL;
  196.       wc.lpszMenuName = NULL;
  197.       wc.lpszClassName = CLASSPOPUP;
  198.  
  199.       if( ! RegisterClass( &wc ) )
  200.          return( FALSE );
  201.    }
  202.    return( VBRegisterModel( hmodDLL, &modelBtn ) );                                           /*  Just register the button(s)  */
  203. }
  204.  
  205.  
  206.  
  207. /**********************************************  Window control procedure  *****************************************************/
  208.  
  209.                                                                                                    /*  Button control routine  */
  210. LONG FAR PASCAL _export MainWndProc( HCTL hCtl, HWND hWnd, WORD msg, WORD wParam, LONG lParam )
  211. {
  212.    switch( msg )
  213.    {
  214.       case VBN_DRAWITEM:                                                    /*  Control needs repainted...same as WM_DRAWITEM  */
  215.       {
  216.          LPDRAWITEMSTRUCT lpDs = (LPDRAWITEMSTRUCT)lParam;
  217.          BTNSTRUCT far *Bs = DEREF( hCtl );
  218.          TEXTMETRIC tm;
  219.          RECT Rect;
  220.  
  221.          if( lpDs->itemAction & ODA_FOCUS )
  222.          {
  223.             if( Bs->hFont )
  224.                SelectObject( lpDs->hDC, Bs->hFont );
  225.  
  226.             GetTextMetrics( lpDs->hDC, &tm );
  227.             Rect.top = 0;
  228.             Rect.left = 16;
  229.             Rect.right = Bs->Xsize - 1;
  230.             Rect.bottom = Bs->Ysize - 1;
  231.  
  232.             DrawFocusRect( lpDs->hDC, &Rect );
  233.             return( FALSE );
  234.          }
  235.  
  236.          Bs->ButtonDown = 0;                                                     /*  Assume the control draw in "up" position  */
  237.          if( lpDs->itemAction & ODA_SELECT )
  238.             if( lpDs->itemState & ODS_SELECTED )                                  /*  If criteria matches, the button is down  */
  239.                Bs->ButtonDown = 1;
  240.  
  241.          PaintControl( hCtl, hWnd );
  242.          Bs = DEREF( hCtl );
  243.  
  244.          return( FALSE );
  245.       }
  246.  
  247.       case WM_SIZE:                                                       /*  Support for Width and Height changes to control  */
  248.       {
  249.          BTNSTRUCT far *Bs = DEREF( hCtl );
  250.  
  251.          Bs->Xsize = LOWORD( lParam );
  252.          Bs->Ysize = HIWORD( lParam );
  253.          break;
  254.       }
  255.  
  256.       case WM_SETFONT:                                              /*  If parent (VB) is setting a new font, support is here  */
  257.       {
  258.          BTNSTRUCT far *Bs = DEREF( hCtl );
  259.  
  260.          Bs->hFont = wParam;
  261.          if( lParam )                                                            /*  If lParam is non-zero, repaint right now  */
  262.             PaintControl( hCtl, hWnd );
  263.  
  264.          return( FALSE );
  265.       }
  266.  
  267.       case WM_GETFONT:
  268.       {
  269.          BTNSTRUCT far *Bs = DEREF( hCtl );
  270.  
  271.          return( Bs->hFont );                                                 /*  If requesting font used, return font handle  */
  272.       }
  273.  
  274.       case WM_SETTEXT:                                                                      /*   Support for CAPTION property  */
  275.       {
  276.          BTNSTRUCT far *Bs = DEREF( hCtl );
  277.  
  278.          lstrcpy( Bs->Caption, (LPSTR)lParam );
  279.          InvalidateRect( hWnd, NULL, TRUE );
  280.          return( FALSE );
  281.       }
  282.  
  283.       case WM_GETTEXT:
  284.       {
  285.          BTNSTRUCT far *Bs = DEREF( hCtl );
  286.  
  287.          lstrcpy( (LPSTR)lParam, Bs->Caption );
  288.          return( lstrlen( Bs->Caption ) );
  289.       }
  290.  
  291.       case WM_GETTEXTLENGTH:
  292.       {
  293.          BTNSTRUCT far *Bs = DEREF( hCtl );
  294.  
  295.          return( lstrlen( Bs->Caption ) );
  296.       }
  297.  
  298.       case VBM_SETPROPERTY:
  299.       {
  300.          BTNSTRUCT far *Bs = DEREF( hCtl );
  301.  
  302.          switch( wParam )
  303.          {
  304.             case PROP_VALUE:
  305.                if( (BOOL)lParam )
  306.                   Bs->Selected = 1;
  307.                else
  308.                   Bs->Selected = 0;
  309.                PaintControl( hCtl, hWnd );
  310.                return( FALSE );
  311.  
  312.             case PROP_COLOR:
  313.                Bs->Color = lParam;
  314.                PaintControl( hCtl, hWnd );
  315.                return( FALSE );
  316.  
  317.             case PROP_CHKBRDCOLOR:
  318.                Bs->CheckBorderColor = lParam;
  319.                PaintControl( hCtl, hWnd );
  320.                return( FALSE );
  321.  
  322.             case PROP_SHADOW:
  323.                Bs->Shadow = (BOOL)lParam;
  324.                PaintControl( hCtl, hWnd );
  325.                return( FALSE );
  326.  
  327.             case PROP_SHADOWCOLOR:
  328.                Bs->ShadowColor = lParam;
  329.                PaintControl( hCtl, hWnd );
  330.                return( FALSE );
  331.          }
  332.          break;
  333.       }
  334.  
  335.       case VBM_GETPROPERTY:
  336.       {
  337.          BTNSTRUCT far *Bs = DEREF( hCtl );
  338.  
  339.          switch( wParam )
  340.          {
  341.             case PROP_VALUE:
  342.                *(WORD far *)lParam = Bs->Selected;
  343.                return( FALSE );
  344.  
  345.             case PROP_COLOR:
  346.                *(LONG far *)lParam = Bs->Color;
  347.                return( FALSE );
  348.  
  349.             case PROP_CHKBRDCOLOR:
  350.                *(LONG far *)lParam = Bs->CheckBorderColor;
  351.                return( FALSE );
  352.  
  353.             case PROP_SHADOW:
  354.                *(BOOL far *)lParam = Bs->Shadow;
  355.                return( FALSE );
  356.  
  357.             case PROP_SHADOWCOLOR:
  358.                *(LONG far *)lParam = Bs->ShadowColor;
  359.                return( FALSE );
  360.  
  361.             case PROP_VERSION:
  362.                *(WORD far *)lParam = 100;
  363.                return( FALSE );
  364.          }
  365.          break;
  366.       }
  367.  
  368.       case WM_CHAR:
  369.          if( wParam != 32 )
  370.             break;
  371.  
  372.       case VBM_MNEMONIC:
  373.       case WM_LBUTTONUP:
  374.       {
  375.          BTNSTRUCT far *Bs = DEREF( hCtl );
  376.  
  377.          if( ( LOWORD( lParam ) < Bs->Xsize && LOWORD( lParam >= 0 ) && HIWORD( lParam ) < Bs->Ysize && LOWORD( lParam ) >= 0 ) ||
  378.              msg == WM_CHAR )
  379.             VBFireEvent( hCtl, EVENT_CLICK, NULL );
  380.  
  381.          break;
  382.       }
  383.  
  384.       case VBM_INITPROPPOPUP:
  385.       {
  386.          BTNSTRUCT far *Gp = DEREF( hCtl );
  387.  
  388.          switch( wParam )
  389.          {
  390.             case 2:
  391.             case 3:
  392.             case PROP_COLOR:
  393.             case PROP_CHKBRDCOLOR:
  394.             case PROP_SHADOWCOLOR:
  395.             {
  396.                FARPROC DlgProc;
  397.  
  398.                if( VBGetMode() == MODE_DESIGN )
  399.                {
  400.                   ColorHctl = hCtl;
  401.                   ColorID = wParam;
  402.                   ColorHwnd = hWnd;
  403.  
  404.                   return( CreateWindow( CLASSPOPUP, NULL, WS_POPUP, 0, 0, 0, 0,
  405.                                         NULL, NULL, hmodDLL, NULL ) );
  406.                }
  407.                return( NULL );
  408.             }
  409.          }
  410.          break;
  411.       }
  412.    }
  413.    return( VBDefControlProc( hCtl, hWnd, msg, wParam, lParam ) );          /*  If nothing done here, pass to VB default routine  */
  414. }
  415.  
  416.  
  417. LONG _export FAR PASCAL PopupWndProc( HWND hWnd, WORD msg, WORD wParam, LONG lParam )
  418. {
  419.    switch( msg )
  420.    {
  421.       case WM_SHOWWINDOW:
  422.          if( wParam )
  423.          {
  424.             PostMessage( hWnd, WM_USER, 0, 0L );
  425.             return( 0L );
  426.          }
  427.          break;
  428.  
  429.       case WM_USER:
  430.          VBDialogBoxParam( hmodDLL, "SETCOLOR", MakeProcInstance( SetColor, hmodDLL ), 0L );
  431.          return( 0L );
  432.    }
  433.    return( DefWindowProc( hWnd, msg, wParam, lParam ) );
  434. }
  435.  
  436.  
  437.  
  438. BOOL _export FAR PASCAL SetColor( HWND hDlg, WORD msg, WORD wParam, LONG lParam )
  439. {
  440.    switch( msg )
  441.    {
  442.       case WM_INITDIALOG:
  443.       {
  444.          BTNSTRUCT far *Gp = DEREF( ColorHctl );
  445.          WORD Red, Green, Blue;
  446.          DWORD dwColor;
  447.          char str[ 6 ];
  448.  
  449.          VBGetControlProperty( ColorHctl, ColorID, &dwColor );                                /*  Get current color of property  */
  450.  
  451.          if( dwColor & 0x80000000 )                                         /*  If it's a system color offset, get system color  */
  452.             dwColor = GetSysColor( LOWORD( lParam ) + 1 );
  453.  
  454.          Red = GetRValue( dwColor );                                                            /*  Break color into components  */
  455.          Green = GetGValue( dwColor );
  456.          Blue = GetBValue( dwColor );
  457.  
  458.          SetProp( hDlg, MAKEINTRESOURCE( 1 ), CreateSolidBrush( RGB ( Red, Green, Blue ) ) );            /*  Save created brush  */
  459.  
  460.          SetScrollRange( GetDlgItem( hDlg, 100 ), SB_CTL, 0, 255, TRUE );                        /*  Initialize scrollbar sizes  */
  461.          SetScrollRange( GetDlgItem( hDlg, 102 ), SB_CTL, 0, 255, TRUE );
  462.          SetScrollRange( GetDlgItem( hDlg, 104 ), SB_CTL, 0, 255, TRUE );
  463.  
  464.          SetScrollPos( GetDlgItem( hDlg, 100 ), SB_CTL, Red, TRUE );                          /*  Initialze scrollbar positions  */
  465.          SetScrollPos( GetDlgItem( hDlg, 102 ), SB_CTL, Green, TRUE );
  466.          SetScrollPos( GetDlgItem( hDlg, 104 ), SB_CTL, Blue, TRUE );
  467.  
  468.          wsprintf( str, "%d", Red );
  469.          SetDlgItemText( hDlg, 101, str );                                       /*  Change editbox text to reflect color comp.  */
  470.          wsprintf( str, "%d", Green );
  471.          SetDlgItemText( hDlg, 103, str );
  472.          wsprintf( str, "%d", Blue );
  473.          SetDlgItemText( hDlg, 105, str );
  474.          return( TRUE );
  475.       }
  476.  
  477.       case WM_DRAWITEM:
  478.       {
  479.          LPDRAWITEMSTRUCT lpDs = (LPDRAWITEMSTRUCT)lParam;
  480.  
  481.          if( lpDs->CtlID == 106 )
  482.          {
  483.             RECT Rect;
  484.             HDC hDC;
  485.  
  486.             hDC = GetDC( GetDlgItem( hDlg, lpDs->CtlID ) );
  487.             SelectObject( hDC, GetProp( hDlg, MAKEINTRESOURCE( 1 ) ) );
  488.             GetWindowRect( GetDlgItem( hDlg, lpDs->CtlID ), &Rect );
  489.             Rectangle( hDC, 0, 0, Rect.right - Rect.left, Rect.bottom - Rect.top );
  490.             SelectObject( lpDs->hDC, GetStockObject( NULL_BRUSH ) );
  491.          }
  492.          break;
  493.       }
  494.  
  495.       case WM_HSCROLL:
  496.       {
  497.          DWORD dwColor;
  498.          int Pos;
  499.          char str[ 10 ];
  500.          int junk;
  501.  
  502.          Pos = GetScrollPos( HIWORD( lParam ), SB_CTL );
  503.  
  504.          switch( wParam )
  505.          {
  506.             case SB_BOTTOM:
  507.                SetScrollPos( HIWORD( lParam ), SB_CTL, 0, TRUE );
  508.                break;
  509.  
  510.             case SB_TOP:
  511.                SetScrollPos( HIWORD( lParam ), SB_CTL, 255, TRUE );
  512.                break;
  513.  
  514.             case SB_THUMBPOSITION:
  515.             case SB_THUMBTRACK:
  516.                SetScrollPos( HIWORD( lParam ), SB_CTL, LOWORD( lParam ), TRUE );
  517.                break;
  518.  
  519.             case SB_PAGEDOWN:
  520.                if( Pos > 240 )
  521.                   SetScrollPos( HIWORD( lParam ), SB_CTL, 255, TRUE );
  522.                else
  523.                   SetScrollPos( HIWORD( lParam ), SB_CTL, Pos + 16, TRUE );
  524.                break;
  525.  
  526.             case SB_PAGEUP:
  527.                if( Pos < 16 )
  528.                   SetScrollPos( HIWORD( lParam ), SB_CTL, 0, TRUE );
  529.                else
  530.                   SetScrollPos( HIWORD( lParam ), SB_CTL, Pos - 16, TRUE );
  531.                break;
  532.  
  533.             case SB_LINEDOWN:
  534.                if( Pos < 255 )
  535.                   SetScrollPos( HIWORD( lParam ), SB_CTL, Pos + 1, TRUE );
  536.                break;
  537.  
  538.             case SB_LINEUP:
  539.                if( Pos > 0 )
  540.                   SetScrollPos( HIWORD( lParam ), SB_CTL, Pos - 1, TRUE );
  541.                break;
  542.          }
  543.  
  544.          wsprintf( str, "%d", GetScrollPos( GetDlgItem( hDlg, 100 ), SB_CTL ) );
  545.          SetDlgItemText( hDlg, 101, str );
  546.  
  547.          wsprintf( str, "%d", GetScrollPos( GetDlgItem( hDlg, 102 ), SB_CTL ) );
  548.          SetDlgItemText( hDlg, 103, str );
  549.  
  550.          wsprintf( str, "%d", GetScrollPos( GetDlgItem( hDlg, 104 ), SB_CTL ) );
  551.          SetDlgItemText( hDlg, 105, str );
  552.  
  553.          dwColor = RGB( GetDlgItemInt( hDlg, 101, &junk, TRUE ),
  554.                         GetDlgItemInt( hDlg, 103, &junk, TRUE ),
  555.                         GetDlgItemInt( hDlg, 105, &junk, TRUE ) );
  556.  
  557.          DeleteObject( GetProp( hDlg, MAKEINTRESOURCE( 1 ) ) );
  558.          SetProp( hDlg, MAKEINTRESOURCE( 1 ), CreateSolidBrush( dwColor ) );
  559.  
  560.          InvalidateRect( GetDlgItem( hDlg, 106 ), NULL, FALSE );
  561.          break;
  562.       }
  563.  
  564.       case WM_COMMAND:
  565.          if( HIWORD( lParam ) == EN_KILLFOCUS )
  566.          {
  567.             DWORD dwColor;
  568.             int junk;
  569.  
  570.             dwColor = RGB( GetDlgItemInt( hDlg, 101, &junk, TRUE ),
  571.                            GetDlgItemInt( hDlg, 103, &junk, TRUE ),
  572.                            GetDlgItemInt( hDlg, 105, &junk, TRUE ) );
  573.  
  574.             DeleteObject( GetProp( hDlg, MAKEINTRESOURCE( 1 ) ) );
  575.             SetProp( hDlg, MAKEINTRESOURCE( 1 ), CreateSolidBrush( dwColor ) );
  576.  
  577.             InvalidateRect( GetDlgItem( hDlg, 106 ), NULL, FALSE );
  578.             break;
  579.          }
  580.  
  581.          if( wParam == IDOK || wParam == IDCANCEL )
  582.          {
  583.             if( wParam == IDOK )
  584.             {
  585.                int junk;
  586.                DWORD dwColor;
  587.                BTNSTRUCT far *Gp = DEREF( ColorHctl );
  588.  
  589.                dwColor = RGB( GetDlgItemInt( hDlg, 101, &junk, TRUE ),
  590.                               GetDlgItemInt( hDlg, 103, &junk, TRUE ),
  591.                               GetDlgItemInt( hDlg, 105, &junk, TRUE ) );
  592.  
  593.                VBSetControlProperty( ColorHctl, ColorID, dwColor );
  594.             }
  595.  
  596.             DeleteObject( GetProp( hDlg, MAKEINTRESOURCE( 1 ) ) );
  597.             RemoveProp( hDlg, MAKEINTRESOURCE( 1 ) );
  598.  
  599.             if( wParam == IDOK )
  600.             {
  601.                InvalidateRect( ColorHwnd, NULL, TRUE );
  602.                return( TRUE );
  603.             }
  604.             EndDialog( hDlg, TRUE );
  605.             return( TRUE );
  606.          }
  607.          break;
  608.    }
  609.    return( FALSE );
  610. }
  611.  
  612.  
  613. void PaintControl( HCTL hCtl, HWND hWnd )                                                 /*  Paint control using current style  */
  614. {
  615.    HPEN hPen;
  616.    HDC hDC;
  617.    HBRUSH hBrush;
  618.    BTNSTRUCT far *Bs = DEREF( hCtl );
  619.    RECT Rect;
  620.    long OldColor;
  621.  
  622.    hDC = GetDC( hWnd );
  623.  
  624.    SelectObject( hDC, GetStockObject( BLACK_PEN ) );                                             /*  Draw black button outline  */
  625.  
  626.    MoveTo( hDC, 7, 0 );
  627.    LineTo( hDC, 0, 7 );
  628.    LineTo( hDC, 7, 14 );
  629.    LineTo( hDC, 14, 7 );
  630.    LineTo( hDC, 7, 0 );
  631.  
  632.    SelectObject( hDC, SendMessage( GetParent( hWnd ), WM_CTLCOLOR, hDC, MAKELONG( hWnd, 0 ) ) );
  633.    SelectObject( hDC, CreatePen( PS_SOLID, 1, GetBkColor( hDC ) ) );
  634.  
  635.    FloodFill( hDC, 7, 2, RGB( 0, 0, 0 ) );
  636.    Rectangle( hDC, 4, 4, 11, 11 );
  637.  
  638.    DeleteObject( SelectObject( hDC, CreatePen( PS_SOLID, 1, RGB( 128, 128, 128 ) ) ) );            /*  Use dark gray pen first  */
  639.  
  640.    if( ! Bs->ButtonDown )                                                                              /*  If button is raised  */
  641.    {
  642.       MoveTo( hDC, 7, 13 );
  643.       LineTo( hDC, 13, 7 );                                                                     /*  Draw lower and right lines  */
  644.       LineTo( hDC, 7, 1 );
  645.    }
  646.    else
  647.    {
  648.       MoveTo( hDC, 7, 1 );
  649.       LineTo( hDC, 1, 7 );
  650.       LineTo( hDC, 7, 13 );
  651.    }
  652.  
  653.    DeleteObject( SelectObject( hDC, GetStockObject( WHITE_PEN ) ) );
  654.    if( ! Bs->ButtonDown )
  655.    {
  656.       MoveTo( hDC, 7, 1 );
  657.       LineTo( hDC, 1, 7 );
  658.       LineTo( hDC, 7, 13 );
  659.    }
  660.  
  661.    if( Bs->Selected )
  662.       SelectObject( hDC, CreatePen( PS_SOLID, 1, Bs->CheckBorderColor ) );
  663.    else
  664.       SelectObject( hDC, CreatePen( PS_SOLID, 1, RGB( 192, 192, 192 ) ) );
  665.  
  666.    MoveTo( hDC, 7 + Bs->ButtonDown, 4  );
  667.    LineTo( hDC, 4 + Bs->ButtonDown, 7  );
  668.    LineTo( hDC, 7 + Bs->ButtonDown, 10 );
  669.    LineTo( hDC, 10 + Bs->ButtonDown, 7 );
  670.    LineTo( hDC, 7 + Bs->ButtonDown, 4 );
  671.  
  672.    if( Bs->Selected )
  673.    {
  674.       if( ! Bs->ButtonDown )
  675.          SetPixel( hDC, 11, 7, RGB( 192, 192, 192 ) );
  676.       DeleteObject( SelectObject( hDC, CreatePen( PS_SOLID, 1, Bs->Color ) ) );
  677.    }
  678.    else
  679.       DeleteObject( SelectObject( hDC, CreatePen( PS_SOLID, 1, RGB( 192, 192, 192 ) ) ) );
  680.  
  681.    MoveTo( hDC, 5 + Bs->ButtonDown, 7 );
  682.    LineTo( hDC, 10 + Bs->ButtonDown, 7 );
  683.    MoveTo( hDC, 7 + Bs->ButtonDown, 5  );
  684.    LineTo( hDC, 7 + Bs->ButtonDown, 10 );
  685.    MoveTo( hDC, 6 + Bs->ButtonDown, 6 );
  686.    LineTo( hDC, 9 + Bs->ButtonDown, 6 );
  687.    MoveTo( hDC, 6 + Bs->ButtonDown, 8 );
  688.    LineTo( hDC, 9 + Bs->ButtonDown, 8 );
  689.  
  690.    DeleteObject( SelectObject( hDC, GetStockObject( NULL_PEN ) ) );
  691.  
  692.    if( Bs->hFont )
  693.       SelectObject( hDC, Bs->hFont );
  694.  
  695.    if( Bs->Shadow )
  696.    {
  697.       Rect.left = 18;
  698.       Rect.right = Bs->Xsize + 18;
  699.       Rect.top = 1;
  700.       Rect.bottom = Bs->Ysize + 1;
  701.  
  702.       OldColor = GetTextColor( hDC );
  703.       SetTextColor( hDC, Bs->ShadowColor );
  704.       DrawText( hDC, Bs->Caption, lstrlen( Bs->Caption ), &Rect, DT_LEFT | DT_TOP );
  705.       SetTextColor( hDC, OldColor );
  706.       SetBkMode( hDC, TRANSPARENT );
  707.    }
  708.  
  709.    Rect.left = 18 + ( Bs->Shadow != 0 );
  710.    Rect.top = 1 + ( Bs->Shadow != 0 );
  711.    Rect.right = Bs->Xsize + 18 + ( Bs->Shadow != 0 );
  712.    Rect.bottom = Bs->Ysize + 1 + ( Bs->Shadow != 0 );
  713.  
  714.    DrawText( hDC, Bs->Caption, lstrlen( Bs->Caption ), &Rect, DT_LEFT | DT_TOP );
  715.  
  716.    SelectObject( hDC, GetStockObject( ANSI_FIXED_FONT ) );
  717.    ReleaseDC( hWnd, hDC );
  718. }
  719.  
  720.  
  721.  
  722.