HBRUSH CffffDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{....
if(pWnd->GetDlgCtrlID()==IDC_EDIT1);
//pDC->SetTextCharacterExtra(20);//正确
(edit.GetDC())->SetTextCharacterExtra(20);//不正确(edit为控件变量)
...
}
pDC和(edit.GetDC())为什么不同.应该相同啊同一个控件的CDC指针啊!
{....
if(pWnd->GetDlgCtrlID()==IDC_EDIT1);
//pDC->SetTextCharacterExtra(20);//正确
(edit.GetDC())->SetTextCharacterExtra(20);//不正确(edit为控件变量)
...
}
pDC和(edit.GetDC())为什么不同.应该相同啊同一个控件的CDC指针啊!
而这里的pDC为参数,在CEdit重画时还有效
The SetTextCharacterExtra function sets the intercharacter spacing. Intercharacter spacing is added to each character, including break characters, when the system writes a line of text. int SetTextCharacterExtra(
HDC hdc, // handle to DC
int nCharExtra // extra-space value
);
Parameters
hdc
[in] Handle to the device context.
nCharExtra
[in] Specifies the amount of extra space, in logical units, to be added to each character. If the current mapping mode is not MM_TEXT, the nCharExtra parameter is transformed and rounded to the nearest pixel.
Return Values
If the function succeeds, the return value is the previous intercharacter spacing. If the function fails, the return value is 0x80000000. Windows NT/2000/XP: To get extended error information, call GetLastError.Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Wingdi.h; include Windows.h.
Library: Use Gdi32.lib.
VC中的GDI操作,操作在什么地方主要还是看DC的类型和DC的所有者。
大哥都看看msnd才回答,不要乱说啊!
我查过了也有人问过,只是没人解释过都是骗分的.所以我只好旧时从提了.
如果pDC一直是对话框的DC指针的话,我在上面if内加入pdc->textout(1,1,"反");
输出的字符怎么会在控件(1,1)位置显示呢?答案只有一个pdc是控件的.
edit.GetDC()->textout(1,1,"反");的效果是一样的.请大家思考后回答.
答对的分数任你要,前提斑竹不反对.
不过GetDC是获得的客户区的DC,每一次访问都不一定一样。OnCtlColor参数中的pDC在MSDN中的定义是:
Contains a pointer to the display context for the child window. May be temporary.并不是客户区的DC,这可能就是差别所在。另外,pDC的句柄和GetDC得到的DC指针的句柄根本不一样,所以在操作上当然会有不同的结果。
The framework calls this member function when a child control is about to be drawn. Most controls send this message to their parent (usually a dialog box) to prepare the pDC for drawing the control using the correct colors.
Here pDC may be temporary
不用pDC的话,可能就用系统默认的,结果
(edit.GetDC())->SetTextCharacterExtra(20);的效果就看不出
GetDC方法获得的是与该窗口关联的临时的设备上下文对象,不能保存以供长期使用。而设备上下文句柄由windows系统保存着,可以随时从窗口句柄出发获得。这种临时的设备上下文对象在线程进入空闲消息处理时,由MFC自动清理。
afx_msg HBRUSH OnCtlColor(
CDC* pDC,
CWnd* pWnd,
UINT nCtlColor
);
Parameters
pDC
Contains a pointer to the display context for the child window. May be temporary.但是,它们并不是相同的东西!!!!
用
TRACE("(%x,%x)",pDC,(m_editCtrl.GetDC()));
就可以发现了。