⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageviewer.h

📁 图像显示软件源码
💻 H
📖 第 1 页 / 共 2 页
字号:
#       define ShowBitmap2(Bitmap, Text) BitmapView((Bitmap), _T(__FILE__), __LINE__, FUNC, (Text))

#       define ShowDC(DC)        BitmapView((HBITMAP)GetCurrentObject((DC), OBJ_BITMAP), _T(__FILE__), __LINE__, FUNC, NULL)
#       define ShowDC2(DC, Text) BitmapView((HBITMAP)GetCurrentObject((DC), OBJ_BITMAP), _T(__FILE__), __LINE__, FUNC, (Text))

#       define ShowIcon(Icon)        IconView ((Icon), _T(__FILE__), __LINE__, FUNC, NULL)
#       define ShowIcon2(Icon, Text) IconView ((Icon), _T(__FILE__), __LINE__, FUNC, (Text))

#       define ShowCursor(Cursor)        IconView ((Cursor), _T(__FILE__), __LINE__, FUNC, NULL)
#       define ShowCursor2(Cursor, Text) IconView ((Cursor), _T(__FILE__), __LINE__, FUNC, (Text))

#       define ShowFont(Font)                FontView ((Font), NULL, _T(__FILE__), __LINE__, FUNC, NULL)
#       define ShowFont2(Font, Text)         FontView ((Font), NULL, _T(__FILE__), __LINE__, FUNC, Text)
#       define ShowFont3(Sample, Font, Text) FontView ((Font), Sample, _T(__FILE__), __LINE__, FUNC, Text)

#       define ShowRegion(Region)                RegionView((Region), NULL, _T(__FILE__), __LINE__, FUNC, NULL)
#       define ShowRegion2(Region, Text)         RegionView((Region), NULL, _T(__FILE__), __LINE__, FUNC, (Text))
#       define ShowRegion3(Region, Bitmap, Text) RegionView((Region), (Bitmap), _T(__FILE__), __LINE__, FUNC, (Text))
#       define ShowRegion4(Region, DC, Text)     RegionView((Region), (HBITMAP)GetCurrentObject((DC), OBJ_BITMAP), _T(__FILE__), __LINE__, FUNC, (Text))

#       ifdef _INC_COMMCTRL   // defined in CommCtrl.h; header needed for HIMAGELIST
#           define ShowImageList(List, Index, Flags)        ImageListView((List), (Index), (Flags), _T(__FILE__), __LINE__, FUNC, NULL)
#           define ShowImageList2(List, Index, Flags, Text) ImageListView((List), (Index), (Flags), _T(__FILE__), __LINE__, FUNC, (Text))
#       else // _INC_COMMCTRL
#           define ShowImageList(List, Index, Flags)
#           define ShowImageList2(List, Index, Flags, Text)
#       endif // _INC_COMMCTRL

#       ifdef _GDIPLUS_H   // defined in GdiPlus.h, header needed for the Gdiplus namespace

            // Use an inline static class member function to avoid LNK2005 errors.
            // This is placed here and not in the dll so users of the dll do not
            // have to have GDI+ installed on their machines.
            //
            // This code assumes that the calling code has properly initialized
            // the GDI+ library by calling GdiplusStartup()

            namespace pja_ImageViewer
            {
                class GDIPlus
                {
                public:
                    static LRESULT ImageView (Gdiplus::Image &Image, LPCTSTR File, UINT Line, LPCTSTR Function, LPCTSTR Text)
                    {
                        LRESULT ret = ERROR_INVALID_PARAMETER;

                        UINT Width = Image.GetWidth();
                        UINT Height = Image.GetHeight();

                        HDC DC = CreateCompatibleDC(NULL);
                        HBITMAP hBitmap = GetBGBitmap(Width, Height);
                        HGDIOBJ hGDIObj = SelectObject(DC, hBitmap);
                        {
                            // seperate scope for Graphics object
                            Gdiplus::Graphics Graphics(DC);
                            if (Gdiplus::Ok == Graphics.DrawImage(&Image, 0, 0, Width, Height))
                            {
                                ret = BitmapView(hBitmap, File, Line, Function, Text);
                            }
                        }
                        SelectObject(DC, hGDIObj);
                        DeleteObject(hBitmap);
                        DeleteDC(DC);

                        return ret;
                    }
                }; // class GDIPlus
            } // namespace pja_ImageViewer

#           define ShowGDIPlusBitmap(Image)        pja_ImageViewer::GDIPlus::ImageView((Image), _T(__FILE__), __LINE__, FUNC, NULL)
#           define ShowGDIPlusBitmap2(Image, Text) pja_ImageViewer::GDIPlus::ImageView((Image), _T(__FILE__), __LINE__, FUNC, (Text))
#       else
#           define ShowGDIPlusBitmap(Image)
#           define ShowGDIPlusBitmap2(Image, Text)
#       endif // _GDIPLUS_H


        // The following pja_ImageViewer namespace and it's contained classes and
        // functions are used as helpers for the ShowGraphic macro.
        // The ShowGraphic macro is only available in VC 7.0 and above.

#       if _MSC_VER >= 1300

#           include <stdio.h>
#           include <stdarg.h>

            namespace pja_ImageViewer
            {
                class CFormatText
                {
                private:
                    LPTSTR Text;

                public:
                    CFormatText(LPCTSTR Format, va_list ArgList)
                        : Text(NULL)
                    {
                        if (NULL != Format)
                        {
                            int BufferSize = _vsctprintf(Format, ArgList) + 1;
                            Text = new TCHAR[BufferSize];
#                           if _MSC_VER >= 1400
                                _vstprintf_s(Text, BufferSize, Format, ArgList);
#                           else
                                _vstprintf(Text, Format, ArgList);
#                           endif
                        }
                    }

                    ~CFormatText()
                    {
                        delete[] Text;
                    }

                    operator LPCTSTR()
                    {
                        return Text;
                    }
                }; // class CFormatText

                class CShowGraphic
                {
                private:
                    LPCTSTR m_File;
                    UINT    m_Line;
                    LPCTSTR m_Function;

                public:
                    CShowGraphic(LPCTSTR File, UINT Line, LPCTSTR Function)
                    : m_File(File), m_Line(Line), m_Function(Function)
                    {
                    }

                    LRESULT operator()(HBITMAP hBitmap, LPCTSTR Format = NULL, ...)
                    {
                        va_list ArgList;
                        va_start(ArgList, Format);
                        return BitmapView(hBitmap, m_File, m_Line, m_Function, CFormatText(Format, ArgList));
                    }

                    LRESULT operator()(HDC hDC, LPCTSTR Format = NULL, ...)
                    {
                        va_list ArgList;
                        va_start(ArgList, Format);
                        return BitmapView(reinterpret_cast<HBITMAP>(GetCurrentObject(hDC, OBJ_BITMAP)), m_File, m_Line, m_Function, CFormatText(Format, ArgList));
                    }

                    // HICON and HCURSOR are polymorphic so this function serves both (see windef.h)
                    LRESULT operator()(HICON hIcon, LPCTSTR Format = NULL, ...)
                    {
                        va_list ArgList;
                        va_start(ArgList, Format);
                        return IconView(hIcon, m_File, m_Line, m_Function, CFormatText(Format, ArgList));
                    }

                    LRESULT operator()(HFONT hFont, LPCTSTR Format = NULL, ...)
                    {
                        va_list ArgList;
                        va_start(ArgList, Format);
                        return FontView(hFont, NULL, m_File, m_Line, m_Function, CFormatText(Format, ArgList));
                    }

                    // Place the sample text first in the parameter list to avoid ambiguity errors
                    LRESULT operator()(LPCTSTR Sample, HFONT hFont, LPCTSTR Format = NULL, ...)
                    {
                        va_list ArgList;
                        va_start(ArgList, Format);
                        return FontView(hFont, Sample, m_File, m_Line, m_Function, CFormatText(Format, ArgList));
                    }

                    LRESULT operator()(HRGN hRgn, LPCTSTR Format = NULL, ...)
                    {
                        va_list ArgList;
                        va_start(ArgList, Format);
                        return RegionView(hRgn, NULL, m_File, m_Line, m_Function, CFormatText(Format, ArgList));
                    }

                    LRESULT operator()(HRGN hRgn, HBITMAP hBitmap, LPCTSTR Format = NULL, ...)
                    {
                        va_list ArgList;
                        va_start(ArgList, Format);
                        return RegionView(hRgn, hBitmap, m_File, m_Line, m_Function, CFormatText(Format, ArgList));
                    }

                    LRESULT operator()(HRGN hRgn, HDC hDC, LPCTSTR Format = NULL, ...)
                    {
                        va_list ArgList;
                        va_start(ArgList, Format);
                        return RegionView(hRgn, reinterpret_cast<HBITMAP>(GetCurrentObject(hDC, OBJ_BITMAP)), m_File, m_Line, m_Function, CFormatText(Format, ArgList));
                    }

#                   ifdef _INC_COMMCTRL // defined in CommCtrl.h; header needed for HIMAGELIST
                        LRESULT operator()(HIMAGELIST hImageList, int iImg, UINT nCustomFlags, LPCTSTR Format = NULL, ...)
                        {
                            va_list ArgList;
                            va_start(ArgList, Format);
                            return ImageListView(hImageList, iImg, nCustomFlags, m_File, m_Line, m_Function, CFormatText(Format, ArgList));
                        }
#                   endif // _INC_COMMCTRL

#                   ifdef _GDIPLUS_H // defined in GdiPlus.h, header needed for the Gdiplus namespace
                        LRESULT operator()(Gdiplus::Image &Image, LPCTSTR Format = NULL, ...)
                        {
                            va_list ArgList;
                            va_start(ArgList, Format);
                            return GDIPlus::ImageView(Image, m_File, m_Line, m_Function, CFormatText(Format, ArgList));
                        }
#                   endif // _GDIPLUS_H                     
                }; // class CShowGraphic
            } // namespace pja_ImageViewer

#           define ShowGraphic pja_ImageViewer::CShowGraphic(_T(__FILE__), __LINE__, _T(__FUNCTION__))
#       endif // _MSC_VER >= 1300

#   else // VIEWER_ACTIVE
#       define ShowBitmap(Bitmap)                       (LRESULT)(0)
#       define ShowDC(DC)                               (LRESULT)(0)
#       define ShowIcon(Icon)                           (LRESULT)(0)
#       define ShowCursor(Cursor)                       (LRESULT)(0)
#       define ShowFont(Font)                           (LRESULT)(0)
#       define ShowImageList(List, Index, Flags)        (LRESULT)(0)
#       define ShowRegion(Region)                       (LRESULT)(0)
#       define ShowGDIPlusBitmap(Image)                 (LRESULT)(0)

#       define ShowBitmap2(Bitmap, Text)                (LRESULT)(0)
#       define ShowDC2(DC, Text)                        (LRESULT)(0)
#       define ShowIcon2(Icon, Text)                    (LRESULT)(0)
#       define ShowCursor2(Cursor, Text)                (LRESULT)(0)
#       define ShowFont2(Font, Text)                    (LRESULT)(0)
#       define ShowImageList2(List, Index, Flags, Text) (LRESULT)(0)
#       define ShowRegion2(Region, Text)                (LRESULT)(0)
#       define ShowGDIPlusBitmap2(Image, Text)          (LRESULT)(0)

#       define ShowFont3(Sample, Font, Text)            (LRESULT)(0)
#       define ShowRegion3(Region, Bitmap, Text)        (LRESULT)(0)

#       define ShowRegion4(Region, DC, Text)            (LRESULT)(0)

#       if _MSC_VER >= 1300             // VC 7.0 and above
#           define ShowGraphic __noop
#       endif // _MSC_VER >= 1300
#   endif // VIEWER_ACTIVE

#endif // PJA_IMAGE_VIEWER_UTILITY_HEADER_FILE_INCLUDED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -