Boite de demarrage (win32,vc++)

Description

Suite a question sur SetTimer() dans forum.
Sauf que PAS de MFC cause jamais fait.
Boite de demarrage reste environ 3 secondes.
Facile a modifier ou, quand et comment la fermer.
Tout est dans zip pour recompliler.

Source / Exemple :


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

#define BNU_INIT (WM_USER+1)

HINSTANCE hinst;
HWND  hwndapp, hinit = 0;
DWORD count = 0;
char *szappname = "DlgInit";

BOOL CALLBACK InitDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
{
  switch(mssg) {
    case WM_INITDIALOG:
      SetTimer(hdlg, 1, 300, 0);
      return 1;
    case WM_TIMER:
      if(++count > 10) {DestroyWindow(hdlg); return 0;}
      SetDlgItemInt(hdlg, IDST_INIT, count, 0);
      break;
    case WM_DESTROY:
      KillTimer(hdlg, 1); hinit = 0;
  }
  return 0;
}

LRESULT CALLBACK AppWndProc(HWND hwnd, UINT mssg, WPARAM wParam, LPARAM lParam)
{
  switch(mssg) {
    case WM_CREATE:
      PostMessage(hwnd, BNU_INIT, 0, 0);
      return 0;
    case BNU_INIT:
      hinit = CreateDialog(hinst, MAKEINTRESOURCE(IDD_INIT), hwnd, InitDlgProc);
      return 0;
    case WM_DESTROY:
      if(hinit) DestroyWindow(hinit);
      PostQuitMessage(0);
  }
  return DefWindowProc(hwnd, mssg, wParam, lParam);
}

void InitInstance()
{
  WNDCLASSEX  wclsx;
  wclsx.cbSize        = sizeof(WNDCLASSEX);
  wclsx.style         = CS_HREDRAW | CS_VREDRAW;
  wclsx.hCursor       = LoadCursor(0, IDC_ARROW);
  wclsx.hInstance     = hinst;
  wclsx.cbClsExtra = wclsx.cbWndExtra = 0;
  wclsx.hIconSm = 0; wclsx.lpszMenuName = 0;
  wclsx.hIcon         = LoadIcon(0, IDI_APPLICATION);
  wclsx.lpfnWndProc   = AppWndProc;
  wclsx.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  wclsx.lpszClassName = szappname;
  if(!RegisterClassEx(&wclsx)) goto errInit;
  hwndapp = CreateWindowEx(0, szappname, szappname,
               WS_OVERLAPPED | WS_SYSMENU,
               CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
               0, 0, hinst, 0);
  return;
errInit:
  MessageBox(0, "ERREUR", szappname, MB_ICONERROR);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
{
  MSG  msg;
  hinst = hInstance;
  InitInstance();
  if(!hwndapp) return 0;
  ShowWindow(hwndapp, SW_SHOW); UpdateWindow(hwndapp);
  while(GetMessage (&msg, 0, 0, 0)) {
    if(hinit == 0 || !IsDialogMessage(hinit, &msg)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
  }
  return 0;
}

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.