Click to See Complete Forum and Search --> : gotoxy/TextOut etc.
UnfitElf
November 23rd, 2005, 06:14 PM
Hi people,
What i need is some way to have a function like gotoxy that will work for an edit.
The user needs to be able to specify two values (row and column) and the edit's cursor need to jump to that position.
Ive been trying to find something that will enable me to do this for a a long time now and havent come up with anything.
Im 99.999% sure that there is no API or anything that will allow me to do this, so im looking for peoples ideas.
Any ideas at all would greatly appreciated!!
Note: It would be prefered if these ideas were for an edit/rich edit however , even ideas like TextOut() would be a HUGE help!!!
TextOut would be great however, it needs to be done everytime the WM_PAINT message is sent or u would loose the text.
Thanks heaps in advance!!
wildfrog
November 23rd, 2005, 07:17 PM
What if you get the text from edit control (using WM_GETTEXT/EM_GETTEXTEX). Then you count the number of characters in that text until you have encountered the desired number of line breaks. Now you know how many character you need to skip to get to the line. Then add the number of columns (you have to be sure that the specific line has enough characters). Then use WM_SETSEL change te position of the marker.
- petter
UnfitElf
November 24th, 2005, 11:56 PM
Hi,
Thanks heaps, thats a real good idea, i cant believe i havent thought of that or come accross it.
Ill have a look into doing it that way.
One more question.. in some text editers there is an option to stop the cursor from stopping at the end of each line and being automatically moved when you hit the arrow keys.
Its a bad explanation but when you hit the down arrow key the cursor will do down directally one space and not shift left or right even if the line it is moving to doesnt have any text. Is there a simple option to do this, or is it done some other way?
Thanks
UnfitElf
December 1st, 2005, 03:34 AM
I think that idea about WM_SETSEL is going to be great. Still however unsure about the second problem
Bump
UnfitElf
December 5th, 2005, 03:56 PM
OK people just an update to how things are going.
Ive done what i require however i feel its very messy and im sure there must be a better way..
Anyhow what i did was full the richedit with spaces (the richedit is a fixed width and height so this is ok).
I then used the EM_SETSEL message to set the caret to the right position (thanks wildfrog).
I have come up with 2 ways of outputing data to the richedit and am unsure of what would be the best of the two methods.
Method 1:
I send the richedit the VK_INSERT keydown message to put it into overwrite mode when the richedit is first created.
I then pass a string to my function which does the following
int i = 0;
while(text[i] != '\0')
{
SendMessage(hRich, WM_CHAR, (WPARAM)text[i], (LPARAM)0);
i++;
}
Method 2:
I dont worry about having the richedit in overwrite mode.
I pass the string to my function, and get its length. I then get the current caret position and add the length of the string onto the current position and send the richedit a EM_SETSEL message.
I then send it a EM_REPLACESEL.
int len;
CHARRANGE range;
SendMessage(hRich, EM_EXGETSEL, 0, (LPARAM)&range);
len = strlen(text);
SendMessage(hRich, EM_SETSEL, (WPARAM)range.cpMin, (LPARAM)(range.cpMax + len));
SendMessage(hRich, EM_REPLACESEL, (WPARAM)false, (LPARAM)text);
What method would be the best and why?
Thanks very much
wildfrog
December 5th, 2005, 04:12 PM
What method would be the best and why?I'd go for the second solution. The Rich Edit control is full of 'strange behaviour' and what if it's already in 'override mode' when you send the VK_INSERT keydown message?
- petter
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.