please give a example for using Plgblt(winapi procedure)(10分)

  • 主题发起人 主题发起人 kerry
  • 开始时间 开始时间
K

kerry

Unregistered / Unconfirmed
GUEST, unregistred user!
please give a example for using Plgblt(winapi procedure)

it can rotate , change the shape of a bitmap, who can know how
to use it?
 
我根本就不知道它能干些嘛,好在给你找了一个例子(c语言的),不知能否有所帮助:
MODULE: PAINT.C
PURPOSE: Given an HDC and a pointer to a bounding rectangle
draw all graphics/fonts based on the flags set in
the dwGraphicsOptions global variable.
FUNTIONS: Paint - main painting routine
GetFirstGraphicSlot- computes bounding rect of 1st graphic
GetNextGraphicSlot - computes bounding rect of next graphic
DrawFonts - draws enumerated fonts
BuildFontList - builds a list of fonts of fonts supported by a given DC
MyEnumFaces - enumerates the font facenames supported by a given DC
MyEnumCopy - copies LOGFONT & TEXTMETRIC info to a global variable
MyEnumCount - counts total number of fonts supported by a given DC
FreeFontList - frees a (BuildFontList-) font list #include <windows.h> #include <string.h> #include "common.h" #include "paint.h" #include "resource.h" /******************************************************************************/ * * FUNCTION: Paint * * INPUTS: hdc - device context to paint * lpRect - bounding rectangle of device to paint * * RETURNS: TRUE if painting went ok, or * FALSE if error while painting *
BOOL Paint (HDC hdc, LPRECT lpRect)
{
RECT rect;
HPEN hpenSave;
RECTI ri;
if (gdwGraphicsOptions &amp; DRAWAXIS)
{
rect = *lpRect;
hpenSave = SelectObject (hdc, GetStockObject (BLACK_PEN));
if (giMapMode == MM_TEXT || giMapMode == MM_ANISOTROPIC)
{
MoveToEx (hdc, rect.left - glcyMenu/2, rect.bottom, NULL);
LineTo (hdc, rect.left, rect.bottom + glcyMenu/2);
LineTo (hdc, rect.left + glcyMenu/2, rect.bottom);
MoveToEx (hdc, rect.left, rect.bottom + glcyMenu/2, NULL);
LineTo (hdc, rect.left, rect.top); LineTo (hdc, rect.right + glcyMenu/2, rect.top);
MoveToEx (hdc, rect.right, rect.top - glcyMenu/2, NULL);
LineTo (hdc, rect.right + glcyMenu/2, rect.top);
LineTo (hdc, rect.right, rect.top + glcyMenu/2);
}
else
{
MoveToEx (hdc, rect.left - glcyMenu/2, rect.bottom, NULL);
LineTo (hdc, rect.left, rect.bottom + glcyMenu/2);
LineTo (hdc, rect.left + glcyMenu/2, rect.bottom);
MoveToEx (hdc, rect.left, rect.bottom + glcyMenu/2, NULL);
LineTo (hdc, rect.left, rect.top); LineTo (hdc, rect.right + glcyMenu/2, rect.top);
MoveToEx (hdc, rect.right, rect.top + glcyMenu/2, NULL);
LineTo (hdc, rect.right + glcyMenu/2, rect.top);
LineTo (hdc, rect.right, rect.top - glcyMenu/2);
}
SelectObject (hdc, hpenSave);
}
if (gdwGraphicsOptions &amp; ENUMFONTS)
{
DrawFonts (hdc, lpRect);
return TRUE;
}
giDeltaX = (int) ((lpRect->right - BORDER) / NUM_GRAPHICS_XSLOTS);
giDeltaY = (int) ((lpRect->bottom - lpRect->top - BORDER) / NUM_GRAPHICS_YSLOTS);
GetFirstGraphicSlot (lpRect, &amp;ri); if (gdwGraphicsOptions &amp; ARC)
{
Arc (hdc, ri.left, ri.top, ri.right, ri.bottom, ri.left, ri.top, ri.right-10, ri.bottom-10);
GetNextGraphicSlot (&amp;ri);
}
if (gdwGraphicsOptions &amp; ELLIPSE)
{
Ellipse (hdc, ri.left, ri.top, ri.right, ri.bottom);
GetNextGraphicSlot (&amp;ri);
}
if (gdwGraphicsOptions &amp; LINETO)
{
int i;
for (i = PS_SOLID; i <= PS_DASHDOTDOT; i++)
{
MoveToEx (hdc, ri.left, ri.top + (i+1)*giDeltaY/7, NULL);
LineTo (hdc, ri.right, ri.top + (i+1)*giDeltaY/7);
}
GetNextGraphicSlot (&amp;ri);
}
if (gdwGraphicsOptions &amp; PIE)
{
Pie (hdc, ri.left, ri.top, ri.right, ri.bottom, ri.left, ri.top, ri.right-10, ri.bottom-10);
GetNextGraphicSlot (&amp;ri);
}
if (gdwGraphicsOptions &amp; PLG_BLT)
{
HBITMAP hbm;
BITMAP bm;
HDC hdcMem;
POINT ap[3];
hbm = LoadBitmap (ghInst, "printer");
hdcMem = CreateCompatibleDC (hdc);
SelectObject (hdcMem, hbm);
GetObject (hbm, sizeof(BITMAP), (LPSTR)&amp;bm);
ap[0].x = (LONG) (ri.left + (ri.right - ri.left)/4);
ap[0].y = (LONG) (ri.top + (ri.bottom - ri.top)/4);
ap[1].x = (LONG) ri.right; ap[1].y = (LONG) ri.top;
ap[2].x = (LONG) ri.left;
ap[2].y = (LONG) ri.bottom;

//---------------------------------------------------------
PlgBlt (hdc, ap, hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, NULL, 0, 0);
//----------------------------------------------------------

DeleteDC(hdcMem);
DeleteObject(hbm);
GetNextGraphicSlot (&amp;ri);
}
if (gdwGraphicsOptions &amp; POLYBEZIER)
{
POINT ap[4];
ap[0].x = (LONG) ri.left;
ap[0].y = (LONG) ri.top;
ap[1].x = (LONG) ri.left;
ap[1].y = (LONG) ri.bottom;
ap[2].x = (LONG) ri.right;
ap[2].y = (LONG) ri.top;
ap[3].x = (LONG) ri.right;
ap[3].y = (LONG) ri.bottom;
PolyBezier (hdc, ap, 4);
GetNextGraphicSlot (&amp;ri);
}
if (gdwGraphicsOptions &amp; POLYGON)
{
POINT ap[5];
ap[0].x = (LONG) ri.left;
ap[0].y = (LONG) ri.top;
ap[1].x = (LONG) ri.right;
ap[1].y = (LONG) ri.bottom;
ap[2].x = (LONG) ri.right;
ap[2].y = (LONG) ri.top;
ap[3].x = (LONG) ri.left;
ap[3].y = (LONG) ri.bottom;
ap[4].x = (LONG) ri.left;
ap[4].y = (LONG) ri.top;
Polygon (hdc, ap, 4);
GetNextGraphicSlot (&amp;ri);
}
if (gdwGraphicsOptions &amp; POLYLINE)
{
POINT ap[4];
ap[0].x = (LONG) ri.left;
ap[0].y = (LONG) ri.top;
ap[1].x = (LONG) ri.left;
ap[1].y = (LONG) ri.bottom;
ap[2].x = (LONG) ri.right;
ap[2].y = (LONG) ri.top;
ap[3].x = (LONG) ri.right;
ap[3].y = (LONG) ri.bottom;
Polyline (hdc, ap, 4);
GetNextGraphicSlot (&amp;ri);
}
if (gdwGraphicsOptions &amp; POLYPOLYGON)
{
POINT ap[8];
int ai[2] = { 4, 4 };
ap[0].x = (LONG) ri.left;
ap[0].y = (LONG) ri.top;
ap[1].x = (LONG) (ri.left + giDeltaX/4);
ap[1].y = (LONG) ri.top;
ap[2].x = (LONG) (ri.left + giDeltaX/4);
ap[2].y = (LONG) (ri.top + giDeltaY/4);
ap[3].x = (LONG) ri.left;
ap[3].y = (LONG) (ri.top + giDeltaY/4);
ap[4].x = (LONG) (ri.right - 2*giDeltaX/3);
ap[4].y = (LONG) (ri.bottom - 2*giDeltaY/3);
ap[5].x = (LONG) ri.right;
ap[5].y = (LONG) (ri.bottom - 2*giDeltaY/3);
ap[6].x = (LONG) ri.right;
ap[6].y = (LONG) ri.bottom;
ap[7].x = (LONG) (ri.right - 2*giDeltaX/3);
ap[7].y = (LONG) ri.bottom;
PolyPolygon (hdc, ap, ai, 2);
GetNextGraphicSlot (&amp;ri);
}
if (gdwGraphicsOptions &amp; RECTANGLE)
{
Rectangle (hdc, ri.left, ri.top, ri.right, ri.bottom);
GetNextGraphicSlot (&amp;ri);
}
if (gdwGraphicsOptions &amp; ROUNDRECT)
{
RoundRect (hdc, ri.left, ri.top, ri.right, ri.bottom, 15, 25);
GetNextGraphicSlot (&amp;ri);
}
if (gdwGraphicsOptions &amp; STRETCH_BLT)
{
HBITMAP hbm;
BITMAP bm;
HDC hdcMem;
hbm = LoadBitmap (ghInst, "printer");
hdcMem = CreateCompatibleDC (hdc);
SelectObject (hdcMem, hbm);
GetObject (hbm, sizeof(BITMAP), (LPSTR)&amp;bm);
StretchBlt (hdc, ri.left, ri.top, ri.right-ri.left, ri.bottom - ri.top, hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
DeleteDC(hdcMem);
DeleteObject(hbm);
GetNextGraphicSlot (&amp;ri);
}
return TRUE; } /******************************************************************************/ * * FUNCTION: GetFirstGraphicSlot * * INPUTS: pri - pointer to a RECTI * /******************************************************************************/ void GetFirstGraphicSlot (LPRECT lpRect, PRECTI pri) { pri->left = BORDER; pri->top = lpRect->top + BORDER; pri->right = giDeltaX; pri->bottom = giDeltaY; giColumn = 1; } /******************************************************************************/ * * FUNCTION: GetNextGraphicSlot * * INPUTS: pri - pointer to a RECTI * /******************************************************************************/
void GetNextGraphicSlot (PRECTI pri)
{
if (++giColumn <= NUM_GRAPHICS_XSLOTS)
{
pri->left += giDeltaX;
pri->right += giDeltaX;
}
else
{
giColumn = 1;
pri->left = BORDER;
pri->top += giDeltaY;
pri->right = giDeltaX;
pri->bottom += giDeltaY;
}
} /******************************************************************************/ * * FUNCTION: DrawFonts * * INPUTS: hdc - device context to enumerate from &amp; draw on * pRect - pointer to bounding rect to draw fonts in * * LOCAL VARS: i, j - loop variables * xText - starting x position to draw text * yText - starting y position to draw text * iMaxStrLen - length in pels of string to draw * /******************************************************************************/
void DrawFonts (HDC hdc, LPRECT lpRect)
{
int i, j, xText, yText, iMaxStrLen = 0;
PARFONTS paf;
paf = BuildFontList (hdc);
xText = yText = 2;
if (giMapMode == MM_TEXT | giMapMode == MM_ANISOTROPIC) SetTextAlign (hdc, TA_TOP);
else SetTextAlign (hdc, TA_BOTTOM);
for (i = 0; i < nFaces; i++)
{
for (j = 0; j < (paf + i)->nFonts; j++)
{
HFONT hFont, hSaveFont;
SIZE size;
POINT LogPtExtent;
LogPtExtent.x = lpRect->right;
LogPtExtent.y = lpRect->bottom;
hFont = CreateFontIndirect ((paf + i)->lf + j);
hSaveFont = SelectObject (hdc, hFont);
TextOut (hdc, xText, yText, ((paf + i)->lf + j)->lfFaceName, strlen(((paf + i)->lf + j)->lfFaceName));
GetTextExtentPoint (hdc, ((paf + i)->lf + j)->lfFaceName, strlen(((paf+i)->lf+j)->lfFaceName), &amp;size);
size.cx += 2;
iMaxStrLen = iMaxStrLen > (int)size.cx ? iMaxStrLen: (int) size.cx;
if (!(i == (nFaces - 1) &amp;&amp; j == ((paf + i)->nFonts - 1)))
{
TEXTMETRIC *pNextTM;
pNextTM = j < ((paf+i)->nFonts-1) ? (paf+i)->tm+j+1 : (paf+i+1)->tm;
yText += (int) ((paf + i)->tm + j)->tmHeight;
if (yText + (int) pNextTM->tmHeight > (int) LogPtExtent.y)
{
yText = 2;
xText += iMaxStrLen + 2;
iMaxStrLen = 0;
}
}
SelectObject (hdc, hSaveFont);
DeleteObject (hFont);
if (xText > (int) LogPtExtent.x)
{
if (GetDeviceCaps (hdc, TECHNOLOGY) &amp; DT_RASDISPLAY) {
int k;
int iFontsLeft = (paf + i)->nFonts - j - 1;
char buf[40];
SIZE size;
for (k = i + 1; k < nFaces; k++) iFontsLeft += (paf + k)->nFonts;
wsprintf (buf, GetStringRes(IDS_FMT_MOREDSPFNTNL), iFontsLeft);
GetTextExtentPoint (hdc, buf, strlen(buf), &amp;size);
if ((xText = lpRect->right - size.cx) < glcyMenu + 1) xText = glcyMenu/2 + 1;
TextOut (hdc, xText, lpRect->bottom, buf, strlen(buf)); goto done_enumfonts;
}
else
{
if(!(i == nFaces - 1 &amp;&amp; j == (paf + i)->nFonts - 1))
{
EndPage (hdc);
xText = yText = 2;
StartPage (hdc);
}
}
}
}
}
done_enumfonts: FreeFontList (paf);
}

/******************************************************************************/ * * FUNCTION: BuildFontList * * GLOBAL VARS: (see above) * /******************************************************************************/

PARFONTS BuildFontList (HDC hdcIn)
{
nFaces = 0;
hdcGlobal = hdcIn;
EnumFonts (hdcGlobal, NULL, (FONTENUMPROC)MyEnumCount, (LPARAM)&amp;nFaces);
parFontsGlobal = (PARFONTS) LocalAlloc (LPTR, sizeof(ARFONTS) * (nFaces+1));
iFace = 0;
EnumFonts (hdcGlobal, NULL, (FONTENUMPROC)MyEnumFaces, 0);
return parFontsGlobal;
}
/******************************************************************************/ * * FUNCTION: MyEnumFaces * * GLOBAL VARS: (see above) * /******************************************************************************/
int CALLBACK MyEnumFaces (LPLOGFONT lpLogFont, LPTEXTMETRIC lpTEXTMETRICs, DWORD fFontType, LPVOID lpData)
{
int nFonts;
nFonts = 0;
EnumFonts (hdcGlobal, lpLogFont->lfFaceName, (FONTENUMPROC)MyEnumCount, (LPARAM)&amp;nFonts);
parFontsGlobal[iFace].lf = (LOGFONT *) LocalAlloc (LPTR, sizeof(LOGFONT) nFonts);
parFontsGlobal[iFace].tm = (TEXTMETRIC *) LocalAlloc (LPTR, sizeof(TEXTMETRIC) nFonts);
parFontsGlobal[iFace].Type = (int *)LocalAlloc (LPTR, sizeof(int) * nFonts);
if ((parFontsGlobal[iFace].lf == NULL) || (parFontsGlobal[iFace].tm == NULL) || (parFontsGlobal[iFace].Type == NULL))
{
ErrMsgBox (GetStringRes(IDS_LALLOCFAIL), ERR_MOD_NAME);
return FALSE;
}
parFontsGlobal[iFace].nFonts = nFonts;
jFont = 0;
EnumFonts (hdcGlobal, lpLogFont->lfFaceName, (FONTENUMPROC)MyEnumCopy, 0);
iFace++;
return TRUE;
} /******************************************************************************/ * * FUNCTION: MyEnumCopy * * GLOBAL VARS: (see above) * /******************************************************************************/
int CALLBACK MyEnumCopy (LPLOGFONT lpLogFont, LPTEXTMETRIC lpTEXTMETRICs, DWORD fFontType, LPVOID lpData)
{
LOGFONT *lplf;
TEXTMETRIC *lptm;
int *pType;
lplf = parFontsGlobal[iFace].lf;
lptm = parFontsGlobal[iFace].tm;
pType = parFontsGlobal[iFace].Type;
lplf[jFont] = *lpLogFont;
lptm[jFont] = *lpTEXTMETRICs;
pType[jFont] = fFontType;
jFont++;
return TRUE;
}
/******************************************************************************/ * * FUNCTION: MyEnumCount * * GLOBAL VARS: (see above) * /******************************************************************************/
int CALLBACK MyEnumCount (LPLOGFONT lpLogFont, LPTEXTMETRIC lpTEXTMETRICs,DWORD fFontType, LPVOID lpData)
{
(*(LPINT)lpData)++;
return TRUE;
}
/******************************************************************************/ * * FUNCTION: FreeFontList * * INPUTS: paf - pointer to ARFONTS struct to free * /******************************************************************************/
void FreeFontList (PARFONTS paf)
{
int i;
for (i = 0; i < nFaces; i++)
{
LocalFree (LocalHandle ((LPSTR) ((paf + i)->lf )));
LocalFree (LocalHandle ((LPSTR) ((paf + i)->tm )));
LocalFree (LocalHandle ((LPSTR) ((paf + i)->Type))); }
LocalFree (LocalHandle ((LPSTR) paf));
}

 
接受答案了.
 
后退
顶部