9 Replies - 467 Views - Last Post: 22 March 2013 - 09:19 AM Rate Topic: -----

#1 codingweek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-March 13

Facing a problem in selecting the text in edit window ?

Posted 20 March 2013 - 11:07 PM

Its actually difficult to explain the problem.Let's try : :sweatdrop:
I am trying to develop a GUI compiler using win32 API.I have used 2 MDI forms, one for writing the code,second 2 show the o/p.
The "coding MDI form" contains the Edit box.(re-sizable with the window)
But the problem stand when i click "run" from menu, the compiler has to read the text from the Edit box of "coding MDI form".I can't really focus on this edit window, to scan the text for Lexical Analyser !

Here is the code for the "Run" menu item:


	switch(LOWORD(wParam))
	 {
	 case IDM_NEW:			hInstance = GetWindowWord(hWnd,GWW_HINSTANCE);
					 x=x+7;y=y+7;

				Child1 = CreateWindow("ChildClass","Program  -      nameless",WS_CHILD|WS_OVERLAPPEDWINDOW
,x,y,1155,550,hWnd,NULL,hInstance,NULL);
																ShowWindow(Child1,SW_SHOWNORMAL);
															
																   break;


case IDM_RUN:															hInstance = GetWindowWord(hWnd,GWW_HINSTANCE);
																Child2 = CreateWindow("ChildClass","Output",WS_CHILD|WS_OVERLAPPEDWINDOW,5,550,1155,200,hWnd,NULL,hInstance,NULL);
															ShowWindow(Child2,SW_SHOWNORMAL);
														
													      break;




Here is the code for the MDI child form:

LRESULT  CALLBACK _export ChildProc( HWND hChild, UINT iMessage, WPARAM wParam,LPARAM lParam )
{

	HWND 	Edit1;
	HINSTANCE hInstance1;
	PAINTSTRUCT ps;
	int nWidth,nHeight;
	 switch (iMessage)
	 {

			 case WM_CREATE :


			 case WM_SIZE:
											hInstance1 = GetWindowWord(hChild,GWW_HINSTANCE);
											Edit1 = CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_MULTILINE|ES_WANTRETURN|ES_READONLY| WS_VSCROLL|WS_HSCROLL| WS_BORDER,0,0,1000,500,hChild,100,hInstance1,NULL);
											nWidth = LOWORD(lParam);  /* width  */
											nHeight = HIWORD(lParam); /* height */

											MoveWindow (Edit1,0,0,nWidth,nHeight,1);

											ShowWindow(Edit1,SW_SHOWNORMAL);
											break;
			 default :
											return DefWindowProc( hChild, iMessage, wParam, lParam );
	 }
	 return 0;

}




The question is how focus on this edit window, to scan the text. The screenshot might be helpful !
Thankyou !

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Facing a problem in selecting the text in edit window ?

#2 codingweek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-March 13

Re: Facing a problem in selecting the text in edit window ?

Posted 20 March 2013 - 11:25 PM

Actually, i am not getting the handle of the edit window,which can solve every problem !
Was This Post Helpful? 0
  • +
  • -

#3 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 815
  • Posts: 2,413
  • Joined: 20-March 10

Re: Facing a problem in selecting the text in edit window ?

Posted 21 March 2013 - 02:54 AM

Use SendMessage with the WM_GETTEXT parameter set

something like

char text[2048];// size of text buffer to be set by user or program
SendMessage(Edit1,WM_GETTEXT,(WPARAM)sizeof(text),(LPARAM)text);


Edit1 is the handle to your textbox

Regards

Snoopy.
Was This Post Helpful? 1
  • +
  • -

#4 codingweek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-March 13

Re: Facing a problem in selecting the text in edit window ?

Posted 21 March 2013 - 10:46 PM

Well, its not working.If the buffer is not refreshed or something ! :helpsmilie:
According to u I've added the piece:
I've globally declared
char text[2048];

Now in MDI child form:
LRESULT  CALLBACK _export ChildProc( HWND hChild, UINT iMessage, WPARAM wParam,LPARAM lParam )
{

	HWND 	Edit1;
	HINSTANCE hInstance1;
	PAINTSTRUCT ps;
	int nWidth,nHeight;
	 switch (iMessage)
	 {

			 case WM_CREATE :


			 case WM_SIZE:
											hInstance1 = GetWindowWord(hChild,GWW_HINSTANCE);
											Edit1 = CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_MULTILINE|ES_WANTRETURN|ES_READONLY| WS_VSCROLL|WS_HSCROLL| WS_BORDER,0,0,1000,500,hChild,100,hInstance1,NULL);
											nWidth = LOWORD(lParam);  /* width  */
											nHeight = HIWORD(lParam); /* height */

											MoveWindow (Edit1,0,0,nWidth,nHeight,1);

											ShowWindow(Edit1,SW_SHOWNORMAL);

											[color="#FF0000"]SendMessage(Edit1,WM_GETTEXT,(WPARAM)sizeof(text),(LPARAM)text);
											MessageBox(hChild,text,"text:",MB_OK);[/color]
											break;
			 default :
											return DefWindowProc( hChild, iMessage, wParam, lParam );
	 }
	 return 0;

}

and added a message box to see the content of "text".

Now i've added same message box to see the content of "text" in "run" menu item.
 case IDM_RUN:
																[color="#FF0000"]MessageBox(Child1,text,"text:",MB_OK);[/color]
																hInstance = GetWindowWord(hWnd,GWW_HINSTANCE);
																Child2 = CreateWindow("ChildClass","Output",WS_CHILD|WS_OVERLAPPEDWINDOW,5,550,1155,200,hWnd,NULL,hInstance,NULL);
																ShowWindow(Child2,SW_SHOWNORMAL);

																break;



When i run the program:the message box comes empty which is perfectly OK :^: as at the start there is no text in the edit window.But if I write some text in the edit box then click "run",it should have shown the text but unfortunately :snap: "the message box comes empty" !
Was This Post Helpful? 0
  • +
  • -

#5 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 815
  • Posts: 2,413
  • Joined: 20-March 10

Re: Facing a problem in selecting the text in edit window ?

Posted 22 March 2013 - 01:04 AM

No it shouldn't,

SendMessage code should be in case IDM_RUN:

The way you are attempting it makes no sense.

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#6 codingweek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-March 13

Re: Facing a problem in selecting the text in edit window ?

Posted 22 March 2013 - 07:06 AM

Really thanks for not giving up on me !
i've tried ur suggestion:

 case IDM_RUN:
															   SendMessage(Edit1,WM_GETTEXT,(WPARAM)sizeof(text),(LPARAM)text);
										                  MessageBox(Child1,text,"text:",MB_OK);
																hInstance = GetWindowWord(hWnd,GWW_HINSTANCE);
																Child2 = CreateWindow("ChildClass","Output",WS_CHILD|WS_OVERLAPPEDWINDOW,5,550,1155,200,hWnd,NULL,hInstance,NULL);
																ShowWindow(Child2,SW_SHOWNORMAL);

																break;





But after compiling:

"Error RONTU_CO.CPP 163: Undefined symbol 'Edit1' in function pascal WndProc(unsigned int,unsigned int,unsigned int,long)"


its not getting the handle of the edit1 window.z
Was This Post Helpful? 0
  • +
  • -

#7 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 815
  • Posts: 2,413
  • Joined: 20-March 10

Re: Facing a problem in selecting the text in edit window ?

Posted 22 March 2013 - 07:22 AM

How are you declaring your HWND Edit1 ?

you may have to make HWND Edit1 global

I take it your case IDM_RUN: is in another form from your MDI child window ?

Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#8 codingweek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-March 13

Re: Facing a problem in selecting the text in edit window ?

Posted 22 March 2013 - 08:37 AM

this might give a clearer view !

Edit1 is declared globally.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#9 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 815
  • Posts: 2,413
  • Joined: 20-March 10

Re: Facing a problem in selecting the text in edit window ?

Posted 22 March 2013 - 08:51 AM

Hmm,

Can I see the LRESULT CALLBACK of your main form where IDM_RUN is ?

Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#10 codingweek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-March 13

Re: Facing a problem in selecting the text in edit window ?

Posted 22 March 2013 - 09:19 AM

never mind i am using a old compiler turbo c++ 4.5 :surrender:

here is the source code.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1