请教下,RichEdit 控件,如何获取内容的行数 #369
huangzhengyi
started this conversation in
General
Replies: 3 comments 10 replies
-
有人知道怎么实现嘛?怎么获取行数 |
Beta Was this translation helpful? Give feedback.
0 replies
-
该变量会在 DoInit 中进行初始化,你应该关心的是 DoInit 后为什么 m_pTwh 为空,断点到 DoInit 中查看一下关键代码段的返回值相信可以找到你的问题根源: |
Beta Was this translation helpful? Give feedback.
8 replies
-
GetLineCount 要在 m_pTwh 初始化后才会返回正确值。 int RichEdit::GetLineCount() const
{
+ if( !m_pTwh ) return 0;
LRESULT lResult;
TxSendMessage(EM_GETLINECOUNT, 0, 0, &lResult);
return (int)lResult;
} m_pTwh 的初始化在 DoInit 接口中 void RichEdit::DoInit()
{
if (m_bInited)
return;
CREATESTRUCT cs;
cs.style = m_lTwhStyle;
cs.x = 0;
cs.y = 0;
cs.cy = 0;
cs.cx = 0;
cs.lpszName = m_sText.c_str();
+ CreateHost(this, &cs, &m_pTwh);
if (m_pTwh) {
m_pTwh->SetTransparent(TRUE);
LRESULT lResult;
m_pTwh->GetTextServices()->TxSendMessage(EM_SETLANGOPTIONS, 0, 0, &lResult);
m_pTwh->GetTextServices()->TxSendMessage(EM_SETEVENTMASK, 0, ENM_CHANGE, &lResult);
m_pTwh->OnTxInPlaceActivate(NULL);
if (m_pHorizontalScrollBar) {
m_pHorizontalScrollBar->SetScrollRange(0);
}
if (m_pVerticalScrollBar) {
m_pVerticalScrollBar->SetScrollRange(0);
}
}
m_bInited = true;
} DoInit 接口在基类 PlaceHolder 的 Init 接口中会调用 void PlaceHolder::Init()
{
+ DoInit();
} PlaceHolder::Init 方法在 SetWindow 方法中会调用 void PlaceHolder::SetWindow(Window* pManager, Box* pParent, bool bInit)
{
m_pWindow = pManager;
m_pParent = pParent;
+ if (bInit && m_pParent) Init();
} 你 new 了新的控件,给他设置了各种样式,但是你没有告诉它应该显示在什么位置。 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
通过 GetLineCount 获取行数,由于m_pTwh 还没有初始化,这种情况应该怎么去实现
Beta Was this translation helpful? Give feedback.
All reactions