954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Accessing TextBox from Main() in VC++

Dear DANIWEB community members,

I am a newbie with Windoze programming, and I hope you could help me going with my project as I have a really just a technical question:

I have a simple GUI with some buttons and text boxes defined in a form .h file, and I have some custom functions that run in Main() in the .cpp file. Amongst the other stuff, my functions return various status messages like 'Socket initialized, IP:' and error codes...

I have the non-editable text box in which I would like to display all that stuff, but apparently I cannot get to it from main()!!! This is most odd experience: I have the header included, the form's class and its members (all those boxed) defined in the included header.. and I cannot seemingly use it!

For now, I have to run my functions inside the event handlers which I think is not a very nice and structured way to do it. Besides, the other stuff that my functions return is rather useful and it does not get passed beyond the scope... I really would like to make use of main()... so how do I communicate with the TextBox (and with other controls for that matter) in the form from main()?

Thank you so much, and I'd really be grateful to someone taking a couple of minutes of their time to get me going!


I know there got to be some method like GetObjectByName() or something? Microsoft's Documentation is really bad: it looks like they got lost in some of their stuff by now and barely generate the class descriptions via scripts... and use it for help...

Gramotey
Newbie Poster
3 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

I'm assuming this is a non-managed program, not Windows Forms which is managed cli/c++.

Why don't you call win32 api MessageBox() , which can be called from main().

main() can use the other windows controls providing it knows about the window's HWND handle.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Well... a message box is a message box: it's in a separate little window, and it displays just one message at a time. I would like to be able to see the history and what's gonna go wrong with the device etc.
My proggy looks like this so far, and all communication aspects have been handled: I just rule that power supply from the command line... but people wantz windowz and buttonz...

Attachments screen001.png 35.98KB
Gramotey
Newbie Poster
3 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

How are the functions in main() getting called? Pass them another parameter -- the HWND to the command history window.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Dear Ancient Dragon,

Thank you! I see what you say now, and I will try... however it keeps bothering me that there is some pretty and simple way to communicate among the various controls. This experiment will take some time now, as I am a newbie.

Gramotey
Newbie Poster
3 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: