C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Using RichEdit control in win32Applicaion in VC++ Windows Programming Rate Topic: -----

#1 RautRupali  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 07-June 07


Dream Kudos: 0

Share |

Using RichEdit control in win32Applicaion in VC++

Post icon  Posted 07 June 2007 - 04:00 AM

Hi all :) ,

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...



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);
			}
		}

Was This Post Helpful? 0
  • +
  • -


#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • Icon

Reputation: 1005
  • View blog
  • Posts: 7,698
  • Joined: 18-February 07


Dream Kudos: 1250

Expert In: Java/C++

Re: Using RichEdit control in win32Applicaion in VC++

Posted 07 June 2007 - 05:24 AM

where is pXMLDOMDoc declared? what version of MSXML are you using?
Was This Post Helpful? 0
  • +
  • -

#3 rameshg87  Icon User is offline

  • New D.I.C Head
  • Icon

Reputation: 3
  • View blog
  • Posts: 34
  • Joined: 06-June 07


Dream Kudos: 50

Re: Using RichEdit control in win32Applicaion in VC++

Posted 07 June 2007 - 05:35 AM

Instead of trying Textout, try getting the handle to the rich edit window and use SetWindowText. The format of SetWindowText is

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: 07 June 2007 - 07:47 AM

Was This Post Helpful? 0
  • +
  • -

#4 rameshg87  Icon User is offline

  • New D.I.C Head
  • Icon

Reputation: 3
  • View blog
  • Posts: 34
  • Joined: 06-June 07


Dream Kudos: 50

Re: Using RichEdit control in win32Applicaion in VC++

Posted 07 June 2007 - 05:43 AM

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().
Was This Post Helpful? 0
  • +
  • -

#5 RautRupali  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 07-June 07


Dream Kudos: 0

Re: Using RichEdit control in win32Applicaion in VC++

Posted 07 June 2007 - 08:04 PM

View PostNickDMax, on 7 Jun, 2007 - 06:24 AM, said:

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.
Was This Post Helpful? 0
  • +
  • -

#6 RautRupali  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 07-June 07


Dream Kudos: 0

Re: Using RichEdit control in win32Applicaion in VC++

Posted 07 June 2007 - 08:51 PM

[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

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.
Was This Post Helpful? 0
  • +
  • -

#7 RautRupali  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 07-June 07


Dream Kudos: 0

Re: Using RichEdit control in win32Applicaion in VC++

Posted 07 June 2007 - 10:37 PM

Please Help.....


Still my problem is not solved.
Was This Post Helpful? 0
  • +
  • -

#8 rameshg87  Icon User is offline

  • New D.I.C Head
  • Icon

Reputation: 3
  • View blog
  • Posts: 34
  • Joined: 06-June 07


Dream Kudos: 50

Re: Using RichEdit control in win32Applicaion in VC++

Posted 08 June 2007 - 12:14 AM

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: 08 June 2007 - 12:15 AM

Was This Post Helpful? 0
  • +
  • -

#9 RautRupali  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 07-June 07


Dream Kudos: 0

Re: Using RichEdit control in win32Applicaion in VC++

Posted 08 June 2007 - 12:46 AM

Hi....

I cant able to attach this folder...

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

thanks
Was This Post Helpful? 0
  • +
  • -

#10 rameshg87  Icon User is offline

  • New D.I.C Head
  • Icon

Reputation: 3
  • View blog
  • Posts: 34
  • Joined: 06-June 07


Dream Kudos: 50

Re: Using RichEdit control in win32Applicaion in VC++

Posted 08 June 2007 - 03:50 AM

My email id is rameshg87@yahoo.com
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users