Thread: Problems with my edit control...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    132

    Problems with my edit control...

    Okay I currently have two problems with my edit control, one being that when I use SetWindowText to set a "buffer" for an edit control any \n's are translated in the process to |s how do I make it so then \n's are kept as newline's (i.e. as if the user had pressed the enter key in a ES_MULTILINE edit control)?

    Now my second problem is, how do I change text colour for text as I add it into the buffer? Do I have to place text into an edit control differently then I am in order to have each line (not necessary each line, but it depends on what is happening in the program) a different colour (as required)? I have no idea how to change the text colour for each line while using the SetWindowText() function considering that all the text is placed into the edit control at the same time.

    All help is appreciated,
    Tyouk

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    AFAIK

    \n\r if edit has ES_MULTILINE

    can't be done in non Rich Edit, all text is same font and colour.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    132
    Okay I have ES_MULTILINE specified in the creation of the edit control, however, it still wont place a new line (I've tried '\n', "\r\n", "\n\r" but no combination works).

    Could someone explain to me the differences between an edit control and a rich edit. And is there anyway to setup (not using C++, just C) an edit control (or since I most likely need a rich edit control, then a rich edit) so then all I have to do is change the contents of a buffer (say it's assigned as char buffer[10001] and the contents of the edit will automatically be changed?

  4. #4
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    The rich edit control has more features such as multiple undos and more text formatting messages. I'm not 100% sure, but I also believe it offers better performance in some areas (someone tell me if I'm wrong here).

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    132
    Okay I tried to create a rich edit control based on a tutorial I found, and it said that I had to use the LoadLibrary() call to load in the richedit library, either the 2.0/3.0 (richedit20.dll) versions or the 1.0 (richedit32.dll) version. When I set it up so then it tried loading the richedit20.dll first, if failed then it would try loading the richedit32.dll both failed and the richedit wasn't created. Can anyone tell me the problem? My code is as follows:

    Code:
    // link with the richedit library
    hLib = LoadLibrary(TEXT("RICHEDIT20.DLL"));
    	if( !hLib ) {
    		hLib = LoadLibrary(TEXT("RICHEDIT32.DLL"));
    		if( !hLib ) {
    			MessageBox(NULL, TEXT("Failed to load rich edit library!"), TEXT("Initialization Error"), MB_OK | MB_ICONERROR);
    			return(0);
    		}
    		else { lstrcpy(chCntrlName, TEXT("RICHEDIT")); }
    	}
    	else { lstrcpy(chCntrlName, RICHEDIT_CLASS); }
    Oh that code was placed in my main windows procedure under the WM_CREATE message, however, the rich edit I am trying to create is in a totally different procedure (for an MDI child window).

    Thanks

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Sorry, might need this to get the edit to display the new lines.

    ES_MULTILINE|ES_WANTRETURN

    As to the loadlibrary and rich edit

    RICHED20.DLL loads for me (not richedit20.dll ) create with RichEdit20A as the class name.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    132
    Okay I fixed the library loading, I am running WinXP Pro and so I had to load the MSFTEDIT.DLL (for version 4.1 of the richedit libraries). I read that in MSDN, except I couldn't find anything that would tell me why the richedit's wont actually display.

    Basically I'm making a program where each window that comes up has an editbox (single line) at the bottom of the window with the rest of the window supposed to be the richedit box (disabled and background colour changed to white), all the code for this worked with an editbox but now that I changed it to a richedit it wont display the richedit itself and so I can't tell if the code for changing the background of the control works or not.

    Any help would be greatly appreciated!
    Tyouk

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    What handle is returned from the create?
    What did GetLastError() return if the handle is null?

    Have you got the WS_VISIBLE on the edit or called ShowWindow()?

    Post some code so we don't have to guess.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Registered User
    Join Date
    May 2002
    Posts
    132
    It states that the last error code returned was 1407: Cannot find window class

    Code:
    hDisplay = CreateWindowEx(WS_EX_CLIENTEDGE, chCntrlName, "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | /*WS_DISABLED |*/ ES_MULTILINE, rect.left, rect.top, rect.right - rect.left, rect.bottom - 17 - rect.top, hwnd, NULL, g_hInst, NULL); // creating text display area
    			if( hDisplay == NULL ) { error = GetLastError(); sprintf(buffer, "Last Error Code: %d", error); MessageBox(NULL, buffer, "Error", MB_OK); }
    Thats the code I was using to display the richedit, chCntrlName comes from when I load the richedit library and is set as follows:

    Code:
    // load richedit library
    		hLib = LoadLibrary(TEXT("MSFTEDIT.DLL"));
    		if( !hLib ) {
    			hLib = LoadLibrary(TEXT("RICHEDIT20.DLL"));
    			if( !hLib ) {
    				hLib = LoadLibrary(TEXT("RICHEDIT32.DLL"));
    				if( !hLib ) {
    					MessageBox(NULL, TEXT("Failed to load rich edit library!"), TEXT("Initialization Error"), MB_OK | MB_ICONERROR);
    					return;
    				}
    				else { lstrcpy(chCntrlName, TEXT("RICHEDIT")); }
    			}
    			else { lstrcpy(chCntrlName, RICHEDIT_CLASS); }
    		}
    		else { lstrcpy(chCntrlName, RICHEDIT_CLASS); }
    The code is slightly screwed up, trying to load the 4.1 library then the 1.0 and then the 2.0/3.0 if they fail loading in that order. I'll have to fix that Anyways. There is the code dealing with it.

    Thanks,
    Tyouk

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    what is in this define RICHEDIT_CLASS?

    Is the same text in the string holding the class name when you call the create?

    Again it is NOT

    RICHEDIT20.DLL

    it is

    RICHED20.DLL

    It is NOT

    RICHEDIT32.DLL

    it is

    RICHED32.DLL

    run a search on your PC for these files.

    this works on a Win2000 with IE v6 and MSVC.NET 2003
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  11. #11
    Registered User
    Join Date
    May 2002
    Posts
    132
    Well what do you place in the class parameter of the CreateWindowEx() function call? I read a tutorial that said I had to use RICHEDIT_CLASS, it's defined in richedit.h thats all I know about it.

    Yes the same string is in chCntrlName when I call CreateWindowEx(), chCntrlName is a global variable in my program used to store the class name for richedit text (or at least that was the idea), that way I could initialize everything that needed setting up prior to the program actually doing it's job and then could create any richedit controls as needed later on from other functions or windows procedures.

    And you were right about the filenames. Again those came from the same tutorial (I guess the tutorial is a little outdated, or perhaps it's just completely wrong).
    Last edited by tyouk; 10-15-2003 at 03:53 AM.

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    RichEdit20A with the RICHED20.DLL

    this works on a Win2000 with IE v6 and MSVC.NET 2003



    As you are creating a WS_CHILD edit you must cast the HMENU to an int ID

    ie
    #define IDC_MYRICHEDIT 40001//above the defines used by MSVC complier

    ,hParent, (HMENU) IDC_MYRICHEDIT,
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  13. #13
    Registered User
    Join Date
    May 2002
    Posts
    132
    ERRRRR... Okay sorry to have wasted your time novacain and anyone else who offered any suggestions. My problem was that I was calling the function to create the new window (that contained the richedit control) prior to the Initialize() function loading the appropriate DLL. I fixed this problem, but now my program decided that it wants to end prior to it really doing anything, you barely catch a glimpse of the program before it closes.

    Thanks for all your help now to sort through this problem!
    Tyouk

  14. #14
    Registered User
    Join Date
    May 2002
    Posts
    132
    OMG, I guess I'm more tired then I thought... hehehe. Forgetting the break; in my windows procedure that separated the WM_CREATE code from the WM_DESTROY code!

    lol, thanks for your help all... works great
    Tyouk

  15. #15
    Registered User
    Join Date
    May 2002
    Posts
    132
    Okay nevermind, it wasn't giving me the error message while the program continued to close on me because I forgot the break; or erased it or something... but as soon as I fixed that problem with the program closing, it decided to not work out that way and again I receive the 1407: Cannot find window class. error. Here is my code that all deals with creating the richedit controls:

    in my WM_CREATE message I have the following code:

    Code:
    .
    .
    .
    // initialize the program and any structs needed
    Initialize();
    CreateStatus();
    break;
    then in my Initialize() function I have:

    Code:
    // load richedit library
    hLib = LoadLibrary(TEXT("MSFTEDIT.DLL"));
    if( !hLib ) {
    	hLib = LoadLibrary(TEXT("RICHED32.DLL"));
    	if( !hLib ) {
    		hLib = LoadLibrary(TEXT("RICHED20.DLL"));
    		if( !hLib ) {
    			MessageBox(NULL, TEXT("Failed to load rich edit library!"), TEXT("Initialization Error"), MB_OK | MB_ICONERROR);
    			return;
    		}
    		else { lstrcpy(chCntrlName, TEXT("RICHEDIT")); }
    	}
    	else { lstrcpy(chCntrlName, RICHEDIT_CLASS); }
    }
    else { lstrcpy(chCntrlName, RICHEDIT_CLASS); }
    the above code has already been pasted but I'm making it easier to clarify what is happening in my program by posting it again all in one post... the next code is in my CreateStatus() function:

    Code:
    char error[45];
    int err;
    MDICREATESTRUCT mcs;
    
    mcs.szTitle = "Status: Atraeon";
    mcs.szClass = g_szStatus;
    mcs.hOwner = g_hInst;
    mcs.x = CW_USEDEFAULT;
    mcs.cx = 600;
    mcs.y = CW_USEDEFAULT;
    mcs.cy = 500;
    mcs.style = MDIS_ALLCHILDSTYLES;
    	
    g_hStatus = (HWND)SendMessage(g_hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);
    if( g_hStatus == NULL ) {
    	err = GetLastError();
    	sprintf(error, "Status window creation failed. (%d)", err);
    	MessageBox(NULL, error, TEXT("Creation Failure"), MB_ICONERROR | MB_OK);
    }
    ShowWindow(g_hMDIClient, SW_SHOW);
    The above deals with creating the window in my MDI client. The next bit of code is found under the WM_CREATE in my StatusWndProc procedure which deals with the Status window.

    Code:
    HWND hDisplay; // defined at the beginning of the windows procedure
    hDisplay = CreateWindowEx(WS_EX_CLIENTEDGE, "RICHEDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_DISABLED | ES_MULTILINE, rect.left, rect.top, rect.right - rect.left, rect.bottom - 17 - rect.top, hwnd, (HMENU)IDC_MYRICHEDIT, g_hInst, NULL); // creating text display area
    if( hDisplay == NULL ) {
    	error = GetLastError();
    	sprintf(buffer, "Failure to create richedit control for status window. (%d)", error);
    	MessageBox(NULL, buffer, "Error", MB_OK);
    }
    Thats all the code that deals with creating my first richedit control for the program. I've also added the HMENU (defined at the beginning of the program as 40000) and added it to the CreateWindowEx call. None of it works. I've tried placing "RichEdit20A", "RichEdit20W", RICHEDIT_CLASS, "RICHEDIT", and various other "classes" into the CreateWindowEx call under my StatusWndProc call (in WM_CREATE) but none of them work. I've tried using the chCntrlName as well that is set under the Initialize() function. I'm getting no errors besides the ones outputted by my Message Boxes throughout the code. And the only one I get relating to this series of code is the 1407 error returned by GetLastError when the handle is returned as NULL.

    Any help would be greatly appreciated!
    Tyouk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can't disable ctrl-V on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-06-2008, 08:37 AM
  2. Controlling edit control input
    By Gerread in forum Windows Programming
    Replies: 6
    Last Post: 05-03-2007, 08:56 PM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. How can I send a text string to an edit control
    By marc74 in forum Windows Programming
    Replies: 5
    Last Post: 01-06-2005, 10:14 PM
  5. Get Notified of ENTER in single line EDIT control
    By Morpheus in forum Windows Programming
    Replies: 1
    Last Post: 06-29-2002, 07:07 PM