|
Hi,
Has anyone any ideas why LineScroll() does not work in a subclassed edit box?
When inserting text and trying to scroll to the end, a carriage return is added to the top of the text and the caret goes to the second line.
It looks pretty much like this:
<snip>
CString Container("");
int nLines;
GetWindowText(Container);
Container += "\r\n" + strText;
SetWindowText(Container);
nLines = GetLineCount();
LineScroll(nLines);
<snip>
Cheers,
/Fredrik
Do you Sonork? I do! 100.11430 PhatBoy
|
|
|
|
|
Hmmm... Will LineScroll(...) work of you do not have a scrollbar visible? If you are trying to "get to the end" of the text, why not use SetSel(...) to move the caret to the end of the text?
Or am I just missing what you are trying to do?
BTW: try not to use "" to represent an empty string with dealing with CStrings, use afxEmptyString instead. And, you do not need to initialize a CString with an empty string. It constructs to an empty string by default. (Initializing it with an empty string just wastes time.)
-=- James.
|
|
|
|
|
Well, the scrollbar is visible, and I am indeed trying to scroll to the last line of the box. I tried to use SetSel(), but then the text disappears... Using LineScroll() works with a non-subclassed edit box.
I have written handlers for OnChar(), OnKeyDown() and OnRButtonDown() in the subclassed version. Could that cause any trouble?
Cheers,
/Fredrik
Do you Sonork? I do! 100.11430 PhatBoy
|
|
|
|
|
> I have written handlers for OnChar(), OnKeyDown() and
> OnRButtonDown() in the subclassed version. Could that
> cause any trouble?
I would not think so. And what do you mean by "the text dissa[ears" when you use SetSel(...)?
-=- James.
|
|
|
|
|
James R. Twine wrote:
I would not think so. And what do you mean by "the text disappears" when you use SetSel(...)?
The text that is entered in the edit box disappears.
It is not visible, and it can't be retrieved with GetWindowText().
Cheers,
/Fredrik
Do you Sonork? I do! 100.11430 PhatBoy
|
|
|
|
|
I realized if have been a bit unclear ; what I am doing is that I have subclassed an edit box and added an OnChar handler. The OnChar handler adds text and scrolls to the bottom.
Looks something like this:
void CMySubclassedEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
 CString strText("Text\r\n>");
 CString Container;
 int nLines;
 if (nChar == 0x0D)
 {
   GetWindowText(Container);
   Container += "\r\n" + strText;
   SetWindowText(Container);
   nLines = GetLineCount();
   LineScroll(nLines);
 }
 CEdit::OnChar(nChar, nRepCnt, nFlags);
}
Cheers,
/Fredrik
Do you Sonork? I do! 100.11430 PhatBoy
|
|
|
|
|
>> The text that is entered in the edit box disappears.
>> It is not visible, and it can't be retrieved with GetWindowText().
If you are using the above code, and the text dissapears when you use SetSel(...), it might be due to the fact that your call to SetSel is incorrect, and is selecting the entire control. Then, the base CEdit::OnChar(...) gets called, which will replace the selection with whatever character was entered (a CR or LF); the result: no text in the control.
Also, in the above code, "nLines" is not initialized. That might result in some strange scrolling effects.
Lastly, if all you want to do is add a CRLF and some text to an edit control, the easiest (and faster than the code you posted) is to do a CEdit::SetSel(...) to get to the end of the control, and then call CEdit::ReplaceSel(...) with the text you want to add to the control. And since pasting normally moves the caret to the end of the pastes text, you will still be at the end of the edit control's text.
Peace!
-=- James.
|
|
|
|
|
James R. Twine wrote:
>If you are using the above code, and the text dissapears when you use SetSel(...), >it might be due to the fact that your call to SetSel is incorrect, and is selecting the entire control. >Then, the base CEdit::OnChar(...) gets called, >which will replace the selection with whatever character was entered (a CR or LF); >the result: no text in the control.
Ah, right you are.
It works if I remove the selection afterwards, naturally.
Thank you for the help, much appreciated!
Cheers,
/Fredrik
Do you Sonork? I do! 100.11430:PhatBoy
|
|
|
|
|
Hi All,
How will get all the machine name which are corrently connected in a network?
Sangeetha
|
|
|
|
|
Hi!
How can I create a tab control like the ones used in VC++, Office, Homesite etc. for switching documents. It's upside-down and the selected one is generally in white.
Thanks
/ mike
|
|
|
|
|
|
Thanks! How could I've missed that one?
/ mike
|
|
|
|
|
Hi All,
Is there any way to change the background color of a TextBox and the text Color?
Thanks in Advance.
Sangeetha
|
|
|
|
|
|
You can also check http://www.codeproject.com/editctrl/enhfocusedit.asp. Not meant to be a self-plug, but I really do not see the need for (1) a potential dynamic memory allocation whenever a paint cycle happens, or (2) the need to draw the text yourself...
You can just handle the correct messages, and let Windows do all of the work for you. Functions of interest in the code are CFocusEditCtrl::CtlColor(...) and CFocusEditCtrl::OnEraseBkgnd(...). The code also handles Disabled and Read-Only edit controls.
-=- James.
|
|
|
|
|
Season greetings to all .
In my MFC-app I have a logon-dialog that presents the user with a list-box to select between (hardcoded) odbc-connections.
My question is: Is there a way to list the defined obdc-connections in this list-box instead of whichever is hard-coded?
HarryS - Norway
|
|
|
|
|
use SQLDataSources and SQLDrivers to enumerate data sources and odbc drivers via code
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
How would I get the list of offline and online users into list boxes in my program if I wanted to make an MSN messanger client with more features than what MSN has at the moment?
Are there any resources people can tell me about using the MSN commands like Block Sender, etc etc??
Thanks
Ashman
www.settlers.net
|
|
|
|
|
does anybody know where i can download the MFC help file. In .hlp or html format.
|
|
|
|
|
When you BUY visual studio, it comes with it.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
How do I tell at runtime if am in an sdi/mdi or dlg app?
i.e are there some #defines I can use.
If so - what are they?
-cheb
|
|
|
|
|
I wonder why you thought it was an easy question
Anyway first do this
AfxGetMainWnd
to get a pointer to the main window
now call this function on the CWnd* returned
GetRuntimeClass
you'll get the class name using the m_lpszClassName member
now use IsDerivedFrom and pass the CRuntimeClass* for CDialog, CFrameWnd and CMDIFrameWnd till one of them matches
got it?
Nish
p.s. I haven't tried it out yet, so there might be somethin I missed...
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Sounds good.
I thought it would be easy as I assumed that there would be #defines buried in MFC some where for sure.
I just did not know where.
Anyway, thanks this is a good robust solution.
-cheb
|
|
|
|
|
I don't know if there are any #defines, but you might try:
AfxGetMainWnd()->IsKindOf( RUNTIME_CLASS(CDialog) );
AfxGetMainWnd()->IsKindOf( RUNTIME_CLASS(CFrameWnd) );
AfxGetMainWnd()->IsKindOf( RUNTIME_CLASS(CMDIFrameWnd) );
I haven't, though, given this a try, so I can't guarantee it will work.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Hello!!
I am building a TAPI application in which there is one server and many clients.i.e. N client machines would be connecting and communicating with 1 server machine. Once the connection is established, server would be accepting the data sent by the clients and then the same data would be again sent back to the same client who sent it to the server, through modem. The application should have the capability to do data transmission and receive simulnateously with n-clients.
The application is supposed to run on Win 98,WinNT, WIN 2000 and Win XP. I am using C programming and TAPI 2.0. I do not want to use COM/DCOM. Can you please tell me if it is possible to build an application of n-clients and 1 server using language C, TAPI 2.0 and without COM/DCOM.
I already have built an application for data communication between single client and single server.
Data transmission is done through the COM port to which the modem is connected.
Can anyone please help and advise as to how I could go on to build a n-client 1 server TAPI application.
Any help would be higly appreciated.
Thanks
Sandeep
|
|
|
|