🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.ms-windows.programmer.misc
Article #2465

Entryfield Border

#2465
From: das11
Date: Mon, 04 Jan 1993 21:41
440 lines
16489 bytes
I am trying to create a ribbon window that appears at the top of the screen.
Within the ribbon, there is an area for coordinates to be displayed, 
a combobox and an entryfield.  The ribbon draws correctly and everything
seems to work except:

	* How come there is no black line around the entryfield (border).

Is this a result becuase I am painting the window myself?

I have included the code of the RIBBON module.  This module is meant to
be autonomus.  What happens is the a main window procedure will use the
given APIs to control the behavior.

Thank you.
David Sobeski
DAS11@JAGUAR.UCS.UOFS.EDU


*** Example of a window procedure for the main window: ***

#include "ribbon.h"
LONG FAR PASCAL WndProc(HWND hwnd, WORD msg, WORD wParam, LONG lParam)
{
   static HWND hwndRibbon;       // handle of the ribbon window

   switch (msg)
   {
      case WM_CREATE:
         hwndRibbon = RibbonCreate(hwnd);
         break;
     
      case WM_SIZE:
         POINT coord;
         coord.x = LOWORD(lParam);
         coord.y = HIWORD(lParam);

         RibbonResize(hwndRibbon, coord);
         break;

      case WM_MOUSEMOVE:
         if (wParam == MK_LBUTTON)
         {
            SetCapture(hwnd);
            RibbonSetCoord(hwndRibbon, X_COORD, LOWORD(lParam));
            RibbonSetCoord(hwndRibbon, Y_COORD, LOWORD(lParam));
            ReleaseCapture();
         }
         break;

      case WM_DESTROY:
         RibbonDestroy(hwndRibbon);
         PostQuitMessage(0);
         break;
   }
   return (DefWndProc(hwnd, msg, wParam, lParam));
}

THE FOLLOWING IS THE CODE FOR THE RIBBON MODULE:

/* ---------------------------- ribbon.cpp ---------------------------- */
/*                                                                      */
/*    DESCRIPTION:                                                      */
/*    -----------                                                       */
/*    This module contains all the code necessary for an application to */
/*    implement a ribbon.                                               */
/*                                                                      */
/* -------------------------------------------------------------------- */

#define WIN31
#include <windows.h>
#include <string.h>
#include <stdlib.h>

#include "ribbon.h"

/**********
 Constant definitions
 **********/
const char szClassName[]     = "RIBBON";     // class to register
const char szAppName[]       = "";           // application name
const int  cyCoord           = 57;           // icon bar height
const int  RB_TEXTSIZE       = 5;            // size of coordinate text

/**********
 Control ids
 **********/
const int  TX_SYMBOL         = 1000;
const int  CB_SYMBOL         = 1001;
const int  TX_CAPTION        = 1010;
const int  EF_CAPTION        = 1011;
const int  TX_ID             = 1020;
const int  EF_ID             = 1021;

static char  INIT_COORD[] = "0";
static char  szXCoord[RB_TEXTSIZE];
static char  szYCoord[RB_TEXTSIZE];
static char  szCXCoord[RB_TEXTSIZE];
static char  szCYCoord[RB_TEXTSIZE];

/**********
 Function prototypes
 **********/
long FAR PASCAL RibbonProc(HWND, WORD, WORD, LONG);
void CreateRibbon(HWND);
void PaintRibbon(HWND, WORD);
HBRUSH CtlColorRibbon(HWND, WORD, LONG);

/* -------------------------------------------------------------------- */
/*    Function:            RibbonCreate                                 */
/*                         EXTERNAL FUNCTION                            */
/*                                                                      */
/*    Parameters:          hwndParent - handle of the parent window     */
/*                                                                      */
/*    Returns:             HWND       - handle of the icon bar          */
/*                                                                      */
/*    Description:         Creates the icon bar window.                 */
/* -------------------------------------------------------------------- */
HWND long FAR PASCAL RibbonCreate(HWND hwndParent)
{
   WNDCLASS   wndclass;      // window class for the icon bar
   HWND       hwnd;          // handle of the icon bar window

   wndclass.style            = CS_HREDRAW | CS_VREDRAW;
   wndclass.lpfnWndProc      = (WNDPROC)RibbonProc;
   wndclass.cbClsExtra       = 0;
   wndclass.cbWndExtra       = 0;
   wndclass.hInstance        = GetWindowWord(hwndParent, GWW_HINSTANCE);
   wndclass.hIcon            = NULL;
   wndclass.hCursor          = LoadCursor(NULL, IDC_ARROW);
   wndclass.hbrBackground    = GetStockObject(LTGRAY_BRUSH);
   wndclass.lpszMenuName     = 0;
   wndclass.lpszClassName    = szClassName;

   RegisterClass(&wndclass);

   hwnd = CreateWindow(szClassName,
                       szAppName,
                       WS_CHILDWINDOW,
                       0, 0, 0, 0,
                       hwndParent,
                       NULL,
                       GetWindowWord(hwndParent, GWW_HINSTANCE),
                       NULL);

   strcpy(szXCoord,  INIT_COORD);
   strcpy(szYCoord,  INIT_COORD);
   strcpy(szCXCoord, INIT_COORD);
   strcpy(szCYCoord, INIT_COORD);

   ShowWindow(hwnd, SW_SHOW);
   UpdateWindow(hwnd);

   return (hwnd);
}

/* -------------------------------------------------------------------- */
/*    Function:            RibbonDestroy                                */
/*                         EXTERNAL FUNCTION                            */
/*                                                                      */
/*    Parameters:          hwndParent - handle of the parent window     */
/*                                                                      */
/*    Returns:             HWND       - handle of the icon bar          */
/*                                                                      */
/*    Description:         Destroys the icon bar window.                */
/* -------------------------------------------------------------------- */
BOOL long FAR PASCAL RibbonDestroy(HWND hwnd)
{
   HWND   hwndParent;        // handle of the parent window

   hwndParent = GetParent(hwnd);

   DestroyWindow(hwnd);
   UnregisterClass(szClassName, GetWindowWord(hwndParent, GWW_HINSTANCE));

   return (TRUE);
}

/* -------------------------------------------------------------------- */
/*    Function:            RibbonResize                                 */
/*                         EXTERNAL FUNCTION                            */
/*                                                                      */
/*    Parameters:          hwnd      - handle of the icon bar           */
/*                         ptlClient - the cx and cy of the parent      */
/*                                     window                           */
/*                                                                      */
/*    Returns:             BOOL      - function completed.              */
/*                                                                      */
/*    Description:         Sizes the icon bar to fit within its parent  */
/*                         window.                                      */
/* -------------------------------------------------------------------- */
BOOL long FAR PASCAL RibbonResize(HWND hwnd, POINT ptlClient)
{
   MoveWindow(hwnd,          // handle of the icon bar
              0,             // x-coordinate
              31,            // y-coordinate
              ptlClient.x,   // width of the icon bar
              cyCoord+1,     // height of the icon bar
              TRUE);         // force a repaint

   return (TRUE);
}

/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
BOOL FAR PASCAL RibbonSetCoord(HWND hwnd, int coord, int iCoord)
{
   HDC  hdc;
   char szCoord[RB_TEXTSIZE];

   if (strlen(szCoord) > RB_TEXTSIZE)
      return (FALSE);

   itoa(iCoord, szCoord, 10);
   switch (coord)
   {
      case X_COORD   : strcpy(szXCoord,  szCoord);   break;
      case Y_COORD   : strcpy(szYCoord,  szCoord);   break;
      case CX_COORD  : strcpy(szCXCoord, szCoord);   break;
      case CY_COORD  : strcpy(szCYCoord, szCoord);   break;
      default        : return (FALSE);
   }

   PaintRibbon(hwnd, NULL);
   return (TRUE);    
}

/* -------------------------------------------------------------------- */
/*    Function:            RibbonWndProc                                */
/*                         INTERNAL FUNCTION                            */
/*                                                                      */
/*    Parameters:          hwnd    - handle of the icon bar window      */
/*                         msg     - message                            */
/*                         wParam  - message parameter                  */
/*                         lParam  - message parameter                  */
/*                                                                      */
/*    Returns:             LONG    - default window procedure           */
/*                                                                      */
/*    Description:         This is the function that handles all the    */
/*                         messages to the icon bar.                    */
/* -------------------------------------------------------------------- */
long FAR PASCAL RibbonProc(HWND hwnd, WORD msg, WORD wParam, LONG lParam)
{
   static HBRUSH hBrush;

   switch (msg)
   {
      case WM_CREATE:
         CreateRibbon(hwnd);
         break;

      case WM_PAINT:
         PaintRibbon(hwnd, WM_PAINT);
         break;

      case WM_CTLCOLOR:
         hBrush = CtlColorRibbon(hwnd, wParam, lParam);
         return (hBrush);

      case WM_DESTROY:
         DeleteObject(hBrush);
         break;
   }

   return (DefWindowProc(hwnd, msg, wParam, lParam));
}

/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
void CreateRibbon(HWND hwnd)
{
   CreateWindow("static",
                "Symbol",
                WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT,
                210, 8, 50, 20,
                hwnd,
                TX_SYMBOL,
                GetWindowWord(hwnd, GWW_HINSTANCE),
                NULL);

   CreateWindow("combobox",
                "",
                WS_CHILDWINDOW | WS_VISIBLE |
                CBS_DROPDOWN | CBS_SORT | CBS_AUTOHSCROLL,
                275, 5, 200, 200,
                hwnd,
                CB_SYMBOL,
                GetWindowWord(hwnd, GWW_HINSTANCE),
                NULL);

   CreateWindow("static",
                "Id",
                WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT,
                500, 8, 50, 20,
                hwnd,
                TX_ID,
                GetWindowWord(hwnd, GWW_HINSTANCE),
                NULL);

   CreateWindow("edit",
                "",
                WS_CHILDWINDOW | WS_VISIBLE |
                ES_LEFT | ES_AUTOHSCROLL,
                530, 6, 50, 20,
                hwnd,
                EF_ID,
                GetWindowWord(hwnd, GWW_HINSTANCE),
                NULL);

   CreateWindow("static",
                "Caption",
                WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT,
                210, 35, 50, 20,
                hwnd,
                TX_CAPTION,
                GetWindowWord(hwnd, GWW_HINSTANCE),
                NULL);

   CreateWindow("edit",
                "",
                WS_CHILDWINDOW | WS_VISIBLE |
                ES_LEFT | ES_AUTOHSCROLL,
                275, 33, 175, 20,
                hwnd,
                EF_CAPTION,
                GetWindowWord(hwnd, GWW_HINSTANCE),
                NULL);

   SetFocus(GetDlgItem(hwnd, EF_CAPTION));
}

/* -------------------------------------------------------------------- */
/*    Function:            PaintRibbon                                  */
/*                         INTERNAL FUNCTION                            */
/*                                                                      */
/*    Parameters:          hwnd    - handle of the icon bar window      */
/*                                                                      */
/*    Returns:             NONE                                         */
/*                                                                      */
/*    Description:         This is the function performs the drawing of */
/*                         the icon bar.                                */
/* -------------------------------------------------------------------- */
void PaintRibbon(HWND hwnd, WORD msg)
{
   HDC            hdc;       // handle to the icon bar device context
   PAINTSTRUCT    ps;        // the paint structure
   RECT           rClient;   // coordinates of the icon bar client area

   if (msg == WM_PAINT)
      hdc = BeginPaint(hwnd, &ps);
   else
      hdc = GetDC(hwnd);

   GetClientRect(hwnd, &rClient);

   /**********
    Draw black line on the bottom of the icon bar.
    **********/
   SelectObject(hdc, GetStockObject(BLACK_PEN));
   MoveTo(hdc, 0, cyCoord);
   LineTo(hdc, rClient.right, cyCoord);

   /**********
    Draw the white lines on the top and left side to give the icon bar
    the chiseled look.
    **********/
   SelectObject(hdc, GetStockObject(WHITE_PEN));
   MoveTo(hdc, 0, 0);
   LineTo(hdc, rClient.right, 0);    // draw the left side 
   MoveTo(hdc, 0, 0);
   LineTo(hdc, 0, rClient.bottom);   // draw the line across the top

   /**********
    Make the coordinate area chiseled.
    **********/
   SelectObject(hdc, GetStockObject(BLACK_PEN));
   MoveTo(hdc, 4,   5);   
   LineTo(hdc, 170, 5);   // horizontal line
   MoveTo(hdc, 4,   5);
   LineTo(hdc, 4,   50);  // vertical line
   SelectObject(hdc, GetStockObject(WHITE_PEN));
   MoveTo(hdc, 4,   50);
   LineTo(hdc, 171, 50);  // horizontal line
   MoveTo(hdc, 170, 5);
   LineTo(hdc, 170, 50);  // vertical line

   /**********
    Set the text in the ribbon to have a light gray background.
    **********/
   SelectObject(hdc, GetStockObject(ANSI_VAR_FONT));
   SetTextColor(hdc, RGB(0, 0, 0));                    // black
   SetBkColor(hdc, RGB(192, 192, 192));                // light gray

   TextOut(hdc, 10, 10, "X-Coord:",  strlen("X-Coord:"));
   TextOut(hdc, 10, 34, "Y-Coord:",  strlen("Y-Coord:"));
   TextOut(hdc, 90, 10, "CX-Coord:", strlen("CX-Coord:"));
   TextOut(hdc, 90, 34, "CY-Coord:", strlen("CY-Coord:"));

   SelectObject(hdc, GetStockObject(ANSI_VAR_FONT));
   SetTextColor(hdc, RGB(0, 0, 0));                 
   SetBkColor(hdc, RGB(192, 192, 192));             

   TextOut(hdc, 60,  10, szXCoord,  strlen(szXCoord));
   TextOut(hdc, 60,  34, szYCoord,  strlen(szYCoord));
   TextOut(hdc, 145, 10, szCXCoord, strlen(szCXCoord));
   TextOut(hdc, 145, 34, szCYCoord, strlen(szCYCoord));

   if (msg == WM_PAINT)
      EndPaint(hwnd, &ps);
   else
      ReleaseDC(hwnd, hdc);
}

/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
HBRUSH CtlColorRibbon(HWND hwnd, WORD wParam, LONG lParam)
{
   HBRUSH hBrush;
   POINT  point;

   if (HIWORD(lParam) == CTLCOLOR_EDIT)
   {
      hBrush = CreateSolidBrush(RGB(255, 255, 255));
      SetBkColor(wParam, RGB(255, 255, 255));
   }
   else
   {
      hBrush = CreateSolidBrush(RGB(192, 192, 192));
      SetBkColor(wParam, RGB(192, 192, 192));
   }


   SetTextColor(wParam, RGB(0, 0, 0));
   UnrealizeObject(hBrush);
   point.x = point.y = 0;
   ClientToScreen(hwnd, &point);
   SetBrushOrg(wParam, point.x, point.y);

   return ((DWORD)hBrush);
}
Technical Details
Message-ID: <1993Jan4.164144.1@jaguar.uofs.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!yale.edu!jvnc.net!netnews.upenn.edu!prijat!jaguar.uofs.edu!das11

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!yale.edu!jvnc.net!netnews.upenn.edu!prijat!jaguar.uofs.edu!das11
From: das11@jaguar.uofs.edu
Newsgroups: comp.os.ms-windows.programmer.misc
Subject: Entryfield Border
Message-ID: <1993Jan4.164144.1@jaguar.uofs.edu>
Date: 4 Jan 93 21:41:44 GMT
Sender: news@prijat.cs.uofs.edu
Organization: University of Scranton
Lines: 440
Nntp-Posting-Host: jaguar.uofs.edu