Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simple splash screen code needed

Posted on 1998-11-20
9
Medium Priority
?
374 Views
Last Modified: 2012-05-04
I have a W95/98 32 bit application that uses nothing more complicated in the GUI than MessageBox. The program is a 'front end' to other programs and does some processing for about 10 seconds. Currently, if all goes well, there is no visible change to the desk top to show that my program is running.

I now want to display a 'splash screen' during these 10 seconds which is taken from an image file (bmp or gif etc). The idea is this.

Program starts.
Loads image file.
Displays image file on screen.
Carries out 10 seconds of processing.
Remove image from screen.
program exits.

I would like the simplest code to read, display and remove the image as possible.

I am currently writing my application in MSVC 5.0 (*not* with MFC!)
0
Comment
Question by:icd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 2

Expert Comment

by:cyrilbdt
ID: 1178343
from vc choose Project|Add to project|Components and control.
Dialog pop up to choose directory. Choose "Developer Studio Components". There is Splash Screen. Insert it in your project and you have all the needed source.
PS
Your program should be MDI/SDI. if it is not create simple project of SDI ot MDI program insert splash screen and look at inserted code.

hope this helps
0
 
LVL 5

Author Comment

by:icd
ID: 1178344
As I mentioned, this is *not* an MFC application. I will however accept your answer if there are no other suggestions that do not require MFC.
0
 
LVL 2

Expert Comment

by:lucidity
ID: 1178345
use the code from this site

http://www.codeguru.com/bitmap/index.shtml

A drolling idiot could do this as long as you remember..

-Add the functions from the page and make sure you replace your dialogs OnPaint with the one one the page

-Import your bitmap into your project and make sure that you replace the IDC_BITMAP from the code with the resource name of your newly imported bitmap.

-remember to write down the dimensions of your image so that you can place the size in the BitBlt function.

-It wouldn't hurt to put a MoveWindow(X,Y,Hieght,Width) in your Init Dialog to make sure you dialog will fir the image in.


oh ya, this drooling idiot should know how to make a dialog box and create a class for AND override some functions.

wasn't that fun!.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Author Comment

by:icd
ID: 1178346
lucidity

Thanks for that resource however this 'drooling idiot' is NOT using MFC and does not want to impose the overheads of MFC on an application that is quite happily using windows API functions.

All other potential answerers to this question please note.

I DO NOT WANT A SOLUTION THAT REQUIRES MFC

Call me an old fuddy duddy if you wish but windows API functions will be quite sufficient thank you!

0
 
LVL 32

Accepted Solution

by:
jhance earned 800 total points
ID: 1178347
It's simple either with MFC or without it.  You open a window for your splash screen, you draw some image or text into it, you continue with your processing (without showing your main window), when you're done with it, you close the splash window.

If you can't figure this out, let me know and I can post some code.
0
 
LVL 32

Expert Comment

by:jhance
ID: 1178348
Here's a quick and dirty non-MFC example that shows a (blank) splash screen and then open the main window:

// splashtest.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"

#define MAX_LOADSTRING 100

// Stuff for SPLASH Window
HINSTANCE hSplashInstance, hSplashInst;
HWND hSplashWnd;

LRESULT CALLBACK SplashProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
      int wmId, wmEvent;
      PAINTSTRUCT ps;
      HDC hdc;

      switch (message)
      {
            case WM_COMMAND:
                  wmId    = LOWORD(wParam);
                  wmEvent = HIWORD(wParam);
                  // Parse the menu selections:
                  switch (wmId)
                  {
                        case IDM_EXIT:
                           DestroyWindow(hWnd);
                           break;
                        default:
                           return DefWindowProc(hWnd, message, wParam, lParam);
                  }
                  break;
            case WM_PAINT:
                  hdc = BeginPaint(hWnd, &ps);
                  // TODO: Add any drawing code here...
                  RECT rt;
                  GetClientRect(hWnd, &rt);

                  EndPaint(hWnd, &ps);
                  break;
            case WM_DESTROY:
                  PostQuitMessage(0);
                  break;
            default:
                  return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}


BOOL InitSplashInstance(HINSTANCE hSplashInstance, int nCmdShow)
{

   hSplashInst = hSplashInstance; // Store instance handle in our global variable

   hSplashWnd = CreateWindow("SplashClass", NULL, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hSplashInstance, NULL);

   if (!hSplashWnd)
   {
      return FALSE;
   }

   ShowWindow(hSplashWnd, nCmdShow);
   UpdateWindow(hSplashWnd);

   return TRUE;
}

ATOM SplashRegisterClass(HINSTANCE hSplashInstance)
{
      WNDCLASSEX wcex;

      wcex.cbSize = sizeof(WNDCLASSEX);

      wcex.style                  = CS_HREDRAW | CS_VREDRAW;
      wcex.lpfnWndProc      = (WNDPROC)SplashProc;
      wcex.cbClsExtra            = 0;
      wcex.cbWndExtra            = 0;
      wcex.hInstance            = hSplashInstance;
      wcex.hIcon                  = NULL;
      wcex.hCursor            = NULL;
      wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
      wcex.lpszMenuName      = NULL;
      wcex.lpszClassName      = "SplashClass";
      wcex.hIconSm            = NULL;

      return RegisterClassEx(&wcex);
}



//



// Global Variables:
HINSTANCE hInst;                                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                                                // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];                                                // The title bar text

// Foward declarations of functions included in this code module:
ATOM                        MyRegisterClass(HINSTANCE hInstance);
BOOL                        InitInstance(HINSTANCE, int);
LRESULT CALLBACK      WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK      About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
       // TODO: Place code here.
      MSG msg;
      HACCEL hAccelTable;

      // Create and display a SPLASH SCREEN
      HINSTANCE hSplashInst;
      SplashRegisterClass(hSplashInstance);
      if(!InitSplashInstance(hSplashInstance, nCmdShow)){
            return FALSE;
      }
      //

      // Initialize global strings
      LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
      LoadString(hInstance, IDC_SPLASHTEST, szWindowClass, MAX_LOADSTRING);
      MyRegisterClass(hInstance);

      Sleep(2000);

      // Perform application initialization:
      if (!InitInstance (hInstance, nCmdShow))
      {
            return FALSE;
      }

      hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SPLASHTEST);

      // Main message loop:
      ShowWindow(hSplashWnd, SW_HIDE);

      while (GetMessage(&msg, NULL, 0, 0))
      {
            if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
            {
                  TranslateMessage(&msg);
                  DispatchMessage(&msg);
            }
      }

      return msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
      WNDCLASSEX wcex;

      wcex.cbSize = sizeof(WNDCLASSEX);

      wcex.style                  = CS_HREDRAW | CS_VREDRAW;
      wcex.lpfnWndProc      = (WNDPROC)WndProc;
      wcex.cbClsExtra            = 0;
      wcex.cbWndExtra            = 0;
      wcex.hInstance            = hInstance;
      wcex.hIcon                  = LoadIcon(hInstance, (LPCTSTR)IDI_SPLASHTEST);
      wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
      wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
      wcex.lpszMenuName      = (LPCSTR)IDC_SPLASHTEST;
      wcex.lpszClassName      = szWindowClass;
      wcex.hIconSm            = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

      return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND      - process the application menu
//  WM_PAINT      - Paint the main window
//  WM_DESTROY      - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
      int wmId, wmEvent;
      PAINTSTRUCT ps;
      HDC hdc;
      TCHAR szHello[MAX_LOADSTRING];
      LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

      switch (message)
      {
            case WM_COMMAND:
                  wmId    = LOWORD(wParam);
                  wmEvent = HIWORD(wParam);
                  // Parse the menu selections:
                  switch (wmId)
                  {
                        case IDM_ABOUT:
                           DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
                           break;
                        case IDM_EXIT:
                           DestroyWindow(hWnd);
                           break;
                        default:
                           return DefWindowProc(hWnd, message, wParam, lParam);
                  }
                  break;
            case WM_PAINT:
                  hdc = BeginPaint(hWnd, &ps);
                  // TODO: Add any drawing code here...
                  RECT rt;
                  GetClientRect(hWnd, &rt);
                  DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
                  EndPaint(hWnd, &ps);
                  break;
            case WM_DESTROY:
                  PostQuitMessage(0);
                  break;
            default:
                  return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
      switch (message)
      {
            case WM_INITDIALOG:
                        return TRUE;

            case WM_COMMAND:
                  if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
                  {
                        EndDialog(hDlg, LOWORD(wParam));
                        return TRUE;
                  }
                  break;
      }
    return FALSE;
}

0
 
LVL 5

Author Comment

by:icd
ID: 1178349
jhance

Thanks for that code, I have made some slight changes, I removed the WM_COMMAND case statement from SplashProc (since IDM_EXIT was not defined when I compiled it) and added a DestroyWindow(hSplashWnd) after the 'Sleep' statement in WinMain. Most of the other routines I removed (WndProc, InitInstance, MyRegisterClass). This gave me a minimal splash screen program.

I need to do a little more however.

1. I don't know how to put an image into the window. This image should be from an external file (since the program I am writing does not have any resources of its own).

2. I have experimented with some windows styles for the splash screen, currently I am using WS_DLGFRAME but I can't seem to get rid of the title bar to make it more like a real splash screen.

3. I need to look into how I size the window. Do you know of any on-line resources explaining 'device-units' and how to check the size of the desk-top

Sorry for these additional questions, as I stated before I am not familiar with Windows API. If you feel it is appropriate I will increase the points if you can answer these further points.

0
 
LVL 32

Expert Comment

by:jhance
ID: 1178350
1. I don't know how to put an image into the window. This image should be from an external file (since the program I am writing does not have any resources of its own).

Use CreateBitmap to create an bitmap and then use BitBlt to draw it into the spash window.  It's probably easiest to do this starting with a dialog based bitmap image.  They you just need to get it's handle.

2. I have experimented with some windows styles for the splash screen, currently I am using WS_DLGFRAME but I can't seem to get rid of the title bar to make it more like a real splash screen.

3. I need to look into how I size the window. Do you know of any on-line resources explaining 'device-units' and how to check the size of the desk-top


I changed the code as follows to create a non-captioned window and to size it to 320x240:

// splashtest.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"

#define MAX_LOADSTRING 100

// Stuff for SPLASH Window
HINSTANCE hSplashInstance, hSplashInst;
HWND hSplashWnd, hMainWnd;

LRESULT CALLBACK SplashProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
      int wmId, wmEvent;
      PAINTSTRUCT ps;
      HDC hdc;

      switch (message)
      {
            case WM_COMMAND:
                  wmId    = LOWORD(wParam);
                  wmEvent = HIWORD(wParam);
                  // Parse the menu selections:
                  switch (wmId)
                  {
                        case IDM_EXIT:
                           DestroyWindow(hWnd);
                           break;
                        default:
                           return DefWindowProc(hWnd, message, wParam, lParam);
                  }
                  break;
            case WM_PAINT:
                  hdc = BeginPaint(hWnd, &ps);
                  // TODO: Add any drawing code here...
                  RECT rt;
                  GetClientRect(hWnd, &rt);

                  EndPaint(hWnd, &ps);
                  break;
            case WM_DESTROY:
                  PostQuitMessage(0);
                  break;
            default:
                  return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}


BOOL InitSplashInstance(HINSTANCE hSplashInstance, int nCmdShow)
{

   hSplashInst = hSplashInstance; // Store instance handle in our global variable

   hSplashWnd = CreateWindowEx(WS_EX_CLIENTEDGE | WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE,
         "SplashClass", NULL, WS_POPUP,
      100, 100, 320, 240, hMainWnd, NULL, hSplashInstance, NULL);

   if (!hSplashWnd)
   {
         MessageBox(NULL, "ERROR", "ERROR", MB_OK);
      return FALSE;
   }

   ShowWindow(hSplashWnd, nCmdShow);
   UpdateWindow(hSplashWnd);

   return TRUE;
}

ATOM SplashRegisterClass(HINSTANCE hSplashInstance)
{
      WNDCLASSEX wcex;

      wcex.cbSize = sizeof(WNDCLASSEX);

      wcex.style                  = CS_HREDRAW | CS_VREDRAW;
      wcex.lpfnWndProc      = (WNDPROC)SplashProc;
      wcex.cbClsExtra            = 0;
      wcex.cbWndExtra            = 0;
      wcex.hInstance            = hSplashInstance;
      wcex.hIcon                  = NULL;
      wcex.hCursor            = NULL;
      wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
      wcex.lpszMenuName      = NULL;
      wcex.lpszClassName      = "SplashClass";
      wcex.hIconSm            = NULL;

      return RegisterClassEx(&wcex);
}



//



// Global Variables:
HINSTANCE hInst;                                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                                                // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];                                                // The title bar text

// Foward declarations of functions included in this code module:
ATOM                        MyRegisterClass(HINSTANCE hInstance);
BOOL                        InitInstance(HINSTANCE, int);
LRESULT CALLBACK      WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK      About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
       // TODO: Place code here.
      MSG msg;
      HACCEL hAccelTable;

      // Create and display a SPLASH SCREEN
      HINSTANCE hSplashInst;
      SplashRegisterClass(hSplashInstance);
      if(!InitSplashInstance(hSplashInstance, SW_SHOW)){
            return FALSE;
      }
      //

      // Initialize global strings
      LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
      LoadString(hInstance, IDC_SPLASHTEST, szWindowClass, MAX_LOADSTRING);
      MyRegisterClass(hInstance);



      // Perform application initialization:
      if (!InitInstance (hInstance, SW_HIDE))
      {
            return FALSE;
      }

      hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SPLASHTEST);

      // Main message loop:
      Sleep(1000);
      ShowWindow(hSplashWnd, SW_HIDE);
      ShowWindow(hMainWnd, SW_SHOW);
      UpdateWindow(hMainWnd);

      while (GetMessage(&msg, NULL, 0, 0))
      {
            if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
            {
                  TranslateMessage(&msg);
                  DispatchMessage(&msg);
            }
      }

      return msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
      WNDCLASSEX wcex;

      wcex.cbSize = sizeof(WNDCLASSEX);

      wcex.style                  = CS_HREDRAW | CS_VREDRAW;
      wcex.lpfnWndProc      = (WNDPROC)WndProc;
      wcex.cbClsExtra            = 0;
      wcex.cbWndExtra            = 0;
      wcex.hInstance            = hInstance;
      wcex.hIcon                  = LoadIcon(hInstance, (LPCTSTR)IDI_SPLASHTEST);
      wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
      wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
      wcex.lpszMenuName      = (LPCSTR)IDC_SPLASHTEST;
      wcex.lpszClassName      = szWindowClass;
      wcex.hIconSm            = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

      return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   //HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hMainWnd)
   {
      return FALSE;
   }

   ShowWindow(hMainWnd, nCmdShow);
   UpdateWindow(hMainWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND      - process the application menu
//  WM_PAINT      - Paint the main window
//  WM_DESTROY      - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
      int wmId, wmEvent;
      PAINTSTRUCT ps;
      HDC hdc;
      TCHAR szHello[MAX_LOADSTRING];
      LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

      switch (message)
      {
            case WM_COMMAND:
                  wmId    = LOWORD(wParam);
                  wmEvent = HIWORD(wParam);
                  // Parse the menu selections:
                  switch (wmId)
                  {
                        case IDM_ABOUT:
                           DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
                           break;
                        case IDM_EXIT:
                           DestroyWindow(hWnd);
                           break;
                        default:
                           return DefWindowProc(hWnd, message, wParam, lParam);
                  }
                  break;
            case WM_PAINT:
                  hdc = BeginPaint(hWnd, &ps);
                  // TODO: Add any drawing code here...
                  RECT rt;
                  GetClientRect(hWnd, &rt);
                  DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
                  EndPaint(hWnd, &ps);
                  break;
            case WM_DESTROY:
                  PostQuitMessage(0);
                  break;
            default:
                  return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
      switch (message)
      {
            case WM_INITDIALOG:
                        return TRUE;

            case WM_COMMAND:
                  if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
                  {
                        EndDialog(hDlg, LOWORD(wParam));
                        return TRUE;
                  }
                  break;
      }
    return FALSE;
}

0
 
LVL 5

Author Comment

by:icd
ID: 1178351
jhance.

Thanks for those pointers. With a little research/trial/error on my part I think I have a working solution. I would welcome any comments you may make on the solution.

#include <windows.h>

HINSTANCE      hSplashInstance;
HINSTANCE      hSplashInst;
HWND            hSplashWnd;
HBITMAP            imgHandle;
BITMAP            gBitMap;

LRESULT CALLBACK SplashProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
      PAINTSTRUCT      ps;
      HDC                  hdc;
      HDC                  hDCMem;

      switch (message) {
      case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);
            // TODO: Add any drawing code here...
            hDCMem = CreateCompatibleDC(hdc);
            SelectObject(hDCMem, imgHandle);
            SetMapMode(hDCMem, GetMapMode(hdc));  
            // Draw the bitmap using the BitBlt function        
            if (BitBlt(
                  hdc,                // The destination device context
                  0, 0,               // Coordinates of the destination rectangle
                  gBitMap.bmWidth,   // Width of the dest. and source rectangle
                  gBitMap.bmHeight,// Height of the dest. and source rectangle
                  hDCMem, 0, 0, SRCCOPY)) {
                  DeleteDC(hDCMem);
            }


            RECT rt;
            GetClientRect(hWnd, &rt);

            EndPaint(hWnd, &ps);
            break;
      case WM_DESTROY:
            PostQuitMessage(0);
            break;
      default:
            return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}


BOOL InitSplashInstance(HINSTANCE hSplashInstance, int nCmdShow) {

      imgHandle = (HBITMAP)LoadImage(NULL,"splash.bmp",NULL,NULL,NULL,LR_LOADFROMFILE);
      if (!imgHandle) {
            return FALSE;
      }
      GetObject(imgHandle, sizeof(BITMAP), &gBitMap);

      hSplashInst = hSplashInstance; // Store instance handle in our global variable

      hSplashWnd = CreateWindowEx(WS_EX_CLIENTEDGE | WS_EX_DLGMODALFRAME |
       WS_EX_WINDOWEDGE, "SplashClass", NULL, WS_POPUP, 100, 100, gBitMap.bmWidth, gBitMap.bmHeight,
       NULL, NULL, hSplashInstance, NULL);
             
      if (!hSplashWnd) {
            return FALSE;
      }

      ShowWindow(hSplashWnd, nCmdShow);
      UpdateWindow(hSplashWnd);

      return TRUE;
}

ATOM SplashRegisterClass(HINSTANCE hSplashInstance) {
      WNDCLASSEX wcex;

      wcex.cbSize = sizeof(WNDCLASSEX);

      wcex.style = CS_HREDRAW | CS_VREDRAW;
      wcex.lpfnWndProc = (WNDPROC)SplashProc;
      wcex.cbClsExtra = 0;
      wcex.cbWndExtra = 0;
      wcex.hInstance = hSplashInstance;
      wcex.hIcon = NULL;
      wcex.hCursor = NULL;
      wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
      wcex.lpszMenuName = NULL;
      wcex.lpszClassName = "SplashClass";
      wcex.hIconSm = NULL;

      return RegisterClassEx(&wcex);
}

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow) {

      // Create and display a SPLASH SCREEN
      SplashRegisterClass(hSplashInstance);
      if(!InitSplashInstance(hSplashInstance, nCmdShow)){
            return FALSE;
      }

      Sleep(2000);

      DestroyWindow(hSplashWnd);

      Sleep(2000);

      return(0);
}

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question