Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 转换位图C++;启动屏幕代码转换为PNG图像_C++_Bitmap_Gdi+_Alphablending_Libpng - Fatal编程技术网

C++ 转换位图C++;启动屏幕代码转换为PNG图像

C++ 转换位图C++;启动屏幕代码转换为PNG图像,c++,bitmap,gdi+,alphablending,libpng,C++,Bitmap,Gdi+,Alphablending,Libpng,这是我的代码,我想将PNG图像显示为启动屏幕 p>我不知道我将使用LBPNG或GDI+或其他任何C++代码,这些代码通常可以通过C++代码< /P>显示PNG图像作为飞溅屏幕。 装载机普拉斯cpp #include "stdafx.h" #include <windows.h> #include <stdio.h> #include "resource.h" #include "loadersplash.h" #incl

这是我的代码,我想将PNG图像显示为启动屏幕

<> p>我不知道我将使用LBPNG或GDI+或其他任何C++代码,这些代码通常可以通过C++代码< /P>显示PNG图像作为飞溅屏幕。 装载机普拉斯cpp

    #include "stdafx.h"
    #include <windows.h>
    #include <stdio.h>
    #include "resource.h"
    #include "loadersplash.h"

    #include <objidl.h>
    #include <gdiplus.h>
    using namespace Gdiplus;
    #pragma comment (lib, "gdiplus.lib")
    /*----------------------------------*/
    // Construction/Destruction
    /*----------------------------------*/

    #ifdef __LOADER_SPLASH
    SPLASH::SPLASH()
    {
        hSplashWnd = hParentWindow = NULL;
        SHOWING = FALSE;
    }

    SPLASH::~SPLASH()
    {
        Hide();
        DestroyWindow(hSplashWnd);
        hSplashWnd = NULL;
    }

    void SPLASH::Init(HWND hWnd, HINSTANCE hInst, int resid)
    {
        hParentWindow = hWnd;
        hSplashWnd = CreateWindowEx(WS_EX_CLIENTEDGE, "STATIC", NULL, WS_POPUP | SS_BITMAP, 0, 0, 400, 300, hWnd, NULL, hInst, NULL);
        if (hSplashWnd){
            SendMessage(hSplashWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)LoadBitmap(hInst, MAKEINTRESOURCE(resid)));
            this->SHOWING = TRUE;
        }
        this->SHOWING = FALSE;
    }

    void SPLASH::Show()
    {
        int x, y;
        int pwidth, pheight;
        int tx, ty;
        HDWP windefer;
        RECT rect, prect;
        GetClientRect(hSplashWnd, &rect);
        x = rect.right; y = rect.bottom;
        GetWindowRect(this->hParentWindow, &prect);
        pwidth = prect.right - prect.left;
        pheight = prect.bottom - prect.top;
        tx = (pwidth / 2) - (x / 2);
        ty = (pheight / 2) - (y / 2);
        tx += prect.left;
        ty += prect.top;

        windefer = BeginDeferWindowPos(1);
        DeferWindowPos(windefer, hSplashWnd, HWND_NOTOPMOST, tx, ty, 50, 50, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOZORDER);
        EndDeferWindowPos(windefer);

        ShowWindow(hSplashWnd, SW_SHOWNORMAL);
        UpdateWindow(hSplashWnd);
        this->SHOWING = TRUE;
    }

    void SPLASH::Hide()
    {
        ShowWindow(hSplashWnd, SW_HIDE);
        this->SHOWING = FALSE;
    }

    void SPLASH::SetSplashImage(HWND hwndSplash, HBITMAP hbmpSplash)
    {
        // get the size of the bitmap
        BITMAP bm;
        GetObject(hbmpSplash, sizeof(bm), &bm);
        SIZE sizeSplash = { bm.bmWidth, bm.bmHeight };

        // get the primary monitor's info
        POINT ptZero = { 0 };
        HMONITOR hmonPrimary = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
        MONITORINFO monitorinfo = { 0 };
        monitorinfo.cbSize = sizeof(monitorinfo);
        GetMonitorInfo(hmonPrimary, &monitorinfo);

        // center the splash screen in the middle of the primary work area
        const RECT & rcWork = monitorinfo.rcWork;
        POINT ptOrigin;
        ptOrigin.x = 0;
        ptOrigin.y = rcWork.top + (rcWork.bottom - rcWork.top - sizeSplash.cy) / 2;

        // create a memory DC holding the splash bitmap
        HDC hdcScreen = GetDC(NULL);
        HDC hdcMem = CreateCompatibleDC(hdcScreen);
        HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcMem, hbmpSplash);

        // use the source image's alpha channel for blending
        BLENDFUNCTION blend = { 0 };
        blend.BlendOp = AC_SRC_OVER;
        blend.SourceConstantAlpha = 255;
        blend.AlphaFormat = AC_SRC_ALPHA;

        // paint the window (in the right location) with the alpha-blended bitmap
        UpdateLayeredWindow(hwndSplash, hdcScreen, &ptOrigin, &sizeSplash,
            hdcMem, &ptZero, RGB(0, 0, 0), &blend, ULW_ALPHA);

        // delete temporary objects
        SelectObject(hdcMem, hbmpOld);
        DeleteDC(hdcMem);
        ReleaseDC(NULL, hdcScreen);
    }
    #endif //__LOADER_SPLASH
这可能会有帮助:这可能会有帮助:
// SPLASH.h: interface for the SPLASH class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SPLASH_H__41182F11_BB6F_11D6_B0F5_00B0D01AD687__INCLUDED_)
#define AFX_SPLASH_H__41182F11_BB6F_11D6_B0F5_00B0D01AD687__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifdef __LOADER_SPLASH

class SPLASH
{
public:
    void Hide();
    void Show();
    void Init(HWND hWnd, HINSTANCE hInst, int resid);
    BOOL SHOWING;
    void SetSplashImage(HWND hwndSplash, HBITMAP hbmpSplash);

    SPLASH();
    virtual ~SPLASH();

private:
    UINT TimerID;
    HWND hParentWindow;
    HWND hSplashWnd;

};

//class CPNGTestDlg : public CDialog
//{
//  BOOL            LoadPNG();
//};

#endif //__LOADER_SPLASH

#endif // !defined(AFX_SPLASH_H__41182F11_BB6F_11D6_B0F5_00B0D01AD687__INCLUDED_)