Re: ListBox with no selected item
I thought you would want to add strings to the bottom of the edit, just like
a listbox would add lines.
This is how I've done it in the past:
int TextLength = GetWindowTextLength();
SetSel(TextLength,TextLength);
ReplaceSel(Text+"\r\n");
When I have done the edit control route I have created a class called
CAppendEdit which looks like this:
#pragma once
// LSAppendEdit
class CAppendEdit : public CEdit
{
DECLARE_DYNAMIC(CAppendEdit)
public:
CAppendEdit();
virtual ~CAppendEdit();
void AddString(CString Text);
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/);
};
// CAppendEdit.cpp : implementation file
//
#include "stdafx.h"
#include "appendedit.h"
// CAppendEdit
IMPLEMENT_DYNAMIC(CAppendEdit, CEdit)
CAppendEdit::CAppendEdit()
{
}
CAppendEdit::~CAppendEdit()
{
}
BEGIN_MESSAGE_MAP(CAppendEdit, CEdit)
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
// LSAppendEdit message handlers
HBRUSH CAppendEdit::CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/)
{
return (HBRUSH)GetStockObject(WHITE_BRUSH);
}
void CAppendEdit::AddString(CString Text)
{
int TextLength = GetWindowTextLength();
SetSel(TextLength,TextLength);
ReplaceSel(Text+"\r\n");
}
AliR.
"No_Name" <no_mail@no_mail.com> wrote in message
news:golkmo$dlt$1@aioe.org...
Tom Serface a utilis? son clavier pour ?crire :
I didn't know about the Windows CE thing. Thanks for adding that.
Edit control would work as well and with read-only you can still scroll.
OP would have to format lines to display correctly, but that would be an
easy task.
Hello,
I finally switched from ListBox to a multiline Edit Box, as you suggested,
and the problem is solved, thanks !
However, I still have a problem : when displayed, the whole lines I put
into the CEdit box are selected, and I can't find a way to unselect them.
Here is my code :
(myEdit is the name of the multiline Edit)
CString strLine;
strLine.Format(_T("%s\r\n%s\r\n%s\r\n%s"), _T("HIT F4 FOR OPTION
4"),_T("HIT F5 FOR OPTION 5"),_T("HIT F6 FOR OPTION 6"),_T("HIT F7 FOR
OPTION 7"));
myEdit.SetWindowTextW(strLine);
myEdit.SetSel(-1, 0, TRUE);
// At this point, the Edit content is fully selected !
int lStarting = 0, lEnding =0;
myEdit.GetSel(lStarting, lEnding);
myEdit.SetSel(lEnding,lEnding);
// At this point, the Edit content is still fully selected !
Thank you for any help.