Code mot clignotant

sisi06 Messages postés 4 Date d'inscription lundi 15 mars 2010 Statut Membre Dernière intervention 15 mars 2010 - 15 mars 2010 à 21:03
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 - 21 mars 2010 à 15:43
Bonjour,
je voudrais S.V.P un code en language C (C++) qui me permet d'avoir le mot "WELCOME" en mode clignotant en divers couleurs
merci pour votre aide

5 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
15 mars 2010 à 21:21
- Quel OS ?
- Quel composant d'affichage ?

ciao...
BruNews, MVP VC++
0
sisi06 Messages postés 4 Date d'inscription lundi 15 mars 2010 Statut Membre Dernière intervention 15 mars 2010
15 mars 2010 à 21:56
- vista
- c'est quoi composant d'affichage??
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
15 mars 2010 à 22:32
EDIT
STATIC
LISTBOX
etc, etc.

ciao...
BruNews, MVP VC++
0
sisi06 Messages postés 4 Date d'inscription lundi 15 mars 2010 Statut Membre Dernière intervention 15 mars 2010
15 mars 2010 à 22:40
je ne sais pas je suis debutante et je ne connais pas trop ces trucs
je veux seulement afficher le mot WELCOME lors de l'execution de programme qui clignote avec des couleurs
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
21 mars 2010 à 15:43
Salut,

Couleur -> SetTextColor/SetBkColor dans WM_CTLCOLORSTATIC.
Clignotement -> SetTimer + SetWindowText
Taille -> CreateFontIndirect

Toutes ces fonctions sont documentées dans la msdn.

Appli GUI en C sans MFC:
#ifdef UNICODE
#define _T(x) L ## x
typedef unsigned short TCHAR;
#else
#define _T(x) x
typedef char TCHAR;
#endif

#include <windows.h>

HINSTANCE _hThisInstance;              /* Handle du module                    */
HWND _hWnd;                            /* Handle de la fenêtre                */
HWND _hStatic;                         /* Handle sur le static                */
LPTSTR _lpAppName = _T("WELCOME");     /* Nom de l'appli                      */

BOOL _bDisplayed = TRUE;               /* Pour alterner l'affichage           */
HFONT _hMainFont = NULL;               /* Police de base                      */
HBRUSH _hMainBrush = NULL;             /* Brush de la couleur de la fenêtre   */

WORD __stdcall Err_ShowLast(TCHAR* lpTitle)
{
  DWORD nLastError;
  LPTSTR lpMessageBuffer;

  nLastError = GetLastError();

  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                NULL, nLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                (TCHAR*)(void*)&lpMessageBuffer, 0, NULL);

  MessageBox(NULL, lpMessageBuffer, lpTitle, MB_OK | MB_ICONERROR);

  LocalFree(lpMessageBuffer);
  return 1;
}

LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT nMessage, WPARAM wParam, LPARAM lParam)
{
  int bHandled;               /* Pour savoir si le message est traité          */
  long nResult;

  nResult = 0;
  bHandled = 0;
  switch (nMessage)
  {
    case WM_CTLCOLORSTATIC:
      if ((HWND)lParam == _hStatic)
      {
        SetTextColor((HDC)wParam, RGB(255, 0, 0));
        SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNFACE));
        nResult = (long)_hMainBrush;
        bHandled = 1;
      }
      break;
    case WM_DESTROY:
      /* On signale que le thread va s'arrêter */
      PostQuitMessage(0);
      bHandled = 1;
      break;
  }
  if (! bHandled)
    nResult = DefWindowProc(hWnd, nMessage, wParam, lParam);
  return nResult;
}

HFONT __stdcall GetStaticFont()
{
  NONCLIENTMETRICS metrics; /* Récupération des métriques                     */
  HFONT hResult;

  hResult = NULL;

  metrics.cbSize = sizeof(NONCLIENTMETRICS);
  if (! SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
      sizeof(NONCLIENTMETRICS), &metrics, 0))
  goto the_end;

  metrics.lfCaptionFont.lfHeight = 80;
  metrics.lfCaptionFont.lfWeight = FW_BOLD;
  hResult = CreateFontIndirect(&metrics.lfCaptionFont);

the_end:
  return hResult;
}

HWND __stdcall CreateMyStatic()
{
  HWND hResult;

  hResult = CreateWindowEx(0, _T("STATIC"), _T("WELCOME"),
                           WS_VISIBLE | WS_CHILD,
                           10, 10, 450, 100,
                           _hWnd, NULL, _hThisInstance, NULL);
  if (! hResult) goto the_end;
  SendMessage(hResult, WM_SETFONT, (long)_hMainFont, 0);

the_end:
  return hResult;
}

BOOL __stdcall CreateMyWindow()
{
  WNDCLASSEX wincl;       /* Classe de la fenêtre utilisée                    */
  int nResult;

  nResult = 0;

  /* Création de la classe de fenêtre */
  wincl.cbSize = sizeof(WNDCLASSEX);
  wincl.style = 0;
  wincl.lpfnWndProc = WindowProcedure;
  wincl.cbClsExtra = 0;
  wincl.cbWndExtra = 0;
  wincl.hInstance = _hThisInstance;
  wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
  wincl.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  wincl.lpszMenuName = 0;
  wincl.lpszClassName = _lpAppName;
  wincl.hIconSm = NULL;

  /* Enregistrement de la classe */
  if (! RegisterClassEx(&wincl)) goto the_end;

  /* Création de la fenêtre */
  _hWnd = CreateWindowEx(0, _lpAppName, _lpAppName,
                         WS_OVERLAPPED | WS_SYSMENU,
                         CW_USEDEFAULT, CW_USEDEFAULT, 500, 200,
                         HWND_DESKTOP, NULL, _hThisInstance, NULL);
  if (! _hWnd) goto the_end;

  _hStatic = CreateMyStatic();
  if (! _hStatic) goto the_end;

  /* Affichage de la fenêtre */
  ShowWindow (_hWnd, SW_SHOW);

  nResult = 1;
the_end:
  return nResult;
}

VOID CALLBACK TimerCallback(HWND hwnd,  UINT uMsg,  UINT_PTR idEvent,  DWORD dwTime)
{
  if (_bDisplayed)
    SetWindowText(_hStatic, _T(""));
  else
    SetWindowText(_hStatic, _T("WELCOME"));

  _bDisplayed = ! _bDisplayed;
}

/**
 * Main
 */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  MSG message;                        /* Messages envoyés à l'application     */
  UINT nTimer;                        /* Identifiant du timer                 */
  int nResult;

  /* Récupération du handle du module */
  _hThisInstance = hInstance;

  _hMainFont = GetStaticFont();
  _hMainBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));

  if (! CreateMyWindow())
  {
    nResult = Err_ShowLast(_T("Cannot create main window"));
    goto the_end;
  }

  nTimer = SetTimer(NULL, 0, 750, TimerCallback);

  /* Boucle de traitement des messages */
  while (GetMessage(&message, NULL, 0, 0))
  {
    TranslateMessage(&message);
    DispatchMessage(&message);
  }
  nResult = message.wParam;

  KillTimer(NULL, nTimer);

the_end:
  if (_hMainFont != NULL)
    DeleteObject(_hMainFont);
  if (_hMainBrush != NULL)
    DeleteObject(_hMainBrush);
  return nResult;
}
0
Rejoignez-nous