home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_2 / VB_LABEL / VBLABEL.C next >
Encoding:
C/C++ Source or Header  |  1992-05-23  |  23.6 KB  |  920 lines

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