如何设置Windows窗体应用程序(C + +)有Aero / Glass背景?

问题描述:

我正在使用Visual Studio 2010 Pro在C ++中创建Windows窗体应用程序。我想创建一个透明的背景,也就是使用Aero Glass效果,类似于它在Windows照片查看器中环绕UI底部的方式。在这一点上,我已经查看了所有的功能,而你可以改变颜色和不透明度,这不是我正在寻找的。我想要那个很好的模糊的玻璃效果。

I am working on creating a Windows Forms Application in C++ using Visual Studio 2010 Pro. I wanted to create a transparent background, that is, using the Aero Glass effect, similar to the way it surrounds the bottom of the UI in Windows Photo Viewer. At this point, I've looked through all of the features, and while you can change color and opacity, it's not exactly what I'm looking for. I want that nice blurred glass effect.

我从Visual Studio给你的模板代码开始这个项目,所以我真的没有太多的链接。我只是从工具箱中添加了几个项目,并将它们链接到Form1.h文件中的函数。我为我缺乏输入道歉,我是新的Windows UI编程;我希望我可以添加更多的信息。为了简单起见,这里是Form1.h代码:

I started this project from the template code that Visual Studio gives you, so I don't really have much to link. I just added a few items from the toolbox and linked them to functions in the Form1.h file. I apologize for my lack of input, I'm quite new to Windows UI programming; I wish I could add more information. For the sake of simplicity, here is the Form1.h code:

#pragma once


namespace Secret { //my project's name is "Secret"

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
    Form1(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form1()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::Button^  button1;
private: System::Windows::Forms::RichTextBox^  richTextBox1;
private: System::Windows::Forms::TextBox^  textBox1;
private: Microsoft::VisualBasic::PowerPacks::ShapeContainer^  shapeContainer1;
private: Microsoft::VisualBasic::PowerPacks::RectangleShape^  rectangleShape1;
private: Microsoft::VisualBasic::PowerPacks::LineShape^  lineShape1;
private: Microsoft::VisualBasic::PowerPacks::OvalShape^  ovalShape2;
private: Microsoft::VisualBasic::PowerPacks::OvalShape^  ovalShape1;
protected: 

private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
        this->button1 = (gcnew System::Windows::Forms::Button());
        this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
        this->textBox1 = (gcnew System::Windows::Forms::TextBox());
        this->shapeContainer1 = (gcnew Microsoft::VisualBasic::PowerPacks::ShapeContainer());
        this->lineShape1 = (gcnew Microsoft::VisualBasic::PowerPacks::LineShape());
        this->ovalShape2 = (gcnew Microsoft::VisualBasic::PowerPacks::OvalShape());
        this->ovalShape1 = (gcnew Microsoft::VisualBasic::PowerPacks::OvalShape());
        this->rectangleShape1 = (gcnew Microsoft::VisualBasic::PowerPacks::RectangleShape());
        this->SuspendLayout();
        // 
        // button1
        // 
        this->button1->Location = System::Drawing::Point(107, 171);
        this->button1->Name = L"button1";
        this->button1->Size = System::Drawing::Size(75, 23);
        this->button1->TabIndex = 0;
        this->button1->Text = L"Save";
        this->button1->UseVisualStyleBackColor = true;
        this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
        // 
        // richTextBox1
        // 
        this->richTextBox1->Location = System::Drawing::Point(12, 12);
        this->richTextBox1->Name = L"richTextBox1";
        this->richTextBox1->Size = System::Drawing::Size(260, 126);
        this->richTextBox1->TabIndex = 1;
        this->richTextBox1->Text = L"";
        this->richTextBox1->TextChanged += gcnew System::EventHandler(this, &Form1::richTextBox1_TextChanged);
        // 
        // textBox1
        // 
        this->textBox1->Location = System::Drawing::Point(13, 145);
        this->textBox1->Name = L"textBox1";
        this->textBox1->Size = System::Drawing::Size(259, 20);
        this->textBox1->TabIndex = 2;
        this->textBox1->Text = L"filename.txt";
        // 
        // shapeContainer1
        // 
        this->shapeContainer1->Location = System::Drawing::Point(0, 0);
        this->shapeContainer1->Margin = System::Windows::Forms::Padding(0);
        this->shapeContainer1->Name = L"shapeContainer1";
        this->shapeContainer1->Shapes->AddRange(gcnew cli::array< Microsoft::VisualBasic::PowerPacks::Shape^  >(4) {this->lineShape1, 
            this->ovalShape2, this->ovalShape1, this->rectangleShape1});
        this->shapeContainer1->Size = System::Drawing::Size(290, 268);
        this->shapeContainer1->TabIndex = 3;
        this->shapeContainer1->TabStop = false;
        // 
        // lineShape1
        // 
        this->lineShape1->Name = L"lineShape1";
        this->lineShape1->X1 = 14;
        this->lineShape1->X2 = 270;
        this->lineShape1->Y1 = 228;
        this->lineShape1->Y2 = 228;
        // 
        // ovalShape2
        // 
        this->ovalShape2->Location = System::Drawing::Point(135, 207);
        this->ovalShape2->Name = L"ovalShape2";
        this->ovalShape2->Size = System::Drawing::Size(20, 44);
        // 
        // ovalShape1
        // 
        this->ovalShape1->Location = System::Drawing::Point(16, 208);
        this->ovalShape1->Name = L"ovalShape1";
        this->ovalShape1->Size = System::Drawing::Size(252, 42);
        // 
        // rectangleShape1
        // 
        this->rectangleShape1->Location = System::Drawing::Point(14, 206);
        this->rectangleShape1->Name = L"rectangleShape1";
        this->rectangleShape1->Size = System::Drawing::Size(257, 46);
        // 
        // Form1
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->BackColor = System::Drawing::SystemColors::Control;
        this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::None;
        this->ClientSize = System::Drawing::Size(290, 268);
        this->Controls->Add(this->textBox1);
        this->Controls->Add(this->richTextBox1);
        this->Controls->Add(this->button1);
        this->Controls->Add(this->shapeContainer1);
        this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::Fixed3D;
        this->MaximizeBox = false;
        this->Name = L"Form1";
        this->Text = L"Secret";
        this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
        this->ResumeLayout(false);
        this->PerformLayout();

    }
#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
         }
private: System::Void richTextBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
         }
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
         }
};
}

感谢您的任何帮助!

您正在寻找的是DWM(桌面窗口管理器)API, href =http://msdn.microsoft.com/en-us/library/aa969512%28v=vs.85%29.aspx =nofollow> DwmExtendFrameIntoClientArea 。

What you're looking for is the DWM (Desktop Window Manager) API, especially the function DwmExtendFrameIntoClientArea.

这里有一些C#代码演示了如何做到这一点: CodeProject

Here's some C# code that demonstrates how to do this: CodeProject

此外,启用桌面合成功能时,请务必不要扩展框架,否则遇到问题

Also, make sure not to extend the frame when desktop composition is enabled, or you'll run into problems.