home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code2 / vbgp / vbgp.c next >
C/C++ Source or Header  |  1992-05-22  |  24KB  |  884 lines

  1.  
  2.       /*  Custom groupbox control for Visual Basic  May 1992 by Mark Gamber  */
  3.  
  4.  
  5. #include "windows.h"
  6. #include "commdlg.h"
  7. #include "vbapi.h"
  8.  
  9.                                                                                                         /*  Function prototypes  */
  10.  
  11. LONG _export FAR PASCAL GroupWndProc( HCTL, HWND, WORD, WORD, LONG );
  12. void PaintButton( HCTL, HWND );
  13. BOOL _export FAR PASCAL SetColor( HWND, WORD, WORD, LONG );
  14. LONG _export FAR PASCAL PopupWndProc( HWND, WORD, WORD, LONG );
  15.  
  16.  
  17. typedef struct {                                                                      /*  Control data structure passed by HCTL  */
  18.    HSZ WaveFile;
  19.    int Width, Height, WaveOn;
  20.    int Raised, WaveStyle;
  21.    int Shadow, Align, WaveLoop;
  22.    long ShadowColor;
  23.    long Hilite;
  24.    long Lolite;
  25.    HFONT hFont;
  26.    HSZ hszCaption;
  27. } GPSTRUCT;
  28.  
  29. #define GPDEREF(hctl) ((GPSTRUCT far *)VBDerefControl(hctl))                  /*  Use this macro to lock HCTL in window process  */
  30.  
  31. char GPAlignTypes[] = "0 - Left\0"\
  32.                     "1 - Center\0"\
  33.                     "2 - Right\0"\
  34.                     "\0";
  35.  
  36. char WaveStyles[] = "0 - Synchronous\0"\
  37.                     "1 - Asynchronous\0"\
  38.                     "";
  39.  
  40. char *CLASSPOPUP = "CPopup";
  41.  
  42. PROPINFO Prop_Width =
  43. {
  44.    "Width",
  45.    DT_SHORT | PF_fSetMsg | PF_fGetMsg | PF_fSaveData,
  46.    0, 0, NULL, 0
  47. };
  48.  
  49. PROPINFO Prop_Height =
  50. {
  51.    "Height",
  52.    DT_SHORT | PF_fSetMsg | PF_fGetMsg | PF_fSaveData,
  53.    2, 0, NULL, 0
  54. };
  55.  
  56. PROPINFO Prop_Raised =
  57. {
  58.    "Raised",
  59.    DT_BOOL | PF_fSetMsg | PF_fGetMsg | PF_fSaveData,
  60.    4, 0, NULL, 0
  61. };
  62.  
  63. PROPINFO Prop_Shadow =
  64. {
  65.    "TextShadow",
  66.    DT_BOOL | PF_fSetMsg | PF_fGetMsg | PF_fSaveData,
  67.    6, 0, NULL, 0
  68. };
  69.  
  70. PROPINFO Prop_ShadowColor =
  71. {
  72.    "TextShadowCol",
  73.    DT_COLOR | PF_fSetMsg | PF_fGetMsg | PF_fSaveData | PF_fEditable,
  74.    8, 0, NULL, 0
  75. };
  76.  
  77. PROPINFO Prop_Align =
  78. {
  79.    "Alignment",
  80.    DT_ENUM | PF_fSetMsg | PF_fGetMsg | PF_fSaveData,
  81.    0, 0, 0, GPAlignTypes, 2
  82. };
  83.  
  84. PROPINFO Prop_Hilite =
  85. {
  86.    "HiliteColor",
  87.    DT_COLOR | PF_fSetMsg | PF_fGetMsg | PF_fSaveData | PF_fEditable,
  88.    0, 0, NULL, 0
  89. };
  90.  
  91. PROPINFO Prop_Lolite =
  92. {
  93.    "ShadowColor",
  94.    DT_COLOR | PF_fSetMsg | PF_fGetMsg | PF_fSaveData | PF_fEditable,
  95.    0, 0, NULL, 0
  96. };
  97.  
  98. PROPINFO Prop_WaveFile =
  99. {
  100.    "WaveFile",
  101.    DT_HSZ | PF_fSetData | PF_fGetData | PF_fSaveData | PF_fEditable,
  102.    0, 0, NULL, 0
  103. };
  104.  
  105. PROPINFO Prop_WaveStyle =
  106. {
  107.    "WaveStyle",
  108.    DT_ENUM | PF_fSetMsg | PF_fGetMsg | PF_fSaveData,
  109.    0, 0, 0, WaveStyles, 1
  110. };
  111.  
  112. PROPINFO Prop_WaveLoop =
  113. {
  114.    "WaveLoop",
  115.    DT_BOOL | PF_fSetMsg | PF_fGetMsg | PF_fSaveData,
  116.    0, 0, NULL, 0
  117. };
  118.  
  119. PROPINFO Prop_WaveEnabled =
  120. {
  121.    "WaveEnabled",
  122.    DT_BOOL | PF_fSetMsg | PF_fGetMsg | PF_fSaveData,
  123.    0, 0, NULL, 0
  124. };
  125.  
  126. PROPINFO Prop_Version =
  127. {
  128.    "Version",
  129.    DT_SHORT | PF_fGetMsg,
  130.    0, 0, NULL, 0
  131. };
  132.  
  133. #define VBGP_BASE        12
  134. #define VBGP_HEIGHT      (VBGP_BASE)
  135. #define VBGP_WIDTH       (VBGP_BASE+1)
  136. #define VBGP_RAISED      (VBGP_BASE+2)
  137. #define VBGP_SHADOW      (VBGP_BASE+3)
  138. #define VBGP_SHCOLOR     (VBGP_BASE+4)
  139. #define VBGP_ALIGN       (VBGP_BASE+5)
  140. #define VBGP_HILITE      (VBGP_BASE+6)
  141. #define VBGP_LOLITE      (VBGP_BASE+7)
  142. #define VBGP_WAVEFILE    (VBGP_BASE+8)
  143. #define VBGP_WAVESTYLE   (VBGP_BASE+9)
  144. #define VBGP_WAVELOOP    (VBGP_BASE+10)
  145. #define VBGP_WAVEENABLED (VBGP_BASE+11)
  146. #define VBGP_VERSION     (VBGP_BASE+12)
  147.  
  148. PPROPINFO proplistGP[] =
  149. {
  150.    PPROPINFO_STD_CAPTION,
  151.    PPROPINFO_STD_CTLNAME,
  152.    PPROPINFO_STD_BACKCOLOR,
  153.    PPROPINFO_STD_FORECOLOR,
  154.    PPROPINFO_STD_LEFT,
  155.    PPROPINFO_STD_TOP,
  156.    PPROPINFO_STD_FONTNAME,
  157.    PPROPINFO_STD_FONTBOLD,
  158.    PPROPINFO_STD_FONTITALIC,
  159.    PPROPINFO_STD_FONTSTRIKE,
  160.    PPROPINFO_STD_FONTUNDER,
  161.    PPROPINFO_STD_FONTSIZE,
  162.    &Prop_Height,
  163.    &Prop_Width,
  164.    &Prop_Raised,
  165.    &Prop_Shadow,
  166.    &Prop_ShadowColor,
  167.    &Prop_Align,
  168.    &Prop_Hilite,
  169.    &Prop_Lolite,
  170.    &Prop_WaveFile,
  171.    &Prop_WaveStyle,
  172.    &Prop_WaveLoop,
  173.    &Prop_WaveEnabled,
  174.    &Prop_Version,
  175.    NULL
  176. };
  177.  
  178. EVENTINFO Event_Clicked =
  179. {
  180.    "Clicked", 0, 0,
  181.    NULL, NULL
  182. };
  183.  
  184. PEVENTINFO eventlistGP[] =
  185. {
  186.    &Event_Clicked,
  187.    NULL
  188. };
  189.  
  190.  
  191. MODEL modelGP =
  192. {
  193.    VB_VERSION,
  194.    MODEL_fChildrenOk | MODEL_fMnemonic,
  195.    (PCTLPROC)GroupWndProc,
  196.    NULL,
  197.    WS_CHILD | WS_CLIPCHILDREN,
  198.    sizeof(GPSTRUCT),
  199.    8000,
  200.    "GrpBox",
  201.    "GrpBox",
  202.    NULL,
  203.    proplistGP,
  204.    eventlistGP
  205. };
  206.  
  207.  
  208. HANDLE hmodDLL;
  209. HCTL ColorHctl;
  210. HWND ColorHwnd;
  211. WORD ColorID;
  212. char MMSystem[] = "MMSYSTEM.DLL";
  213.  
  214.  
  215. BOOL FAR PASCAL LibMain( HANDLE hmod, HANDLE segDS, USHORT cbHeapSize )
  216. {
  217.    hmodDLL = hmod;
  218.  
  219.    UnlockData( 0 );
  220.    return( TRUE );
  221. }
  222.  
  223.  
  224. BOOL _export FAR PASCAL VBINITCC( USHORT usVersion, BOOL fRunTime )
  225. {
  226.    if( ! fRunTime )
  227.    {
  228.       WNDCLASS wc;
  229.  
  230.       wc.style = 0;
  231.       wc.lpfnWndProc = (WNDPROC)PopupWndProc;
  232.       wc.cbClsExtra = 0;
  233.       wc.cbWndExtra = 0;
  234.       wc.hInstance = hmodDLL;
  235.       wc.hIcon = NULL;
  236.       wc.hCursor = NULL;
  237.       wc.hbrBackground = NULL;
  238.       wc.lpszMenuName = NULL;
  239.       wc.lpszClassName = CLASSPOPUP;
  240.  
  241.       if( ! RegisterClass( &wc ) )
  242.          return( FALSE );
  243.    }
  244.    return( VBRegisterModel( hmodDLL, &modelGP ) );
  245. }
  246.  
  247.  
  248. LONG _export FAR PASCAL GroupWndProc( HCTL hCtl, HWND hWnd, WORD msg, WORD wParam, LONG lParam )
  249. {
  250.    switch( msg )
  251.    {
  252.       case WM_CREATE:
  253.       {
  254.          GPSTRUCT far *Gp = GPDEREF( hCtl );
  255.  
  256.          Gp->Width = 50;
  257.          Gp->Height = 30;
  258.          Gp->Raised = 1;
  259.          Gp->Shadow = 0;
  260.          Gp->ShadowColor = 0L;
  261.          Gp->hszCaption = NULL;
  262.          Gp->Align = 0;
  263.          Gp->Hilite = RGB( 255, 255, 255 );
  264.          Gp->Lolite = RGB( 128, 128, 128 );
  265.          break;
  266.       }
  267.  
  268.       case WM_SETFONT:
  269.       {
  270.          GPSTRUCT far *Gp = GPDEREF( hCtl );
  271.  
  272.          Gp->hFont = wParam;
  273.          PaintButton( hCtl, hWnd );
  274.          break;
  275.       }
  276.  
  277.       case WM_GETFONT:
  278.       {
  279.          GPSTRUCT far *Gp = GPDEREF( hCtl );
  280.  
  281.          return( Gp->hFont );
  282.       }
  283.  
  284.       case WM_SETTEXT:
  285.       {
  286.          GPSTRUCT far *Gp = GPDEREF( hCtl );
  287.          HSZ hsz;
  288.  
  289.          if( Gp->hszCaption )
  290.             VBDestroyHsz( Gp->hszCaption );
  291.  
  292.          hsz = VBCreateHsz( (_segment)hCtl, (LPSTR)lParam );
  293.          Gp = GPDEREF( hCtl );
  294.  
  295.          Gp->hszCaption = hsz;
  296.          PaintButton( hCtl, hWnd );
  297.          return( NULL );
  298.       }
  299.  
  300.       case WM_GETTEXT:
  301.       {
  302.          GPSTRUCT far *Gp = GPDEREF( hCtl );
  303.          LPSTR lpStr;
  304.          WORD cch;
  305.  
  306.          if( Gp->hszCaption == NULL )
  307.          {
  308.             *(LPSTR)lParam = 0L;
  309.             wParam = 1;
  310.          }
  311.          else
  312.          {
  313.             lpStr = VBDerefHsz( Gp->hszCaption );
  314.             cch = lstrlen( lpStr ) + 1;
  315.             if( wParam > cch )
  316.                wParam = cch;
  317.  
  318.             lstrcpy( (LPSTR)lParam, lpStr );
  319.          }
  320.          return( (LONG)( wParam - 1 ) );
  321.       }
  322.  
  323.       case WM_GETTEXTLENGTH:
  324.       {
  325.          GPSTRUCT far *Gp = GPDEREF( hCtl );
  326.  
  327.          if( Gp->hszCaption == NULL )
  328.             return( 0L );
  329.  
  330.          return( lstrlen( VBDerefHsz( Gp->hszCaption ) ) );
  331.       }
  332.  
  333.       case WM_SIZE:
  334.       {
  335.          GPSTRUCT far *Gp = GPDEREF( hCtl );
  336.  
  337.          Gp->Width = LOWORD( lParam );
  338.          Gp->Height = HIWORD( lParam );
  339.          PaintButton( hCtl, hWnd );
  340.          break;
  341.       }
  342.  
  343.       case WM_PAINT:
  344.       {
  345.          PAINTSTRUCT Ps;
  346.  
  347.          BeginPaint( hWnd, &Ps );
  348.          PaintButton( hCtl, hWnd );
  349.          EndPaint( hWnd, &Ps );
  350.          break;
  351.       }
  352.  
  353.       case WM_LBUTTONDBLCLK:
  354.       case WM_LBUTTONDOWN:
  355.       {
  356.          GPSTRUCT far *Gp = GPDEREF( hCtl );
  357.          WORD WinVer;
  358.          LPSTR lpStr;
  359.          HANDLE hMM;
  360.          FARPROC lpfnSndPlaySound;
  361.  
  362.          if( Gp->WaveOn )
  363.          {
  364.             WinVer = GetVersion();
  365.             if( HIBYTE( WinVer ) >= 10 && LOBYTE( WinVer ) >= 3 )
  366.             {
  367.                lpStr = VBDerefHsz( Gp->WaveFile );
  368.                if( lstrlen( lpStr ) )
  369.                {
  370.                   hMM = LoadLibrary( MMSystem );
  371.                   if( hMM )
  372.                   {
  373.                      lpfnSndPlaySound = GetProcAddress( hMM, (LPSTR)(DWORD)2 );
  374.  
  375.                      if( lpfnSndPlaySound )
  376.                         ( *lpfnSndPlaySound )( (LPSTR)lpStr,
  377.                                                (int)8 * ( Gp->WaveLoop != 0 ) );
  378.  
  379.                      FreeLibrary( hMM );
  380.                   }
  381.                }
  382.             }
  383.          }
  384.          VBFireEvent( hCtl, 0, NULL );
  385.          break;
  386.       }
  387.  
  388.       case VBM_GETPROPERTY:
  389.       {
  390.          GPSTRUCT far *Gp = GPDEREF( hCtl );
  391.  
  392.          switch( wParam )
  393.          {
  394.             case VBGP_HEIGHT:
  395.                *(WORD far *)lParam = Gp->Height;
  396.                return( FALSE );
  397.  
  398.             case VBGP_WIDTH:
  399.                *(WORD far *)lParam = Gp->Width;
  400.                return( FALSE );
  401.  
  402.             case VBGP_RAISED:
  403.                *(WORD far *)lParam = Gp->Raised;
  404.                return( FALSE );
  405.  
  406.             case VBGP_SHADOW:
  407.                *(WORD far *)lParam = Gp->Shadow;
  408.                return( FALSE );
  409.  
  410.             case VBGP_SHCOLOR:
  411.                *(LONG FAR *)lParam = Gp->ShadowColor;
  412.                return( FALSE );
  413.  
  414.             case VBGP_ALIGN:
  415.                *(WORD far *)lParam = Gp->Align;
  416.                return( FALSE );
  417.  
  418.             case VBGP_HILITE:
  419.                *(LONG far *)lParam = Gp->Hilite;
  420.                return( FALSE );
  421.  
  422.             case VBGP_LOLITE:
  423.                *(LONG far *)lParam = Gp->Lolite;
  424.                return( FALSE );
  425.  
  426.             case VBGP_WAVESTYLE:
  427.                *(LONG far *)lParam = Gp->WaveStyle;
  428.                return( FALSE );
  429.  
  430.             case VBGP_WAVELOOP:
  431.                *(WORD far *)lParam = Gp->WaveLoop;
  432.                return( FALSE );
  433.  
  434.             case VBGP_WAVEENABLED:
  435.                *(WORD far *)lParam = Gp->WaveOn;
  436.                return( FALSE );
  437.  
  438.             case VBGP_VERSION:
  439.                *(WORD far *)lParam = 100;
  440.                return( FALSE );
  441.          }
  442.          break;
  443.       }
  444.  
  445.       case VBM_SETPROPERTY:
  446.       {
  447.          GPSTRUCT far *Gp = GPDEREF( hCtl );
  448.  
  449.          switch( wParam )
  450.          {
  451.             case VBGP_HEIGHT:
  452.                if( Gp->Height != LOWORD( lParam ) )
  453.                {
  454.                   Gp->Height = LOWORD( lParam );
  455.                   PaintButton( hCtl, hWnd );
  456.                }
  457.                return( FALSE );
  458.  
  459.             case VBGP_WIDTH:
  460.                if( Gp->Width != LOWORD( lParam ) )
  461.                {
  462.                   Gp->Width = LOWORD( lParam );
  463.                   PaintButton( hCtl, hWnd );
  464.                }
  465.                return( FALSE );
  466.  
  467.             case VBGP_RAISED:
  468.                if( LOWORD( lParam ) != Gp->Raised )
  469.                {
  470.                   Gp->Raised = LOWORD( lParam );
  471.                   PaintButton( hCtl, hWnd );
  472.                }
  473.                return( FALSE );
  474.  
  475.             case VBGP_SHADOW:
  476.                if( LOWORD( lParam ) != Gp->Shadow )
  477.                {
  478.                   Gp->Shadow = LOWORD( lParam );
  479.                   PaintButton( hCtl, hWnd );
  480.                }
  481.                return( FALSE );
  482.  
  483.             case VBGP_SHCOLOR:
  484.                if( lParam != Gp->ShadowColor )
  485.                {
  486.                   Gp->ShadowColor = lParam;
  487.                   PaintButton( hCtl, hWnd );
  488.                }
  489.                return( FALSE );
  490.  
  491.             case VBGP_ALIGN:
  492.                Gp->Align = LOWORD( lParam );
  493.                PaintButton( hCtl, hWnd );
  494.                return( FALSE );
  495.  
  496.             case VBGP_HILITE:
  497.                Gp->Hilite = lParam;
  498.                PaintButton( hCtl, hWnd );
  499.                return( FALSE );
  500.  
  501.             case VBGP_LOLITE:
  502.                Gp->Lolite = lParam;
  503.                PaintButton( hCtl, hWnd );
  504.                return( FALSE );
  505.  
  506.             case VBGP_WAVESTYLE:
  507.                Gp->WaveStyle = LOWORD( lParam );
  508.                return( FALSE );
  509.  
  510.             case VBGP_WAVELOOP:
  511.                Gp->WaveLoop = LOWORD( lParam );
  512.                return( FALSE );
  513.  
  514.             case VBGP_WAVEENABLED:
  515.                Gp->WaveOn = LOWORD( lParam );
  516.                return( FALSE );
  517.          }
  518.          break;
  519.       }
  520.  
  521.       case VBM_INITPROPPOPUP:
  522.       {
  523.          GPSTRUCT far *Gp = GPDEREF( hCtl );
  524.  
  525.          switch( wParam )
  526.          {
  527.             case 2:
  528.             case 3:
  529.             case VBGP_LOLITE:
  530.             case VBGP_HILITE:
  531.             case VBGP_SHCOLOR:
  532.             case VBGP_WAVEFILE:
  533.             {
  534.                FARPROC DlgProc;
  535.  
  536.                if( VBGetMode() == MODE_DESIGN )
  537.                {
  538.                   ColorHctl = hCtl;
  539.                   ColorID = wParam;
  540.                   ColorHwnd = hWnd;
  541.  
  542.                   return( CreateWindow( CLASSPOPUP, NULL, WS_POPUP, 0, 0, 0, 0,
  543.                                         NULL, NULL, hmodDLL, NULL ) );
  544.                }
  545.                return( NULL );
  546.             }
  547.          }
  548.          break;
  549.       }
  550.    }
  551.    return( VBDefControlProc( hCtl, hWnd, msg, wParam, lParam ) );
  552. }
  553.  
  554.  
  555.  
  556. LONG _export FAR PASCAL PopupWndProc( HWND hWnd, WORD msg, WORD wParam, LONG lParam )
  557. {
  558.    switch( msg )
  559.    {
  560.       case WM_SHOWWINDOW:
  561.          if( wParam )
  562.          {
  563.             PostMessage( hWnd, WM_USER, 0, 0L );
  564.             return( 0L );
  565.          }
  566.          break;
  567.  
  568.       case WM_USER:
  569.          if( ColorID == VBGP_WAVEFILE )
  570.          {
  571.             GPSTRUCT far *Gp = GPDEREF( ColorHctl );
  572.             OPENFILENAME Of;
  573.             HSZ hsz;
  574.             char str[ 128 ];
  575.  
  576.             lstrcpy( str, "*.WAV" );
  577.             Of.lStructSize = sizeof(OPENFILENAME);
  578.             Of.hwndOwner = hWnd;
  579.             Of.hInstance = (HANDLE)NULL;
  580.             Of.lpstrFilter = "Wave Files  (*.WAV)\0*.WAV\0All Files   (*.*)\0*.*\0\0";
  581.             Of.lpstrCustomFilter = (LPSTR)NULL;
  582.             Of.nMaxCustFilter = (DWORD)0;
  583.             Of.nFilterIndex = (DWORD)0;
  584.             Of.lpstrFile = str;
  585.             Of.nMaxFile = (DWORD)128;
  586.             Of.lpstrFileTitle = (LPSTR)NULL;
  587.             Of.nMaxFileTitle = (DWORD)NULL;
  588.             Of.lpstrInitialDir = (LPSTR)NULL;
  589.             Of.lpstrTitle = "Attach Wave File...";
  590.             Of.Flags = (DWORD)NULL;
  591.             Of.nFileOffset = 0;
  592.             Of.nFileExtension = 0;
  593.             Of.lpstrDefExt = (LPSTR)NULL;
  594.             Of.lCustData = NULL;
  595.             Of.lpfnHook = NULL;
  596.             Of.lpTemplateName = (LPSTR)NULL;
  597.  
  598.             if( GetOpenFileName( &Of ) )
  599.                VBSetControlProperty( ColorHctl, VBGP_WAVEFILE, (LONG)(LPSTR)str );
  600.             return( 0L );
  601.          }
  602.  
  603.          VBDialogBoxParam( hmodDLL, "SETCOLOR", MakeProcInstance( SetColor, hmodDLL ), 0L );
  604.          return( 0L );
  605.    }
  606.    return( DefWindowProc( hWnd, msg, wParam, lParam ) );
  607. }
  608.  
  609.  
  610.  
  611. BOOL _export FAR PASCAL SetColor( HWND hDlg, WORD msg, WORD wParam, LONG lParam )
  612. {
  613.    switch( msg )
  614.    {
  615.       case WM_INITDIALOG:
  616.       {
  617.          GPSTRUCT far *Gp = GPDEREF( ColorHctl );
  618.          WORD Red, Green, Blue;
  619.          DWORD dwColor;
  620.          char str[ 6 ];
  621.  
  622.          VBGetControlProperty( ColorHctl, ColorID, &dwColor );                                /*  Get current color of property  */
  623.  
  624.          if( dwColor & 0x80000000 )                                         /*  If it's a system color offset, get system color  */
  625.             dwColor = GetSysColor( LOWORD( lParam ) + 1 );
  626.  
  627.          Red = GetRValue( dwColor );                                                            /*  Break color into components  */
  628.          Green = GetGValue( dwColor );
  629.          Blue = GetBValue( dwColor );
  630.  
  631.          SetProp( hDlg, MAKEINTRESOURCE( 1 ), CreateSolidBrush( RGB ( Red, Green, Blue ) ) );            /*  Save created brush  */
  632.  
  633.          SetScrollRange( GetDlgItem( hDlg, 100 ), SB_CTL, 0, 255, TRUE );                        /*  Initialize scrollbar sizes  */
  634.          SetScrollRange( GetDlgItem( hDlg, 102 ), SB_CTL, 0, 255, TRUE );
  635.          SetScrollRange( GetDlgItem( hDlg, 104 ), SB_CTL, 0, 255, TRUE );
  636.  
  637.          SetScrollPos( GetDlgItem( hDlg, 100 ), SB_CTL, Red, TRUE );                          /*  Initialze scrollbar positions  */
  638.          SetScrollPos( GetDlgItem( hDlg, 102 ), SB_CTL, Green, TRUE );
  639.          SetScrollPos( GetDlgItem( hDlg, 104 ), SB_CTL, Blue, TRUE );
  640.  
  641.          wsprintf( str, "%d", Red );
  642.          SetDlgItemText( hDlg, 101, str );                                       /*  Change editbox text to reflect color comp.  */
  643.          wsprintf( str, "%d", Green );
  644.          SetDlgItemText( hDlg, 103, str );
  645.          wsprintf( str, "%d", Blue );
  646.          SetDlgItemText( hDlg, 105, str );
  647.          return( TRUE );
  648.       }
  649.  
  650.       case WM_DRAWITEM:
  651.       {
  652.          LPDRAWITEMSTRUCT lpDs = (LPDRAWITEMSTRUCT)lParam;
  653.  
  654.          if( lpDs->CtlID == 106 )
  655.          {
  656.             RECT Rect;
  657.             HDC hDC;
  658.  
  659.             hDC = GetDC( GetDlgItem( hDlg, lpDs->CtlID ) );
  660.             SelectObject( hDC, GetProp( hDlg, MAKEINTRESOURCE( 1 ) ) );
  661.             GetWindowRect( GetDlgItem( hDlg, lpDs->CtlID ), &Rect );
  662.             Rectangle( hDC, 0, 0, Rect.right - Rect.left, Rect.bottom - Rect.top );
  663.             SelectObject( lpDs->hDC, GetStockObject( NULL_BRUSH ) );
  664.          }
  665.          break;
  666.       }
  667.  
  668.       case WM_HSCROLL:
  669.       {
  670.          DWORD dwColor;
  671.          int Pos;
  672.          char str[ 10 ];
  673.          int junk;
  674.  
  675.          Pos = GetScrollPos( HIWORD( lParam ), SB_CTL );
  676.  
  677.          switch( wParam )
  678.          {
  679.             case SB_BOTTOM:
  680.                SetScrollPos( HIWORD( lParam ), SB_CTL, 0, TRUE );
  681.                break;
  682.  
  683.             case SB_TOP:
  684.                SetScrollPos( HIWORD( lParam ), SB_CTL, 255, TRUE );
  685.                break;
  686.  
  687.             case SB_THUMBPOSITION:
  688.             case SB_THUMBTRACK:
  689.                SetScrollPos( HIWORD( lParam ), SB_CTL, LOWORD( lParam ), TRUE );
  690.                break;
  691.  
  692.             case SB_PAGEDOWN:
  693.                if( Pos > 240 )
  694.                   SetScrollPos( HIWORD( lParam ), SB_CTL, 255, TRUE );
  695.                else
  696.                   SetScrollPos( HIWORD( lParam ), SB_CTL, Pos + 16, TRUE );
  697.                break;
  698.  
  699.             case SB_PAGEUP:
  700.                if( Pos < 16 )
  701.                   SetScrollPos( HIWORD( lParam ), SB_CTL, 0, TRUE );
  702.                else
  703.                   SetScrollPos( HIWORD( lParam ), SB_CTL, Pos - 16, TRUE );
  704.                break;
  705.  
  706.             case SB_LINEDOWN:
  707.                if( Pos < 255 )
  708.                   SetScrollPos( HIWORD( lParam ), SB_CTL, Pos + 1, TRUE );
  709.                break;
  710.  
  711.             case SB_LINEUP:
  712.                if( Pos > 0 )
  713.                   SetScrollPos( HIWORD( lParam ), SB_CTL, Pos - 1, TRUE );
  714.                break;
  715.          }
  716.  
  717.          wsprintf( str, "%d", GetScrollPos( GetDlgItem( hDlg, 100 ), SB_CTL ) );
  718.          SetDlgItemText( hDlg, 101, str );
  719.  
  720.          wsprintf( str, "%d", GetScrollPos( GetDlgItem( hDlg, 102 ), SB_CTL ) );
  721.          SetDlgItemText( hDlg, 103, str );
  722.  
  723.          wsprintf( str, "%d", GetScrollPos( GetDlgItem( hDlg, 104 ), SB_CTL ) );
  724.          SetDlgItemText( hDlg, 105, str );
  725.  
  726.          dwColor = RGB( GetDlgItemInt( hDlg, 101, &junk, TRUE ),
  727.                         GetDlgItemInt( hDlg, 103, &junk, TRUE ),
  728.                         GetDlgItemInt( hDlg, 105, &junk, TRUE ) );
  729.  
  730.          DeleteObject( GetProp( hDlg, MAKEINTRESOURCE( 1 ) ) );
  731.          SetProp( hDlg, MAKEINTRESOURCE( 1 ), CreateSolidBrush( dwColor ) );
  732.  
  733.          InvalidateRect( GetDlgItem( hDlg, 106 ), NULL, FALSE );
  734.          break;
  735.       }
  736.  
  737.       case WM_COMMAND:
  738.          if( HIWORD( lParam ) == EN_KILLFOCUS )
  739.          {
  740.             DWORD dwColor;
  741.             int junk;
  742.  
  743.             dwColor = RGB( GetDlgItemInt( hDlg, 101, &junk, TRUE ),
  744.                            GetDlgItemInt( hDlg, 103, &junk, TRUE ),
  745.                            GetDlgItemInt( hDlg, 105, &junk, TRUE ) );
  746.  
  747.             DeleteObject( GetProp( hDlg, MAKEINTRESOURCE( 1 ) ) );
  748.             SetProp( hDlg, MAKEINTRESOURCE( 1 ), CreateSolidBrush( dwColor ) );
  749.  
  750.             InvalidateRect( GetDlgItem( hDlg, 106 ), NULL, FALSE );
  751.             break;
  752.          }
  753.  
  754.          if( wParam == IDOK || wParam == IDCANCEL )
  755.          {
  756.             if( wParam == IDOK )
  757.             {
  758.                int junk;
  759.                DWORD dwColor;
  760.                GPSTRUCT far *Gp = GPDEREF( ColorHctl );
  761.  
  762.                dwColor = RGB( GetDlgItemInt( hDlg, 101, &junk, TRUE ),
  763.                               GetDlgItemInt( hDlg, 103, &junk, TRUE ),
  764.                               GetDlgItemInt( hDlg, 105, &junk, TRUE ) );
  765.  
  766.                VBSetControlProperty( ColorHctl, ColorID, dwColor );
  767.             }
  768.  
  769.             DeleteObject( GetProp( hDlg, MAKEINTRESOURCE( 1 ) ) );
  770.             RemoveProp( hDlg, MAKEINTRESOURCE( 1 ) );
  771.  
  772.             if( wParam == IDOK )
  773.                InvalidateRect( ColorHwnd, NULL, TRUE );
  774.  
  775.             EndDialog( hDlg, TRUE );
  776.             return( TRUE );
  777.          }
  778.          break;
  779.    }
  780.    return( FALSE );
  781. }
  782.  
  783.  
  784. void PaintButton( HCTL hCtl, HWND hWnd )
  785. {
  786.    TEXTMETRIC Tm;
  787.    GPSTRUCT far *Gp = GPDEREF( hCtl );
  788.    HDC hDC;
  789.    int Yoff, Align, Len;
  790.    HPEN hWhite;
  791.    HPEN hGray;
  792.    RECT Rect;
  793.    DWORD OldColor;
  794.    LPSTR lpStr;
  795.  
  796.    hDC = GetDC( hWnd );
  797.    SelectObject( hDC, Gp->hFont );
  798.    GetTextMetrics( hDC, &Tm );
  799.  
  800.    SelectObject( hDC, SendMessage( GetParent( hWnd ), WM_CTLCOLOR, hDC, MAKELONG( hWnd, 0 ) ) );
  801.    SelectObject( hDC, GetStockObject( NULL_PEN ) );
  802.    Rectangle( hDC, 0, 0, Gp->Width + 1, Gp->Height + 1 );
  803.  
  804.    hWhite = CreatePen( PS_SOLID, 1, Gp->Hilite );
  805.    hGray = CreatePen( PS_SOLID, 1, Gp->Lolite );
  806.  
  807.    Yoff = Tm.tmHeight / 2;
  808.  
  809.    if( Gp->Raised )
  810.       SelectObject( hDC, hWhite );
  811.    else
  812.       SelectObject( hDC, hGray );
  813.  
  814.    MoveTo( hDC, Gp->Width, Yoff );
  815.    LineTo( hDC, 0, Yoff );
  816.    LineTo( hDC, 0, Gp->Height );
  817.  
  818.    MoveTo( hDC, 2, Gp->Height - 2 );
  819.    LineTo( hDC, Gp->Width - 2, Gp->Height - 2 );
  820.    LineTo( hDC, Gp->Width - 2, Yoff + 1 );
  821.  
  822.    if( Gp->Raised )
  823.       SelectObject( hDC, hGray );
  824.    else
  825.       SelectObject( hDC, hWhite );
  826.  
  827.    MoveTo( hDC, Gp->Width, Yoff + 1 );
  828.    LineTo( hDC, 1, Yoff + 1 );
  829.    LineTo( hDC, 1, Gp->Height - 1 );
  830.  
  831.    MoveTo( hDC, 1, Gp->Height - 1 );
  832.    LineTo( hDC, Gp->Width - 1, Gp->Height - 1 );
  833.    LineTo( hDC, Gp->Width - 1, Yoff + 1 );
  834.  
  835.    if( Gp->hszCaption )
  836.    {
  837.       lpStr = VBDerefHsz( Gp->hszCaption );
  838.       Len = (int)GetTextExtent( hDC, lpStr, lstrlen( lpStr ) );
  839.  
  840.       if( Gp->Align == 0 )
  841.          Align = 0;
  842.  
  843.       if( Gp->Align == 1 )
  844.          Align = ( ( Gp->Width - Len ) / 2 ) - 12;
  845.  
  846.       if( Gp->Align == 2 )
  847.          Align = Gp->Width - Len - 24;
  848.  
  849.       if( lstrlen( lpStr ) );
  850.       {
  851.          if( Gp->Shadow )
  852.          {
  853.             OldColor = GetTextColor( hDC );
  854.  
  855.             SetBkMode( hDC, OPAQUE );
  856.             SetTextColor( hDC, Gp->ShadowColor );
  857.             Rect.top = 0;
  858.             Rect.left = 12 + Align;
  859.             Rect.bottom = Tm.tmHeight;
  860.             Rect.right = 24 + Len + Align;
  861.             DrawText( hDC, lpStr, lstrlen( lpStr ), &Rect, DT_LEFT | DT_TOP );
  862.  
  863.             SetTextColor( hDC, OldColor );
  864.          }
  865.          if( Gp->Shadow )
  866.             SetBkMode( hDC, TRANSPARENT );
  867.          else
  868.             SetBkMode( hDC, OPAQUE );
  869.  
  870.          Rect.top = 0 + ( Gp->Shadow != 0 );
  871.          Rect.bottom = Tm.tmHeight + ( Gp->Shadow != 0 );
  872.          Rect.left = 12 + ( Gp->Shadow != 0 ) + Align;
  873.          Rect.right = 24 + (WORD)GetTextExtent( hDC, lpStr, lstrlen( lpStr ) ) + ( Gp->Shadow != 0 ) + Align;
  874.  
  875.          DrawText( hDC, lpStr, lstrlen( lpStr ), &Rect, DT_LEFT | DT_TOP );
  876.       }
  877.    }
  878.  
  879.    ReleaseDC( hWnd, hDC );
  880.    DeleteObject( hWhite );
  881.    DeleteObject( hGray );
  882. }
  883.  
  884.