Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Text Handling in GDI

This topic is 6035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am making a client that will connect to a server and retrieve data simmilar to a telnet client. I do this using Windows GDI. I was wondering how I could make it so that I could highlight the text that I display as well as to copy it. I currently use TextOut(). I was also wondering how to best make a text engine with GDI in general. What i mean is should i use a linked list or vector to hold all of the lines, how do I best redraw the text after the window is covered up, and how to best set up a way to be able to scroll back to see past text that scroll up off the screen. Thanks in advance!

Share this post

Link to post
Share on other sites
these are all things you will have to expierement with. generally speaking, linked lists that house dynamically allocated arrays (ie vectors) of lines are the best space wise. a circular buffer (vector) could also be used, but requires more complex handling of drawing text since you have to parse through the text finding the new lines.

hilight is as simple as mapping the mouse to the text window to actual text. one way is to use a fixed width font and use rects that bound each character on the screen. then its a matter of knowing the start position and the length (positive or negative) of the selection. with this info you can handle copying. cut is slightly more diffiuclt since you must remove the text and then "compact" the buffer so the void is filled. look up clipboard functions for how to handle placing data in the clipboard.

scroling is just a matter of keeping track of where you are in your buffer, and moving the offset of where you draw the buffer. the simplest approach could be using the pgup and pgdn keys to scroll the buffer one line. more complex approaches include creating your own scrollbar which handles movement (ie changing the draw offset) by using the percentage of how far the thumb (ie the box thing you move) is within the scroll bar.

drawing should be done only during WM_PAINT. any updates to the buffer should call InvalidateRect(), UpdateWindow() to force a redraw if the window. an optimization could be using the paintstruct rect to draw only the text that was drawn over. maybe even have a backbuffer which is the same size as the window in which you pre draw the text when it changes, then only blit that to the window. this helps reduce flicker that may occer when updating the window, as well as be quicker then redrawing the text each time. though at the cost of having to maintain the buffer and ensure that you handle it properly (ie delete objects when required, properly resize the buffer.

test your code throughly and make sure you dont have memory leaks. any time you use selectobject() save the handle it returns so you can selectobject() it back when you are done with the resource you used with selectobject().


oldHandle = SelectObject(MyDC, MyHandle);
// do stuff
SelectObject(MyDC, OldHandle);

// during deletion of objects you can

read the forum for more examples.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!