🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.os2.programmer
Article #1486

Re: OWNERDRAW hItem/Changing control window's output

#1486
From: Col. Ames and Pixel
Date: Mon, 03 Sep 1990 07:27
275 lines
6827 bytes
In article <33603.26e0f210@vaxb.acs.unt.edu> ie15@vaxb.acs.unt.edu writes:
>
>Hey Adam,          
>   List boxes do have settable fonts. So do most all PM controls now in 1.2
>Using WinSetPresParams() you can tell a control to set his colors as well
>as his font.
>
>for example
>
>HWND   hControl;
>ULONG  color;
>CHAR   font[20];
>
>   hControl =WinWindowFromID( hwnd, LB_ITEMS);
>   /* Assuming a window with a listbox with an ID of LB_ITEMS */
>   strcpy( font, "12.Courier");
>   WinSetPresParams( hC, PP_FONTNAMESIZE, sizeof( font), font);
>
>   This is a cheap way to get the columns of a listbox to line up, but hey.

    Yeah.... But I wouldn't wish Courier on my worst enemy :-) :-)

  Here is some of the code I used to do the ownerdraw.
Enjoy....

----------------- Begin Code -----------------

MRESULT EXPENTRY AboutDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
     {
    // Lots of variable I probably dont need...
    // Where is my LINT???


       int sort;
       int currentslots;
       int i;

       SHORT	   sIndex;
       SHORT	   sFontHeight;
       SHORT	   sFontWidth;
       MRESULT	   mresFound;
       USHORT	   usFound;
       POINTL	   ptlTextStart;
       POINTL	   ptlTextOrig;
       USHORT	   idLB;
       POWNERITEM  poiLB;
       HPS	   hpsLB;


       static CHAR szBuffer[41];
       static CHAR szRBuffer[41];

       static CHAR szNumBuffer[3];

       static CHAR szNameBuffer[16];
       static CHAR szAMBuffer[9];
       static CHAR szGroupBuffer[4];
       static CHAR szSlotsBuffer[3];

       static CHAR szName[16];
       static CHAR szTemp[41];
       static CHAR szIt[] ="Hello";
       FONTMETRICS fm;

       pointer	   pptr;





     switch (msg)
	  {
	  case WM_DRAWITEM:
	     {

	       idLB   = (USHORT) SHORT1FROMMP(mp1);
	       poiLB  = (POWNERITEM) PVOIDFROMMP(mp2);



	       if (poiLB->fsState == poiLB->fsStateOld)

		/* Draw into the list box */

		  {

                    // Must clear a rectangle the HPS you get is for the 
                   // Whole LB

		    WinFillRect(poiLB->hps, &(poiLB->rclItem), CLR_BACKGROUND);


		    DrawProfItem (hwnd, poiLB, idLB);


		    return 1;
		  }
	       else if ( (poiLB->fsState == TRUE)
                      && (poiLB->fsStateOld == FALSE) )

		      /* Hilite Item */

		      {

			WinFillRect(poiLB->hps, &(poiLB->rclItem), CLR_BLACK);
			GpiSetColor(poiLB->hps, CLR_YELLOW);


			DrawProfItem (hwnd, poiLB, idLB);


			poiLB->fsState	  = FALSE;
			poiLB->fsStateOld = FALSE;

			return 1;
		      }

	       else if ( (poiLB->fsState == FALSE)
    		    && (poiLB->fsStateOld == TRUE) )

		     {

			/* UNHILITE */

			WinFillRect(poiLB->hps, &(poiLB->rclItem), 
				    CLR_BACKGROUND);

			DrawProfItem (hwnd, poiLB, idLB);



			poiLB->fsState	  = FALSE;
			poiLB->fsStateOld = FALSE;

			return 1;
		      }
	     }

	  case WM_INITDLG:

	    hpsLB = WinGetPS(hwnd);
	    EzfQueryFonts(hpsLB);


	    EzfCreateLogFont(hpsLB,DIALOG_FONT, FONTFACE_SYSTEM,
				     FONTSIZE_12, 0);

	    GpiSetCharSet(hpsLB, DIALOG_FONT);
	    GpiQueryFontMetrics(hpsLB, sizeof(FONTMETRICS), &fm);

	    sFontHeight = (SHORT)fm.lMaxBaselineExt;

	    // YOU MUST SET THIS or the system will try to 
           //  render into a randomly tall space

	    WinSendDlgItemMsg (hwnd,IDD_GENERAL, LM_SETITEMHEIGHT,
				MPFROMSHORT (sFontHeight),
				0L);
	    WinSendDlgItemMsg (hwnd,IDD_PROFCHOOSE, LM_SETITEMHEIGHT,
				MPFROMSHORT (sFontHeight),
				0L);

	    GpiSetCharSet(hpsLB, LCID_DEFAULT);
	    GpiDeleteSetId(hpsLB, DIALOG_FONT);
	    WinReleasePS(hpsLB);
			.
			.
            (Random message handling code)
			.
			.


MRESULT EXPENTRY DrawProfItem(HWND hwnd, POWNERITEM poiLB, USHORT idLB)

{



SHORT	    sIndex;
SHORT	    sFontWidth;
POINTL	    ptlTextStart;
POINTL	    ptlTextOrig;

HPS		hpsLB;


static CHAR szBuffer	 [41];
static CHAR szRBuffer	 [41];
static CHAR szNumBuffer  [3];

static CHAR szNameBuffer [16];
static CHAR szAMBuffer	 [9];
static CHAR szGroupBuffer[4];
static CHAR szSlotsBuffer[3];

static CHAR szName	 [16];
static CHAR szTemp	 [41];

FONTMETRICS fm;




    hpsLB = poiLB->hps;

// Massage the rectangle in OWNERITEM

    ptlTextStart.x = poiLB->rclItem.xLeft;
    ptlTextStart.y = poiLB->rclItem.yBottom + 4	;

    ptlTextOrig.x = ptlTextStart.x ;
    ptlTextOrig.y = ptlTextStart.y ;

// Do the FONT SHUFFLE

    EzfQueryFonts(hpsLB);

    EzfCreateLogFont(hpsLB,DIALOG_FONT, FONTFACE_SYSTEM,
				     FONTSIZE_12, 0);


    GpiSetCharSet(hpsLB, DIALOG_FONT);

    GpiQueryFontMetrics(hpsLB, sizeof(FONTMETRICS), &fm);

// Use 'M' width for a quantum of width

    sFontWidth	= (SHORT)fm.lEmInc;

// Send the LB LM_QUERY... to get the test you sent it in the WM_INITDLG
// Use the idItem in the OWNERITEM

    WinSendDlgItemMsg(hwnd, idLB,
		      LM_QUERYITEMTEXT,
		      MPFROM2SHORT(poiLB->idItem, sizeof (szRBuffer)),
		      MPFROMP (szRBuffer));

    sscanf (szRBuffer, "%s %s %s %s", szNameBuffer,  szAMBuffer,
	    szGroupBuffer, szSlotsBuffer);

// Put pieces of text where I want it

    GpiCharStringAt (hpsLB, &ptlTextStart,
		    (LONG)strlen (szNameBuffer),
		    (PSZ)szNameBuffer);

    ptlTextStart.x = ptlTextOrig.x + ( sFontWidth * 11);

    GpiCharStringAt (hpsLB,&ptlTextStart,
		    (LONG)strlen (szAMBuffer),
		    (PSZ)szAMBuffer);

    ptlTextStart.x = ptlTextOrig.x + ( sFontWidth * 15)+11;

                    ..... do this alot more


// Clean up the font and return it to System Default

    GpiSetCharSet(hpsLB, LCID_DEFAULT);
    GpiDeleteSetId(hpsLB, DIALOG_FONT);



}
_______________________ (end code) _________________
      
    And that is how I put text whereever I wanted to in a ListBox. Hope someone
gains some use from it out there.
 
-- 
 adam hill                                   Everybody lies about sex.     
 hill@evax.arl.utexas.edu    BOING!4Ever     Rub HER feet!
                                             It's better to copulate than never
 AmigaDos2.0 - A VW with $10,000 in options.         --Robert A. Heinlein
Technical Details
Message-ID: <1990Sep3.072715.9477@evax.arl.utexas.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!evax!hill
References: <33584.26dfbad5@vaxb.acs.unt.edu> <1990Sep1.201044.9743@evax.arl.utexas.edu> <33603.26e0f210@vaxb.acs.unt.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!evax!hill
From: hill@evax.arl.utexas.edu (Col. Ames and Pixel)
Newsgroups: comp.os.os2.programmer
Subject: Re: OWNERDRAW hItem/Changing control window's output
Message-ID: <1990Sep3.072715.9477@evax.arl.utexas.edu>
Date: 3 Sep 90 07:27:15 GMT
References: <33584.26dfbad5@vaxb.acs.unt.edu> <1990Sep1.201044.9743@evax.arl.utexas.edu> <33603.26e0f210@vaxb.acs.unt.edu>
Organization: Computer Science Engineering Univ. of Texas at Arlington
Lines: 275