Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Rich Text

Posted on 1999-07-08
16
Medium Priority
?
436 Views
Last Modified: 2008-02-20
I am building an interface which consist of a edit text. To display text in the edit box, I have to file the text in the .txt file (notepad) and display on the edit box by using the SetWindowText. Any way, I found that I have to align the text so that it can be displayed beautifully. This is not a good way in programming. Furthermore, I can't cahnge the text color if I use the SetWindowText(). I want to change the edit box to rich text because the rich text can be edited, copied and pasted. How can I use the rich text? Should I change the edit box formating? Please show me the way and the example.
0
Comment
Question by:jessicalim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
16 Comments
 
LVL 3

Expert Comment

by:Shay050799
ID: 1263395
if its MFC question please delete it and resubmitt it at the MFC category
please
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1263396
???
0
 
LVL 11

Accepted Solution

by:
alexo earned 150 total points
ID: 1263397
jessicalim, this is a windows-specific question and thus should have been posted in the windows programming area instead of here.

Now, to answer it:

An edit control cannot display rich text.  Use a rich edit control instead.

To create a rich edit control, call the CreateWindowEx function, specifying the rich edit window class. If you are using rich edit 1.0 (RICHED32.DLL), specify "RichEdit" for the window class parameter. If you are using rich edit version 2.0 (RICHED20.DLL), specify RICHEDIT_CLASS (defined in RICHEDIT.H) for the window class parameter.

Rich edit controls support most of the window styles used with edit controls as well as additional styles. You should specify the ES_MULTILINE window style if you want to allow more than one line of text in the control.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:jessicalim
ID: 1263398
I tried to create the rich edit. But the rich edit can't appear.
Here's part of the source code:
hEdit = CreateWindowEx(WS_EX_WINDOWEDGE,"RICHEDIT","Rich Edit",
      WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_LEFT|WS_BORDER,
      0,150,782,395,hWnd, NULL, ghInstance, NULL);
ShowWindow(hEdit, SW_SHOW);

I have included the richedit.h also.
Why the rich edit can't appear?

0
 
LVL 11

Expert Comment

by:alexo
ID: 1263399
What is the value of hEdit?
Did you try using GetLastError() to get the reason for the error?
Did you call InitCommonControls() before creating the control?

0
 

Author Comment

by:jessicalim
ID: 1263400
I declared the hEdit as HWND.
I have included the InitCommonControlsEx() and loaded the RICHED32.DLL.
The Rich Edit can only display after I called out the WinHelp() by pressing F1. But I want the Rich Edit to be displayed right after I run the program. I don't want the Rich Edit to be controlled by any keystroke.
 
0
 
LVL 11

Expert Comment

by:alexo
ID: 1263401
This is very strange but I have a feeling it is not a richedit issue.
Can you post the rest of the program (up to the message loop)?
Another suggestion, (if the problem is with the richedit after all) try using the RICHEDIT_CLASS class (no quotes, it is a #define) instead.
0
 

Author Comment

by:jessicalim
ID: 1263402
//The header files

#include <windows.h>
#include <string.h>
#include <commctrl.h>
#include <stdio.h>
#include <richedit.h>

//This is the code I declared in WinMain()
//InitWins is the create main window function

InitWins(hInstance, hPrevInstance);
hAccel = LoadAccelerators(hInstance, "TOT");
LoadLibrary( "c:\\WINNT\\SYSTEM32\\riched20.dll" );
cc.dwSize = sizeof(INITCOMMONCONTROLSEX);
cc.dwICC = ICC_WIN95_CLASSES ;
InitCommonControlsEx(&cc);
....

//This is the code I declared in WndProc()

case WM_CREATE:
InitChild(hWnd);
CreateEditBox(hWnd);//I declared the rich edit
CreateTree(hWnd);
CreateScroll();       
hnewf = CreateFont( 6,0,0,0, W_NORMAL,0,0,0, NSI_CHARSET, UT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, EFAULT_PITCH|FF_DONTCARE,"Arial");
InitTree();      
break;
...

//This is the create rich text function

void CreateEditBox(HWND hWnd)
{
hEdit = CreateWindowEx(WS_EX_WINDOWEDGE,RICHEDIT_CLASS, "rich edit",WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_SUNKEN| ES_SAVESEL| ES_LEFT|WS_BORDER,0,y/4,391*x/400, 79*y/120, hWnd,(HMENU)ID_RICHEDIT,ghInstance,NULL);
error = GetLastError();
}                                
...

I checked from the GetLastError(), the error code is 1407, which means cannot find window class.
Is there any other common controls for rich edit because I can't find any related command (e.g. ICC_TREEVIEW, ICC_UPDOWN_CLASS, etc...)?



0
 
LVL 11

Expert Comment

by:alexo
ID: 1263403
I see you're not into the habit of checking the return values of APIs...
Check if the LoadLibrary(), InitCommonControlsEx(), etc.

0
 

Author Comment

by:jessicalim
ID: 1263404
The return value of the LoadLibrary() is 0x48000000 n the InitCommonControlsEx() is 1. So, what's wrong of the source code?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1263405
Hmmm...  LoadLibrary() returns a valid handle, InitCommonControlsEx() succeeds as well...  I really don't know but I'll try some more guesses.

* Try using InitCommonControls() instead.

* Try replacing "riched20.dll" with "riched32.dll" and using "richedit" or "RichEdit" as the class name.

I'll think about it some more and get back to you.

0
 
LVL 11

Expert Comment

by:alexo
ID: 1263406
Are you compiling with UNICODE support?

Also check http://www.deja.com/getdoc.xp?AN=331402369


0
 
LVL 11

Expert Comment

by:alexo
ID: 1263407
0
 

Author Comment

by:jessicalim
ID: 1263408
alexo,
I can get the rich edit box now. But I didn't create it in WM_CREATE or WM_INITDIALOG. I got it when I placed the create rich edit box source code in one of the menu item in WM_COMMAND. Yes, it comes out when I press on the menu item. Why it acts like this?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1263409
>> Why it acts like this?
I have no idea.  I answered the original question (hopefully to your satisfaction) but the other problem is outside my are of "expertise".  Sorry.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1263410
Only other thing I can think about this problem is maybe the rich edit control needs certain things that are not initialized yet.  Try to move the call to CreateEditBox() to the end of the WM_CREATE handler.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question