- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经使用来自 Codeproject 的 BandObjectLib ( Extending Explorer with Band Objects using .NET and Windows Forms ) 实现了 DeskBand 任务栏工具栏,修改后支持 IDeskBand2 界面,它允许 Windows Vista 中的“开始”菜单在启用我的 DeskBand 任务栏工具栏时保持透明。但是,组合框或文本框中显示的文本会显示底层桌面背景的颜色与文本的原始颜色混合。
标签没有这个问题,因为它通常是使用 GDI(+) 绘制的,它会忽略渲染文本(而不是标签的背景)上的 DWMComposition。
我认为问题是因为 DWM 在 Vista 上关于某些文本元素的工作方式,这在以下页面中有解释:
Using Vista Controls on Aero Glass
Windows Vista Aero Pt. 1 - Adding Glass to a Windows Forms Application
Adding or Retrofitting Aero Glass into Legacy Windows Applications
我只在我的 DeskBand 工具栏上使用组合框,所以我只需要知道如何强制组合框不使用 DWM 显示,即使 DWM 在系统上启用并且通过 IDeskBand2 的实现在 DeskBand 上启用界面。
更新:我进一步研究了它,C++ 代码位于 Adding or Retrofitting Aero Glass into Legacy Windows Applications似乎最有可能让这个工作成为可能,因此组合框显示文本不透明。如果有人可以查看仅与组合框有关的代码并帮助我让它为 C# 组合框工作,那将是我的一个月!我已经开始悬赏,希望能得到答案。
下面是来自上述项目的 EditProc.cpp 类,它应该让您快速了解我正在寻找的解决方案。要了解完整情况,您需要查看整个项目:
/*
*
* $RCSfile: aeroedit.cpp,v $
* $Source: /cvs/common/aeroedit.cpp,v $
* $Author: cvs $
* $Revision: 1.12 $
* $Date: 2007/05/20 10:38:25 $
* $State: Exp $
* Copyright (c) Stefan Kuhr
*/
#include <windows.h>
#include <tchar.h>
#include "safassrt.h"
#include "aaeroint.h"
#include "aerosubc.h"
#include "aeroglss.h"
#include <windowsx.h>
#include <gdiplus.h>
using namespace Gdiplus;
static void UpdateIfSelChanged(HWND hWnd, PAERO_SUBCLASS_WND_DATA pWndData)
{
DWORD dwFirst, dwLast;
SendMessage(hWnd, EM_GETSEL, (WPARAM)&dwFirst, (LPARAM)&dwLast);
if(dwFirst!=pWndData->m_dwSelFirst || dwLast!=pWndData->m_dwSelLast)
{
pWndData->m_dwSelFirst = dwFirst;
pWndData->m_dwSelLast = dwLast;
VERIFY(InvalidateRect(hWnd, NULL, TRUE));
VERIFY(UpdateWindow(hWnd));
}
}
static LRESULT CALLBACK EditProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PAERO_SUBCLASS_WND_DATA pWndData = (PAERO_SUBCLASS_WND_DATA)GetProp(hWnd, WINDOW_DATA_STRING);
ASSERT(pWndData);
ASSERT(pWndData->m_pDwmApiImpl);
WNDPROC pOldProc = pWndData->m_oldWndProc;
ASSERT(pOldProc);
PAERO_SUBCLASS_WND_DATA pWndDataParent = (PAERO_SUBCLASS_WND_DATA)GetProp(GetParent(hWnd), WINDOW_DATA_STRING);
///
/// if aero glass is turned off and if we are not in destruction code,
/// just call the original wnd proc we had prior to subclassing:
///
if(WM_DESTROY!=uMsg && WM_NCDESTROY!=uMsg && WM_DWMCOMPOSITIONCHANGED!=uMsg && pWndDataParent && !pWndData->m_pDwmApiImpl->IsDwmCompositionEnabled())
return CallWindowProc(pOldProc, hWnd, uMsg, wParam, lParam);
if(pWndData->m_uiRedrawMsg==uMsg && pWndData->m_dwFlags & WD_IN_PAINT_CONTROL)
{
HDC hdc = GetDC(hWnd);
hdc = GetDC(hWnd);
if(hdc)
{
RECT rcClient;
GetClientRect(hWnd, &rcClient);
BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) };
params.dwFlags = 0L;//BPPF_ERASE;
HDC hdcPaint = NULL;
HPAINTBUFFER hBufferedPaint = pWndData->m_pUxTheme->BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB, ¶ms, &hdcPaint);
if (hdcPaint)
{
LONG_PTR dwStyle = GetWindowLongPtr(hWnd, GWL_STYLE);
DWORD_PTR dwSyscolorIdx = (dwStyle&WS_DISABLED || dwStyle&ES_READONLY)?COLOR_3DFACE:COLOR_WINDOW;
VERIFY(FillRect(hdcPaint, &rcClient, (HBRUSH)(dwSyscolorIdx+1)));
SendMessage(hWnd, WM_PRINTCLIENT, (WPARAM) hdcPaint, PRF_CLIENT|PRF_CHECKVISIBLE);
/// Make every pixel opaque
VERIFY(S_OK==pWndData->m_pUxTheme->BufferedPaintMakeOpaque_(hBufferedPaint, &rcClient));
VERIFY(S_OK==pWndData->m_pUxTheme->EndBufferedPaint(hBufferedPaint, TRUE));
}
VERIFY(1==ReleaseDC(hWnd, hdc));
pWndData->m_dwFlags &= ~WD_IN_PAINT_CONTROL;
}
return 1;
}
switch(uMsg)
{
case WM_KEYDOWN:
{
LONG_PTR dwStyle = GetWindowLongPtr(hWnd, GWL_STYLE);
if(dwStyle&WS_VSCROLL || dwStyle&ES_MULTILINE)
{
if(!(pWndData->m_dwFlags&WD_CARET_HIDDEN))
{
HideCaret(hWnd);
pWndData->m_dwFlags|=WD_CARET_HIDDEN;
}
}
}
break;
case WM_KEYUP:
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MOUSELEAVE:
{
LONG_PTR dwStyle = GetWindowLongPtr(hWnd, GWL_STYLE);
if(dwStyle&WS_VSCROLL || dwStyle&ES_MULTILINE)
{
if(pWndData->m_dwFlags&WD_CARET_HIDDEN)
{
ShowCaret(hWnd);
pWndData->m_dwFlags&=~WD_CARET_HIDDEN;
}
UpdateIfSelChanged(hWnd, pWndData);
}
}
break;
case WM_NCPAINT:
{
LRESULT lRes = 0;
lRes = CallWindowProc(pOldProc, hWnd, uMsg, wParam, lParam);
DrawEditBorder(hWnd, pWndData);
return lRes;
}
case WM_NCDESTROY:
case WM_DESTROY:
VERIFY(UnsubclassControl(hWnd, EditProc, pWndData));
break;
}
return CallWindowProc(pOldProc, hWnd, uMsg, wParam, lParam);
}
BOOL AeroSubClassEdit(HWND hwnd)
{
return AeroSubClassControl(hwnd, EditProc, WD_IN_PAINT_CONTROL);
}
谢谢,
约翰·伦尼迈尔
MuvEnum, LLC
最佳答案
这太痛苦了,我不知道为什么 Microsoft 没有让 WinForms 控件与 DWMManager 一起工作。 TextBox 很容易做到,您可以在其上方重新绘制位图。 DropDown 比较棘手,因为它内部有一个本地控件“编辑”框。由于它不是 .Net 控件(编辑部分),因此您无法使用 .Net 类轻松重绘它(我仍在尝试弄清楚如何执行此操作)。
不过,我已经弄清楚如何让 DropDown 在玻璃上呈现,但前提是文本框部分被禁用(通过更改样式来完成)。不太理想。我的在 VB.Net 中,我仍在努力。然而,我受到这个项目的启发,这个人用 C# 完成了它,可能对你有很大帮助:
http://dwmwinform.codeplex.com/
附带说明一下,WPF 的所有控件都支持 Aero Glass 效果。它的功能更强大,但使用起来也更耗时(IMO ......而且,如果你正在 retrofit WinForms 应用程序,WPF 对你没有任何好处)。我只是倾向于喜欢 WinForms,因为我编写业务应用程序并且不太关心或没有时间编写动画(WPF 很酷,不要我错了,我更喜欢 WinForms)。
这是我继承 ComboBox(在 Vb.Net 中)的起点。这个网站没有正确发布整个类(class),所以我只包括类(class)的内部:
''' <summary>
''' Enum of Windows messages that will trigger the redraw of the control
''' </summary>
''' <remarks></remarks>
Public Enum WindowsMessage
WM_CHAR = &H100
WM_KEYDOWN = &H102
WM_MOUSEMOVE = &H200
WM_PAINT = 15
WM_PRINT = &H314
End Enum
''' <summary>
''' Constructor
''' </summary>
''' <remarks></remarks>
Sub New()
Me.DropDownStyle = ComboBoxStyle.DropDownList
End Sub
''' <summary>
''' Processing of incoming messages. We're going to get a bitmap of the control and then
''' redraw it onto the form when a few specified windows messages come through.
''' </summary>
''' <param name="m"></param>
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
Select Case m.Msg
Case WindowsMessage.WM_PAINT, WindowsMessage.WM_CHAR, WindowsMessage.WM_KEYDOWN, _
WindowsMessage.WM_MOUSEMOVE, WindowsMessage.WM_PRINT
RedrawControlAsBitmap(Me.Handle)
End Select
End Sub
''' <summary>
''' Redraws a given control as a bitmap ontop of itself.
''' </summary>
''' <param name="hwnd"></param>
''' <remarks></remarks>
Public Sub RedrawControlAsBitmap(ByVal hwnd As IntPtr)
Dim c As Control = Control.FromHandle(hwnd)
If c IsNot Nothing Then
Using bm As New Bitmap(c.Width, c.Height)
c.DrawToBitmap(bm, c.ClientRectangle)
Using g As Graphics = c.CreateGraphics
g.DrawImage(bm, New Point(0, 0))
End Using
End Using
End If
c = Nothing
End Sub
关于toolbar - 如何在 DeskBand 任务栏工具栏上强制使用 C# 呈现 ComboBox 的 GDI+? (透明度问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/870369/
这两个库之间有什么区别吗? 最佳答案 根据the wikipedia article on GDI : With the introduction of Windows XP, GDI was dep
我喜欢 GDI+,因为它具有高性能并且包含在 Windows XP 中。但是,它的模糊类和效果类仅在 GDI+ 1.1 中可用,后者仅随 Windows Vista 或更高版本提供。尽管微软计划很快放
我用 C# 创建了一个图像服务,它采用基础层图像 (JPG),再分层一层更透明的 PNG(32 位),然后输出最终的 JPG 图像。我试图从这个函数中挤出最后一毫秒,但我的代码在 GDI+ 中的 Dr
我正在使用顶点以及 LineTo() 和 MoveTo() 函数制作一系列三角形来表示 3D 形状。 着色/填充这些三角形的最佳方法是什么? 谢谢 最佳答案 MSDN has a sample tha
我在 Win7 系统上注意到过一个问题,以为是 DWM 错误,但在重新启动后已修复。但现在我意识到它在其他人的系统上发生(作为默认行为),并且这也是 Surface Pro 上的正常行为。 如何重现问
是否可以在用户模式下创建自定义 GDI 设备?我们的想法是创建一个设备上下文 (HDC),我们可以将其传递给不透明的组件,这样当组件调用 GDI 函数(如 TextOut)时,我们可以获得实际的文本字
我想知道是否可以枚举所有桌面可见窗口以创建它们的位图并将所有位图组合成一个以便获得桌面的完整屏幕截图? 最有可能使用 GDI/GD+,但也欢迎使用任何外部库。首选语言C\C++。 提前致谢。 最佳答案
我有一个生成元文件 (EMF) 的应用程序。它使用引用设备(又名屏幕)来呈现这些元文件,因此元文件的 DPI 会根据代码运行的机器而变化。 假设我的代码打算创建一个 8.5 x 11 英寸的元文件。
我在同时使用 GDI 和 GDI+ 进行绘图时遇到问题。页面转换——尤其是缩放——似乎在两者之间有点偏离。除了 SetViewportExt 和 SetWindowExt 之外,GDI 上下文的哪些属
我需要从应用程序中获取一个大表(300K+ 行)并且没有导出功能。经过多次不成功的尝试后,我只剩下一个复制粘贴宏,一次一行。如果有办法在绘制时获取字符串,我可以一次获取一页(40 行)。 最佳答案 如
我曾经在我的 Win7 系统上注意到一个问题,认为这是一个 DWM 错误,因为它在重新启动后得到修复。但现在我意识到它正在其他人的系统上发生(作为默认行为),这也是 Surface Pro 上的正常行
我正在寻找一些高级教程,或者可能是用 C++ 或 .NET 编写的开源应用程序,它们可以实现复杂的基于 vector 的应用程序,例如 MS Visio 或 Autocad。我需要知道的是,当用户可以
我正在使用第三方库来绘制图表。该库需要一个 HDC (GDI)。但是我的应用程序使用的是 GDI+。 Q1:这样做安全吗? void f(Gdiplus::Graphics& graphics) {
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 4年前关闭。 Improve t
对不起,如果这是题外话。如果是这样的话;请随时将其移至适当的站点。 GDI/GDI+ 如何在不使用 DirectX 或 OpenGL 等较低级别的 API 与 GPU 通信的情况下渲染到显卡(在屏幕上
我正在尝试在兼容的渲染目标上使用 Gdi 和 Direct 2D 来渲染位图。我使用 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_GDI_COMPATIBLE 选项创建
我们目前正在将一个较旧的应用程序转换为通过 GDI+ 绘制,而不是直接使用 GDI。随着我们逐步翻译系统,有时我们需要从 Gdiplus::Graphics 对象中获取 HDC,以便允许尚未翻译的代码
我正在尝试使用 GDI+ 在屏幕上(整个屏幕,在所有其他窗口的顶部)绘图。 我已将 NULL 传递给 GetDC 以将 HDC 显示到屏幕上,然后使用它创建一个 Graphics 对象,并使用 Dra
GDI+ 非常慢,几乎完全是软件,而 GDI 是高度硬件加速的。GDI+ 是 Graphics 类在 WinForms 上使用的东西,它太慢了。 有没有人制作了 .NET GDI 库以便我们可以有速度
ASP.NET 网站随机引发此 System.Drawing-error: System.Runtime.InteropServices.ExternalException:System.Drawin
我是一名优秀的程序员,十分优秀!