working with richedit controls

Posted on 2004-11-10
Last Modified: 2008-01-16

i'm using win32 api to make a program thats similar to a notepad, it have to accept and save characters of different languages. atm i have the richedit control created but i tried to use EM_GETTEXTRANGE msg to get the stuff in the control to save it but i cant convert wchar_t (which is the type my buffer used to store the stuff) to LPSTR
basically whats happening now is that i created a TEXTRANGE object which consist of 2 part, 1 is a CHARRANGE and the other is a pointer to a string where i'm going to store the stuff. then the TEXTRANGE pointer that i created will be passed to SendMessage with parameter (editbox, EM_GETTEXTRANGE, 0, (LPARAM) textrange)
this should store the stuff that is typed in the edit control to the wchar_t buffer.

buff = new wchar_t[length];
 LPWSTR wstr = buff;
CHARRANGE charrange;
charrange.cpMin = 0;
charrange.cpMax = -1;

TEXTRANGE *textrange = new TEXTRANGE;
textrange->chrg = charrange;
textrange->lpstrText = wstr;

SendMessage(editbox, EM_GETTEXTRANGE, 0, (LPARAM) textrange);

any help is very appreciated
Question by:madonion87
    LVL 16

    Accepted Solution

    buff = new wchar_t[length];
     char lpstr[length];

    wcstombs(lpstr, buff, length-1);
    CHARRANGE charrange;
    charrange.cpMin = 0;
    charrange.cpMax = -1;

    TEXTRANGE *textrange = new TEXTRANGE;
    textrange->chrg = charrange;
    textrange->lpstrText = lpstr;

    SendMessage(editbox, EM_GETTEXTRANGE, 0, (LPARAM) textrange);

    Author Comment

    yea that works, thanks
    but i've found another problem lol

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now