using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WindowsApplication11111111111
{
public partial class Form1 : Form
{
#region 窗体边框阴影效果变量申明 const int CS_DropSHADOW = 0x20000;
const int GCL_STYLE = (-26);
//声明Win32 API
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassLong(IntPtr hwnd, int nIndex); #endregion public Form1()
{
InitializeComponent();
SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW); //API函数加载,实现窗体边框阴影效果
}
}
}以上代码用于实现 对窗体产生阴影效果...在网上找的..使用C#可以运行 .但我需要在VC.NET上面使用.麻烦高手帮我改一下.谢谢..C#我不怎么看得懂....谢谢了
解决方案 »
- c# 读取SQL数据库内数据的平均值问题
- WPF中的媒体播放控制
- ComBox的DisplayMember显示成员无效,显示的为ValueMember成员???
- 如何设定TabPage头的宽度?
- 急~ c#操作文件.c#用什么方法获取一个文本文件的行数?
- 百分求一个winform的treeview实例!!!
- 传输文件流时 出现这样的错误:基础连接已经关闭: 连接被意外关闭。
- 写一个方法 (用C#编) 要求实现在 D盘下 创建一个文件EDV.txt
- 怎样把照片的相对地址存入orcal数据库,再用VS调用?
- 我在form1中添加了button1按钮,怎样写使得单击button1后form1重新load一次?
- 解密RAR文件时 要你输入TXT文件的密码怎么办呀
- C#字符串的一个操作
#pragma once
#include<windows.h>
#pragma comment(lib,"User32.lib")
namespace test { 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>
/// Form1 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
/// 与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。否则,
/// 设计器将不能与此窗体的关联
/// 本地化资源正确交互。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
SetClassLong( (HWND)this->Handle.ToInt32() , GCL_STYLE , GetClassLong((HWND)this->Handle.ToInt32(), GCL_STYLE) |0x20000 );
} protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
} private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->components = gcnew System::ComponentModel::Container();
this->Size = System::Drawing::Size(300,300);
this->Text = L"Form1";
this->Padding = System::Windows::Forms::Padding(0);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
}
#pragma endregion
};
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ServiceMaster
{
class WinAPI
{
[DllImport("user32.dll")]
public extern static IntPtr GetWindow();
[DllImport("user32.dll")]
public extern static bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
public static uint LWA_COLORKEY = 0x00000001;
public static uint LWA_ALPHA = 0x00000002;
#region 阴影效果变量
//声明Win32 API
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassLong(IntPtr hwnd, int nIndex);
[DllImport("user32.dll")]
public extern static uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
[DllImport("user32.dll")]
public extern static uint GetWindowLong(IntPtr hwnd, int nIndex);
#endregion
public enum WindowStyle : int
{
GWL_EXSTYLE = -20
}
public enum ExWindowStyle : uint
{
WS_EX_LAYERED = 0x00080000
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.ServiceProcess;
using System.IO;
namespace ServiceMaster
{
public partial class MainFrom : Form
{
public MainFrom()
{
InitializeComponent();
const int CS_DropSHADOW = 0x20000;
const int GCL_STYLE = (-26);
WinAPI.SetClassLong(this.Handle, GCL_STYLE, WinAPI.GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Parent = WinAPI.GetWindow();
return cp;
}
}
private void SetWindowShadow(byte bAlpha)
{
WinAPI.SetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE,
WinAPI.GetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE) | (uint)WinAPI.ExWindowStyle.WS_EX_LAYERED);
WinAPI.SetLayeredWindowAttributes(this.Handle, 0, bAlpha, WinAPI.LWA_COLORKEY | WinAPI.LWA_ALPHA);
}
}