Sunday, July 12, 2009

Visual C++ OOP.?

Alright, we all know how to program that 'Hello World' in console, that cout or printf command and boom.





So how do we actually input that 'Hello World' in a command in Visual C++ using the GUI that when you input a command button (drag the command button in the toolbox that has it) it will display the message box when you click it?





Hmm?

Visual C++ OOP.?
The actual command is something along the lines of either





MessageBox( 0, "Hello World." );





or





MessageBox( "Hello World." );





depending on where the call is being made from.





That being said, getting to the point of making and successfully compiling that call requires a totally different compilation mode from Console. MFC or .Net is required.





Hope that helps.
Reply:first of all, you need to create a Win32 project with a WinMain() function instead of a normal main() function.





Then you can define a dialog in the resource section (i.e. with the dialog designer of visual studio). You can load this dialog as a main window. You will also need a message loop, otherwise you can't react to windows messages, which are sent i.e. when a button is pressed or the window is closed.





you see, it's a bit complicated. There's a good book of Charles Petzold about Windows API programming, maybe you find a cheap copy. And codeguru.com has some articles and tutorials.
Reply:I dont know alot about VC++





But you can try makeing a button and a label





Then type in the button's eventhandler





label1.text = "Hello world"





That is VB code, but there isnt a bit difference between them.
Reply:In design mode


Add a button to a new form


Double Click the button


In the code window


Type "MessageBox("Hello", "Info", MB_OK);"


between { and }


Then run the program to see the result.


No comments:

Post a Comment