4
.
///
可用于使用bitmap美化按钮,可以从一个bitmap文件中截出一块覆盖到目标button上。
BitBlt
函数
从称为「来源」的设备内容中将一个矩形区的图素传输到称为「目的
(destination)
」的另一个设备内容中相同大小的矩形区。此函数的语法如下:
BitBlt (hdcDst, xDst, yDst, cx, cy, hdcSrc, xSrc, ySrc, dwROP) ;
注:
hdcDst
目标区域的句柄
CDC
类型
xDst
,
yDst
目标区域的起始
x
坐标和
y
坐标
int
型
cx
,
cy
目标区域的结束
x
坐标和
y
坐标
int
型
hdcSrc
源区域的句柄
CDC
类型
xSrc
,
ySrc
源区域的开始
x
坐标和
y
坐标
int
型
dwROP
???
DWORD
类型
以上坐标均为相对坐标
BitBlt(tgtDC,x,y,cxSrc,cySrc,srcDC,0,0,SRCCOPY);
5
.
///
5
.关于自定义COM组件的几种调用方法。
环境:VS2003
1.
使用include
Include xxx.c
文件和xxx_i.c文件
2.
在C++中使用向导生成一个.h头文件
使用
vc.net
,步骤如下:
1
、建立一个
MFC
的应用程序
2
、执行菜单
“
添加
/
添加类
”
,选择
MFC
分类中的
“
类型库中的
MFC
类
”
图四、添加类型库中的
MFC
类
3
、选择组件文件
simple8.dll(
或
tlb
文件
)
,并选择需要包装的接口
3.
使用IDispatch
//
使用IDispatch时不需include文件,只需知道ProgID即可。主要在解释语言中调用COM时使用。
// ProgID
默认为 工程名.接口类名 例如:
ATLTest2.HongSimple
//
因为解释语言无法使用头文件
相关代码:
::CoInitialize( NULL ); // COM
初始化
CLSID clsid; //
通过 ProgID 得到 CLSID
HRESULT hr = ::CLSIDFromProgID( L"ATLTest2.HongSimple", &clsid );
ASSERT( SUCCEEDED( hr ) ); //
如果失败,说明没有注册组件
IDispatch * pDisp = NULL; //
由 CLSID 启动组件,并得到 IDispatch 指针
hr = ::CoCreateInstance( clsid, NULL, CLSCTX_ALL, IID_IDispatch, (LPVOID *)&pDisp );
ASSERT( SUCCEEDED( hr ) ); //
如果失败,说明没有初始化 COM
LPOLESTR pwFunName = L"Add"; //
准备取得 Add 函数的序号 DispID
//
此处函数名不区分大小写,因此也可以写为add --li
DISPID dispID; //
取得的序号,准备保存到这里
hr = pDisp->GetIDsOfNames( //
根据函数名,取得序号的函数
IID_NULL,
&pwFunName, //
函数名称的数组
1, //
函数名称数组中的元素个数
LOCALE_SYSTEM_DEFAULT, //
使用系统默认的语言环境
&dispID ); //
返回值
ASSERT( SUCCEEDED( hr ) ); //
如果失败,说明组件根本就没有 ADD 函数
。。。。。。。。
此处为调用add函数进行处理的代码
。。。。。。。。
pDisp
->Release(); //
释放接口指针
::CoUninitialize(); //
释放 COM
4
.以上方法
效率并不高,好像使
用#import 方式效率最高。
6
.
//
6.Dlg上的Button如何显示Tooltip?
环境:VS2003
前提:
自定义button类
class
MyButton : public CBitmapButton
假设自定义button类名为:mybutton
可以在类中加入成员变量
CToolTipCtrl m_ToolTip;
然后重载 PreSubClass(), PreTranslateMessage()
最后加入成员函数 SetToolTipText()
具体实现如下:
mybutton.h
class
MyButton : public CBitmapButton
{
......
protected:
static CToolTipCtrl m_ToolTip;
......
public:
//set tooltip
virtual void PreSubclassWindow();
virtual BOOL PreTranslateMessage(MSG* pMsg);
void SetToolTipText(LPCTSTR lpszToolTipText);
.....
};
mybutton.cpp
//CToolTipCtrl mybutton::m_ToolTip;
void mybutton::PreSubclassWindow()
{
if(!m_ToolTip.GetSafeHwnd())
m_ToolTip.Create(this);
m_ToolTip.AddTool(this);
CButton::PreSubclassWindow();
}
BOOL mybutton::PreTranslateMessage(MSG* pMsg)
{
m_ToolTip.RelayEvent(pMsg);
return CButton::PreTranslateMessage(pMsg);
}
void mybutton::SetToolTipText(LPCTSTR lpszToolTipText)
{
m_ToolTip.UpdateTipText(lpszToolTipText, this);
}
例如在一个dlg中设置button的tooltip,则实现如下:
xxx
Dlg.h
中
#include
"MyButton.h"
protected
:
MyButton m_btnTest;
xxx
Dlg.cpp
中
BOOL
xxxDlg::OnInitDialog()
{
CDialog::OnInitDialog();
。。。。。
。。。。。
m_btnTest
.SetToolTipText(L"Test");
。。。。
。。。。。
return
TRUE;
}