Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
>HELLO all,

i have problem using c++ windows forms...i want to call second form from first form and from second form when i press button the text or label at first form changes....plz plz i badly need this their is no tutorial
Posted
Comments
Chandrasekharan P 5-May-12 5:01am    
Are you using MFC??

1 solution

Okay, I'm bored - I'll bite. (Though will point out that "plz plz" is not really considered polite) For what it's worth, as english speakers - we generally signify the end of a sentence with a full-stop (.) and use capitals for the first letter in a sentence in addition to the first character in names. Txt spk or sms tlk are generally not received very well in this particular corner of the internet. Recall and observe these guidelines and you'l likely get better, faster results to any questions.

Against my urge to say nothing until after the instructions, I will point out that these instructions are for a Win32 dialog based app, using Code::Blocks
and gcc. (MFC would require the same approach more or less with some differences in implementation)

So here's what you need to do.

1) Create dialog based app
2) Add a new static to the dialog, make sure it has a unique ID - e.g parentsStaticHwnd
3) Copy and paste the DialogProcedure with a new name e.g ChildDialogProc
4) Add resources for the extra dialog and a button or two
5) While handling WM_INITDIALOG in DialogProcedure, use GetDlgItem to get a HWND of the static control you added in step 2. - store into a global var, like hInst (since you need it for both dialogs, and not just the one invoked from your WinMain.
6) Add handler code for the button you added on the 2nd dialog. Just set the text of the window whose HWND you got in step 5 (the static on the main dialog)
7) Wire-up the 2nd dialog so that it is invoked when the button on the first form is pressed - here's my code:
C++
DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDialogProc);


There you have it, done and done. 67 lines of code, 38 lines of resource.rc
 
Share this answer
 
Comments
Richard MacCutchan 5-May-12 12:12pm    
c++ windows forms
enhzflep 5-May-12 12:28pm    
Thank-you, for repeating that which was just as clear and obvious as the remainder of the question. You may have noted that either of lack of inexperience or 1st language other than english makes a significant impact upon the accuracy of the terms used to share ideas. Surely you've seen how frequently the question title is a poor/woeful indicator of the content of the question.

My aim was to discuss the basic steps needed and to indicate that it was a fairly small, (okay, tiny) task.

Thanks for your input.
Richard MacCutchan 5-May-12 12:42pm    
Fair enough. Anyway, 5 for a clear answer.
enhzflep 5-May-12 12:55pm    
Cheers.
Gawd!
You may wish to review that decision though: "either lack of _in_experience or.."
I think we all yearn for a lack of inexperience... :grins:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900