Hi, i´ve been studying WinApi for some time now, and have actually managed to create some stuff in c++ with Visual 2010 Express.

Now, after creating my Menu, I wanted one of its functions to open a Form i've inserted through "Add New Item -> Windows Form".

The problem is, I've searched all Petzold's book and did some googling but didn´t find the actual function to open the Form.

I wanted something like:

case IDM_RUNSIM:
{ 
// When clicked, opens a new dialog box with some stuff in it...
DialogBox (hInst,  MAKEINTRESOURCE(IDD_RunSimDialogBox), hWnd, SimBoxDlgProc) ;	
}
break;

But not for a dialog box, which is declared above.

Also, when I inserted the form, it created its own Form1.h and Form1.cpp, but when I tried to #include "Form1.h" on my main.cpp, the compiler went batshit insane with lots of errors about "namespace", which do not appear when creating a Form in a project from scratch... So, do I have to Include form1.h or not in the main code?

One way might be to change the creation order of forms so that Form1 is created last.
Then in the initialization code you can assign to a global object the handle value & use it in your form through ShowWindow().

Personally, I include the "Form1.h" into my "Main.cpp" & use it (On BCB), but it doesn't seem to work in your case. Might be a error due to lack of #include guards.

You can not add a Form to a pure win32 application program. They can only be added to a CLR style project.

@nbaztec

If I try to include the Form1.h in my Main.cpp, I get errors like "'System' : a namespace with this name does not exist"

It's more like what Ancient Dragon said, when I try to add the form the "easy way", Visual warns me about the project becomming a CLR style project and then crashings ensue...

So, I was thinking about compiling two different projects, one would be the pure win32 app and the other the Form program. I just don't want to have to do the system() trick to execute the Form program from the app, as that will leave an ugly console window open...

You'll probably say something like "learn2createProcess()" so, i'm on my way to it now... =/

To show an additional 'Form' from an Sdk style program you 1st register a class for the form (window) (you'll also need a window procedure specific to that new form's Window Class), call CreateWindowEx() on the new class, and finally, ShowWindow() it. Whether the CreateWindow/ShowWindow calls are in the event handler for a menu selection, a button, whatever, doesn't matter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.