home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / bp_3_94 / vbwin / line3d / line3d.c < prev    next >
C/C++ Source or Header  |  1994-04-24  |  12KB  |  329 lines

  1. // Frame.c - Steuerelementkontrollprozedur FRAME
  2. // Autor: Dipl.-Ing. Andreas Maslo
  3.  
  4. //Line3d.c - Steuerelementprozedur
  5. //Autor: Dipl.-Ing. Andreas Maslo
  6. //(c)1993/94 by IngES/Dipl.-Ing. Andreas Maslo
  7.  
  8. #define  NOCOMM
  9. #include <windows.h>
  10.  
  11. #include <vbapi.h>
  12. #include <string.h>
  13. #include "line3d.h"
  14.  
  15. // lokale Prototypen
  16. VOID NEAR DrawBack(PLINE3D pline3d, HWND hwnd, HDC hdc);
  17. VOID NEAR RecalcArea(PLINE3D pline3d, HWND hwnd);
  18.  
  19. // Line3D-Kontrollprozedur
  20. LONG FAR PASCAL _export Line3dCtlProc
  21. (
  22.     HCTL   hctl,
  23.     HWND   hwnd,
  24.     USHORT msg,
  25.     USHORT wp,
  26.     LONG   lp
  27. )
  28. {
  29.     PLINE3D pline3d = NULL;
  30.     HDC     hdc;
  31.     LPRECT  prect = &pline3d->rectDrawInto;
  32.  
  33.     switch (msg)
  34.     {
  35.         case WM_CREATE:
  36.           //Fenster ÷ffnen
  37.           pline3d = (PLINE3D)VBDerefControl(hctl);
  38.           //standardmΣ▀ig 3D-Rahmen
  39.           pline3d->LineStyle = 3;
  40.           //Font3D eingeschaltet, erhoben
  41.           pline3d-> Font3D = 1;
  42.           //Hintergundfarbe auf grau setzen
  43.           VBSetControlProperty(hctl, IPROP_LINE3D_BACKCOLOR, RGB(192, 192, 192));
  44.           break;
  45.         case WM_SETFONT:
  46.           //zu verwendende Schriftart festlegen
  47.           pline3d = (PLINE3D)VBDerefControl(hctl);
  48.           pline3d->hfont = (HFONT)wp;
  49.           return 0;
  50.         case WM_GETFONT:
  51.           //zu verwendende Schriftart ermitteln
  52.           pline3d = (PLINE3D)VBDerefControl(hctl);
  53.           return pline3d->hfont;
  54.         case WM_SETTEXT:
  55.           //Textinhalt festlegen
  56.           {
  57.            HSZ hsz;
  58.            pline3d = (PLINE3D)VBDerefControl(hctl);
  59.            if (pline3d->hszCaption)
  60.               {
  61.             VBDestroyHsz(pline3d->hszCaption);
  62.               }
  63.            hsz = VBCreateHsz((_segment)hctl, (LPSTR)lp);
  64.            pline3d = (PLINE3D)VBDerefControl(hctl);
  65.            pline3d->hszCaption = hsz;
  66.            //Fensterbereich zum Neuzeichnen ausweisen
  67.            InvalidateRect(hwnd, NULL, TRUE);
  68.            return 0L;
  69.           }
  70.         case WM_GETTEXT:
  71.           //Textinhalt ermitteln
  72.           {
  73.            LPSTR   lpstr;
  74.            WORD    cch;
  75.            pline3d = (PLINE3D)VBDerefControl(hctl);
  76.            if (pline3d->hszCaption == NULL)
  77.               //leere Zeichenkette
  78.               {
  79.                *(LPSTR)lp = 0L;
  80.                wp = 1;
  81.               }
  82.             else
  83.               {
  84.                lpstr = VBDerefHsz(pline3d->hszCaption);
  85.                cch = lstrlen(lpstr) + 1;
  86.                 if (wp > cch)
  87.                  wp = cch;
  88.                  _fstrncpy((LPSTR)lp, lpstr, wp);
  89.                  ((LPSTR)lp)[wp - 1] = '\0';
  90.               }
  91.           }
  92.           return (LONG)(wp - 1);
  93.         case WM_GETTEXTLENGTH:
  94.           //TextlΣnge ermitteln
  95.           pline3d = (PLINE3D)VBDerefControl(hctl);
  96.           if (pline3d->hszCaption == NULL)
  97.               return 0L;
  98.             else
  99.                  return lstrlen(VBDerefHsz(pline3d->hszCaption));
  100.         case WM_PAINT:
  101.           //Fenster neuzeichnen
  102.           pline3d = (PLINE3D)VBDerefControl(hctl);
  103.           if (wp)
  104.               DrawBack(pline3d, hwnd, (HDC)wp);
  105.             else
  106.               {
  107.                PAINTSTRUCT ps;
  108.                BeginPaint(hwnd, &ps);
  109.                DrawBack(pline3d, hwnd, ps.hdc);
  110.                EndPaint(hwnd, &ps);
  111.               }
  112.           break;
  113.         case WM_SIZE:
  114.           //Gr÷▀enΣnderung des Fensters
  115.           pline3d = (PLINE3D)VBDerefControl(hctl);
  116.           RecalcArea(pline3d, hwnd);
  117.           break;
  118.         case VBM_SETPROPERTY:
  119.           //benutzerdefinierte Eigenschaften festlegen
  120.           switch (wp)
  121.               {
  122.                case IPROP_LINE3D_LINESTYLE:
  123.                    //Rahmenstil wurde gewechselt
  124.                  pline3d = (PLINE3D)VBDerefControl(hctl);
  125.                  pline3d->LineStyle = (ENUM)lp;
  126.                  InvalidateRect(hwnd, prect, FALSE);
  127.                break;
  128.              case IPROP_LINE3D_FONT3D:
  129.                    //3D-Schriftstil wurde gewechselt
  130.                  pline3d = (PLINE3D)VBDerefControl(hctl);
  131.                  pline3d->Font3D = (ENUM)lp;
  132.                  InvalidateRect(hwnd, prect, FALSE);
  133.                break;
  134.           }
  135.           break;
  136.     }
  137.     //alles weitere an Visual Basic weiterleiten
  138.     return VBDefControlProc(hctl, hwnd, msg, wp, lp);
  139. }
  140.  
  141.  
  142. //Zeichnen des Steuerelementes
  143. //Aufruf erfolgt durch Botschaft WM_PAINT
  144. VOID NEAR DrawBack
  145. (
  146.     PLINE3D pline3d,
  147.     HWND    hwnd,
  148.     HDC     hdc
  149. )
  150. {
  151.     HBRUSH  hbr;
  152.     HBRUSH  hbrOld = NULL;
  153.     LPSTR   lpstr;
  154.     LPRECT  prect = &pline3d->rectDrawInto;
  155.     HFONT   hfontOld;
  156.     HPEN    hPen;
  157.     LONG    OldColor;
  158.     //Korrekturwert zum Verschieben eines wei▀en
  159.     //Hintergrundtextes zur Erzielung eines
  160.     //3D-Effekts
  161.     SHORT   CorrectionValue;
  162.  
  163.  
  164.     //Rechteck ausfⁿllen und mit selber Farbe umranden
  165.     hbr = (HBRUSH)SendMessage(GetParent(hwnd), WM_CTLCOLOR,
  166.                       hdc, MAKELONG(hwnd, 0));
  167.     hPen=SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(192,192,192)));
  168.     hbrOld = SelectObject(hdc, hbr);
  169.     Rectangle(hdc, prect->left, prect->top, prect->right, prect->bottom);
  170.     //Linie zeichen
  171.     if (pline3d->LineStyle == 1)
  172.         {
  173.          //horizontale 3D-Linie
  174.          DeleteObject(SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(129,129,129))));
  175.          MoveTo (hdc, prect->right, (prect->bottom - prect->top)/2 );
  176.          LineTo (hdc, prect->left,  (prect->bottom - prect->top)/2 );
  177.          DeleteObject(SelectObject(hdc,GetStockObject(WHITE_PEN)));
  178.          MoveTo (hdc, prect->right, (prect->bottom - prect->top)/2+1 );
  179.          LineTo (hdc, prect->left,  (prect->bottom - prect->top)/2+1 );
  180.          DeleteObject(SelectObject(hdc,GetStockObject(BLACK_PEN)));
  181.         }
  182.      else if (pline3d->LineStyle == 2)
  183.         {
  184.          //vertikale 3D-Linie
  185.          DeleteObject(SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(129,129,129))));
  186.          MoveTo (hdc, prect->right/2, prect->top);
  187.          LineTo (hdc, prect->right/2, prect->bottom);
  188.          DeleteObject(SelectObject(hdc,GetStockObject(WHITE_PEN)));
  189.          MoveTo (hdc, prect->right/2+1, prect->top);
  190.          LineTo (hdc, prect->right/2+1, prect->bottom);
  191.          DeleteObject(SelectObject(hdc,GetStockObject(BLACK_PEN)));
  192.         }
  193.      else if (pline3d->LineStyle == 3)
  194.         {
  195.          //3D-Rahmen versenkt
  196.          //dunkelgrauen Stift erzeugen
  197.          DeleteObject(SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(129,129,129))));
  198.          Rectangle(hdc, prect->left, prect->top, prect->right, prect->bottom);
  199.          DeleteObject(SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(255,255,255))));
  200.          Rectangle(hdc, prect->left+1, prect->top+1, prect->right-1, prect->bottom-1);
  201.          DeleteObject(SelectObject(hdc,GetStockObject(BLACK_PEN)));
  202.         }
  203.      else if (pline3d->LineStyle == 4)
  204.         {
  205.          //3D-Rahmen erhoben
  206.          //dunkelgrauen Stift erzeugen
  207.          DeleteObject(SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(255,255,255))));
  208.          Rectangle(hdc, prect->left, prect->top, prect->right, prect->bottom);
  209.          DeleteObject(SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(129,129,129))));
  210.          Rectangle(hdc, prect->left+1, prect->top+1, prect->right-1, prect->bottom-1);
  211.          DeleteObject(SelectObject(hdc,GetStockObject(BLACK_PEN)));
  212.         }
  213.      else if (pline3d->LineStyle == 5)
  214.         {
  215.          //abgerundeter 3D-Rahmen versenkt
  216.          //dunkelgrauen Stift erzeugen
  217.          DeleteObject(SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(129,129,129))));
  218.          //Hinweis: das letzte Koordinatenpaar legt die Ausrundung der Ecken fest
  219.          RoundRect(hdc, prect->left, prect->top, prect->right, prect->bottom,10,10);
  220.          DeleteObject(SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(255,255,255))));
  221.          RoundRect(hdc, prect->left+1, prect->top+1, prect->right-1, prect->bottom-1,10,10);
  222.          DeleteObject(SelectObject(hdc,GetStockObject(BLACK_PEN)));
  223.         }
  224.      else if (pline3d->LineStyle == 6)
  225.         {
  226.          //abgerundeter 3D-Rahmen erhoben
  227.          //dunkelgrauen Stift erzeugen
  228.          DeleteObject(SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(255,255,255))));
  229.          RoundRect(hdc, prect->left, prect->top, prect->right, prect->bottom,10,10);
  230.          DeleteObject(SelectObject(hdc,CreatePen(PS_SOLID,1,RGB(129,129,129))));
  231.          RoundRect(hdc, prect->left+1, prect->top+1, prect->right-1, prect->bottom-1,10,10);
  232.          DeleteObject(SelectObject(hdc,GetStockObject(BLACK_PEN)));
  233.         };
  234.  
  235.     hfontOld = SelectObject(hdc, pline3d->hfont);
  236.     //Text der Eigenschaft CAPTION ermitteln
  237.     lpstr = VBDerefHsz(pline3d->hszCaption);
  238.  
  239.     //3D-Effekt wird durch erstmaliges und leicht
  240.     //versetztes Schreiben des Textes gegenⁿber seiner
  241.     //endgⁿltigen Position mit wei▀er Farbe erzielt
  242.     //Text fⁿr 3D-Effekt im Hintergrund ausgeben
  243.     //Hinweis: dieser Text wird nur dann ausgegeben,
  244.     //         wenn der 3D-Look aktiviert wurde
  245.     if (pline3d->Font3D != 0)
  246.       {
  247.        //nur wenn Eigenschaft auf 1 gesetzt ist, Schrift
  248.        //im 3D-Look ausgeben
  249.        //Hintergrundfarbe bleibt unberⁿhrt, d.h. Text
  250.        //wird transparent ausgegeben; das verhindert,
  251.        //das der nachfolgend versetzt ausgegebene Text
  252.        //den ersten Text vollstΣndig ⁿberschreibt
  253.        SetBkMode(hdc, 1);
  254.        //alte Schriftfarbe sichern
  255.        OldColor = GetTextColor(hdc);
  256.        //Schriftfarbe fⁿr Hintergrundtext ist immer wei▀
  257.        SetTextColor(hdc, RGB(255, 255, 255));
  258.  
  259.        //abhΣngig vom Rechteck des Steuerelementes
  260.        //wei▀en Hintergrundtext leicht versetzen
  261.        if (pline3d->Font3D==1)
  262.          //Korrekturwert zum Verschieben des
  263.          //Hintergrundtextes ist abhΣngig davon, ob
  264.          //der Text erhoben oder versenkt erscheinen soll
  265.          {
  266.          //Text erhoben
  267.          //wei▀er Text wird nach links oben verschoben
  268.          CorrectionValue=1;
  269.          }
  270.        else if (pline3d->Font3D==2)
  271.          {
  272.          //Text versenkt
  273.          //wei▀er Text wird nach rechts unten verschoben
  274.          CorrectionValue=-1;
  275.          };
  276.  
  277.        //Ausgabebereich anpassen
  278.        //Achtung: alle Bereich mⁿssen um den gewΣhlten
  279.        //         Korrekturwert temporΣr geΣndert werden
  280.        prect->left = prect->left-CorrectionValue;
  281.        prect->top = prect->top-CorrectionValue;
  282.        prect->right = prect->right-CorrectionValue;
  283.        prect->bottom = prect->bottom-CorrectionValue;
  284.  
  285.        //wei▀en Hintergrundtext ausgeben
  286.        //Achtung: die Textausgabe ist auch hier wieder abhΣngig von der
  287.        //         Eigenschaft TextStyle!
  288.        //Text zentriert, mehrzeilig, automatischer Zeilenumbruch
  289.        DrawText(hdc, lpstr, -1, prect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
  290.  
  291.        //Rechteck des Steuerelementes wieder auf ursprⁿngliche Gr÷▀e
  292.        //Achtung: alle ursprⁿnglichen Grenzen mⁿssen
  293.        //         wiederhergestellt werden
  294.        prect->left = prect->left+CorrectionValue;
  295.        prect->top = prect->top+CorrectionValue;
  296.        prect->right = prect->right+CorrectionValue;
  297.        prect->bottom = prect->bottom+CorrectionValue;
  298.  
  299.        //alte Textfarbe wiederherstellen
  300.        SetTextColor(hdc, OldColor);
  301.       }
  302.  
  303.     //eigentlichen Text in gewΣhlter Vordergrundfarbe ausgeben
  304.     //Hinweis: dieser Text wird in jedem Fall ausgegeben, und zwar
  305.     //         auch dann, wenn kein 3D-Look aktiviert wurde
  306.     DrawText(hdc, lpstr, -1, prect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
  307.  
  308.     SelectObject(hdc, hfontOld);
  309.     SelectObject(hdc, hbrOld);
  310.     return;
  311. }
  312.  
  313.  
  314. VOID NEAR RecalcArea
  315. (
  316.     PLINE3D pline3d,
  317.     HWND    hwnd
  318. )
  319. {
  320.     LPRECT   prect = &pline3d->rectDrawInto;
  321.     //aktuelle Fenstergr÷▀e ermitteln
  322.     GetClientRect(hwnd, prect);
  323.     return;
  324. }
  325.  
  326.  
  327.  
  328.  
  329.