c

/*************************************************
  Title: スプラッシュ・お試し
  Date:  2005.12.5
  Ver:   0.0.0.4
*************************************************/

#include <windows.h>
#include "resource.h"

void ShowMyBMP(HWND hWnd,
               HDC hdc)
{
  HDC hmdc;
  HBITMAP hBitmap;
  BITMAP bmp;
  HINSTANCE hInst;
  int BMP_W, BMP_H;
  hInst = ( HINSTANCE )GetWindowLong(hWnd, GWL_HINSTANCE);
  hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
  GetObject(hBitmap, sizeof(BITMAP), &bmp);
  BMP_W = ( int )bmp.bmWidth;
  BMP_H = ( int )bmp.bmHeight;
  hmdc = CreateCompatibleDC(hdc);
  SelectObject(hmdc, hBitmap);
  BitBlt(hdc, 0, 0, BMP_W, BMP_H, hmdc, 0, 0, SRCCOPY);
  DeleteDC(hmdc);
  DeleteObject(hBitmap);
}

LRESULT CALLBACK WindowProc(HWND hWnd,
                            UINT uMsg,
                            WPARAM wParam,
                            LPARAM lParam)
{
  HDC hdc;
  PAINTSTRUCT ps;
  STARTUPINFO  stinfo;
  PROCESS_INFORMATION  Procinfo;
  switch(uMsg)
  {
    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      ShowMyBMP(hWnd, hdc);
      EndPaint(hWnd, &ps);
      stinfo.cb = sizeof(stinfo);
      stinfo.lpReserved = NULL;
      stinfo.lpDesktop = NULL;
      stinfo.lpTitle = NULL;
      stinfo.dwFlags = 0;
      stinfo.cbReserved2 = 0;
      stinfo.lpReserved2 = NULL;
      CreateProcess(NULL, TEXT("実行ファイル.exe"), NULL,
                    NULL, FALSE, 0, NULL, NULL, &stinfo,
                    &Procinfo);
//    ↓コレ系だとどうなん?
//    ShellExecute(NULL, "open", mStrItem[item_selcount],
//                 NULL, mExePath, SW_SHOW);
      PostMessage(NULL, WM_PAINT, 0, 0);
      if(! WaitForInputIdle(Procinfo.hProcess, 1000 * 2000))
      {
        Sleep(10);
        PostQuitMessage(0);
      }
      break;
    case WM_DESTROY:
      PostQuitMessage(0);
      break;
    default:
      return( DefWindowProc(hWnd, uMsg, wParam, lParam) );
  }
  return( 0 );
}

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
  int px = 0;
  int py = 0;
  int wx = 300;
  int wy = 180;

  WNDCLASS wc;  //ウィンドウクラス登録
  wc.style = NULL;
  wc.lpfnWndProc = WindowProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = hInstance;
  wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON2));
//  wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = ( HBRUSH )GetStockObject(WHITE_BRUSH);
//  wc.hbrBackground = ( HBRUSH )(COLOR_BTNFACE+1);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = TEXT("SplashWindow");
  if(RegisterClass(&wc) == 0)
    return( 0 );

  HWND hwnd = CreateWindow(
    TEXT("SplashWindow"),
    TEXT("アプリ名を書いときゃいいんじゃね?"),
    NULL,
    px,
    py,
    wx,
    wy,
    NULL,
    NULL,
    hInstance,
    NULL);
  if(hwnd == NULL)
    return( 0 );

  RECT rc_desk;  //デスクトップ全体のサイズを取得
  SystemParametersInfo(SPI_GETWORKAREA, 0, &rc_desk, 0);
  RECT rect1;  //枠も含めたサイズ
  GetWindowRect(hwnd, &rect1);
  RECT rect2;  //クライアント領域(描画領域)を取得する
  GetClientRect(hwnd, &rect2);
  //冗長な計算・・・
  wx += (rect1.right - rect1.left) - (rect2.right - rect2.left);
  wy += (rect1.bottom - rect1.top) - (rect2.bottom - rect2.top);
  px = ( int )((rc_desk.right - rc_desk.left) / 2) - ( int )(wx / 2) + rc_desk.left;
  py = ( int )((rc_desk.bottom - rc_desk.top) / 2) - ( int )(wy / 2) + rc_desk.top;
  //ウインドウを中央に配置する。
  SetWindowPos(hwnd, HWND_TOPMOST, px, py, wx, wy, SWP_SHOWWINDOW);

  ShowWindow(hwnd, nCmdShow);
  UpdateWindow(hwnd);

  MSG msg;
  while(GetMessage(&msg, NULL, 0, 0))
  {
    Sleep(10);
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return( msg.wParam );
}