[comp.windows.ms] Help with SDK Anisotropic Mapping Mode

dsampson@x102a.harris-atd.com (sampson david 58163) (06/29/90)

I'm having difficulty using the Anisotropic mapping mode in the
Windows SDK.  To learn how to use this mode, I'm trying to map a
logical coordinate system that has an X, Y axis extent from zero to
10, to the viewport.  The viewport extent is based on detecting the
client window coordinates.

I then shift the viewport origin from the upper left hand corner of
the window to the lower left corner so that the mappings to the window
from logical coordinates will look like the 1st quadrant of a
cartesian coordinate system.  Then I want to draw a rectangle with a
black pen and fill it with a gray brush.

I've been able to use that default mapping mode (MM_TEXT) with no
trouble.  But when I use the code below, I don't see anything on the
display.  I've played around with the extents and plotting points, but
had no luck.  I'm wondering if I've set the viewport up so that I'm
not really accomplishing what I want (i.e. I'm not looking at what I'm
drawing, or I'm not filling the viewport/client area with the 1st
quadrant of the logical coordinate system).

I've taken some of this out of the Charles Petzold book.  Here's the
paint case from the window's switch (iMessage) statement.  Note that I
have declared all the pen and brush types and the RECT structure.
This code compiles and executes, but doesn't show anything on the
display other than an "empty" client area.


case WM_PAINT:

	/* this gets a handle to the device context, creates the black
	   pen and gray brush, selects them and saves the previous 
 	   pen and brush to the hOldxxxx handles.  I restore them at
	   the end of the paint routine.  */

	hDC = BeginPaint (hWnd, &ps);
	hSolidPen = CreatePen (PS_SOLID, 1, RGB (0, 0, 0) );
	hGrayBrush = GetStockObject (GRAY_BRUSH);
	hOldPen = SelectObject (hDC, hSolidPen);
	hOldBrush = SelectObject (hDC, hGrayBrush);


	/*  I set the map mode to AnIsotropic, get the coordinates 
	    to the client window and store them in the rect struct of
	    type RECT (note GetClientRect returns PHYSICAL coordinates
	    so you can use them directly in the viewport routines without
 	    calling the translation routines for physical and logical 
	    coordinates).  Using the coordinates of the client window,
	    I set the viewport extent to be the entire client area. 
	    Then I shift the viewport origin from the upper left corner
	    of the client window to the lower left corner.  Then I set
	    the x & y axis extents for the logical coordinate system
	    so that I draw using an axis of 0 to 10.  */

	SetMapMode (hDC, MM_ANISOTROPIC);
	GetClientRect (hDC, &rect);
	SetViewportExt (hDC, rect.right, -rect.bottom);
	SetViewportOrg (hDC, 0, rect.bottom);
	SetWindowExt (hDC, 10, 10);

	/* Now draw the rectangle using the logical coordinates */
	Rectangle (hDC, 1, 1, 8, 8);

	/* restore the old pen and brush */
	SelectObject (hDC, hOldPen);
	SelectObject (hDC, hOldBrush);
	
	/* release device context */
	EndPaint (hDC, &ps);
	break;

Thanks in advance





--
-------------------------------------------------------------------------------

David Sampson                                         Harris Corporation
dsampson@x102a.ess.harris.com                   Gov't Aerospace Systems Divison
uunet!x102a!dsampson                                  Melbourne, Florida

-------------------------------------------------------------------------------