1、CListCtrl自定义控件的列分割栏拖动
项目中自定义一个可编辑子项目的CListCtrl控件,因为需要在拖动列分割栏时取消编辑状态,所以
定义了一个HDN_BEGINTRACK事件,发现拖动后会留下一条竖线,于是GOOGLE,一篇英文文章上提供了解
定义了一个HDN_BEGINTRACK事件,发现拖动后会留下一条竖线,于是GOOGLE,一篇英文文章上提供了解
决方法,其实很简单,就是只需在重载的OnNotify事件内处理就行了,例子如下:
BOOL CEditListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
LPNMHDR pNMHDR = (LPNMHDR)lParam;
BOOL CEditListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
LPNMHDR pNMHDR = (LPNMHDR)lParam;
if(pNMHDR->code == HDN_BEGINTRACKA || pNMHDR->code == HDN_BEGINTRACKW || pNMHDR-
>code == NM_CLICK){
//LPNMHEADER phdr = reinterpret_cast(pNMHDR);
CancelEdit(); //取消编辑状态
}
//LPNMHEADER phdr = reinterpret_cast
CancelEdit(); //取消编辑状态
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
}
2、自定义控件的字体
SetFont参数的字体变量需是程序运行时候一直存在的变量,不可以是局部变量,否则不能更改自定义控件的字体格式。
3、加载指定尺寸的图标
如下面的例子是加载16×16的资源ID为IDI_ADD的图标
(HICON)::LoadImage(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ADD), IMAGE_ICON, 16, 16, LR_SHARED);
如下面的例子是加载16×16的资源ID为IDI_ADD的图标
(HICON)::LoadImage(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ADD), IMAGE_ICON, 16, 16, LR_SHARED);
4、关于DestroyWindow
当CreateWindow了一个子窗口,包括使用CDialog::Create创建一个WS_CHILD风格的对话框,父窗口终
当CreateWindow了一个子窗口,包括使用CDialog::Create创建一个WS_CHILD风格的对话框,父窗口终
止时候不需要显示调用子窗口的DestroyWindow;但是若子窗口申请了内存,则需要重载子窗口的
DestroyWindow函数释放内存,且需要在父窗口终止时显示调用子窗口的DestroyWindow。
5、发送WM_LBUTTONDOWN消息
发送WM_LBUTTONDOWN消息模拟鼠标按下,不能使用SendMessage,而应使用PostMessage,原因暂无时间了解。
发送WM_LBUTTONDOWN消息模拟鼠标按下,不能使用SendMessage,而应使用PostMessage,原因暂无时间了解。
6、关于宏定义中的字符连接
当一个宏定义语句定义了一个字符串,其中需用到或者说连接其他宏定义的字符串,那么这时需使用双井号,如下例子:
#define LOCALDB_TABLENAME "mt_flux"
#define LOCALDB_FN_UPLOADFLAG "uploadflag"
#define LOCALDB_FN_FLUXNO "fluxno"
#define LOCALDB_SETUPLOAD_SQL \
"UPDATE "##LOCALDB_TABLENAME" SET "##LOCALDB_FN_UPLOADFLAG "=1 WHERE "##LOCALDB_FN_FLUXNO"=?"
"UPDATE "##LOCALDB_TABLENAME" SET "##LOCALDB_FN_UPLOADFLAG "=1 WHERE "##LOCALDB_FN_FLUXNO"=?"
7、LogFont与CharFormat互相转换(来源:http://blog.csdn.net/carl2380/article/details/3237391)
way1:
CFontDialog::getcharformat
way2:
void CTextLine::ChangeLogFontToCharFormat(CHARFORMAT &cf, const LOGFONT lf, const COLORREF textcolor)
{
//CFE_AUTOCOLOR
cf.dwMask = CFM_BOLD|CFM_CHARSET|CFM_COLOR|CFM_FACE|CFM_ITALIC|/
CFM_SIZE|CFM_UNDERLINE|CFM_STRIKEOUT;
BOOL bIsItalic = lf.lfItalic ;
BOOL bIsBold = (lf.lfWeight > FW_BOLD);//? FW_NORMAL:FW_BOLD;
BOOL bIsUnderline = lf.lfUnderline ;
BOOL bIsStrickout = lf.lfStrikeOut ;
{
//CFE_AUTOCOLOR
cf.dwMask = CFM_BOLD|CFM_CHARSET|CFM_COLOR|CFM_FACE|CFM_ITALIC|/
CFM_SIZE|CFM_UNDERLINE|CFM_STRIKEOUT;
BOOL bIsItalic = lf.lfItalic ;
BOOL bIsBold = (lf.lfWeight > FW_BOLD);//? FW_NORMAL:FW_BOLD;
BOOL bIsUnderline = lf.lfUnderline ;
BOOL bIsStrickout = lf.lfStrikeOut ;
cf.dwEffects |= CFE_PROTECTED;
cf.dwEffects &= ~CFE_AUTOCOLOR;
if (bIsBold)
cf.dwEffects |= CFE_BOLD;
else
cf.dwEffects &= ~CFE_BOLD;
cf.dwEffects &= ~CFE_AUTOCOLOR;
if (bIsBold)
cf.dwEffects |= CFE_BOLD;
else
cf.dwEffects &= ~CFE_BOLD;
if (bIsItalic)
cf.dwEffects |= CFE_ITALIC;
else
cf.dwEffects &= ~CFE_ITALIC;
if (bIsUnderline)
cf.dwEffects |= CFE_UNDERLINE;
else
cf.dwEffects &= ~CFE_UNDERLINE;
cf.dwEffects |= CFE_ITALIC;
else
cf.dwEffects &= ~CFE_ITALIC;
if (bIsUnderline)
cf.dwEffects |= CFE_UNDERLINE;
else
cf.dwEffects &= ~CFE_UNDERLINE;
if (bIsStrickout)
cf.dwEffects |= CFM_STRIKEOUT;
else
cf.dwEffects &= ~CFM_STRIKEOUT;
//设置属性
cf.yHeight = -15 * lf.lfHeight;
cf.crTextColor = textcolor;//;//m_Font_Color;
cf.bCharSet = lf.lfCharSet ;
cf.bPitchAndFamily = lf.lfPitchAndFamily ;
sprintf(cf.szFaceName, lf.lfFaceName);
}
cf.dwEffects |= CFM_STRIKEOUT;
else
cf.dwEffects &= ~CFM_STRIKEOUT;
//设置属性
cf.yHeight = -15 * lf.lfHeight;
cf.crTextColor = textcolor;//;//m_Font_Color;
cf.bCharSet = lf.lfCharSet ;
cf.bPitchAndFamily = lf.lfPitchAndFamily ;
sprintf(cf.szFaceName, lf.lfFaceName);
}
void CTextLine::ChangeCharFormatToLogFont(CHARFORMAT cf, LOGFONT &lf, COLORREF &textcolor)
{
{
lf.lfOutPrecision = 3;
lf.lfClipPrecision =2;
lf.lfQuality = 1;
//粗体
if ((cf.dwEffects &CFE_BOLD )>0)
lf.lfWeight = 700;
else
lf.lfWeight = 400;
lf.lfClipPrecision =2;
lf.lfQuality = 1;
//粗体
if ((cf.dwEffects &CFE_BOLD )>0)
lf.lfWeight = 700;
else
lf.lfWeight = 400;
//斜体
if ((cf.dwEffects &CFE_ITALIC)>0)
lf.lfItalic = 1;
else
lf.lfItalic = 0;
if ((cf.dwEffects &CFE_ITALIC)>0)
lf.lfItalic = 1;
else
lf.lfItalic = 0;
//下划线
if ((cf.dwEffects & CFE_UNDERLINE)>0)
lf.lfUnderline = 1;
else
lf.lfUnderline = 0;
//删除线
if ((cf.dwEffects & CFE_STRIKEOUT)>0)
lf.lfStrikeOut = 1;
else
lf.lfStrikeOut =0;
lf.lfHeight = (-cf.yHeight/15);
textcolor = cf.crTextColor;
lf.lfCharSet = cf.bCharSet;
lf.lfPitchAndFamily = cf.bPitchAndFamily;
sprintf(lf.lfFaceName, cf.szFaceName);}
if ((cf.dwEffects & CFE_STRIKEOUT)>0)
lf.lfStrikeOut = 1;
else
lf.lfStrikeOut =0;
lf.lfHeight = (-cf.yHeight/15);
textcolor = cf.crTextColor;
lf.lfCharSet = cf.bCharSet;
lf.lfPitchAndFamily = cf.bPitchAndFamily;
sprintf(lf.lfFaceName, cf.szFaceName);}