显示启动图像功能的问题 [英] problem with showing a splash image function

查看:83
本文介绍了显示启动图像功能的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!在我开始之前,我想分享一下我在C ++方面的知识,不知怎的,我总是找到它很难学.. zh-b $ b

但是,我是b $ b我在某些显示启动画面的代码上出错了,这是一个很长的代码但是..

Hi everyone!

before I start, I'd like to share that I have 0 knowledge in C++ and somehow I've always found it hard to learn ..

However,
I'm having a error on some code that shows a splash screen, Its a long code but ..

// Splash.cpp

#include "splash.h"
#include "windowsx.h"

typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)
        (HWND hWnd, COLORREF cr, BYTE bAlpha, DWORD dwFlags);

lpfnSetLayeredWindowAttributes g_pSetLayeredWindowAttributes;

#define WS_EX_LAYERED 0x00080000 

static LRESULT CALLBACK ExtWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static CSplash * spl = NULL;
    if(uMsg == WM_CREATE)
    {
        spl = (CSplash*)((LPCREATESTRUCT)lParam)->lpCreateParams;
    }
    if(spl)
        return spl->WindowProc(hwnd, uMsg, wParam, lParam);
    else
        return DefWindowProc (hwnd, uMsg, wParam, lParam);
}

LRESULT CALLBACK CSplash::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
    }

    return DefWindowProc (hwnd, uMsg, wParam, lParam) ;
}

void CSplash:: OnPaint(HWND hwnd)
{
    if (!m_hBitmap)
        return;

    PAINTSTRUCT ps ;
    HDC hDC = BeginPaint (hwnd, &ps) ;

    RECT   rect;
    ::GetClientRect(m_hwnd, &rect);
    
    HDC hMemDC      = ::CreateCompatibleDC(hDC);
    HBITMAP hOldBmp = (HBITMAP)::SelectObject(hMemDC, m_hBitmap);
    
    BitBlt(hDC, 0, 0, m_dwWidth, m_dwHeight, hMemDC, 0, 0, SRCCOPY);

    ::SelectObject(hMemDC, hOldBmp);

    ::DeleteDC(hMemDC);
    
    EndPaint (hwnd, &ps) ;
}

void CSplash::Init()
{
    m_hwnd = NULL;
    m_lpszClassName = TEXT("SPLASH");
    m_colTrans = 0;
    HMODULE hUser32 = GetModuleHandle(TEXT("USER32.DLL"));

    g_pSetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)
                        GetProcAddress(hUser32, "SetLayeredWindowAttributes");
}

CSplash::CSplash()
{
    Init();
}

CSplash::CSplash(LPCTSTR lpszFileName, COLORREF colTrans)
{
    Init();

    SetBitmap(lpszFileName);
    SetTransparentColor(colTrans);
}

CSplash::~CSplash()
{
    FreeResources();
}

HWND CSplash::RegAndCreateWindow()
{
   
    WNDCLASSEX wndclass;
    wndclass.cbSize         = sizeof (wndclass);
    wndclass.style          = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW;
    wndclass.lpfnWndProc    = ExtWndProc;
    wndclass.cbClsExtra     = 0;
    wndclass.cbWndExtra     = DLGWINDOWEXTRA;
    wndclass.hInstance      = ::GetModuleHandle(NULL);
    wndclass.hIcon          = NULL;
    wndclass.hCursor        = ::LoadCursor( NULL, IDC_WAIT );
    wndclass.hbrBackground  = (HBRUSH)::GetStockObject(LTGRAY_BRUSH);
    wndclass.lpszMenuName   = NULL;
    wndclass.lpszClassName  = m_lpszClassName;
    wndclass.hIconSm        = NULL;

    if(!RegisterClassEx (&wndclass))
        return NULL;

    DWORD nScrWidth  = ::GetSystemMetrics(SM_CXFULLSCREEN);
    DWORD nScrHeight = ::GetSystemMetrics(SM_CYFULLSCREEN);

    int x = (nScrWidth  - m_dwWidth) / 2;
    int y = (nScrHeight - m_dwHeight) / 2;
    m_hwnd = ::CreateWindowEx(WS_EX_TOPMOST|WS_EX_TOOLWINDOW, m_lpszClassName, 
                              TEXT("Banner"), WS_POPUP, x, y, 
                              m_dwWidth, m_dwHeight, NULL, NULL, NULL, this);

    if(m_hwnd)
    {
        MakeTransparent();
        ShowWindow   (m_hwnd, SW_SHOW) ;
        UpdateWindow (m_hwnd);
    }
    return m_hwnd;
}

int CSplash::DoLoop()
{
  
    if(!m_hwnd)
        ShowSplash();

    MSG msg ;
    while (GetMessage (&msg, NULL, 0, 0))
    {
        TranslateMessage (&msg) ;
        DispatchMessage  (&msg) ;
    }

    return msg.wParam ;

}

void CSplash::ShowSplash()
{
    CloseSplash();
    RegAndCreateWindow();
}


DWORD CSplash::SetBitmap(LPCTSTR lpszFileName)
{
    
    HBITMAP    hBitmap       = NULL;
    hBitmap = (HBITMAP)::LoadImage(0, lpszFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    return SetBitmap(hBitmap);
}

DWORD CSplash::SetBitmap(HBITMAP hBitmap)
{
    int nRetValue;
    BITMAP  csBitmapSize;
    
   FreeResources();
    
    if (hBitmap)
    {
        m_hBitmap = hBitmap;
        nRetValue = ::GetObject(hBitmap, sizeof(csBitmapSize), &csBitmapSize);
        if (nRetValue == 0)
        {
            FreeResources();
            return 0;
        }
        m_dwWidth = (DWORD)csBitmapSize.bmWidth;
        m_dwHeight = (DWORD)csBitmapSize.bmHeight;
    }
       
    return 1;
}

void CSplash::FreeResources()
{
    if (m_hBitmap)
        ::DeleteObject (m_hBitmap);
    m_hBitmap = NULL;
}

int CSplash::CloseSplash()
{
    
    if(m_hwnd)
    {
        DestroyWindow(m_hwnd);
        m_hwnd = 0;
        UnregisterClass(m_lpszClassName, ::GetModuleHandle(NULL));
        return 1;
    }
    return 0;
}

bool CSplash::SetTransparentColor(COLORREF col)
{
    m_colTrans = col;

    return MakeTransparent();
}

bool CSplash::MakeTransparent()
{
   if(m_hwnd && g_pSetLayeredWindowAttributes && m_colTrans )
    {     
        SetWindowLong(m_hwnd, GWL_EXSTYLE, GetWindowLong(m_hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
        g_pSetLayeredWindowAttributes(m_hwnd, m_colTrans, 0, LWA_COLORKEY);
    }    
    return TRUE;
}

splash2.cpp:

splash2.cpp:

#include "stdafx.h"
#include "Splash.h"


void SplashShow(){
    CSplash splash1(TEXT(".\\System/Splash.bmp"), RGB(128, 128, 128));
    splash1.ShowSplash();
    Sleep(3000);
    splash1.CloseSplash();
}

现在,我为长代码道歉,只是想分享完整的代码以防万一。

我在Splash.cpp第30行收到错误 



这可能是图片没有出现的问题吗?



请帮忙......

Now, I apologize for the long code, just wanted to share the full code just in case.
I'm getting an error on line 30 in Splash.cpp 

Could this be a problem that the image is not showing up ?

Please help ...

推荐答案




在我开始之前,我想分享一下我有0在C ++方面的知识,不知怎的,我总是发现它很难学.. zh-b $ b

我在某些显示启动画面的代码上出错,它很长代码但是..


before I start, I'd like to share that I have 0 knowledge in C++ and somehow I've always found it hard to learn ..

I'm having a error on some code that shows a splash screen, Its a long code but ..

// Splash.cpp #include "splash.h" #include "windowsx.h" typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes) (HWND hWnd, COLORREF cr, BYTE bAlpha, DWORD dwFlags); lpfnSetLayeredWindowAttributes g_pSetLayeredWindowAttributes; #define WS_EX_LAYERED 0x00080000

...

}

... }

splash2.cpp:
$

splash2.cpp:

#include "stdafx.h"
#include "Splash.h"


void SplashShow(){
    CSplash splash1(TEXT(".\\System/Splash.bmp"), RGB(128, 128, 128));
    splash1.ShowSplash();
    Sleep(3000);
    splash1.CloseSplash();
}



我在Splash.cpp第30行收到错误 



这可能是一个问题,图片没有显示?




I'm getting an error on line 30 in Splash.cpp 

Could this be a problem that the image is not showing up ?

>在开始之前,我想分享一下我在C ++中的0知识


>我有一个某些显示启动画面的代码出错,



然后我认为我们可以放心地假设您没有编写代码
$你发布了b $ b。正确?



>我在Splash.cpp第30行收到错误

>这可能是图片没有出现的问题吗?



简答:是¥b $ b

长答案:当构建中存在编译或链接错误时,将不会创建exe

文件,所以自然没有程序可以运行。如果没有

程序运行,那么显然程序没有输出。



因为你自己没有写过这段代码,所以如果您确定了获得它的来源,那将有所帮助。这样我们就可以获得任何价值b $ b缺失的部分 - 比如splash.h - 阅读随附的文档等。



代码看起来非常类似 - 几乎完全相同 - 在这里可用的课程:



CSplash - 飞溅窗口类

https://www.codeproject.com/Articles/7658/CSplash-A-Splash-Window-班级



这是你从哪里来的?



- Wayne

>before I start, I'd like to share that I have 0 knowledge in C++
>I'm having a error on some code that shows a splash screen,

Then I think we can safely assume that you didn't write the code
you posted. Correct?

>I'm getting an error on line 30 in Splash.cpp
>Could this be a problem that the image is not showing up ?

Short answer: Yes

Long answer: When there are compile or link errors in a build, no exe
file will be created so naturally there is no program to run. If no
program runs then obviously there can be no output from the program.

Since you clearly did not write this code yourself, it would help if
you identified the source where you got it. That way we can get any
missing pieces - such as splash.h - read any accompanying documentation, etc.

The code looks very similar - almost identical - to the class available here:

CSplash - A Splash Window Class
https://www.codeproject.com/Articles/7658/CSplash-A-Splash-Window-Class

Is that where you got it from?

- Wayne


这篇关于显示启动图像功能的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆