C ++启动画面创建标准控件 [英] C++ Splash screen create standart controls

查看:141
本文介绍了C ++启动画面创建标准控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我是新来的,如果我在错误的部分对不起.
这是我的问题.
我做了一个分层窗口(WS_EX_LAYERED)并在上面绘制了一个位图.
使用msdn中的alpha混合功能.
幕后:启动画面
这是屏幕.
图片

这是我的源代码

Hello all,
i''m new here, if i''m in the wrong section sorry.
Here is my problem.
I did a Layered Window (WS_EX_LAYERED) and draw a bitmap on it.
Using alpha blending function from msdn.
Behind the Scenes: The Splash Screen
Here is a screen.
Picture

and here is my sourcecode

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <windows.h>
#include <WindowsX.h>
#include <GdiPlus.h>
#include "resource.h"
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#pragma comment ( lib, "Gdiplus.lib" )

ULONG_PTR m_gdiplusToken;
HBITMAP hBmpSplash;

BOOL Blend(
    HWND hWnd,      // Must be a layered window
    HBITMAP hBmp,   // The image. Must be 32bpp ARGB format
    BYTE alpha )    // Overall opacity (0=transparent, 255=opaque)
{
    BLENDFUNCTION bf =
    {
        AC_SRC_OVER,    // BlendOp
        0,              // BlendFlags
        alpha,          // SourceConstantAlpha
        AC_SRC_ALPHA    // AlphaFormat
    };

    // Find the image's size in pixels
    BITMAP bm = {};
    if( sizeof(bm) != GetObject(hBmp, sizeof(bm), &bm) ) return FALSE;
    SIZE size = { bm.bmWidth, bm.bmHeight };

    // Create a screen device context and select the image into it.
    HDC hdc = CreateCompatibleDC(NULL);
    if( !hdc ) return FALSE;
    HBITMAP hBmpOld = SelectBitmap(hdc, hBmp);

    // Update the layered window
    POINT ptSrc = { 0, 0 };
    BOOL bRet = UpdateLayeredWindow(
        hWnd,
        NULL /*hdcDst NULL to use the default palette for the screen*/,
        NULL /*pptDst NULL because the removed isn't changing */,
        &size,
        hdc,
        &ptSrc,
        RGB(0,0,0),
        &bf,
        ULW_ALPHA );

    // Restore the device context and clean up
    SelectBitmap(hdc, hBmpOld);
    DeleteDC(hdc);

    return bRet;
}

LRESULT CALLBACK WndProc(HWND window, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch (uMsg) {

    case WM_CREATE:
        break;

    case WM_MOUSEMOVE:
        break;

	case WM_LBUTTONDOWN:
	{
		PostMessage(window, WM_NCLBUTTONDOWN, HTCAPTION,NULL);
		break;
	}

    case WM_NCDESTROY:
        PostQuitMessage(0);
        break;
    }

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

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR,
   int nCmdShow)
{
	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
	Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
	hBmpSplash = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SPLASH));
	
	WNDCLASSEX wcex;

	wcex.cbSize          = sizeof(WNDCLASSEX);
	wcex.style           = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wcex.lpfnWndProc     = WndProc;
	wcex.cbClsExtra      = 0;
	wcex.cbWndExtra      = 8; // 8 bytes, to allow for 64-bit architecture
	wcex.hInstance       = hInstance; // CHECK
	wcex.hIcon           = NULL;
	wcex.hCursor         = ::LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground   = (HBRUSH)NULL_BRUSH; // CHECK
	wcex.lpszMenuName    = NULL;
	wcex.lpszClassName	 = "GDI_Window";
	wcex.hIconSm         = NULL;
	
	RegisterClassEx(&wcex);

	HWND wnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_LAYERED, "GDI_Window", "GDI Window", WS_POPUP , 0, 0, 700, 500, NULL, NULL, hInstance, NULL);
	
	Blend(wnd, hBmpSplash, 255);
	ShowWindow(wnd, nCmdShow);
	UpdateWindow(wnd);

	MSG msg = { 0 };

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

	Gdiplus::GdiplusShutdown(m_gdiplusToken);
   return 0;                                                              
}



一切正常,除了我无法绘制标准的控件,例如按钮,编辑控件等.
对我有什么解决办法吗?

PS:我不想使用MFC.



Everythings works fine, except that i can''t draw standart controls like buttons, edit control, etc.
Did you have any solution for me?

PS: I don''t want to use MFC.

推荐答案

您想要的单词是标准".如果创建了一个窗口,则可以向其添加控件,而在该窗口上绘制图像这一事实并不重要.在C#时代,WinAPI C对我而言似乎是一种受虐狂.为什么?
The word you want is ''standard''. If you created a window, then you can add controls to it, the fact you drew an image on it is immaterial. WinAPI C in the age of C# seems like masochism to me. Why ?


这篇关于C ++启动画面创建标准控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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