MFC Edit重绘后,设置password属性受影响

tsmaomaoyu 2015-06-10 04:17:31
Edit重绘后,设置password属性,可以把输入密码显示为“*”,但如果用鼠标选中输入的密码,然后点击其他控件如Edit或者是Button,密码就会显示为明文,再把鼠标点击设置为password的edit,又会变为***
有没有大神遇到过呢,听说是在重绘的时候需要设置一下属性,但我一直没查到是怎么设置的,求解
另外,我重绘的combobox,设置为Drop List格式之后,不能再使用SetCurSel(x)来设置默认选项了,否则就会出错崩溃,应该也是因为重绘的问题
...全文
238 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tsmaomaoyu 2015-06-12
  • 打赏
  • 举报
回复
引用 6 楼 kongling16688 的回复:
[quote=引用 5 楼 tsmaomaoyu 的回复:]
引用
[quote=引用 2 楼 kongling16688 的回复:] 楼上+1. 重绘的话最好自己实现一下加密效果。 至于combox那个,应该是你代码有问题,把代码贴上来看看。
设置dropdown和droplist是有哪些区别呢?上面的代码,设置为droplist除了设置默认选项外,其他功能都很好;设置为dropdown的话,可以设置默认选项了,但是,鼠标滑动的时候就没有我设置好的高亮显示了[/quote] 鼠标划过的高亮可以参考这个帖子。 http://blog.csdn.net/visualeleven/article/details/6622248[/quote] 用帖子的方法试过了,这个也是设置为dropdown的话可以高亮,设置为droplist就不行了
风若飞 2015-06-11
  • 打赏
  • 举报
回复
引用 5 楼 tsmaomaoyu 的回复:
引用
[quote=引用 2 楼 kongling16688 的回复:] 楼上+1. 重绘的话最好自己实现一下加密效果。 至于combox那个,应该是你代码有问题,把代码贴上来看看。
设置dropdown和droplist是有哪些区别呢?上面的代码,设置为droplist除了设置默认选项外,其他功能都很好;设置为dropdown的话,可以设置默认选项了,但是,鼠标滑动的时候就没有我设置好的高亮显示了[/quote] 鼠标划过的高亮可以参考这个帖子。 http://blog.csdn.net/visualeleven/article/details/6622248
tsmaomaoyu 2015-06-10
  • 打赏
  • 举报
回复
引用
引用 2 楼 kongling16688 的回复:
楼上+1. 重绘的话最好自己实现一下加密效果。 至于combox那个,应该是你代码有问题,把代码贴上来看看。
设置dropdown和droplist是有哪些区别呢?上面的代码,设置为droplist除了设置默认选项外,其他功能都很好;设置为dropdown的话,可以设置默认选项了,但是,鼠标滑动的时候就没有我设置好的高亮显示了
tsmaomaoyu 2015-06-10
  • 打赏
  • 举报
回复
引用 1 楼 happyparrot 的回复:
既然都已经重绘了,干脆不要用文本框自带的加密效果,自己封装在这个文本控件中就行了。如果设定为加密效果,自己显示时用*号显示
第一次做项目,对于什么都是两把刀,我刚才自己搜资料也没有搜到,大神能不能给个参考代码呢
tsmaomaoyu 2015-06-10
  • 打赏
  • 举报
回复
#include "stdafx.h" #include "TEST.h" #include "McomboBox.h" int nListBoxTextLeft = 0; static WNDPROC m_pWndProc = 0; extern "C" LRESULT FAR PASCAL BitComboBoxListBoxProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam) { //TRACE("BitComboBoxListBoxProc 0x%.4X\n",nMsg); return CallWindowProc(m_pWndProc, hWnd, nMsg, wParam, lParam); } McomboBox::McomboBox() { m_nIDLeft = m_nIDRight = m_nIDCenter = 0; m_nIDListLeft, m_nIDListRight, m_nIDListTop, m_nIDListBot = 0; } McomboBox::~McomboBox() { } BEGIN_MESSAGE_MAP(McomboBox, CComboBox) //{{AFX_MSG_MAP(CBitComboBox) ON_WM_PAINT() ON_WM_DESTROY() ON_WM_ERASEBKGND() ON_WM_SETFOCUS() //}}AFX_MSG_MAP ON_MESSAGE(WM_CTLCOLORLISTBOX, OnCtlColorListBox) END_MESSAGE_MAP() LRESULT McomboBox::OnCtlColorListBox(WPARAM wParam, LPARAM lParam) { // Here we need to get a reference to the listbox of the combobox // (the dropdown part). We can do it using //TRACE("OnCtlColorListBox()\n"); if (this->m_listbox.m_hWnd == 0) { HWND hWnd = (HWND)lParam; if (hWnd != 0 && hWnd != m_hWnd) { // Save the handle m_listbox.m_hWnd = hWnd; // Subclass ListBox m_pWndProc = (WNDPROC)GetWindowLong(m_listbox.m_hWnd, GWL_WNDPROC); SetWindowLong(m_listbox.m_hWnd, GWL_WNDPROC, (LONG)BitComboBoxListBoxProc); } } return DefWindowProc(WM_CTLCOLORLISTBOX, wParam, lParam); } #define SET_ZERO(X) memset((void *)&X,0,sizeof(X)); void McomboBox::OnPaint() { CPaintDC dc(this); // device context for painting RECT rc; CDC MemDC; GetClientRect(&rc); MemDC.CreateCompatibleDC(&dc); CBitmap bmpComboRight,bmpComboLeft, bmpComboCenter,bmpComboBot; BITMAP bitRight, bitLeft, bitCenter; SET_ZERO(bitRight); SET_ZERO(bitLeft); SET_ZERO(bitCenter); if( m_nIDLeft ) { bmpComboLeft.LoadBitmap(m_nIDLeft); bmpComboLeft.GetBitmap(&bitLeft); MemDC.SelectObject(bmpComboLeft); dc.BitBlt(rc.left,rc.top,bitLeft.bmWidth,bitLeft.bmHeight,&MemDC,0,0,SRCCOPY); } if( m_nIDRight ) { bmpComboRight.LoadBitmap(m_nIDRight); bmpComboRight.GetBitmap(&bitRight); MemDC.SelectObject(bmpComboRight); dc.BitBlt(rc.right-bitRight.bmWidth,rc.top,bitRight.bmWidth,bitRight.bmHeight,&MemDC,0,0,SRCCOPY); } if( m_nIDCenter ) { bmpComboCenter.LoadBitmap(m_nIDCenter); bmpComboCenter.GetBitmap(&bitCenter); MemDC.SelectObject(bmpComboCenter); dc.StretchBlt(rc.left+bitLeft.bmWidth,rc.top,rc.right-bitLeft.bmWidth-bitRight.bmWidth,bitCenter.bmHeight,&MemDC,0,0,bitCenter.bmWidth,bitCenter.bmHeight,SRCCOPY); } CString sz; GetWindowText(sz); rc.left += nListBoxTextLeft; //Select the font only if list box is created if( m_listbox ) dc.SelectObject(m_listbox.GetFont()); dc.SetBkMode(TRANSPARENT); RECT rcRepaint; GetClientRect(&rcRepaint); rcRepaint.left = rcRepaint.left + bitLeft.bmWidth; rcRepaint.right = rcRepaint.right - bitRight.bmWidth; rcRepaint.top += 3; rcRepaint.bottom -= 8; //Set the normal/highlight color when its repainted if( GetFocus()->m_hWnd == m_hWnd ) { dc.FillSolidRect(&rcRepaint,m_colBackGroundHighLight); dc.SetTextColor(m_colTextHighLight); TRACE("Filling rect again on focus high\n"); } else { dc.FillSolidRect(&rcRepaint,m_colBackGroundNormal); dc.SetTextColor(m_colTextNormal); TRACE("Filling rect again on focus normal\n"); } dc.DrawText(sz,&rc,DT_VCENTER | DT_SINGLELINE); if( m_listbox ) { //TRACE("Painting the listbox\n"); CDC *pDC = m_listbox.GetDC(); m_listbox.GetClientRect(&rc); CBrush pBrush; pBrush.CreateSolidBrush(m_colBackGroundNormal); m_listbox.GetDC()->FillRect(&rc,&pBrush); //Draw the left side of the list box DrawListLeft(); //Draw the right side of the list box DrawListRight(); //Draw the top of the list bar DrawListTop(); //Draw the bottom of the list bar DrawListBot(); pDC->SetTextColor(m_colTextNormal); CBrush brItemData; RECT rcItemData; CString szItemString; brItemData.CreateSolidBrush(m_colBackGroundNormal); for(int i =0;i<m_listbox.GetCount();i++) { m_listbox.GetText(i,szItemString); m_listbox.GetItemRect(i,&rcItemData); rcItemData.left += bitLeft.bmWidth+5; pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(m_colTextNormal); nListBoxTextLeft = rcItemData.left; //CFont* def_font = pDC->SelectObject(&m_Font); pDC->SelectObject(m_listbox.GetFont()); pDC->DrawText(szItemString,&rcItemData, DT_VCENTER | DT_SINGLELINE); //pDC->SelectObject(def_font); } } } BOOL McomboBox::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { // TODO: Add your specialized code here and/or call the base class // Remove the CBS_SIMPLE and CBS_DROPDOWN styles and add the one I'm designed for dwStyle &= ~0xF; dwStyle |= CBS_DROPDOWNLIST; // Make sure to use the CBS_OWNERDRAWVARIABLE style dwStyle |= CBS_OWNERDRAWVARIABLE; // Use default strings. We need the itemdata to store the state of the lamps dwStyle |= CBS_HASSTRINGS; dwStyle |= CBS_DROPDOWN; return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext); } void McomboBox::OnDestroy() { if (m_listbox.GetSafeHwnd() != NULL) m_listbox.UnsubclassWindow(); CComboBox::OnDestroy(); } void McomboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your code to draw the specified item //TRACE("DrawItem()\n"); if( lpDrawItemStruct->itemID == -1 ) return; CDC pDC; pDC.Attach(lpDrawItemStruct->hDC); CBrush pBrush; CString sItem; if(lpDrawItemStruct->itemState & ODS_FOCUS) { pBrush.CreateSolidBrush(m_colBackGroundHighLight); pDC.FillRect(&lpDrawItemStruct->rcItem, &pBrush); pDC.SetTextColor(m_colTextHighLight); } else { pBrush.CreateSolidBrush(m_colBackGroundNormal); pDC.FillRect(&lpDrawItemStruct->rcItem, &pBrush); pDC.SetTextColor(m_colTextNormal); } //Draw the left image of the list box DrawListLeft(); //Draw the right image of the list box DrawListRight(); //Draw the bottom for the last item if( lpDrawItemStruct->itemID == m_listbox.GetCount()-1 ) DrawListBot(); //Draw the top for the first item if( lpDrawItemStruct->itemID == 0 ) DrawListTop(); // Copy the text of the item to a string this->GetLBText(lpDrawItemStruct->itemID, sItem); pDC.SetBkMode(TRANSPARENT); // Draw the text after the images left postion lpDrawItemStruct->rcItem.left = nListBoxTextLeft; pDC.SelectObject(m_listbox.GetFont()); pDC.DrawText(sItem, &lpDrawItemStruct->rcItem, DT_VCENTER | DT_SINGLELINE); } void McomboBox::SetComboBitmap(UINT nIDLeft, UINT nIDRight, UINT nIDCenter) { m_nIDCenter = nIDCenter; m_nIDLeft = nIDLeft; m_nIDRight = nIDRight; } void McomboBox::SetComboListBitmap(UINT nIDListLeft, UINT nIDListRight, UINT nIDListTop, UINT nIDListBot) { m_nIDListLeft = nIDListLeft; m_nIDListRight = nIDListRight, m_nIDListTop = nIDListTop, m_nIDListBot = nIDListBot; } void McomboBox::DrawListLeft(int nHeight) { RECT rc; CDC MemDC; CDC *pDC = m_listbox.GetDC(); MemDC.CreateCompatibleDC(pDC); m_listbox.GetClientRect(&rc); CBitmap bmpImage; BITMAP bitImage; if( m_nIDListLeft ) { bmpImage.LoadBitmap(m_nIDListLeft); bmpImage.GetBitmap(&bitImage); MemDC.SelectObject(bmpImage); pDC->StretchBlt(rc.left,rc.top,bitImage.bmWidth,rc.bottom,&MemDC,0,0,bitImage.bmWidth,bitImage.bmHeight,SRCCOPY); } } void McomboBox::DrawListRight(int nHeight) { RECT rc; CDC MemDC; CDC *pDC = m_listbox.GetDC(); MemDC.CreateCompatibleDC(pDC); m_listbox.GetClientRect(&rc); CBitmap bmpImage; BITMAP bitImage; if( m_nIDListRight ) { bmpImage.LoadBitmap(m_nIDListRight); bmpImage.GetBitmap(&bitImage); MemDC.SelectObject(bmpImage); pDC->StretchBlt(rc.right-bitImage.bmWidth,rc.top,bitImage.bmWidth,rc.bottom,&MemDC,0,0,bitImage.bmWidth,bitImage.bmHeight,SRCCOPY); } } void McomboBox::DrawListTop(int nWidth) { RECT rc; CDC MemDC; CDC *pDC = m_listbox.GetDC(); MemDC.CreateCompatibleDC(pDC); m_listbox.GetClientRect(&rc); CBitmap bmpImage; BITMAP bitImage; if( m_nIDListTop ) { bmpImage.LoadBitmap(m_nIDListTop); bmpImage.GetBitmap(&bitImage); MemDC.SelectObject(bmpImage); pDC->StretchBlt(rc.left,rc.top,rc.right,bitImage.bmHeight,&MemDC,0,0,bitImage.bmWidth,bitImage.bmHeight,SRCCOPY); } } void McomboBox::DrawListBot(int nWidth) { //Width must be check, sometimes we may not need to stretch to the whole control's width RECT rc; CDC MemDC; CDC *pDC = m_listbox.GetDC(); MemDC.CreateCompatibleDC(pDC); m_listbox.GetClientRect(&rc); CBitmap bmpImage; BITMAP bitImage; if( m_nIDListBot ) { bmpImage.LoadBitmap(m_nIDListBot); bmpImage.GetBitmap(&bitImage); MemDC.SelectObject(bmpImage); pDC->StretchBlt(rc.left,rc.bottom-bitImage.bmHeight,rc.right,bitImage.bmHeight,&MemDC,0,0,bitImage.bmWidth,bitImage.bmHeight,SRCCOPY); } } void McomboBox::SetHighlightColor(COLORREF colBackGround, COLORREF colText) { m_colBackGroundHighLight = colBackGround; m_colTextHighLight = colText; } void McomboBox::SetNormalPositionColor(COLORREF colBackGround, COLORREF colText) { m_colBackGroundNormal = colBackGround; m_colTextNormal = colText; } 以上是重绘实现的代码,使用dropdown的时候可以设置默认选项,设置为droplist就不行了
风若飞 2015-06-10
  • 打赏
  • 举报
回复
楼上+1. 重绘的话最好自己实现一下加密效果。 至于combox那个,应该是你代码有问题,把代码贴上来看看。
快乐鹦鹉 2015-06-10
  • 打赏
  • 举报
回复
既然都已经重绘了,干脆不要用文本框自带的加密效果,自己封装在这个文本控件中就行了。如果设定为加密效果,自己显示时用*号显示

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧