编辑框的背景色一般是白色的, 时间长了看起来比较费劲, 用vc自带的也可以改背景色, 这里提供一个更快捷的方案.
注意,for vc2010
1. 用vc2010建一个扩展项目
2. 创建该项目,按照下面图示走完向导。
3. 完成后项目建立, 依次修改
STDMETHODIMP CConnect::OnStartupComplete (SAFEARRAY ** /*自定义*/ ) // 项目加载后触发
和
STDMETHODIMP CConnect::Exec(BSTR bstrCmdName, vsCommandExecOption ExecuteOption, VARIANT * /*pvarVariantIn*/, VARIANT * /*pvarVariantOut*/, VARIANT_BOOL *pvbHandled) // 选择命令后触发
1 // 项目启动后触发
2 STDMETHODIMP CConnect::OnStartupComplete (SAFEARRAY ** /*自定义*/ )
3 {
4 //RunBackGroundChange();
5 CAddMyComment ac(m_pDTE);
6 COLORREF clrBlack = 0x00c2c2c2; // 银色
7 ac.SetColor(clrBlack);
8 ac.SetColor(clrBlack);
9
10 return S_OK;
11 }
STDMETHODIMP CConnect::Exec(BSTR bstrCmdName, vsCommandExecOption ExecuteOption, VARIANT * /*pvarVariantIn*/, VARIANT * /*pvarVariantOut*/, VARIANT_BOOL *pvbHandled)
{
*pvbHandled = VARIANT_FALSE;
if(ExecuteOption == vsCommandExecOptionDoDefault)
{
if(!_wcsicmp(bstrCmdName, L"backgroundchange.Connect.backgroundchange"))
{
RunBackGroundChange();
*pvbHandled = VARIANT_TRUE;
return S_OK;
}
}
return S_OK;
}
1
2 // 改变编辑器背景颜色
3 void CAddMyComment::ChangeFont(void)
4 {
5 CComPtr<EnvDTE::Properties> spProperties;
6
7 // Modify font size
8 m_spDTE->get_Properties(CComBSTR("FontsAndColors"), CComBSTR("TextEditor"), &spProperties);
9 CComPtr<EnvDTE::Property> spProperty;
10 spProperties->Item(CComVariant(L"FontSize"), &spProperty); // FontSize
11 ATLASSERT(spProperty);
12 spProperty->put_Value(CComVariant(11));
13
14 CComPtr<EnvDTE::Property> spProperty1;
15 spProperties->Item(CComVariant(CComBSTR(L"FontsAndColorsItems")), &spProperty1); // FontsAndColorsItems
16 ATLASSERT(spProperty1);
17 CComPtr<IDispatch> spDispatch;
18 spProperty1->get_Object(&spDispatch);
19 CComPtr<EnvDTE::FontsAndColorsItems> spFontsAndColorsItems;
20 spFontsAndColorsItems = spDispatch;
21 ATLASSERT(spFontsAndColorsItems);
22 #if 0
23 // 显示颜色命名
24 long count ;
25 spFontsAndColorsItems->get_Count(&count);
26 for(long i=0; i<count; ++i) {
27 CComPtr<EnvDTE::ColorableItems> spColor;
28 spFontsAndColorsItems->Item(CComVariant(i), &spColor);
29 if(spColor) {
30 CComBSTR bstrName;
31 spColor->get_Name(&bstrName);
32 ATLTRACE(L"[%d]%s\n",i, bstrName);
33 }
34 }
35 #endif
36
37 #if 1
38 // Modify Plain Text Background
39 CComPtr<EnvDTE::ColorableItems> spColorableItems_PlainText;
40 spFontsAndColorsItems->Item(CComVariant(1), &spColorableItems_PlainText);
41 CComPtr<EnvDTE::ColorableItems> spColorableItems_LineNumber;
42 spFontsAndColorsItems->Item(CComVariant(5), &spColorableItems_LineNumber);
43 //CComPtr<EnvDTE::ColorableItems> spColorableItems_Identifier;
44 //spFontsAndColorsItems->Item(CComVariant(L"Identifier"), &spColorableItems_Identifier);
45
46 COLORREF clrWhite = #ffffff;
47 COLORREF clrBlack = #000000;
48 clrBlack = 0x00c2c2c2; // 银色
49 COLORREF clrWhite2 = 12632256;
50 clrWhite2 = clrWhite;
51 OLE_COLOR color;
52 spColorableItems_PlainText->get_Background(&color);
53 if(color == clrBlack) {
54 spColorableItems_PlainText->put_Background(clrWhite);
55 spColorableItems_LineNumber->put_Background(clrWhite);
56 //spColorableItems_PlainText->put_Foreground(clrBlack);
57 }else {
58 spColorableItems_PlainText->put_Background(clrBlack);
59 spColorableItems_LineNumber->put_Background(clrBlack);
60 //spColorableItems_PlainText->put_Foreground(clrWhite2);
61 }
62 #endif
63 }
64
4. 执行命令, 进入项目后, 在菜单工具下会创建一个菜单项
点选后, 会在白色背景和银色间切换, 初始会进入银色背景。
5. 可直接使用msi安装包安装该插件, 同时该附件包含源代码
/Files/wangkang2009/backgroundchange.rar
posted on 2013-04-17 14:55
wangkang 阅读(2158)
评论(0) 编辑 收藏 引用