|
#include "StdAfx.h"
#include "extra.h"
#include "resource.h"
BOOL IsDirectory(LPCTSTR Directory)
{
DWORD dwAttr=GetFileAttributes(Directory);
if(dwAttr==INVALID_FILE_ATTRIBUTES)
return 0;
return (dwAttr & FILE_ATTRIBUTE_DIRECTORY);
}
BOOL IsFile(LPCTSTR File)
{
DWORD dwAttr=GetFileAttributes(File);
if(dwAttr==INVALID_FILE_ATTRIBUTES)
return 0;
return (!(dwAttr & FILE_ATTRIBUTE_DIRECTORY));
}
BOOL DoEvents()
{
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
{
if (GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
if(
(msg.message==WM_CLOSE)
)
{
exit(0);
return FALSE;
}
DispatchMessage(&msg);
}
else
{
return TRUE;
}
}
return TRUE;
}
PBITMAPINFO CreateBitmapInfoStruct(HBITMAP hBmp)
{
BITMAP bmp;
PBITMAPINFO pbmi;
WORD cClrBits;
GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp);
cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
if (cClrBits == 1) cClrBits = 1;
else
if(cClrBits <= 4) cClrBits = 4;
else
if (cClrBits <= 8) cClrBits = 8;
else
if (cClrBits <= 16)cClrBits = 16;
else
if (cClrBits <= 24)cClrBits = 24;
else cClrBits = 32;
if (cClrBits != 24) pbmi = (PBITMAPINFO) LocalAlloc(LPTR,sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD) * (2^cClrBits));
else pbmi = (PBITMAPINFO) LocalAlloc(LPTR,sizeof(BITMAPINFOHEADER));
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = bmp.bmWidth;
pbmi->bmiHeader.biHeight = bmp.bmHeight;
pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
if (cClrBits < 24)
pbmi->bmiHeader.biClrUsed = 2^cClrBits;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = (pbmi->bmiHeader.biWidth + 7) /8 * pbmi->bmiHeader.biHeight * cClrBits;
pbmi->bmiHeader.biClrImportant = 0;
return pbmi;
}
void CreateBMPFile(LPTSTR pszFile, PBITMAPINFO pbi,HBITMAP hBMP, HDC hDC)
{
HANDLE hf;
BITMAPFILEHEADER hdr;
PBITMAPINFOHEADER pbih;
LPBYTE lpBits;
DWORD dwTotal;
DWORD cb;
BYTE *hp;
DWORD dwTmp;
pbih = (PBITMAPINFOHEADER) pbi;
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);
GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight,lpBits, pbi, DIB_RGB_COLORS);
hf = CreateFile(pszFile,GENERIC_READ | GENERIC_WRITE,(DWORD) 0, (LPSECURITY_ATTRIBUTES) NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL);
if(hf == INVALID_HANDLE_VALUE)
return;
hdr.bfType = 0x4d42;
hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) +pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD) + pbih->biSizeImage);
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof (RGBQUAD);
WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), (LPDWORD) &dwTmp, (LPOVERLAPPED) NULL);
WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER)+ pbih->biClrUsed * sizeof (RGBQUAD), (LPDWORD) &dwTmp, (LPOVERLAPPED) NULL);
dwTotal = cb = pbih->biSizeImage;
hp = lpBits;
while (cb > sizeof(hp)) {
WriteFile(hf, (LPSTR) hp, (int) sizeof(hp),(LPDWORD) &dwTmp, (LPOVERLAPPED) NULL);
cb-= sizeof(hp);
hp += sizeof(hp);
}
WriteFile(hf, (LPSTR) hp, (int) cb,(LPDWORD) &dwTmp, (LPOVERLAPPED) NULL);
CloseHandle(hf);
GlobalFree((HGLOBAL)lpBits);
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I have been programming for the past 6 years in VBasic, Delphi, C, C++ .
I also have extended knowledge of webdesign (HTML, CSS, JavaScript, VBScript), webprogramming (PHP, ASP, ASP.NET (C#)) and database integration (mySql, MSSQL Server).
And when I`m not programming I`m working out or working on some personal projects .
Last but not least I`m looking for a project-based job in programming or webdesign .