- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作 outlook 2007 插件。在为 CommandBarButton 设置图标时,图标的背景变黑了。
我使用的代码是:
private CommandBar _menuBar;
private void AddScheduleMeetingButton()
{
var scheduleButton = (CommandBarButton)_menuBar
.Controls.Add(MsoControlType.msoControlButton, missing, missing, 1, true);
scheduleButton.BeginGroup = true;
scheduleButton.Caption = ScheduleButtonCaption;
scheduleButton.Picture = GetImage(Resources.schedule_meeting16);
scheduleButton.Style = MsoButtonStyle.msoButtonIconAndCaption;
scheduleButton.Click += UnirowScheduleButtonClick;
scheduleButton.Visible = true;
}
使用 Microsoft 提供的 AxHost 方法的 GetImage() 函数:
private IPictureDisp GetImage(Icon newIcon)
{
IPictureDisp tempImage = null;
try
{
var newImageList = new ImageList();
newImageList.Images.Add(newIcon);
tempImage = MyHost.GetIPictureDispFromPicture(newImageList.Images[0]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return tempImage;
}
我做错了什么?
最佳答案
在 Office 中有一个特殊的解决方法来支持使用 CommandBarButton
自定义图标透明度。参见 MS KB288771有关如何利用 Win32 API 为 Office CommandBar 按钮创建透明图片的信息。
C:\MyTestPic.bmp
。 Click
事件中:Private Sub Command1_Click()
Dim oPic As StdPicture
Dim oWord As Object
Dim oCommandBar As Object
Dim oButton As Object
' Load the picture (.bmp file) to use for the button image.
Set oPic = LoadPicture("C:\MyTestPic.bmp")
' Start Microsoft Word for Automation and create a new
' toolbar and button to test the PasteFace method.
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set oCommandBar = oWord.CommandBars.Add("Test Bar")
oCommandBar.Visible = True
Set oButton = oCommandBar.Controls.Add(1)
With oButton
.Caption = "Test Button"
.Style = 1
' Here we create a mask based on the image and put both
' the image and the mask on the clipboard. Any color areas with
' magenta will be transparent.
CopyBitmapAsButtonFace oPic, &HFF00FF
' PasteFace will now add the image with transparency.
.PasteFace
.Visible = True
End With
MsgBox "You have a new button with a transparent picture.", _
vbMsgBoxSetForeground
Set oButton = Nothing
If MsgBox("Do you want to delete the toolbar?", _
vbYesNo Or vbQuestion) = vbYes Then
oCommandBar.Delete
End If
Set oCommandBar = Nothing
Set oWord = Nothing
End Sub
(5)。在“项目”菜单上,单击“添加模块”,然后将以下代码粘贴到新模块的代码窗口中:
Option Explicit
Public Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Public Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
' ===================================================================
' GDI/Drawing Functions (to build the mask)
' ===================================================================
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" _
(ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" _
(ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" _
(ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" _
(ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, _
ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function SelectObject Lib "gdi32" _
(ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject As Long) As Long
Private Declare Function GetBkColor Lib "gdi32" _
(ByVal hdc As Long) As Long
Private Declare Function SetBkColor Lib "gdi32" _
(ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function GetTextColor Lib "gdi32" _
(ByVal hdc As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" _
(ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _
ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateHalftonePalette Lib "gdi32" _
(ByVal hdc As Long) As Long
Private Declare Function SelectPalette Lib "gdi32" _
(ByVal hdc As Long, ByVal hPalette As Long, _
ByVal bForceBackground As Long) As Long
Private Declare Function RealizePalette Lib "gdi32" _
(ByVal hdc As Long) As Long
Private Declare Function OleTranslateColor Lib "oleaut32.dll" _
(ByVal lOleColor As Long, ByVal lHPalette As Long, _
lColorRef As Long) As Long
Private Declare Function GetDIBits Lib "gdi32" _
(ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, _
ByVal nNumScans As Long, lpBits As Any, lpBI As Any, _
ByVal wUsage As Long) As Long
Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" _
(ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
' ===================================================================
' Clipboard APIs
' ===================================================================
Private Declare Function OpenClipboard Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function RegisterClipboardFormat Lib "user32" _
Alias "RegisterClipboardFormatA" (ByVal lpString As String) As Long
Private Declare Function GetClipboardData Lib "user32" _
(ByVal wFormat As Long) As Long
Private Declare Function SetClipboardData Lib "user32" _
(ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Const CF_DIB = 8
' ===================================================================
' Memory APIs (for clipboard transfers)
' ===================================================================
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(pDest As Any, pSource As Any, ByVal cbLength As Long)
Private Declare Function GlobalAlloc Lib "kernel32" _
(ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" _
(ByVal hMem As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" _
(ByVal hMem As Long) As Long
Private Declare Function GlobalSize Lib "kernel32" _
(ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" _
(ByVal hMem As Long) As Long
Private Const GMEM_DDESHARE = &H2000
Private Const GMEM_MOVEABLE = &H2
' ===================================================================
' CopyBitmapAsButtonFace
'
' This is the public function to call to create a mask based on the
' bitmap provided and copy both to the clipboard. The first parameter
' is a standard VB Picture object. The second should be the color in
' the image you want to be made transparent.
'
' Note: This code sample does limited error handling and is designed
' for VB only (not VBA). You will need to make changes as appropriate
' to modify the code to suit your needs.
'
' ===================================================================
Public Sub CopyBitmapAsButtonFace(ByVal picSource As StdPicture, _
ByVal clrMaskColor As OLE_COLOR)
Dim hPal As Long
Dim hdcScreen As Long
Dim hbmButtonFace As Long
Dim hbmButtonMask As Long
Dim bDeletePal As Boolean
Dim lMaskClr As Long
' Check to make sure we have a valid picture.
If picSource Is Nothing Then GoTo err_invalidarg
If picSource.Type <> vbPicTypeBitmap Then GoTo err_invalidarg
If picSource.Handle = 0 Then GoTo err_invalidarg
' Get the DC for the display device we are on.
hdcScreen = GetDC(0)
hPal = picSource.hPal
If hPal = 0 Then
hPal = CreateHalftonePalette(hdcScreen)
bDeletePal = True
End If
' Translate the OLE_COLOR value to a GDI COLORREF value based on the palette.
OleTranslateColor clrMaskColor, hPal, lMaskClr
' Create a mask based on the image handed in (hbmButtonMask is the result).
CreateButtonMask picSource.Handle, lMaskClr, hdcScreen, _
hPal, hbmButtonMask
' Let VB copy the bitmap to the clipboard (for the CF_DIB).
Clipboard.SetData picSource, vbCFDIB
' Now copy the Button Mask.
CopyButtonMaskToClipboard hbmButtonMask, hdcScreen
' Delete the mask and clean up (a copy is on the clipboard).
DeleteObject hbmButtonMask
If bDeletePal Then DeleteObject hPal
ReleaseDC 0, hdcScreen
Exit Sub
err_invalidarg:
Err.Raise 481 'VB Invalid Picture Error
End Sub
' ===================================================================
' CreateButtonMask -- Internal helper function
' ===================================================================
Private Sub CreateButtonMask(ByVal hbmSource As Long, _
ByVal nMaskColor As Long, ByVal hdcTarget As Long, ByVal hPal As Long, _
ByRef hbmMask As Long)
Dim hdcSource As Long
Dim hdcMask As Long
Dim hbmSourceOld As Long
Dim hbmMaskOld As Long
Dim hpalSourceOld As Long
Dim uBM As BITMAP
' Get some information about the bitmap handed to us.
GetObjectAPI hbmSource, 24, uBM
' Check the size of the bitmap given.
If uBM.bmWidth < 1 Or uBM.bmWidth > 30000 Then Exit Sub
If uBM.bmHeight < 1 Or uBM.bmHeight > 30000 Then Exit Sub
' Create a compatible DC, load the palette and the bitmap.
hdcSource = CreateCompatibleDC(hdcTarget)
hpalSourceOld = SelectPalette(hdcSource, hPal, True)
RealizePalette hdcSource
hbmSourceOld = SelectObject(hdcSource, hbmSource)
' Create a black and white mask the same size as the image.
hbmMask = CreateBitmap(uBM.bmWidth, uBM.bmHeight, 1, 1, ByVal 0)
' Create a compatble DC for it and load it.
hdcMask = CreateCompatibleDC(hdcTarget)
hbmMaskOld = SelectObject(hdcMask, hbmMask)
' All you need to do is set the mask color as the background color
' on the source picture, and set the forground color to white, and
' then a simple BitBlt will make the mask for you.
SetBkColor hdcSource, nMaskColor
SetTextColor hdcSource, vbWhite
BitBlt hdcMask, 0, 0, uBM.bmWidth, uBM.bmHeight, hdcSource, _
0, 0, vbSrcCopy
' Clean up the memory DCs.
SelectObject hdcMask, hbmMaskOld
DeleteDC hdcMask
SelectObject hdcSource, hbmSourceOld
SelectObject hdcSource, hpalSourceOld
DeleteDC hdcSource
End Sub
' ===================================================================
' CopyButtonMaskToClipboard -- Internal helper function
' ===================================================================
Private Sub CopyButtonMaskToClipboard(ByVal hbmMask As Long, _
ByVal hdcTarget As Long)
Dim cfBtnFace As Long
Dim cfBtnMask As Long
Dim hGMemFace As Long
Dim hGMemMask As Long
Dim lpData As Long
Dim lpData2 As Long
Dim hMemTmp As Long
Dim cbSize As Long
Dim arrBIHBuffer(50) As Byte
Dim arrBMDataBuffer() As Byte
Dim uBIH As BITMAPINFOHEADER
uBIH.biSize = 40
' Get the BITMAPHEADERINFO for the mask.
GetDIBits hdcTarget, hbmMask, 0, 0, ByVal 0&, uBIH, 0
CopyMemory arrBIHBuffer(0), uBIH, 40
' Make sure it is a mask image.
If uBIH.biBitCount <> 1 Then Exit Sub
If uBIH.biSizeImage < 1 Then Exit Sub
' Create a temp buffer to hold the bitmap bits.
ReDim Preserve arrBMDataBuffer(uBIH.biSizeImage + 4) As Byte
' Open the clipboard.
If Not CBool(OpenClipboard(0)) Then Exit Sub
' Get the cf for button face and mask.
cfBtnFace = RegisterClipboardFormat("Toolbar Button Face")
cfBtnMask = RegisterClipboardFormat("Toolbar Button Mask")
' Open DIB on the clipboard and make a copy of it for the button face.
hMemTmp = GetClipboardData(CF_DIB)
If hMemTmp <> 0 Then
cbSize = GlobalSize(hMemTmp)
hGMemFace = GlobalAlloc(&H2002, cbSize)
If hGMemFace <> 0 Then
lpData = GlobalLock(hMemTmp)
lpData2 = GlobalLock(hGMemFace)
CopyMemory ByVal lpData2, ByVal lpData, cbSize
GlobalUnlock hGMemFace
GlobalUnlock hMemTmp
If SetClipboardData(cfBtnFace, hGMemFace) = 0 Then
GlobalFree hGMemFace
End If
End If
End If
' Now get the mask bits and the rest of the header.
GetDIBits hdcTarget, hbmMask, 0, uBIH.biSizeImage, _
arrBMDataBuffer(0), arrBIHBuffer(0), 0
' Copy them to global memory and set it on the clipboard.
hGMemMask = GlobalAlloc(&H2002, uBIH.biSizeImage + 50)
If hGMemMask <> 0 Then
lpData = GlobalLock(hGMemMask)
CopyMemory ByVal lpData, arrBIHBuffer(0), 48
CopyMemory ByVal (lpData + 48), _
arrBMDataBuffer(0), uBIH.biSizeImage
GlobalUnlock hGMemMask
If SetClipboardData(cfBtnMask, hGMemMask) = 0 Then
GlobalFree hGMemMask
End If
End If
' We're done.
CloseClipboard
End Sub
(6)。按 F5 运行 Visual Basic 应用程序。单击命令按钮使 Word 自动化,添加新的工具栏和按钮,并粘贴具有透明度的位图图像。
关于c# - CommandBarButton 图标变黑背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12443977/
我正在使用 CSS background: url(stuffhere.jpeg)对于我的背景,但是当你点击其他视频时,“元素”不是页面,背景不会改变。 我试过了 和 ,并尝试为#home 和#pr
这两个 CSS 属性有区别吗: background: none; background: transparent; 它们都有效吗? 应该使用哪一个,为什么? 最佳答案 它们之间没有区别。 如果您没有
csslint 警告回退背景(十六进制或 RGB)应该在 RGBA 背景之前。"evidence="background: rgba(0, 0, 0, 0.8);/* FF3+,Saf3+,Opera
我在我正在制作的新网站上使用 Flip 插件: http://www.concept-it.be/padre (点击联系人,然后点击电子邮件地址)。 正如你所看到的,当翻转开始后,div 的背景变成灰
有没有办法使用“前后”图像作为全尺寸背景?我想会很棒!我正在尝试将此类示例用作整页大小的图像; http://www.catchmyfame.com/2009/06/25/jquery-beforea
我认为答案是否定的,但是... 有没有办法说: background-size: contain 90% 所以它的作用正是 contain 会做的,但是然后将它调整得更小一些? 最佳答案 理想的解决方
将鼠标悬停在给定文本的每个字母上将更改文本的整个字体 + 正文背景颜色。我试过了,但我的尝试失败了。相反,字体只在被悬停的字母之后发生变化,我什至不知道如何从 div 选择器中影响正文背景颜色。 .h
我想给我的 UITableView 提供背景图片,所以我尝试了这个方法: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional
我正在尝试使用 Python 3.6 使用 PIL/Numpy(每个屏幕截图~0.01s)快速截取准备处理的屏幕截图。理想情况下,窗口不需要位于前台,即即使另一个窗口覆盖它,屏幕截图仍然成功。 到目前
我正在尝试做一些可能不可能的事情,但让我们看看你怎么想。这是我的代码: html { background: url(../img/pattern.png) repeat, url(../im
一位设计师想出了这种类型的背景,如下图所示。我想避免使用图像背景。因此,如果可以使用 CSS background 属性复制它,我会努力思考。 最底层只是一个线性渐变,没有问题。但是在其之上分层的圆形
当 TreeView(或应用程序)失去焦点时,如何更改所选 TreeViewItem 的背景。在这种情况下,默认情况下选定的项目具有浅灰色背景。 编辑:第一个答案后的尝试:但是找不到带有 Target
一位设计师想出了这种类型的背景,如下图所示。我想避免使用图像背景。因此,如果可以使用 CSS background 属性复制它,我会努力思考。 最底层只是一个线性渐变,没有问题。但是在其之上分层的圆形
我需要有一个带有 CSS 的背景作为附加的图像我不能让它与线性渐变一起工作。 我正在尝试以下操作,但我无法仅创建 1 个白色条纹。 div { background: #5cbcb0; bac
我有一个ListView,它有一个页眉和页脚。它们在 CardView 中的布局。以及其中必须为背景的内容列表。这是一张可以清楚看到的图片:我现在是这样的: 以及如何做: 我这样做了,ScrollVi
我目前有一个 DIV,其背景图像设置如下: background: url(../images/site/common/body-bannar-bkground.png) repeat 0 0; 如何
我有一个 slider ,需要在不使用 .style.backgroundImage 的情况下更改背景。那么我该如何通过向 slider 或其他东西添加一些类来做到这一点呢? 'use strict'
好的,所以在 photoshop 中,我创建了一个具有透明背景和一些文本的 8 位彩色图像。然后我创建了一个具有透明背景和一些文本的 16 位颜色的图像。 当我右键单击两个图像并转到属性时,它显示两个
我有一个问题困扰着我,我似乎在 Google 上找不到答案。我用一段代码创建了一个小型测试应用程序,它执行如下操作: 在 MainActivity 中,我创建了一个 SomeClass 的实例,它有一
我想做这个, 在 Android Studio 的预览中看起来不错,但在运行时我得到这个 正如您在屏幕开头看到的那样,颜色是白色,我想添加我自己的颜色,在本例中为绿色。 最初它使用的是 Cordina
我是一名优秀的程序员,十分优秀!