#define STRICT // enable strict type checking
#include "stdafx.h"
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <io.h>
#include <direct.h>
#include <stdlib.h>
#include <assert.h>
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include "dibapi.h" HDIB CreateDIB(DWORD dwWidth, DWORD dwHeight, WORD wBitCount)
{
BITMAPINFOHEADER bi; // bitmap header
LPBITMAPINFOHEADER lpbi; // pointer to BITMAPINFOHEADER
DWORD dwLen; // size of memory block
HDIB hDIB;
DWORD dwBytesPerLine; // Number of bytes per scanline
// Make sure bits per pixel is valid
if (wBitCount <= 1)
wBitCount = 1;
else if (wBitCount <= 4)
wBitCount = 4;
else if (wBitCount <= 8)
wBitCount = 8;
else if (wBitCount <= 24)
wBitCount = 24;
else
wBitCount = 4; // set default value to 4 if parameter is bogus
// initialize BITMAPINFOHEADER
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = dwWidth; // fill in width from parameter
bi.biHeight = dwHeight; // fill in height from parameter
bi.biPlanes = 1; // must be 1
bi.biBitCount = wBitCount; // from parameter
bi.biCompression = BI_RGB;
bi.biSizeImage = 0; // 0's here mean "default"
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
// calculate size of memory block required to store the DIB. This
// block should be big enough to hold the BITMAPINFOHEADER, the color
// table, and the bits
dwBytesPerLine = WIDTHBYTES(wBitCount * dwWidth);
dwLen = bi.biSize + PaletteSize((LPBYTE)&bi) + (dwBytesPerLine * dwHeight);
// alloc memory block to store our bitmap
hDIB = GlobalAlloc(GHND, dwLen);
// major bummer if we couldn't get memory block
if (!hDIB)
return NULL;
// lock memory and get pointer to it
lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
// use our bitmap info structure to fill in first part of
// our DIB with the BITMAPINFOHEADER
*lpbi = bi;
// Since we don't know what the colortable and bits should contain,
// just leave these blank. Unlock the DIB and return the HDIB.
GlobalUnlock(hDIB);
//return handle to the DIB
return hDIB;
}
/*************************************************************************
*
* CreateDefaultDIB()
*
* Parameters:
*
* DWORD dwWidth - Width for new bitmap, in pixels
* DWORD dwHeight - Height for new bitmap
*
* Return Value:
*
* HDIB - Handle to new DIB
*
* Description:
*
* This function allocates memory for and initializes a new DIB by
* filling in the BITMAPINFOHEADER, allocating memory for the color
* table, and allocating memory for the bitmap bits. As with all
* HDIBs, the header, colortable and bits are all in one contiguous
* memory block. This function is similar to the CreateBitmap()
* Windows API.
*
* The colortable is initialized with system palette, but bitmap bits
* are left uninitialized (zeroed) in the returned HDIB.
*
*
************************************************************************/
HDIB CreateDefaultDIB(DWORD dwWidth, DWORD dwHeight)
{
// Get DC
HDC hDC = GetDC(NULL);
if (!hDC)
return NULL; // DC bts/pixel
int nDeviceBitsPixel = GetDeviceCaps(hDC, BITSPIXEL); // create DIB according to DC
HDIB hDIB = CreateDIB(dwWidth, dwHeight, nDeviceBitsPixel); // DIB buffer
LPBITMAPINFO lpbmi = (LPBITMAPINFO)GlobalLock(hDIB);
LPBYTE lpDIBBits = FindDIBBits((LPBYTE)lpbmi);
DWORD dwBitsSize = lpbmi->bmiHeader.biHeight * BytesPerLine((LPBYTE)&(lpbmi->bmiHeader)); // set DIB color to White
for (DWORD l=0; l<dwBitsSize; ++l)
lpDIBBits[l] = 0xff; // if no palette, return DIB handle
if (nDeviceBitsPixel > 8)
{
GlobalUnlock(hDIB);
ReleaseDC(NULL, hDC);
return hDIB;
} // if there is palette, set system palette to DIB // colors in system palette
int nColors = PalEntriesOnDevice(hDC); // Number of palette entries
// Copy the current system palette into our logical palette
PALETTEENTRY pe[256];
GetSystemPaletteEntries(hDC, 0, nColors, pe); // set color table
for (int i=0; i<nColors; ++i)
{
lpbmi->bmiColors[i].rgbRed = pe[i].peRed;
lpbmi->bmiColors[i].rgbGreen = pe[i].peGreen;
lpbmi->bmiColors[i].rgbBlue = pe[i].peBlue;
lpbmi->bmiColors[i].rgbReserved = 0;
} // clean up
GlobalUnlock(hDIB);
ReleaseDC(NULL, hDC); return hDIB;
}
}这是一个窗宽窗位调整的CPP代码,为什么我运行的时候,出现了如下错误:
1>d:\窗宽窗位的调整\dibapi.cpp(3467) : error C2065: 'i' : undeclared identifier
>d:\窗宽窗位的调整\dibapi.cpp(3469) : error C2228: left of '.peRed' must have class/struct/union
1>d:\窗宽窗位的调整\dibapi.cpp(3470) : error C2228: left of '.peGreen' must have lass/struct/union
1>d:\窗宽窗位的调整\dibapi.cpp(3471) : error C2228: left of '.peBlue' must have class/struct/union
应该如何解决呢?跪求高手指点!谢谢各位了!
#include "stdafx.h"
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <io.h>
#include <direct.h>
#include <stdlib.h>
#include <assert.h>
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include "dibapi.h" HDIB CreateDIB(DWORD dwWidth, DWORD dwHeight, WORD wBitCount)
{
BITMAPINFOHEADER bi; // bitmap header
LPBITMAPINFOHEADER lpbi; // pointer to BITMAPINFOHEADER
DWORD dwLen; // size of memory block
HDIB hDIB;
DWORD dwBytesPerLine; // Number of bytes per scanline
// Make sure bits per pixel is valid
if (wBitCount <= 1)
wBitCount = 1;
else if (wBitCount <= 4)
wBitCount = 4;
else if (wBitCount <= 8)
wBitCount = 8;
else if (wBitCount <= 24)
wBitCount = 24;
else
wBitCount = 4; // set default value to 4 if parameter is bogus
// initialize BITMAPINFOHEADER
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = dwWidth; // fill in width from parameter
bi.biHeight = dwHeight; // fill in height from parameter
bi.biPlanes = 1; // must be 1
bi.biBitCount = wBitCount; // from parameter
bi.biCompression = BI_RGB;
bi.biSizeImage = 0; // 0's here mean "default"
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
// calculate size of memory block required to store the DIB. This
// block should be big enough to hold the BITMAPINFOHEADER, the color
// table, and the bits
dwBytesPerLine = WIDTHBYTES(wBitCount * dwWidth);
dwLen = bi.biSize + PaletteSize((LPBYTE)&bi) + (dwBytesPerLine * dwHeight);
// alloc memory block to store our bitmap
hDIB = GlobalAlloc(GHND, dwLen);
// major bummer if we couldn't get memory block
if (!hDIB)
return NULL;
// lock memory and get pointer to it
lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
// use our bitmap info structure to fill in first part of
// our DIB with the BITMAPINFOHEADER
*lpbi = bi;
// Since we don't know what the colortable and bits should contain,
// just leave these blank. Unlock the DIB and return the HDIB.
GlobalUnlock(hDIB);
//return handle to the DIB
return hDIB;
}
/*************************************************************************
*
* CreateDefaultDIB()
*
* Parameters:
*
* DWORD dwWidth - Width for new bitmap, in pixels
* DWORD dwHeight - Height for new bitmap
*
* Return Value:
*
* HDIB - Handle to new DIB
*
* Description:
*
* This function allocates memory for and initializes a new DIB by
* filling in the BITMAPINFOHEADER, allocating memory for the color
* table, and allocating memory for the bitmap bits. As with all
* HDIBs, the header, colortable and bits are all in one contiguous
* memory block. This function is similar to the CreateBitmap()
* Windows API.
*
* The colortable is initialized with system palette, but bitmap bits
* are left uninitialized (zeroed) in the returned HDIB.
*
*
************************************************************************/
HDIB CreateDefaultDIB(DWORD dwWidth, DWORD dwHeight)
{
// Get DC
HDC hDC = GetDC(NULL);
if (!hDC)
return NULL; // DC bts/pixel
int nDeviceBitsPixel = GetDeviceCaps(hDC, BITSPIXEL); // create DIB according to DC
HDIB hDIB = CreateDIB(dwWidth, dwHeight, nDeviceBitsPixel); // DIB buffer
LPBITMAPINFO lpbmi = (LPBITMAPINFO)GlobalLock(hDIB);
LPBYTE lpDIBBits = FindDIBBits((LPBYTE)lpbmi);
DWORD dwBitsSize = lpbmi->bmiHeader.biHeight * BytesPerLine((LPBYTE)&(lpbmi->bmiHeader)); // set DIB color to White
for (DWORD l=0; l<dwBitsSize; ++l)
lpDIBBits[l] = 0xff; // if no palette, return DIB handle
if (nDeviceBitsPixel > 8)
{
GlobalUnlock(hDIB);
ReleaseDC(NULL, hDC);
return hDIB;
} // if there is palette, set system palette to DIB // colors in system palette
int nColors = PalEntriesOnDevice(hDC); // Number of palette entries
// Copy the current system palette into our logical palette
PALETTEENTRY pe[256];
GetSystemPaletteEntries(hDC, 0, nColors, pe); // set color table
for (int i=0; i<nColors; ++i)
{
lpbmi->bmiColors[i].rgbRed = pe[i].peRed;
lpbmi->bmiColors[i].rgbGreen = pe[i].peGreen;
lpbmi->bmiColors[i].rgbBlue = pe[i].peBlue;
lpbmi->bmiColors[i].rgbReserved = 0;
} // clean up
GlobalUnlock(hDIB);
ReleaseDC(NULL, hDC); return hDIB;
}
}这是一个窗宽窗位调整的CPP代码,为什么我运行的时候,出现了如下错误:
1>d:\窗宽窗位的调整\dibapi.cpp(3467) : error C2065: 'i' : undeclared identifier
>d:\窗宽窗位的调整\dibapi.cpp(3469) : error C2228: left of '.peRed' must have class/struct/union
1>d:\窗宽窗位的调整\dibapi.cpp(3470) : error C2228: left of '.peGreen' must have lass/struct/union
1>d:\窗宽窗位的调整\dibapi.cpp(3471) : error C2228: left of '.peBlue' must have class/struct/union
应该如何解决呢?跪求高手指点!谢谢各位了!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货