locked
How to create a splash screen in visual c++ for window form?

    Question

  • Hi
    i am new to visual c++ and i am using visual c++ 2008 express edition
    how do i start a form with the splash screen?

    Wednesday, October 22, 2008 3:50 AM

Answers

  • Right-click your project in Solution Explorer and choose References.  Add Refence and select Microsoft.VisualBasic.

    Make your main .cpp file look like this:

    #include "stdafx.h"
    #include "frmSplash.h"   // <--- Your splash form
    #include "Form1.h"

    using namespace cppSplashScreen;   // <-- Change this to your namespace
    using namespace Microsoft:: VisualBasic:: ApplicationServices;

    public ref class MyApp : WindowsFormsApplicationBase {
    protected:
      virtual void OnCreateSplashScreen() override {
        this->SplashScreen = gcnew frmSplash;
      }
      virtual void OnCreateMainForm() override {
        // Do your initialization work here...
        //..
        System:: Threading:: Thread:: Sleep(5000);   // Pretend we're doing work

        // Then create the main form, the splash screen will automatically close
        this->MainForm = gcnew Form1;
      }
    };

    [STAThreadAttribute]
    int main(array<System:Tongue Tiedtring ^> ^args)
    {
      // Enabling Windows XP visual effects before any controls are created
      Application::EnableVisualStyles();
      Application:Tongue TiedetCompatibleTextRenderingDefault(false);

      // Create app instance
      MyApp^ app = gcnew MyApp;
      app->Run(args);
      return 0;
    }

    Thursday, October 23, 2008 12:11 PM
  • Hi cygoh85,


    From your post info above, the first error is caused by mismatched type.


    this->MainForm=gcnew Form1;

    The “MainForm”’s type is “Microsoft::VisualBasic::ApplicationServices::WindowsFormsApplicationBase::MainForm”, and “Form1”’s type is “System::Windows::Forms::Form”, you are unable to implicitly assign “Form” object to a variable  of “MainForm” type, it is illegal.


    Form1^ app=gcnew Form1;

    For ambiguous symbol issue, you can assign the scope like the following code snippet.

    Form1^ app=gcnew MyApp::Form1;


    For your information, there is an awesome sample about splash screen in .Net framework, though it is C#, I believe it is not a problem to convert it to managed C++ code.

     

    A Pretty Good Splash Screen in C#

     

    By the way, you can upload your project to http://skydrive.live.com/

    So that we can download it and do some troubleshooting.


    Regards,

    Xun

    Friday, October 24, 2008 7:32 AM

All replies

  • Right-click your project in Solution Explorer and choose References.  Add Refence and select Microsoft.VisualBasic.

    Make your main .cpp file look like this:

    #include "stdafx.h"
    #include "frmSplash.h"   // <--- Your splash form
    #include "Form1.h"

    using namespace cppSplashScreen;   // <-- Change this to your namespace
    using namespace Microsoft:: VisualBasic:: ApplicationServices;

    public ref class MyApp : WindowsFormsApplicationBase {
    protected:
      virtual void OnCreateSplashScreen() override {
        this->SplashScreen = gcnew frmSplash;
      }
      virtual void OnCreateMainForm() override {
        // Do your initialization work here...
        //..
        System:: Threading:: Thread:: Sleep(5000);   // Pretend we're doing work

        // Then create the main form, the splash screen will automatically close
        this->MainForm = gcnew Form1;
      }
    };

    [STAThreadAttribute]
    int main(array<System:Tongue Tiedtring ^> ^args)
    {
      // Enabling Windows XP visual effects before any controls are created
      Application::EnableVisualStyles();
      Application:Tongue TiedetCompatibleTextRenderingDefault(false);

      // Create app instance
      MyApp^ app = gcnew MyApp;
      app->Run(args);
      return 0;
    }

    Thursday, October 23, 2008 12:11 PM
  • thanks a lot for your guide..try it out tmr

     

    Thursday, October 23, 2008 4:17 PM
  •  

    Could just make a regular form with a timer, then when the timer reaches zero, close that form and show the main one?
    Thursday, October 23, 2008 6:19 PM
  • Hi

    i am having error at these lines

     

    error C2059: syntax error : '>'

    this->SplashScreen = gcnew frmSplash;

    error C2664: 'Microsoft::VisualBasic::ApplicationServices::WindowsFormsApplicationBase::MainForm:Tongue Tiedet' : cannot convert parameter 1 from 'Form1 ^' to 'System::Windows::Forms::Form ^'

    this->MainForm=gcnew Form1;

     

    error C2872: 'Form1' : ambiguous symbol

    could be '.\MyApp.cpp(10) : Form1'

    or 'c:\documents and settings\cygoh\desktop\myapp\myapp\Form1.h(22) : MyApp::Form1'

    Form1^ app=gcnew Form1;

     

    i am using visual c++ express 2008 edition

    thank you for your help

    Friday, October 24, 2008 4:42 AM
  • It looks like the class "Form1" is defined more than once and it doesn't know which you mean?

     

     

    As for the other error, it looks like whatever function you're trying to use can't use "Form1" but needs a System.Windows.Forms.Form class.

     

    Friday, October 24, 2008 7:16 AM
  • Hi cygoh85,


    From your post info above, the first error is caused by mismatched type.


    this->MainForm=gcnew Form1;

    The “MainForm”’s type is “Microsoft::VisualBasic::ApplicationServices::WindowsFormsApplicationBase::MainForm”, and “Form1”’s type is “System::Windows::Forms::Form”, you are unable to implicitly assign “Form” object to a variable  of “MainForm” type, it is illegal.


    Form1^ app=gcnew Form1;

    For ambiguous symbol issue, you can assign the scope like the following code snippet.

    Form1^ app=gcnew MyApp::Form1;


    For your information, there is an awesome sample about splash screen in .Net framework, though it is C#, I believe it is not a problem to convert it to managed C++ code.

     

    A Pretty Good Splash Screen in C#

     

    By the way, you can upload your project to http://skydrive.live.com/

    So that we can download it and do some troubleshooting.


    Regards,

    Xun

    Friday, October 24, 2008 7:32 AM
  • thanks for all your help, i figured out how to do it already

     

    Sunday, October 26, 2008 12:10 PM
  • Great.  Please close the thread by marking it answered.
    Sunday, October 26, 2008 2:15 PM