Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 2571|回复: 5
打印 上一主题 下一主题

[原创] Aero Pack For .NET - Enchance Your GUI

[复制链接]

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

跳转到指定楼层
1#
发表于 2009-10-20 06:17 PM |只看该作者 |倒序浏览
我这里用C#,不会的话请用C#2VB.NET Converter (迟些我会上载)

一定要是Vista以上的作业系统才可以使用,要怎么探测自己处理
  1. If (System.Environment.OSVersion.Major >=6)
  2. {
  3. //TODO
  4. }else{
  5. Messagebox.Show(null,"dwm.exe Not Enabled");
  6. }
复制代码
首先是Vista里的Button
方法非常简单,只需把Button的属性项里的FlatStyle设为System (设置之后将会有Fade的效果)

之后是MenuStrip
在MenuStrip里面的Item,全部背景色都是深蓝色的,丑极了。我们只需要更改一点点东西就可以把背景色变成天蓝色的渐变。
方法:去Toolbox的Toolbox Tab点右键,在.NET Components Tab里面找Main Menu,有3个两个已经打勾,把剩下的一个也打勾,再把已加入的Mainmenu元件拖出即可

这个是非常简单的东西,之后我要教的是APIs
API 函数呼叫教学
  1. //方法一:旧的,我喜欢这个(VB),C#我不知道对不对
  2. private static extern int DwmExteadFameIntoClientArea lib "dwmapi.dll" alias "DwmExteadClientIntoFrameArea"(IntPtr Hwnd, MARGINS margin)
  3. //private = 类型,protected,private,public,etc.
  4. //static extern = 不知道,照抄 :)
  5. //int = 函数回转类型
  6. //DwmExteadFrameIntoClientArea = 设置的函数呼叫名称
  7. //lib "" = dll名称
  8. //alias = dll里面的函数名称
  9. //() = 函数呼叫所需资料

  10. //方法二:新款的,我不太会用
  11. [System.Runtime.InteropService.DllImport("dwmapi.dll")] _
  12. private static extern int DwmExteadFrameIntoClientArea(Intptr HWND, MARGINS margin)
  13. //System.Runtime.InteropService.DllImport("") = 导入DLL函数,("")为DLL名称
复制代码
程式库函数名称函数资料使用说明效果
dwmapi.dllDwmExteadFrameIntoClientAreaIntptr hwnd, MARGINS margin

returns int

MARGINS为新的数据类型
struct MARGINS
{
int left;
int right;
int top;
int bottom;
}

在这个教学中,所有的Intptr hwnd都是放<Object.Handle>
这里就要放this.handle,如果你不会的话Margins就放
new margins(this.left *2,this.right*2,this.top*2,this.botton*2)
其实这个是把匡的半透明(Frame's Transparent) 延展到程序区域(Client Area)
可以把指定位置变成Aero Transparent
dwmapi.dll
DwmIsCompositionEnabledint isaeroenabled

returns int
if(DwmIsCompositionEnabled == true)
只有true和false,可以说是boolean,但是我不知道为什么他用Integer
可以探测Aero Interface是否已经启用
uxtheme.dllSetWindowThemeIntPtr Hwnd
String TextSubAppName
String TextSubIDList
SetWindowTheme(object.Handle, "explorer", null);
只需把object变成你要弄的东西即可
可以把Highlight(蓝色)变成Aero的蓝色渐变,还有tree view的+和-变成斜边三角形,MouseOver还会发亮
(下面有图)
user32.dllSendMessageIntPtr hWnd
int msg
int wParam
int lParam
这个有很多功能,我下面会在解释很多效果,但是我只会放几个,其他有网站参考

SendMessage的用法
Progressbar :
  1. SendMessage(progressbar1.Handle, 0x400 + 16, 0x0001, 0); //Normal; Green

  2. SendMessage(progressbar1.Handle, 0x400 + 16, 0x0002, 0); //Error; Red

  3. SendMessage(progressbar1.Handle, 0x400 + 16, 0x0003, 0); //Pause; Yellow
复制代码
TextBox : (可以变得好像Search Box那样)
  1. SendMessage(textbox1.Handle, 0x1500 + 1, IntPtr.Zero,
  2.                 "Please type in something."); //Please type in something是你要的String
复制代码
在Label加上发光效果(好像Form Title那样)
这个要用很多API……我根本看不懂
在Project里加入一个Code File
GlassText.cs [二楼]
然后
  1.             GlassText glasstxt = new GlassText(); //OOP : 引入GlassText.cs
  2.             glasstxt.DrawTextOnGlass(this.Handle, lblText.Text, lblText.Font, lblText.Bounds,10 ); //10应该是glow的pixel(px)
复制代码
问题 1:在有Aero Transparent的区域放入Label会变得非常丑
问题 2:在有Aero Transparent的区域放入图片会变得非常丑
其实这些问题都有一个非常简单也非常麻烦的解决方法,那就是不要用Label和ImageBox


更新中

[ 本帖最后由 goodhermit95 于 2009-10-20 09:48 PM 编辑 ]




收藏收藏0

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

2#
发表于 2009-10-20 09:49 PM |只看该作者
GlassText.cs


  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using System.Runtime.InteropServices;
  7. using System.Diagnostics;

  8. namespace textonglass
  9. {
  10.     class GlassText
  11.     {
  12.         private const int DTT_COMPOSITED = (int)(1UL << 13);
  13.         private const int DTT_GLOWSIZE = (int)(1UL << 11);
  14.         //Text format consts
  15.         private const int DT_SINGLELINE = 0x00000020;
  16.         private const int DT_CENTER = 0x00000001;
  17.         private const int DT_VCENTER = 0x00000004;
  18.         private const int DT_NOPREFIX = 0x00000800;
  19.         //Const for BitBlt
  20.         private const int SRCCOPY = 0x00CC0020;
  21.         //Consts for CreateDIBSection
  22.         private const int BI_RGB = 0;
  23.         private const int DIB_RGB_COLORS = 0 ;//color table in RGBs
  24.         private struct MARGINS
  25.         {
  26.             public int m_Left;
  27.             public int m_Right;
  28.             public int m_Top;
  29.             public int m_Buttom;
  30.         };
  31.         private struct POINTAPI
  32.         {
  33.             public int x;
  34.             public int y;
  35.         };
  36.         private struct DTTOPTS
  37.         {
  38.             public uint dwSize;
  39.             public uint dwFlags;
  40.             public uint crText;
  41.             public uint crBorder;
  42.             public uint crShadow;
  43.             public int iTextShadowType;
  44.             public POINTAPI ptShadowOffset;
  45.             public int iBorderSize;
  46.             public int iFontPropId;
  47.             public int iColorPropId;
  48.             public int iStateId;
  49.             public int fApplyOverlay;
  50.             public int iGlowSize;
  51.             public IntPtr pfnDrawTextCallback;
  52.             public int lParam;
  53.         };
  54.         private struct RECT
  55.         {
  56.             public int left;
  57.             public int top;
  58.             public int right;
  59.             public int bottom;
  60.         };
  61.         private struct BITMAPINFOHEADER
  62.         {
  63.             public int biSize;
  64.             public int biWidth;
  65.             public int biHeight;
  66.             public short biPlanes;
  67.             public short biBitCount;
  68.             public int biCompression;
  69.             public int biSizeImage;
  70.             public int biXPelsPerMeter;
  71.             public int biYPelsPerMeter;
  72.             public int biClrUsed;
  73.             public int biClrImportant;
  74.         };
  75.         private struct RGBQUAD
  76.         {
  77.             public byte rgbBlue;
  78.             public byte rgbGreen;
  79.             public byte rgbRed;
  80.             public byte rgbReserved;
  81.         };
  82.         private struct BITMAPINFO
  83.         {
  84.             public BITMAPINFOHEADER bmiHeader  ;
  85.             public RGBQUAD bmiColors ;
  86.         };
  87.         //API declares
  88.         [DllImport("dwmapi.dll")]
  89.         private static extern void DwmIsCompositionEnabled(ref int enabledptr);
  90.         [DllImport("dwmapi.dll")]
  91.         private static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margin);
  92.         [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
  93.         private static extern IntPtr GetDC(IntPtr hdc);
  94.         [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  95.         private static extern int  SaveDC(IntPtr hdc);
  96.         [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
  97.         private static extern int ReleaseDC(IntPtr hdc, int state);
  98.         [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  99.         private static extern IntPtr CreateCompatibleDC(IntPtr hDC);
  100.         [DllImport("gdi32.dll", ExactSpelling = true)]
  101.         private static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
  102.         [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  103.         private static extern bool DeleteObject(IntPtr hObject);
  104.         [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  105.         private static extern bool DeleteDC(IntPtr hdc);
  106.         [DllImport("gdi32.dll")]
  107.         private static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
  108.         [DllImport("UxTheme.dll", ExactSpelling = true, SetLastError = true, CharSet = CharSet.Unicode)]
  109.         private static extern int DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string text, int iCharCount, int dwFlags, ref RECT pRect, ref DTTOPTS pOptions);
  110.         [DllImport("UxTheme.dll", ExactSpelling = true, SetLastError = true)]
  111.         private static extern int DrawThemeText(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string text, int iCharCount, int dwFlags1, int dwFlags2, ref RECT pRect);
  112.         [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  113.         private static extern IntPtr CreateDIBSection(IntPtr hdc,ref BITMAPINFO pbmi, uint iUsage, int ppvBits, IntPtr hSection, uint dwOffset);
  114.         private bool  IsCompositionEnabled()
  115.         {
  116.             
  117.                 if (Environment.OSVersion.Version.Major < 6)
  118.                     return false ;

  119.                 int compositionEnabled = 0;
  120.                 DwmIsCompositionEnabled(ref compositionEnabled);
  121.                 if (compositionEnabled > 0)
  122.                 {
  123.                     return true;
  124.                 }
  125.                 else
  126.                 {
  127.                     return false;
  128.                 }
  129.         }
  130.         public void FillBlackRegion(Graphics gph, Rectangle rgn)
  131.         {
  132.             RECT rc = new RECT();
  133.             rc.left = rgn.Left;
  134.             rc.right = rgn.Right;
  135.             rc.top = rgn.Top;
  136.             rc.bottom = rgn.Bottom;
  137.             IntPtr destdc = gph.GetHdc();    //hwnd must be the handle of form,not control
  138.             IntPtr Memdc = CreateCompatibleDC(destdc);
  139.             IntPtr bitmap;
  140.             IntPtr bitmapOld = IntPtr.Zero;
  141.             BITMAPINFO dib = new BITMAPINFO();
  142.             dib.bmiHeader.biHeight = -(rc.bottom - rc.top);
  143.             dib.bmiHeader.biWidth = rc.right - rc.left;
  144.             dib.bmiHeader.biPlanes = 1;
  145.             dib.bmiHeader.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
  146.             dib.bmiHeader.biBitCount = 32;
  147.             dib.bmiHeader.biCompression = BI_RGB;
  148.             if (!(SaveDC(Memdc) == 0))
  149.             {
  150.                 bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0);
  151.                 if (!(bitmap == IntPtr.Zero))
  152.                 {
  153.                     bitmapOld = SelectObject(Memdc, bitmap);
  154.                     BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, SRCCOPY);
  155.                 }
  156.                 //Remember to clean up
  157.                 SelectObject(Memdc, bitmapOld);
  158.                 DeleteObject(bitmap);
  159.                 ReleaseDC(Memdc, -1);
  160.                 DeleteDC(Memdc);
  161.             }
  162.             gph.ReleaseHdc();
  163.         }
  164.         public void DrawTextOnGlass(IntPtr hwnd, String text, Font font, Rectangle ctlrct, int iglowSize)
  165.         {
  166.             if (IsCompositionEnabled())
  167.             {
  168.                 RECT rc = new RECT();
  169.                 RECT rc2 = new RECT();
  170.                 rc.left = ctlrct.Left;
  171.                 rc.right = ctlrct.Right + 2 * iglowSize;  //make it larger to contain the glow effect
  172.                 rc.top = ctlrct.Top;
  173.                 rc.bottom = ctlrct.Bottom + 2 * iglowSize;
  174.                 //Just the same rect with rc,but (0,0) at the lefttop
  175.                 rc2.left = 0;
  176.                 rc2.top = 0;
  177.                 rc2.right = rc.right - rc.left;
  178.                 rc2.bottom = rc.bottom - rc.top;
  179.                 IntPtr destdc = GetDC(hwnd);    //hwnd must be the handle of form,not control
  180.                 IntPtr Memdc = CreateCompatibleDC(destdc);   // Set up a memory DC where we'll draw the text.
  181.                 IntPtr bitmap;
  182.                 IntPtr bitmapOld = IntPtr.Zero;
  183.                 IntPtr logfnotOld;
  184.                 int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX;   //text format
  185.                 BITMAPINFO dib = new BITMAPINFO();
  186.                 dib.bmiHeader.biHeight = -(rc.bottom - rc.top);         // negative because DrawThemeTextEx() uses a top-down DIB
  187.                 dib.bmiHeader.biWidth = rc.right - rc.left;
  188.                 dib.bmiHeader.biPlanes = 1;
  189.                 dib.bmiHeader.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
  190.                 dib.bmiHeader.biBitCount = 32;
  191.                 dib.bmiHeader.biCompression = BI_RGB;
  192.                 if (!(SaveDC(Memdc) == 0))
  193.                 {
  194.                     bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0);   // Create a 32-bit bmp for use in offscreen drawing when glass is on
复制代码


回复

使用道具 举报

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

3#
发表于 2009-10-20 09:49 PM |只看该作者


  1.                     if (!(bitmap == IntPtr.Zero))
  2.                     {
  3.                         bitmapOld = SelectObject(Memdc, bitmap);
  4.                         IntPtr hFont = font.ToHfont();
  5.                         logfnotOld = SelectObject(Memdc, hFont);
  6.                         try
  7.                         {
  8.                             System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
  9.                             DTTOPTS dttOpts = new DTTOPTS();
  10.                             dttOpts.dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS));
  11.                             dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
  12.                             dttOpts.iGlowSize = iglowSize;
  13.                             DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts);
  14.                             BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, SRCCOPY);
  15.                         }
  16.                         catch (Exception e)
  17.                         {
  18.                             Trace.WriteLine(e.Message);
  19.                         }
  20.                         //Remember to clean up
  21.                         SelectObject(Memdc, bitmapOld);
  22.                         SelectObject(Memdc, logfnotOld);
  23.                         DeleteObject(bitmap);
  24.                         DeleteObject(hFont);
  25.                         ReleaseDC(Memdc, -1);
  26.                         DeleteDC(Memdc);
  27.                     }
  28.                 }
  29.             }
  30.         }
  31.     }
  32. }
复制代码


回复

使用道具 举报

15

主题

1

好友

156

积分

高级会员

Rank: 3Rank: 3Rank: 3

4#
发表于 2009-10-21 10:24 PM |只看该作者
good...这个好


回复

使用道具 举报

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

5#
发表于 2009-10-25 04:17 PM |只看该作者

回复 #4 缘之人 的帖子

我考完试将会出DLL!


回复

使用道具 举报

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

6#
发表于 2011-3-6 10:32 PM |只看该作者
顶一下,每次找到要死==


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-7-2 04:33 PM , Processed in 0.107587 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部