要求在窗体的某个区域内显示文本,但不能使用文本框,
要能做到多行显示,自动换行,当文本太长时,能够用
滚动条浏,能用不同的颜色显示不同的文本内容。
请问这样的效果如何作?
谈谈思路即可,如有类似源码最好。多谢了。
要能做到多行显示,自动换行,当文本太长时,能够用
滚动条浏,能用不同的颜色显示不同的文本内容。
请问这样的效果如何作?
谈谈思路即可,如有类似源码最好。多谢了。
解决方案 »
- 网络游戏人物头上面的字(也就是人物的名称)也是把文字转成贴图的形式在渲染的么?
- 想要文字上下滚动式播放,怎么办
- 菜鸟提问:关于字符串分析?
- 大家帮忙呀,关于文件系统的
- 为什么在线程中调用 ExcelApp->CreateDispatch("excel.application")函数失败?
- ADO的用法问题
- 提换了新的GUID,编译的时候有警告,注册失败?
- 50分求助!!关于状态栏的一些疑问。。。
- 好多朋友都要<<高质量C,C++>>这本书,现提供给大家学习
- gb2312转化为unicode
- 为什末好多网站的网页不能保存????
- 如何能在处理完windows消息后,再把该消息放回windows的消息队列?
我也想到用DrawText来作,但有一点,就是滚动条不好处理。
http://www.codeguru.com/controls/MemViewer.html
This article was contributed by Zhou,jianjun.
Click here for larger image Environment: VC6, NT4, Win2000, Win9x/ME Abstract
The Memory Viewer displays memory contents starting at a specified address (0x00400000 by default), it shows memory contents as the HEX format in a binary editor. With this viewer, programmer can watch where Windows runs an application, where is Windows data page, and even where is CMOS information (0x000FF5C0). It shows the memory contents by bytes and explains bytes to ASCII as much as possible. If a memory page is not readable, it shows '?' instead. A toolbar at the top of the window displays the starting address for the memory display. Edit the value in the toolbar and press the button 'Go' beside to change the starting address. Use the scrollbar at the side of the window to view other memory locations in the system's address space without changing the starting address of the display. Scrollbar can go to anywhere in any address without problem. The treasure in this program is the class CSW_EditorBase. It is called 'EditorBase' because it can be a basic class for any kind of editor, such as an Information Window or a Binary Viewer. The class has all the necessary frame members for an editor control. Editors are easily built by deriving just a few members from CSW_EditorBase, and they don't have to take care of flashing, selections, scrollbars, drawing part, and other boring works has to be done on each kind of editors job over and over. If you are looking for a tiny text window, it would be a very nice startup. In fact, the purpose of the Memory Viewer is just to test this idea and implement the class CSW_EditorBase. It proves well. How a common text editor works
To draw texts line by line, you have to decide : The number of lines, GetTotalLines() in CSW_EditorBase; The height of a line, which is the maximum height of all characters in a line. GetLineH() in CSW_EditorBase; A line index from a client Y position on pixels. GetLineFromY() in CSW_EditorBase; The number of columns, it should be the maximum columns in all lines. It is used to calculate scrollbars range in most situations. GetTotalCols() in CSW_EditorBase; A width of a column. It is very important when the font is varied. GetColW() in CSW_EditorBase; A column index from a client X position on pixels. GetColFromX() in CSW_EditorBase; Get the string in a line. GetLineStr() in CSW_EditorBase; A method to draw a line. OnDrawItem() in CSW_EditorBase; Calculate scrollbar ranges. OnUpdateBars() in CSW_EditorBase; Override OnPaint(), MouseMove() and other CWnd methods. To remove some refresh problems, only draws the visible lines and moves the whole client area when scrolling. It may be other works such as how to save all text or draw an image inside.
Class CSW_EditorBase members
Abstract class CSW_EditorBase derives from CWnd and has the following member functions: Line functions, a line can be a line of text and its alignment // Get the number of total lines
virtual UINT GetTotalLines (void) = 0;
// Get the height of a line
virtual UINT GetLineH (int nLine);
// Get a line number from a position( in pixel)
virtual int GetLineFromY (int &Y);Column functions, a column can be a char and its alignment, or an image // Get the maximum number of columns in all lines
virtual UINT GetTotalCols (void) = 0;
// Get the with of a column
virtual UINT GetColW (int nCol);
virtual int GetColFromX (int &X); // Cell functions
// Get the line and column index from a point
virtual BOOL GetLineColFromPt(CPoint ↦Pt,
int &iLine,
int &iCol); // String functions
// Get the string for a line
virtual void GetLineStr (int nLine, CString& str) = 0; // Paint
virtual BOOL OnDrawItem ( CDC *pDC,
UINT nLine,
LPCTSTR lpStr,
int FirstSelectedChar = -1,
int LastSelectedChar = -1); // Scroll bars, update scrollbars range
void OnUpdateBars (void); // Don't derive again in subclass, normally. afx_msg BOOL OnEraseBkgnd (CDC *pDC);
afx_msg void OnPaint (void);
afx_msg void OnSize (UINT nType, int cx, int cy); afx_msg void OnHScroll ( UINT nSBCode,
UINT nPos,
CScrollBar* pScrollBar);
afx_msg void OnVScroll ( UINT nSBCode,
UINT nPos,
CScrollBar* pScrollBar); afx_msg void OnLButtonDown (UINT nFlags, CPoint point);
afx_msg void OnLButtonDblClk (UINT nFlags, CPoint point);
afx_msg void OnMouseMove (UINT nFlags, CPoint point);
afx_msg void OnLButtonUp (UINT nFlags, CPoint point);
afx_msg BOOL OnMouseWheel (UINT nFlags,
short zDelta,
CPoint pt);
...How to use class CSW_EditorBase
Derive a new class from CSW_EditorBase, overrides some members as necessary. GetTotalLines(),GetTotalCols() and GetLineStr() are essential. Creates an instance of the new class and puts it inside a view window. See CSW_TextInfo as a simple example. class CSW_TextInfo : public CSW_EditorBase
{
private:
// Save all lines here
CStringArray m_StrData;
// Keep the maximun number of columns
int m_MaxColNBR;
// public members
public:
CSW_TextInfo ();
// Add a line of string
void AddLine (LPCTSTR lpStr);
// Clean all information
void Clean (void);
// Members overrides from its parent class
protected:
virtual UINT GetTotalLines (void);
virtual UINT GetTotalCols (void);
virtual void GetLineStr (int nLine, CString& str);
};See CSW_BDisplay in the source for a complicated example. MemViewer History
v2.0 is on process v1.0 (01/December/2001) First public release Downloads
Download source and demo project - 35KBHistory
Date Posted: December 3, 2001
Date Last Updated: December 5, 2001