void CMyEdit::OnSetFocus(CWnd* pOldWnd)
{
CEdit::OnSetFocus(pOldWnd);
// TODO: Add your message handler code here
ModifyStyleEx(0, WS_EX_RIGHT);
RedrawWindow();
}void CMyEdit::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
// TODO: Add your message handler code here
ModifyStyleEx(WS_EX_RIGHT, 0);
RedrawWindow();
}以上代码为什么无效?
{
CEdit::OnSetFocus(pOldWnd);
// TODO: Add your message handler code here
ModifyStyleEx(0, WS_EX_RIGHT);
RedrawWindow();
}void CMyEdit::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
// TODO: Add your message handler code here
ModifyStyleEx(WS_EX_RIGHT, 0);
RedrawWindow();
}以上代码为什么无效?
解决方案 »
- 请问关于简单的视图分割的问题
- 如何修改TIME_WAIT状态的维持时间?
- 重命名CListCtrl的Item无法响应退格键的问题
- 做一个程序在98的时候启动 然后锁住桌面 用户不能操作 像网吧里的一样 请问如何实现
- 关于lib的连接错误
- 关于WinExec函数的运用
- 用VC建立一个ODBC程序后,怎样更新数据库?
- 《windows网络编程技术〉中的疑问:usage()??
- 写串口操作//在WaitForSingleObject添加清空缓冲区purgecom函数对吗???
- 服务启动无法创建快捷方式
- 再问关于InstallShield的问题,完成后我些总结给大家。暂时只有30分了
- 关于GetFieldValue的问题
我现在的机器没有ntddk和VS.net,ie是5.0版本。我现在不清楚是代码问题还是环境问题了。因为我在codeproject上是看到了修改WS_EX_....属性的示范代码的,不过那只是擦边球,而且语焉不详。
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CEdit* pEditLeft=(CEdit*)GetDlgItem(IDC_EDIT1);
CRect rect;
pEditLeft->GetWindowRect(rect);
ScreenToClient(rect);
m_EditRight.CreateEx(WS_EX_CLIENTEDGE,"edit",NULL,
WS_CHILD|ES_RIGHT,rect,this,IDC_EDIT2);
m_EditRight.SetFont(pEditLeft->GetFont(),false); //两个edit设为相同的字体
return TRUE;
}void CAboutDlg::OnChangealign()
{
// TODO: Add your control notification handler code here
CWnd* pLeft=GetDlgItem(IDC_EDIT1);
CWnd* pRight=GetDlgItem(IDC_EDIT2);
if(pLeft->IsWindowVisible())//如果右对齐的显示,则隐藏;否则隐藏左对齐的那个
{
pLeft->ShowWindow(false);
pRight->ShowWindow(true);
//设置edit的内容,如果是multiline的edit,有一种更简单的办法,就是在创建的时候用SetHandle和GetHandle把它们的缓冲区设为相同,这样就不用每次去GetWindowText和SetWindowText
CString text;
pLeft->GetWindowText(text);
pRight->SetWindowText(text);
}
else
{
pLeft->ShowWindow(true);
pRight->ShowWindow(false);
CString text;
pRight->GetWindowText(text);
pLeft->SetWindowText(text);
}
}
我试了一下,好像没变化。to JennyVenus():
ModifyStyleEx和ModifyStyle最后都是通过调用SetWindowLong来实现的,所以这个应该没区别。to webber84(***闭关修炼中***):
创建一个隐藏一个的方法我知道,在codeproject上有这种实现方法。你可以参考一下下面这个连接:http://www.codeguru.com/editctrl/BorderEdit.shtml
另外,如果确实对齐方式不能改(我记错了的话),那哪些exStyle可以改,哪些不可以改呢?有相关的资料吗?
至于哪些可以改,我想可以改的是多数,需要的时候你尽管用,如果实现有问题再回过来想办法。我也没有见过相关的资料。
可能我们的msdn版本都太旧了
The window has generic "right-aligned" properties. This depends on the window class. This style has an effect only if the shell language is Hebrew, Arabic, or another language that supports reading-order alignment; otherwise, the style is ignored.
Using the WS_EX_RIGHT style for static or edit controls has the same effect as using the SS_RIGHT or ES_RIGHT style, respectively. Using this style with button controls has the same effect as using BS_RIGHT and BS_RIGHTBUTTON styles. 文章里说ES_RIGHT和WS_EX_RIGHT是等效的。