duilib 自定义控件,如何控制CWindowWnd跟着移动

simple 2020-06-08 07:52:00
自己写控件UIEditCombo,支持编辑,随着Edit内容的变化,下拉菜单的选项也会变化,会选择Edit的内容相关的选项;
控件都编写好了,但碰到问题:
当鼠标按住标题移动时,combo选项的窗口不会跟着一起移动,或者是关闭combo窗口(但没有消息通知killfocus)


一直找不到方法,求思路和方法;
...全文
954 34 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
34 条回复
切换为时间正序
请发表友善的回复…
发表回复
simple 2020-07-07
  • 打赏
  • 举报
回复
引用 33 楼 zjq9931 的回复:
我后面写一个简单点的吧。
期待
  • 打赏
  • 举报
回复
引用 31 楼 simple 的回复:
用的是第一种方法,窗口收到移动的时候,把焦点设置到窗口,让EditCombo丢失焦点;
但这样破坏了封装,不在你们有没有更好的方法;


我后面写一个简单点的吧。
simple 2020-07-06
  • 打赏
  • 举报
回复
引用 30 楼 zjq9931 的回复:
[quote=引用 29 楼 simple 的回复:]下载地址:https://download.csdn.net/download/Cyd520608/12578454
下载了,在我这边编译,运行是正常的。win10 vs2015 也就是下拉后,点击标题栏移动窗口,下拉的窗口会消失掉。再次下拉时,会出现在正确的位置上。 或者说你已经改好了? [/quote] 用的是第一种方法,窗口收到移动的时候,把焦点设置到窗口,让EditCombo丢失焦点; 但这样破坏了封装,不在你们有没有更好的方法;
  • 打赏
  • 举报
回复
引用 29 楼 simple 的回复:
下载地址:https://download.csdn.net/download/Cyd520608/12578454

下载了,在我这边编译,运行是正常的。win10 vs2015
也就是下拉后,点击标题栏移动窗口,下拉的窗口会消失掉。再次下拉时,会出现在正确的位置上。

或者说你已经改好了?
  • 打赏
  • 举报
回复
引用 31 楼 simple 的回复:
[quote=引用 30 楼 zjq9931 的回复:][quote=引用 29 楼 simple 的回复:]下载地址:https://download.csdn.net/download/Cyd520608/12578454

下载了,在我这边编译,运行是正常的。win10 vs2015
也就是下拉后,点击标题栏移动窗口,下拉的窗口会消失掉。再次下拉时,会出现在正确的位置上。

或者说你已经改好了?
[/quote]
用的是第一种方法,窗口收到移动的时候,把焦点设置到窗口,让EditCombo丢失焦点;
但这样破坏了封装,不在你们有没有更好的方法;[/quote]

没有太好的办法。暂时想不到。
simple 2020-07-05
  • 打赏
  • 举报
回复
https://blog.csdn.net/Cyd520608/article/details/107134957 demo也发上去了,但还在审核,后面在发上来
simple 2020-07-05
  • 打赏
  • 举报
回复
下载地址:https://download.csdn.net/download/Cyd520608/12578454
  • 打赏
  • 举报
回复
引用 26 楼 simple 的回复:
[quote=引用 24 楼 zjq9931 的回复:]
CEditComboUI
的实现没有发。

代码太多,2000+行,一次才能发300行。。。
周末的时候我弄到博客上去[/quote]
嗯,到时候研究一下。
simple 2020-07-02
  • 打赏
  • 举报
回复
引用 24 楼 zjq9931 的回复:
CEditComboUI 的实现没有发。
代码太多,2000+行,一次才能发300行。。。 周末的时候我弄到博客上去
xiaohuh421 2020-07-01
  • 打赏
  • 举报
回复
点击标题栏的时候, 应该让cmobo弹窗消失, 才是正常的用户交互吧. 要让他一些移动, 那就是监听窗口移动消息, 通知到那个弹框呗
  • 打赏
  • 举报
回复
引用 23 楼 simple 的回复:
代码太多,2000+行,发不上去

CEditComboUI
的实现没有发。
  • 打赏
  • 举报
回复
引用 19 楼 simple 的回复:
父亲应该是正常的,其他操作都是正常的

不知道了,无法重现你的问题,能否发上来创建控件相关的代码?
simple 2020-06-23
  • 打赏
  • 举报
回复
引用 18 楼 zjq9931 的回复:
[quote=引用 17 楼 simple 的回复:] CEditComboUI是窗口的一部分啊,窗口移动的时候并不会触发CEditComboUI::SetPos。
是不是CEditComboUI的父窗口没有设定呢?[/quote] 父亲应该是正常的,其他操作都是正常的
simple 2020-06-23
  • 打赏
  • 举报
回复
代码太多,2000+行,发不上去
simple 2020-06-23
  • 打赏
  • 举报
回复


#include "stdafx.h"
#include "UIEditCombo.h"

//////////////////////////////////////////////////////////////////////////
class CEditCombo_EditWnd : public CWindowWnd
{
public:
	CEditCombo_EditWnd();

	void Init(IEditCombo_EditUI* pOwner);
	RECT CalPos();

	LPCTSTR GetWindowClassName() const;
	LPCTSTR GetSuperClassName() const;
	void OnFinalMessage(HWND hWnd);

	LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
	LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnEditChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

protected:
	enum { 
		DEFAULT_TIMERID = 20,
	};

	IEditCombo_EditUI* m_pOwner;
	HBRUSH m_hBkBrush;
	bool m_bInit;
	bool m_bDrawCaret;
};


CEditCombo_EditWnd::CEditCombo_EditWnd() : m_pOwner(NULL), m_hBkBrush(NULL), m_bInit(false), m_bDrawCaret(false)
{
}

void CEditCombo_EditWnd::Init(IEditCombo_EditUI* pOwner)
{
	m_pOwner = pOwner;
	RECT rcPos = CalPos();
	UINT uStyle = WS_CHILD | ES_AUTOHSCROLL | pOwner->GetWindowStyls();
	UINT uTextStyle = m_pOwner->GetTextStyle();
	if(uTextStyle & DT_LEFT) uStyle |= ES_LEFT;
	else if(uTextStyle & DT_CENTER) uStyle |= ES_CENTER;
	else if(uTextStyle & DT_RIGHT) uStyle |= ES_RIGHT;
	if( m_pOwner->IsPasswordMode() ) uStyle |= ES_PASSWORD;
	Create(m_pOwner->GetManager()->GetPaintWindow(), NULL, uStyle, 0, rcPos);

	HFONT hFont=NULL;
	int iFontIndex=m_pOwner->GetFont();
	if (iFontIndex!=-1)
		hFont=m_pOwner->GetManager()->GetFont(iFontIndex);
	if (hFont==NULL)
		hFont=m_pOwner->GetManager()->GetDefaultFontInfo()->hFont;

	SetWindowFont(m_hWnd, hFont, TRUE);
	Edit_LimitText(m_hWnd, m_pOwner->GetMaxChar());
	if( m_pOwner->IsPasswordMode() ) Edit_SetPasswordChar(m_hWnd, m_pOwner->GetPasswordChar());
	Edit_SetText(m_hWnd, m_pOwner->GetText());
	Edit_SetModify(m_hWnd, FALSE);
	SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELPARAM(0, 0));
	Edit_Enable(m_hWnd, m_pOwner->IsEnabled() == true);
	Edit_SetReadOnly(m_hWnd, m_pOwner->IsReadOnly() == true);

	//Styls
	::ShowWindow(m_hWnd, SW_SHOWNOACTIVATE);
	::SetFocus(m_hWnd);
	if (m_pOwner->IsAutoSelAll()) {
		int nSize = GetWindowTextLength(m_hWnd);
		if( nSize == 0 ) nSize = 1;
		Edit_SetSel(m_hWnd, 0, nSize);
	}
	else {
		int nSize = GetWindowTextLength(m_hWnd);
		Edit_SetSel(m_hWnd, nSize, nSize);
	}

	m_bInit = true;    
}

RECT CEditCombo_EditWnd::CalPos()
{
	CDuiRect rcPos = m_pOwner->GetPos();
	RECT rcInset = m_pOwner->GetTextPadding();
	rcPos.left += rcInset.left;
	rcPos.top += rcInset.top;
	rcPos.right -= rcInset.right;
	rcPos.bottom -= rcInset.bottom;
	LONG lEditHeight = m_pOwner->GetManager()->GetFontInfo(m_pOwner->GetFont())->tm.tmHeight;
	if( lEditHeight < rcPos.GetHeight() ) {
		rcPos.top += (rcPos.GetHeight() - lEditHeight) / 2;
		rcPos.bottom = rcPos.top + lEditHeight;
	}

	CControlUI* pParent = static_cast<CControlUI*>(m_pOwner->GetInterface(DUI_CTR_CONTROL));
	RECT rcParent;
	while( pParent = pParent->GetParent() ) {
		if( !pParent->IsVisible() ) {
			rcPos.left = rcPos.top = rcPos.right = rcPos.bottom = 0;
			break;
		}
		rcParent = pParent->GetClientPos();
		if( !::IntersectRect(&rcPos, &rcPos, &rcParent) ) {
			rcPos.left = rcPos.top = rcPos.right = rcPos.bottom = 0;
			break;
		}
	}

	return rcPos;
}

LPCTSTR CEditCombo_EditWnd::GetWindowClassName() const
{
	return _T("EditCombo_EditWnd");
}

LPCTSTR CEditCombo_EditWnd::GetSuperClassName() const
{
	return WC_EDIT;
}

void CEditCombo_EditWnd::OnFinalMessage(HWND hWnd)
{
	m_pOwner->Invalidate();
	// Clear reference and die
	if( m_hBkBrush != NULL ) ::DeleteObject(m_hBkBrush);
	m_pOwner->GetManager()->RemoveNativeWindow(hWnd);
	m_pOwner->m_pEditWindow = NULL;
	m_pOwner->EditDestroy();
	delete this;
}

LRESULT CEditCombo_EditWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	LRESULT lRes = 0;
	BOOL bHandled = TRUE;
	CControlUI *pOwner = static_cast<CControlUI*>(m_pOwner->GetInterface(DUI_CTR_CONTROL));
	if( uMsg == WM_CREATE ) {
		m_pOwner->GetManager()->AddNativeWindow(pOwner, m_hWnd);
		if( m_pOwner->GetManager()->IsLayered() ) {
			::SetTimer(m_hWnd, DEFAULT_TIMERID, ::GetCaretBlinkTime(), NULL);
		}
		bHandled = FALSE;
	}
	else if( uMsg == WM_KILLFOCUS ) 
		lRes = OnKillFocus(uMsg, wParam, lParam, bHandled);
	else if( uMsg == OCM_COMMAND ) {
		if( GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE ) lRes = OnEditChanged(uMsg, wParam, lParam, bHandled);
		else if( GET_WM_COMMAND_CMD(wParam, lParam) == EN_UPDATE ) {
			RECT rcClient;
			::GetClientRect(m_hWnd, &rcClient);
			::InvalidateRect(m_hWnd, &rcClient, FALSE);
		}
	}
	else if( uMsg == WM_KEYDOWN && TCHAR(wParam) == VK_RETURN ) {
		m_pOwner->GetManager()->SendNotify(pOwner, DUI_MSGTYPE_RETURN);
	}
	else if( uMsg == OCM__BASE + WM_CTLCOLOREDIT  || uMsg == OCM__BASE + WM_CTLCOLORSTATIC ) {
		if (m_pOwner->GetManager()->IsLayered() && !m_pOwner->GetManager()->IsPainting()) {
			m_pOwner->GetManager()->AddNativeWindow(pOwner, m_hWnd);
		}
		DWORD clrColor = m_pOwner->GetNativeEditBkColor();
		if( clrColor == 0xFFFFFFFF ) return 0;
		::SetBkMode((HDC)wParam, TRANSPARENT);
		DWORD dwTextColor = m_pOwner->GetTextColor();
		::SetTextColor((HDC)wParam, RGB(GetBValue(dwTextColor),GetGValue(dwTextColor),GetRValue(dwTextColor)));
		if (clrColor < 0xFF000000) {
			if (m_hBkBrush != NULL) ::DeleteObject(m_hBkBrush);
			RECT rcWnd = m_pOwner->GetManager()->GetNativeWindowRect(m_hWnd);
			HBITMAP hBmpEditBk = CRenderEngine::GenerateBitmap(m_pOwner->GetManager(), rcWnd, pOwner, clrColor);
			m_hBkBrush = ::CreatePatternBrush(hBmpEditBk);
			::DeleteObject(hBmpEditBk);
		}
		else {
			if (m_hBkBrush == NULL) {
				m_hBkBrush = ::CreateSolidBrush(RGB(GetBValue(clrColor), GetGValue(clrColor), GetRValue(clrColor)));
			}
		}
		return (LRESULT)m_hBkBrush;
	}
	else if( uMsg == WM_PAINT) {
		if (m_pOwner->GetManager()->IsLayered()) {
			m_pOwner->GetManager()->AddNativeWindow(pOwner, m_hWnd);
		}
		bHandled = FALSE;
	}
	else if( uMsg == WM_PRINT ) {
		if (m_pOwner->GetManager()->IsLayered()) {
			lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam);
			if( m_pOwner->IsEnabled() && m_bDrawCaret ) { // todo:判断是否enabled
				RECT rcClient;
				::GetClientRect(m_hWnd, &rcClient);
				POINT ptCaret;
				::GetCaretPos(&ptCaret);
				RECT rcCaret = { ptCaret.x, ptCaret.y, ptCaret.x, ptCaret.y+rcClient.bottom-rcClient.top };
				CRenderEngine::DrawLine((HDC)wParam, rcCaret, 1, 0xFF000000);
			}
			return lRes;
		}
		bHandled = FALSE;
	}
	else if( uMsg == WM_TIMER ) {
		if (wParam == DEFAULT_TIMERID) {
			m_bDrawCaret = !m_bDrawCaret;
			RECT rcClient;
			::GetClientRect(m_hWnd, &rcClient);
			::InvalidateRect(m_hWnd, &rcClient, FALSE);
			return 0;
		}
		bHandled = FALSE;
	}
	///////////////////////////////新增提示功能/////////////////////////////////////
	else if( uMsg == OCM__BASE + WM_CTLCOLOREDIT  || uMsg == OCM__BASE + WM_CTLCOLORSTATIC ) {  
		if( m_pOwner->GetNativeEditBkColor() == 0xFFFFFFFF ) return NULL;  
		::SetBkMode((HDC)wParam, TRANSPARENT);  

		DWORD dwTextColor;  
		if (m_pOwner->GetNativeEditTextColor() != 0x000000)  
			dwTextColor = m_pOwner->GetNativeEditTextColor();  
		else  
			dwTextColor = m_pOwner->GetTextColor();  

		::SetTextColor((HDC)wParam, RGB(GetBValue(dwTextColor),GetGValue(dwTextColor),GetRValue(dwTextColor)));  
		if( m_hBkBrush == NULL ) {  
			DWORD clrColor = m_pOwner->GetNativeEditBkColor();  
			m_hBkBrush = ::CreateSolidBrush(RGB(GetBValue(clrColor), GetGValue(clrColor), GetRValue(clrColor)));  
		}  
		return (LRESULT)m_hBkBrush;  
	}
	else if (WM_MOUSEWHEEL == uMsg)
	{
		int zDelta = (int)(short)HIWORD(wParam);
		TEventUI event = {0};
		event.Type = UIEVENT_SCROLLWHEEL;
		event.wParam = MAKELPARAM(zDelta < 0 ? SB_LINEDOWN : SB_LINEUP, 0);
		event.lParam = lParam;
		event.dwTimestamp = ::GetTickCount();
		m_pOwner->DoEvent(event);
	} 
	else if (WM_NCHITTEST == uMsg)
	{
		//::MessageBox(m_hWnd, _T("WM_NCHITTEST"), _T("test"), MB_OK);
		POINT pt; 
		pt.x = GET_X_LPARAM(lParam); 
		pt.y = GET_Y_LPARAM(lParam);
		::ScreenToClient(*this, &pt);
		RECT rcClient ;
		::GetClientRect(m_hWnd, &rcClient);
		if (::PtInRect(&rcClient, pt))
		{
			 return HTCLIENT;
		}
		else
		{
			return HTBORDER;
		}
	}
	else if (WM_NCLBUTTONDOWN == uMsg)
	{
// 		POINT pt; 
// 		pt.x = GET_X_LPARAM(lParam); 
// 		pt.y = GET_Y_LPARAM(lParam);
// 		::ScreenToClient(*this, &pt);
// 		RECT rcClient ;
// 		::GetClientRect(m_hWnd, &rcClient);
// 		if (!::PtInRect(&rcClient, pt))
		{
			::MessageBox(m_hWnd, _T("WM_NCLBUTTONDOWN"), _T("test"), MB_OK);
		}
	}
	//////////////////////////////////////////////////////////////////////////
	else bHandled = FALSE;
	if( !bHandled ) return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
	return lRes;
}

LRESULT CEditCombo_EditWnd::OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	LRESULT lRes = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
	if ((HWND)wParam != m_pOwner->GetManager()->GetPaintWindow()) {
		::SendMessage(m_pOwner->GetManager()->GetPaintWindow(), WM_KILLFOCUS, wParam, lParam);
	}
	SendMessage(WM_CLOSE);
	return lRes;
}

LRESULT CEditCombo_EditWnd::OnEditChanged(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	if( !m_bInit ) return 0;
	if( m_pOwner == NULL ) return 0;
	// Copy text back
	int cchLen = ::GetWindowTextLength(m_hWnd) + 1;
	LPTSTR pstr = static_cast<LPTSTR>(_alloca(cchLen * sizeof(TCHAR)));
	ASSERT(pstr);
	if( pstr == NULL ) return 0;
	::GetWindowText(m_hWnd, pstr, cchLen);
	m_pOwner->_SetText(pstr);
	m_pOwner->GetManager()->SendNotify(static_cast<CControlUI*>(m_pOwner->GetInterface(DUI_CTR_CONTROL)), DUI_MSGTYPE_TEXTCHANGED);
	if( m_pOwner->GetManager()->IsLayered() ) m_pOwner->Invalidate();
	m_pOwner->TextChange();
	return 0;
}
simple 2020-06-23
  • 打赏
  • 举报
回复


#pragma once

#define  DUI_CTR_EDITCOMBOELEMENT  (_T("EditComboElement"))
#define  DUI_CTR_EDITCOMBO  (_T("EditCombo"))

class CEditCombo_EditWnd;
class CEditCombo_ComboWnd;

class IEditCombo_ControlUI
{
public:
	virtual int GetWindowStyls() const = 0;
	virtual CPaintManagerUI* GetManager() const = 0;
	virtual CControlUI* GetParent() const = 0;
	virtual LPVOID GetInterface(LPCTSTR pstrName) = 0;
	virtual void Invalidate() = 0;

	virtual bool IsEnabled() const = 0;
	virtual CDuiString GetText() const = 0;
	virtual void SetPos(RECT rc, bool bNeedInvalidate) = 0;
	virtual const RECT& GetPos() const = 0;
	virtual RECT GetRelativePos() const = 0;
	virtual RECT GetClientPos() const = 0;
	virtual bool IsVisible() const = 0;
	virtual void DoEvent(TEventUI &event) = 0;
protected:
	virtual void _SetText(LPCTSTR pstrText) = 0;  // 仅仅设置m_sText
};

class IEditCombo_EditUI : public IEditCombo_ControlUI
{
	friend class CEditCombo_EditWnd;

protected:
	CEditCombo_EditWnd *m_pEditWindow;  // Edit框

public:
	IEditCombo_EditUI() : m_pEditWindow(NULL){}
	virtual int GetFont() const = 0;
	virtual UINT GetTextStyle() const = 0;
	virtual RECT GetTextPadding() const = 0;
	virtual bool IsPasswordMode() const = 0;
	virtual TCHAR GetPasswordChar() const = 0;
	virtual bool IsReadOnly() const = 0;
	virtual bool IsAutoSelAll() const = 0;
	virtual UINT GetMaxChar() const = 0;
	virtual DWORD GetTextColor() const = 0;
	virtual DWORD GetNativeEditBkColor() const = 0;
	virtual DWORD GetNativeEditTextColor() const = 0;
	virtual void TextChange() = 0;
	virtual void EditDestroy() = 0;
};
class IEditCombo_ComboUI : public IEditCombo_ControlUI
{
	friend class CEditCombo_ComboWnd;
protected:
	CEditCombo_ComboWnd *m_pComboWindow;  // Combo弹窗
	UINT m_uButtonState;  // 状态

public:
	IEditCombo_ComboUI() : m_pComboWindow(NULL), m_uButtonState(0){}
	virtual LPCTSTR GetClass() const = 0;
	virtual bool IsFloat() const = 0;
	virtual int GetCurSel() const = 0;
	virtual int GetCount() const = 0;
	virtual void SetManager(CPaintManagerUI* pManager, CControlUI* pParent, bool bInit = true) = 0;
	virtual CControlUI* GetItemAt(int id) = 0;
	virtual void SetFocus() = 0;

	virtual SIZE GetDropBoxSize() const = 0;
	virtual CDuiString GetDropBoxAttributeList() = 0;
	virtual TListInfoUI* GetListInfo() = 0;

	virtual bool SelectItem(int iIndex, bool bTakeFocus = false, bool bTriggerEvent=true, bool bMutil = false) = 0;
};


class CEditComboElementUI : public CListLabelElementUI
{
public:
	CEditComboElementUI() : CListLabelElementUI(){}
	LPCTSTR GetClass() const
	{
		return DUI_CTR_EDITCOMBOELEMENT;
	}
	LPVOID GetInterface(LPCTSTR pstrName)
	{
		if (0 == _tcscmp(pstrName, DUI_CTR_EDITCOMBOELEMENT))
		{
			return static_cast<CEditComboElementUI*>(this);
		}

		return CListLabelElementUI::GetInterface(pstrName);
	}

	void SetFocus() override{}
};

class CEditComboUI : public CContainerUI, public IEditCombo_EditUI, public IEditCombo_ComboUI, public IListOwnerUI
{
public:
	CEditComboUI(void);
	virtual ~CEditComboUI(void);

	LPCTSTR GetClass() const;
	LPVOID GetInterface(LPCTSTR pstrName);
	UINT GetControlFlags() const;
	HWND GetNativeWindow() const;
	HWND GetNativeEditHWND() const;

	int GetWindowStyls() const;
	UINT GetTextStyle() const;
	int GetFont() const;
	CPaintManagerUI* GetManager() const;
	CControlUI* GetParent() const;
	void Invalidate();

	bool IsEnabled() const;
	void SetEnabled(bool bEnable);
	CDuiString GetText() const;
	void _SetText(LPCTSTR pstrtext);
	void SetText(LPCTSTR pstrText);
	RECT GetTextPadding() const;
	void SetTextPadding(RECT rc);
	void SetTextPadding(LPCTSTR pstrValue);
	bool IsVisible() const;
	void TextChange();
	void EditDestroy();

	void SetPasswordMode(bool bPasswordMode);
	bool IsPasswordMode() const;
	void SetPasswordChar(TCHAR szChar);
	TCHAR GetPasswordChar() const;
	void SetMaxChar(UINT uMax);
	UINT GetMaxChar() const;
	void SetReadOnly(bool bReadOnly);
	bool IsReadOnly() const;
	void SetNumberOnly(bool bNumberOnly);
	bool IsNumberOnly() const;
	void SetAutoSelAll(bool bAuto);
	bool IsAutoSelAll() const;
	void SetReplaceSel(LPCTSTR lpszReplace);

	void SetFont(int index);
	void SetPos(RECT rc, bool bNeedInvalidate);
	const RECT& GetPos() const;
	RECT GetRelativePos() const;
	RECT GetClientPos() const;
	void Move(SIZE szOffset, bool bNeedInvalidate);
	void SetVisible(bool bVisible);
	void SetInternVisible(bool bVisible);
	SIZE EstimateSize(SIZE szAvailable);
	void PaintStatusImage(HDC hDC);
	void PaintText(HDC hDC);

	LPCTSTR GetNormalImage();
	void SetNormalImage(LPCTSTR pStrImage);
	LPCTSTR GetHotImage();
	void SetHotImage(LPCTSTR pStrImage);
	LPCTSTR GetPushedImage() const;
	void SetPushedIMage(LPCTSTR pStrImage);
	LPCTSTR GetFocusedImage();
	void SetFocusedImage(LPCTSTR pStrImage);
	LPCTSTR GetDisabledImage();
	void SetDisabledImage(LPCTSTR pStrImage);
	DWORD GetTextColor() const;
	void SetNativeEditBkColor(LPCTSTR pStrColor);
	DWORD GetNativeEditBkColor() const;
	void SetNativeEditTextColor(LPCTSTR pStrColor);
	DWORD GetNativeEditTextColor() const;
	void SetTipValue(LPCTSTR pStrTipValue);
	void SetTipValueColor(LPCTSTR pStrColor);
	DWORD GetTipValueColor();
	CDuiString GetTipValue();
	LPCTSTR GetSrcTipValue();

	void SetTextStyle(UINT uStyle);
	void SetTextColor(DWORD dwTextColor);
	void SetDisabledTextColor(DWORD dwTextColor);
	DWORD GetDisabledTextColor() const;

	DWORD StringToColor(LPCTSTR pstrColor);
	void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);

	void DoEvent(TEventUI& event) override;

protected:
	int m_iWindowStyls;  // 类型
	int m_iFont;  // 字体
	bool m_bReadOnly;  // 是否只读
	bool m_bPasswordMode;  // 密码模式
	TCHAR m_szPasswordChar;  // 密码显示的字符
	UINT m_uMaxChar;  // 最大个数
	bool m_bAutoSelAll;  // 自动全选
	UINT m_uButtonState;  // 按钮状态
	RECT m_rcTextPadding;  // 文本间隔
	DWORD m_dwEditBkColor;  // Edit背景颜色
	DWORD m_dwEditTextColor;  // Edit文本颜色
	DWORD m_dwTipValueColor;  // 提示颜色

	CDuiString m_sTipValue;	 // 提示的值
	CDuiString m_sSrcTipValue;  // 

	UINT m_uTextStyle;
	DWORD m_dwTextColor;
	DWORD m_dwDisabledTextColor;

	TDrawInfo m_diNormal;
	TDrawInfo m_diHot;
	TDrawInfo m_diPushed;
	TDrawInfo m_diFocused;
	TDrawInfo m_diDisabled;


public:
	bool IsFloat() const;
	int GetCurSel() const;
	int GetCount() const;
	void SetManager(CPaintManagerUI* pManager, CControlUI* pParent, bool bInit = true);
	CControlUI* GetItemAt(int id);
	void SetFocus();

	void SetDropBoxSize(SIZE szSize);
	void SetDropBoxSize(LPCTSTR pstrValue);
	SIZE GetDropBoxSize() const;
	void SetDropBoxAttributeList(LPCTSTR pstrList);
	CDuiString GetDropBoxAttributeList();
	TListInfoUI* GetListInfo();

	bool SelectItem(int iIndex, bool bTakeFocus = false, bool bTriggerEvent=true, bool bMutil = false);
	bool SelectRange(int iIndex, bool bTakeFocus = false, bool bTriggerEvent=true, bool bMutil = false);
	bool ExpandItem(int iIndex, bool bExpand = true);
	int GetExpandedItem() const;

	bool SetItemIndex(CControlUI* pControl, int iNewIndex);
	bool SetMultiItemIndex(CControlUI* pStartControl, int iCount, int iNewStartIndex);
	bool Add(CControlUI* pControl);
	bool AddAt(CControlUI* pControl, int iIndex);
	bool Remove(CControlUI* pControl, bool bDoNotDestroy =false);
	bool RemoveAt(int iIndex, bool bDoNotDestroy =false);
	void RemoveAll();


	void SetShowText(bool bShow);
	bool GetShowText() const;
	void SetSelectCloseFlag(bool flag);
	bool GetSelectCloseFlag() const;
	UINT GetItemFixedHeight();
	void SetItemFixedHeight(UINT nHeight);
	int GetItemFont(int index);
	void SetItemFont(int index);
	void SetItemAlign(LPCTSTR pstrValue);
	UINT GetItemTextStyle();
	void SetItemTextStyle(UINT uStyle);
	RECT GetItemTextPadding() const;
	void SetItemTextPadding(RECT rc);
	void SetItemTextPadding(LPCTSTR pstrValue);
	DWORD GetItemTextColor() const;
	void SetItemTextColor(DWORD dwTextColor);
	DWORD GetItemBkColor() const;
	void SetItemBkColor(DWORD dwBkColor);
	LPCTSTR GetItemBkImage() const;
	void SetItemBkImage(LPCTSTR pStrImage);
	bool IsItemAlternateBk() const;
	void SetItemAlternateBk(bool bAlternateBk);
	DWORD GetSelectedItemTextColor() const;
	void SetSelectedItemTextColor(DWORD dwTextColor);
	DWORD GetSelectedItemBkColor() const;
	void SetSelectedItemBkColor(DWORD dwBkColor);
	LPCTSTR GetSelectedItemImage() const;
	void SetSelectedItemImage(LPCTSTR pStrImage);
	DWORD GetHotItemTextColor() const;
	void SetHotItemTextColor(DWORD dwTextColor);
	DWORD GetHotItemBkColor() const;
	void SetHotItemBkColor(DWORD dwBkColor);
	LPCTSTR GetHotItemImage() const;
	void SetHotItemImage(LPCTSTR pStrImage);
	DWORD GetDisabledItemTextColor() const;
	void SetDisabledItemTextColor(DWORD dwTextColor);
	DWORD GetDisabledItemBkColor() const;
	void SetDisabledItemBkColor(DWORD dwBkColor);
	LPCTSTR GetDisabledItemImage() const;
	void SetDisabledItemImage(LPCTSTR pStrImage);
	int GetItemHLineSize() const;
	void SetItemHLineSize(int iSize);
	DWORD GetItemHLineColor() const;
	void SetItemHLineColor(DWORD dwLineColor);
	int GetItemVLineSize() const;
	void SetItemVLineSize(int iSize);
	DWORD GetItemVLineColor() const;
	void SetItemVLineColor(DWORD dwLineColor);
	bool IsItemShowHtml();
	void SetItemShowHtml(bool bShowHtml = true);
private:
	int m_iCurSel;  // 当前选择的item
	bool m_bShowText;  // 不显示文本
	bool m_bSelectCloseFlag;  // (下拉框)关闭
	SIZE m_szDropBox;  // 下拉框大小
	CDuiString m_sDropBoxAttributes;  // 下拉框设置

	// 列表设置
	TListInfoUI m_ListInfo;
};
  • 打赏
  • 举报
回复
引用 17 楼 simple 的回复:
CEditComboUI是窗口的一部分啊,窗口移动的时候并不会触发CEditComboUI::SetPos。

是不是CEditComboUI的父窗口没有设定呢?
simple 2020-06-22
  • 打赏
  • 举报
回复
CEditComboUI是窗口的一部分啊,窗口移动的时候并不会触发CEditComboUI::SetPos。
mmcanyu 2020-06-17
  • 打赏
  • 举报
回复
CEditWnd就是一个子窗口,它可以移动啊,就是CEditComboUI::SetPos触发移动的。
mmcanyu 2020-06-15
  • 打赏
  • 举报
回复
引用 13 楼 simple 的回复:
刚刚看了下代码,在CEditWnd上,我已经处理了WM_NCLBUTTONDOWN消息,但是CEditWnd不会收到这个消息;
而点击窗口标题后,设置焦点到主窗口标题的时候,CEditWnd丢失焦点而关闭combo是可以。
暂时只能这样了。后面再看看有什么突破口了。

1,CEditWnd不可能收到WM_NCLBUTTONDOWN消息。
2,这种处理方式会影响到所有控件,作为一个界面库,最好别这么做。CEditUI::SetPos()里面移动combo也是可以的。
加载更多回复(14)

15,980

社区成员

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

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