📄 viewerlib.cpp
字号:
SelectObject(ImageDC, Image);
// Get the bitmap ready for display
RECT rc = {0, 0, width, height};
FillRect(ImageDC, &rc, NULL != Colour ? BGBrush() : (HBRUSH)GetStockObject(WHITE_BRUSH));
SelectObject(MaskAndColourDC, Mask);
BitBlt(ImageDC, 0, 0, Mask.Width(), height, MaskAndColourDC, 0, 0, SRCCOPY);
if (NULL == Colour)
{
BitBlt(ImageDC, Mask.Width(), 0, Mask.Width(), height, MaskAndColourDC, 0, height, SRCCOPY);
}
else
{
SelectObject(MaskAndColourDC, Colour);
BitBlt(ImageDC, Mask.Width(), 0, Mask.Width(), Mask.Height(), MaskAndColourDC, 0, 0, SRCCOPY);
}
DrawIconEx(ImageDC, Mask.Width() * 2, 0, TheIcon, 0, 0, 0, 0, DI_NORMAL);
// Call BitmapViewW to send the bitmap to the Image Viewer
return BitmapViewW(Image, File, Line, Function, Text);
}
__declspec(dllexport) LRESULT IconViewA (HICON TheIcon,
LPCSTR File,
UINT Line,
LPCSTR Function,
LPCSTR Text)
{
return IconViewW(TheIcon, CA2W(File), Line, CA2W(Function), CA2W(Text));
}
/////////////////////////////////////////////////////////////////////////////
//
// ImageListView
// This function was written by J鰎gen Sigvardsson <jorgen@profitab.com>
// and provided here on August 30, 2004.
//
// Convert the supplied HIMAGELIST to a HBITMAP with three rows of images.
// The top row will be the images drawn normally, the middle row will be
// the images drawn transparently, and the bottom row will be the images
// drawn with the supplied custom flag.
//
// Parameters :
// hImageList [in] - The HIMAGELIST to send
// iImg [in] - The index of the image in the image list, use -1 to
// draw the entire image list
// nCustomFlags [in] - The custom drawing flag for the bottom row
// File [in] - The complete path to the source file that called this function
// Line [in] - The line number in the source file from where the call was made
// Function [in] - The name of the function from where the call was made
// Text [in] - User defined text
//
// Returns :
// ERROR_SUCCESS if the image list was sent to the viewer, a Win32 error code otherwise
//
// Note :
// There are two versions of this function, ImageListViewA is the ANSI version
// and ImageListViewW is the UNICODE version
//
/////////////////////////////////////////////////////////////////////////////
// Need this for ImageList_* functions
#pragma comment(lib, "comctl32.lib")
__declspec(dllexport) LRESULT ImageListViewW(HIMAGELIST hImageList,
int iImg,
UINT nCustomFlags,
LPCWSTR File,
UINT Line,
LPCWSTR Function,
LPCWSTR Text)
{
// Check that the windows are properly setup
if (!AreWindowsReady())
{
return ERROR_NOT_READY;
}
// Validate the parameters
if (!hImageList)
{
ATLTRACE(_T("ImageViewer.dll : ImageListViewW - A NULL HIMAGELIST was passed in\n"));
return ERROR_INVALID_HANDLE;
}
IMAGEINFO info;
if (!ImageList_GetImageInfo(hImageList, 0, &info))
{
ATLTRACE(_T("ImageViewer.dll : ImageListViewW - ImageList_GetImageInfo returned an error\n"));
return ERROR_FUNCTION_FAILED;
}
int nImageCount = ImageList_GetImageCount(hImageList);
if (iImg != -1 && iImg < 0 && iImg >= nImageCount)
{
ATLTRACE(_T("ImageViewer.dll : ImageListViewW - Recieved an invalid image index\n"));
return ERROR_FUNCTION_FAILED;
}
if (iImg != -1) // If image index is not -1, we're just drawing one image
nImageCount = 1;
int nImageWidth, nImageHeight;
if (!ImageList_GetIconSize(hImageList, &nImageWidth, &nImageHeight))
{
ATLTRACE(_T("ImageViewer.dll : ImageListViewW - ImageList_GetIconSize returned zero\n"));
return ERROR_FUNCTION_FAILED;
}
// Create the bitmap that gets displayed in the Image Viewer application
pja::CBitmap Image(NULL, nImageWidth * nImageCount, nImageHeight * 3);
if (NULL == Image)
{
ATLTRACE(_T("ImageViewer.dll : ImageListViewW - Failed to create bitmap\n"));
return ERROR_FUNCTION_FAILED;
}
// Create the memory device context used to draw onto the bitmap
pja::CCompatibleDC ImageDC(NULL);
if (NULL == ImageDC)
{
ATLTRACE(_T("ImageViewer.dll : ImageListViewW - Failed to create memory dc\n"));
return ERROR_FUNCTION_FAILED;
}
SelectObject(ImageDC, Image);
// Get the bitmap ready for display
RECT rcFill = { 0, 0, nImageCount * nImageWidth, nImageHeight * 3 };
FillRect(ImageDC, &rcFill, BGBrush());
int i = 0;
// first row is ILD_NORMAL
for (i = 0; i < nImageCount; ++i)
ImageList_Draw(hImageList, iImg == -1 ? i : iImg, ImageDC, i * nImageWidth, 0, ILD_NORMAL);
// second row is ILD_TRANSPARENT
for (i = 0; i < nImageCount; ++i)
ImageList_Draw(hImageList, iImg == -1 ? i : iImg, ImageDC, i * nImageWidth, nImageHeight, ILD_TRANSPARENT);
// third row is whatever custom flags say
for (i = 0; i < nImageCount; ++i)
ImageList_Draw(hImageList, iImg == -1 ? i : iImg, ImageDC, i * nImageWidth, 2 * nImageHeight, nCustomFlags);
// Call BitmapViewW to send the bitmap to the Image Viewer
return BitmapViewW(Image, File, Line, Function, Text);
}
__declspec(dllexport) LRESULT ImageListViewA(HIMAGELIST hImageList,
int iImg,
UINT nCustomFlags,
LPCSTR File,
UINT Line,
LPCSTR Function,
LPCSTR Text)
{
return ImageListViewW(hImageList, iImg, nCustomFlags, CA2W(File), Line, CA2W(Function), CA2W(Text));
}
/////////////////////////////////////////////////////////////////////////////
//
// RegionView
// This function was originally written by waldermort <waldermort@hotmail.com>
// and provided here on November 7, 2006.
//
// Draw the supplied HRGN onto the supplied bitmap by inverting the colours
// on the bitmap that correspond with the region. If the supplied bitmap is
// NULL then a default bitmap is generated for the region.
//
// Parameters :
// TheRegion [in] - The region to display
// TheBackground [in] - The bitmap to display the region on
// File [in] - The complete path to the source file that called this function
// Line [in] - The line number in the source file from where the call was made
// Function [in] - The name of the function from where the call was made
// Text [in] - User defined text
//
// Returns :
// ERROR_SUCCESS if the region was sent to the viewer, a Win32 error code otherwise
//
// Note :
// There are two versions of this function, RegionViewA is the ANSI version
// and RegionViewW is the UNICODE version
//
/////////////////////////////////////////////////////////////////////////////
__declspec(dllexport) LRESULT RegionViewW (HRGN TheRegion,
HBITMAP TheBackground,
LPCWSTR File,
UINT Line,
LPCWSTR Function,
LPCWSTR Text)
{
// Check that the windows are properly setup
if (!AreWindowsReady())
{
return ERROR_NOT_READY;
}
// Validate the parameters
if (!TheRegion)
{
ATLTRACE(_T("ImageViewer.dll : RegionViewW - A NULL HRGN handle was passed in\n"));
return ERROR_INVALID_HANDLE;
}
RECT RegionRect = {0};
if (GetRgnBox(TheRegion, &RegionRect) <= NULLREGION)
{
ATLTRACE(_T("ImageViewer.dll : RegionViewW - The Region is empty\n"));
return ERROR_INVALID_DATA;
}
HRGN TempRegion = CreateRectRgn(0, 0, 1, 1);
if (ERROR == CombineRgn(TempRegion, TheRegion, NULL, RGN_COPY))
{
ATLTRACE(_T("ImageViewer.dll : RegionViewW - Failed to copy the supplied region\n"));
return ERROR_FUNCTION_FAILED;
}
RECT ImageRect = RegionRect;
// Create the bitmap that gets displayed in the Image Viewer application
pja::CBitmap Image(TheBackground, true);
if (NULL != Image)
{
RECT Union = {0};
if (UnionRect(&Union, &RegionRect, Image.Rect()) && !EqualRect(&Union, Image.Rect()))
{
pja::CBitmap BiggerBitmap(NULL, Union.right - Union.left, Union.bottom - Union.top);
if (NULL != BiggerBitmap)
{
pja::CCompatibleDC BiggerDC(NULL);
SelectObject(BiggerDC, BiggerBitmap);
FillRect(BiggerDC, BiggerBitmap.Rect(), BGBrush());
pja::CCompatibleDC BitmapDC(NULL);
SelectObject(BitmapDC, Image);
BitBlt(BiggerDC,
-Union.left,
-Union.top,
Image.Width(),
Image.Height(),
BitmapDC,
0, 0,
SRCCOPY);
OffsetRgn(TempRegion, -Union.left, -Union.top);
}
Image = BiggerBitmap;
}
}
if (NULL == Image)
{
OffsetRgn(TempRegion, -ImageRect.left, -ImageRect.top);
OffsetRect(&ImageRect, -ImageRect.left, -ImageRect.top);
Image = pja::CBitmap(NULL, ImageRect.right, ImageRect.bottom);
}
if (NULL == Image)
{
ATLTRACE(_T("ImageViewer.dll : RegionViewW - Failed to create bitmap\n"));
return ERROR_FUNCTION_FAILED;
}
// Create the memory device context used to draw onto the bitmap
pja::CCompatibleDC ImageDC(NULL);
if (NULL == ImageDC)
{
ATLTRACE(_T("ImageViewer.dll : RegionViewW - Failed to create memory dc\n"));
return ERROR_FUNCTION_FAILED;
}
SelectObject(ImageDC, Image);
// Get the bitmap ready for display
if (NULL == TheBackground)
{
FillRect(ImageDC, &ImageRect, BGBrush());
}
InvertRgn(ImageDC, TempRegion);
HBRUSH FrameBrush = CreateSolidBrush(BGBrush());
FrameRgn(ImageDC, TempRegion, FrameBrush, 1, 1);
DeleteObject(FrameBrush);
// Call SendImageToViewer to send the bitmap to the Image Viewer
return SendImageToViewer(Image, File, Line, Function, Text, &RegionRect);
}
__declspec(dllexport) LRESULT RegionViewA (HRGN TheRegion,
HBITMAP TheBackground,
LPCSTR File,
UINT Line,
LPCSTR Function,
LPCSTR Text)
{
return RegionViewW(TheRegion, TheBackground, CA2W(File), Line, CA2W(Function), CA2W(Text));
}
/////////////////////////////////////////////////////////////////////////////
//
// FontView
// Draw the supplied font
//
// Parameters :
// TheFont [in] - The font to send
// Sample [in] - The sample text to be used to display the font
// File [in] - The complete path to the source file that called this function
// Line [in] - The line number in the source file from where the call was made
// Function [in] - The name of the function from where the call was made
// Text [in] - User defined text
//
// Returns :
// ERROR_SUCCESS if the font was sent to the viewer, a Win32 error code otherwise
//
// Note :
// There are two versions of this function, FontViewA is the ANSI version
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -