Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,124 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,774 people online right now. Registration is fast and FREE... Join Now!




Using RichEdit control in win32Applicaion in VC++

 
Reply to this topicStart new topic

Using RichEdit control in win32Applicaion in VC++, Windows Programming

RautRupali
7 Jun, 2007 - 04:00 AM
Post #1

New D.I.C Head
*

Joined: 7 Jun, 2007
Posts: 44


My Contributions
Hi all smile.gif ,

I m tring to use RichEdit control in win32application in VC++ using following code syntax.. I want to display XML file contents in RichEdit Box...But Its displaying in only one line....not properly....Please if anyone knows .....Help...


CODE


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
    // TODO: Place code here.
    MSG msg;
    HACCEL hAccelTable;

    // Initialize global strings
    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_ADOSAMPLE, szWindowClass, MAX_LOADSTRING);

    MyRegisterClass(hInstance);

    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_ADOSAMPLE);

    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        
        }
    }

    return msg.wParam;
    
}

ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style            = 0;// | CS_VREDRAW;
    wcex.lpfnWndProc    = (WNDPROC)WndProc;
    wcex.cbClsExtra        = 0;
    wcex.cbWndExtra        = 0;
    wcex.hInstance        = hInstance;
    wcex.hIcon            = LoadIcon(hInstance, (LPCTSTR)IDI_ADOSAMPLE);
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName    = (LPCSTR)IDC_ADOSAMPLE;
    wcex.lpszClassName    = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

    return RegisterClassEx(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
  
   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);

   UpdateWindow(hWnd);

   return TRUE;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;

    PAINTSTRUCT ps;
    HDC hdc;

    TCHAR szHello[MAX_LOADSTRING];
    LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

    switch (message)
    {

    case WM_SIZE :

    //MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE);

     InvalidateRect (hwndEdit, &rect,FALSE);
    /// UpdateWindow (hwndEdit);
        break;
        case WM_ACTIVATE:
            MoveWindow(hWnd, 0,0, 900, 700,false);
            //InvalidateRect (hwndEdit, &rect,FALSE);
            //UpdateWindow (hwndEdit);
            //::LoadLibrary("Msftedit.dll");
            break;
        case WM_CREATE:
            
        hwndEdit = CreateWindow(TEXT ("richedit"), NULL,
                        WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
                      WS_VSCROLL | ES_AUTOVSCROLL | WS_HSCROLL |
                      ES_AUTOHSCROLL | ES_MULTILINE|ES_VERTICAL |WS_THICKFRAME|
                         LBS_SORT| WS_BORDER|LBS_STANDARD ,
                       20 , 20,600 , 600 , hWnd, (HMENU)0,
                         ((LPCREATESTRUCT) lParam) -> hInstance, NULL);
            break;

        case WM_COMMAND:
            wmId    = LOWORD(wParam);
            wmEvent = HIWORD(wParam);
            // Parse the menu selections:
            switch (wmId)
            {

                case IDM_VIEWXML:
                    GetClientRect(    hwndEdit,&rect);
                    InvalidateRect (hwndEdit, &rect,TRUE);
                    UpdateWindow (hwndEdit);
                    ViewXMLFile();
                        break;
                        
                default:
                   return DefWindowProc(hWnd, message, wParam, lParam);
            }
            break;

        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);
            EndPaint(hWnd, &ps);
            break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

       void ViewXMLFile()
        {
            HDC hdc1;

            //MoveWindow(hwndEdit,400,200,400,210,true);

            InvalidateRect (hwndEdit, &rect, FALSE);

            try
            {
                hr = CoInitialize(NULL);
            
                pXMLDOMDoc.CreateInstance(__uuidof(DOMDocument));
                        
                hdc1 = GetDC(hwndEdit);
                    
                pXMLDOMDoc->load("Account.xml");

                TextOut(hdc1 ,10,20,pXMLDOMDoc->Getxml(), strlen(pXMLDOMDoc->Getxml()));

            }
            catch(_com_error &e)
            {
                dump_error(e);
            }
        }

User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Using RichEdit Control In Win32Applicaion In VC++
7 Jun, 2007 - 05:24 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
where is pXMLDOMDoc declared? what version of MSXML are you using?
User is offlineProfile CardPM
+Quote Post

rameshg87
RE: Using RichEdit Control In Win32Applicaion In VC++
7 Jun, 2007 - 05:35 AM
Post #3

New D.I.C Head
Group Icon

Joined: 6 Jun, 2007
Posts: 34


Dream Kudos: 50
My Contributions
Instead of trying Textout, try getting the handle to the rich edit window and use SetWindowText. The format of SetWindowText is

CODE

BOOL SetWindowText
   (
    HWND hWnd,            // handle of window or control
    LPCTSTR lpString     // address of string
   );


If the function succeeds, the return value is nonzero.

This post has been edited by rameshg87: 7 Jun, 2007 - 07:47 AM
User is offlineProfile CardPM
+Quote Post

rameshg87
RE: Using RichEdit Control In Win32Applicaion In VC++
7 Jun, 2007 - 05:43 AM
Post #4

New D.I.C Head
Group Icon

Joined: 6 Jun, 2007
Posts: 34


Dream Kudos: 50
My Contributions
If you insist in using Textout try tracing out the return value of the TextOut. If it is false, try tracing out the error from GetLastError().
User is offlineProfile CardPM
+Quote Post

RautRupali
RE: Using RichEdit Control In Win32Applicaion In VC++
7 Jun, 2007 - 08:04 PM
Post #5

New D.I.C Head
*

Joined: 7 Jun, 2007
Posts: 44


My Contributions
QUOTE(NickDMax @ 7 Jun, 2007 - 06:24 AM) *

where is pXMLDOMDoc declared? what version of MSXML are you using?



HI,
In declared all Interfaces globally(IXMLDOMDOC,IXMLDOMELEMENT...)

All code working fine..XML file is also displayed in RichEdit control...but it's diplaying in only one line...not line by line as in XML file....

How can I display tat file as it is in Richedit control...

thanks,
Rupali.
User is offlineProfile CardPM
+Quote Post

RautRupali
RE: Using RichEdit Control In Win32Applicaion In VC++
7 Jun, 2007 - 08:51 PM
Post #6

New D.I.C Head
*

Joined: 7 Jun, 2007
Posts: 44


My Contributions
[quote name='rameshg87' date='7 Jun, 2007 - 06:35 AM' post='229633']
Instead of trying Textout, try getting the handle to the rich edit window and use SetWindowText. The format of SetWindowText is

CODE

BOOL SetWindowText
   (
    HWND hWnd,            // handle of window or control
    LPCTSTR lpString     // address of string
   );


If the function succeeds, the return value is nonzero.

Hi,
I tried setWindowText() but nothing is displayed in control....

Syntax is as follows...

SetWindowText(hwndEdit,pXMLDOMDoc->Getxml());

Thanks,
Rupali.


User is offlineProfile CardPM
+Quote Post

RautRupali
RE: Using RichEdit Control In Win32Applicaion In VC++
7 Jun, 2007 - 10:37 PM
Post #7

New D.I.C Head
*

Joined: 7 Jun, 2007
Posts: 44


My Contributions
Please Help.....


Still my problem is not solved.
User is offlineProfile CardPM
+Quote Post

rameshg87
RE: Using RichEdit Control In Win32Applicaion In VC++
8 Jun, 2007 - 12:14 AM
Post #8

New D.I.C Head
Group Icon

Joined: 6 Jun, 2007
Posts: 34


Dream Kudos: 50
My Contributions
I have a couple of questions to ask. First check if the string is got from pXMLDOMDoc->Getxml() , is got completely. I think you can do this by checking the string length and displaying it in a message box, or display the entire string in a message box if it is small one. If the string comes fine, then check whether the richedit window is set well. Do this by outputting some other string through this rich edit ,if it works then no probelm. I had problem with the rich edit sometimes ... Can you send the whole code of it that is in the Visual Studio Projects folder , i can also check ??? If only you are interested ....

This post has been edited by rameshg87: 8 Jun, 2007 - 12:15 AM
User is offlineProfile CardPM
+Quote Post

RautRupali
RE: Using RichEdit Control In Win32Applicaion In VC++
8 Jun, 2007 - 12:46 AM
Post #9

New D.I.C Head
*

Joined: 7 Jun, 2007
Posts: 44


My Contributions
Hi....

I cant able to attach this folder...

can u give me ur mail ID..i will send it by mail...

thanks
User is offlineProfile CardPM
+Quote Post

rameshg87
RE: Using RichEdit Control In Win32Applicaion In VC++
8 Jun, 2007 - 03:50 AM
Post #10

New D.I.C Head
Group Icon

Joined: 6 Jun, 2007
Posts: 34


Dream Kudos: 50
My Contributions
My email id is rameshg87@yahoo.com
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:13PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month