How to call a Dialog Box?

Hi!
I'm new to VS and I need some help!
I've made a main form and another (i'll use it as a dialog box).
I have a Main Menu on the main form and I want to call dialog box (form 2) when I press menu item.
I know where tu insert the call code but I dont know what code to use. Help!!!

Another question:
As for the cpp files included in the project....which one is the main one (is it the one with WinMain function )
Does this mean that I can't have main function in other cpps
How does the linking work I want that main cpp does the printing on the  main form and other cpps send data to main. How do I do that



Answer this question

How to call a Dialog Box?

  • Jason Zhao

    There are many way.

    Does WinMain call DataSender If it does then you can just return a value from DataSender() or give DataSender an out parameter. Here are three alternatives:

    // a1.cpp
    extern int DataSender();

    int WinMain()
    {
       int retValue = DataSender();
    }

    // a2.cpp
    extern void DataSender(int& retvalue);

    int WinMain()
    {
       int retValue;
       DataSender(retValue);
    }

    // a3.cpp
    extern void DataSender(int* retvalue);

    int WinMain()
    {
       int retValue;
       DataSender(&retValue);
    }



  • erock12

    OK I got that!
    It is a Windows Application, so I'm OK using WinMain in cpp1.
    so in cpp2 I don't use main function. Alrighty then!
    How do I make it that cpp2 function, lets call it DataSender() sends information to WinMain()



  • Mike V. @ AHL

  • NileshGarje

    As this is the entry point to the program the arguments are provided by whatever invokes your program: in this case the Windows system itself.

    Here is what MSDN has to say about the WinMain function and its arguments:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/winmain.asp

    If you don't care about any of these arguments then it is OK to remove them from the signature. It is similar to the regular main function: the full signature is:

    int __cdecl main(int argc, char** argv)
    {
    }


    but for a lot of simple programs the following is sufficient:

    int __cdecl main()
    {
    }


    Note: to avoid possible linkage problems due to mis-matched calling conventions you should always keep the calling convention specifier. So use:

    int APIENTRY WinMain()
    {
    }


    instead of:

    int WinMain()
    {
    }


  • Matrose

    The entry point for your program depends on the type of application you are building. Is is a console application (main), a Windows application (WinMain), a Windows DLL (DllMain) or Windows Forms application (main or maybe Main). Each program can only have one entry point and to avoid confusion you probably should not have any other global functions called main, WinMain or DllMain.



  • CRSL

  • Jil

    What technology are you using Win32, MFC, ATL, WinForms A search for "Dialog Box" on msdn.microsoft.com shows a lot of hits. Here's an MFC related one:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/vclib/html/_mfc_cdialog.asp

    Each project can only only one entry point: main, wmain, WinMain, DllMain, etc.

    If you all your C++ files are part of the same project then the linker will be invoked automatically: you don't need to do anything.

  • XcoRpio

    Thanks for the links. I think thats what I need!
    Ok, so I use WinMain as main function.
    What about other cpp files Is it legal for them to have int main(void) function (without it it would report compile errors)
    I dont know much about linking, so could you clarify me that
    Look, lets look at my project like this: (it has more thingies but this is enough for the linking explination, I think)
    1st cpp:
    has WinMain function and it calls a main form. There is a space for text in this format
    integer : integer . integer
    these three integer shoud be obtained from the 2nd cpp
    2nd cpp:
    It counts the time spent on the Internet.
    It sends information to WinMain every second.
    Information are int hours, int minutes, int seconds.



  • BigFred

    Oh, so I use DataSender() from 2nd cpp like it is a function from 1st cpp
    And I need to write a prototype of that function in the 1st cpp and with description "extern" to tell WinMain() to look for it in the linked cpps. OK thats clear!

    What is the difference between:


    int WinMain()
    {}


    and


    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR  lpCmdLine,
                         int nCmdShow)

     {}

    I know that the second one takes argumnets, but....from where


  • gika2002

    Thank you! You helped greatly.
    I'm having problem calling a form from a form.
    I've made a main form which is ran from the main function called Program.
    It has its program.cpp file from where it is called and program.h where the look of the form is coded. I have main menu on that form too.
    I also have another form. Modified like a dialog box. Its called Alarm. It also has alarm.cpp and alarm.h files.
    I want to make it so that when I press Alarm on the main menu of form Program, form Alarm (aka Dialog Box) appears.
    I know that I need to add this code

    private: System::Void AlarmMenu_Click(System::Object * sender, System::EventArgs * e) { }
     

    to namespace Program{} which is in the program.h file.
    AlarmMenu is the name of the "button" on the main menu under program form that should call alarm form.
    I also know that call has to be inside the brackets {"tha code"} but I just don't know hot to make the call.
    Any help would be most welcome.
    (I've read some info about dialog boxes at msdn but I still don't get it)


  • How to call a Dialog Box?