Couleur fond appli win32

Résolu
fredsor Messages postés 198 Date d'inscription lundi 24 avril 2006 Statut Membre Dernière intervention 3 avril 2008 - 8 nov. 2007 à 16:56
fredsor Messages postés 198 Date d'inscription lundi 24 avril 2006 Statut Membre Dernière intervention 3 avril 2008 - 16 nov. 2007 à 09:45
Salu a vous,

Je créé une appli win32 sous devc++ en C.
Je créé la fenetre avec CreateWindow, et j'aimerais que le fond soit blanc. Or l'appli se met désespérément avec son fond gris tout terne. Pourtant je spécifie bien mon objet dans ma WNDCLASS :
char szClassName[ ] = "GV3 Mobile";
int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil){
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */
                 
    hinst=hThisInstance;

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = (WNDPROC) WndProc;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
   
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;
       
    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "GV3 Mobile",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           500,                 /* The programs width */
           600,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);
    UpdateWindow(hwnd);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);    }
    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;}

J'ai essayé également des méthodes trouvés sur cppfrance  avec ERASEBKGROUND, sans succès
Voyez vous ce qui ne va pas?

13 réponses

fredsor Messages postés 198 Date d'inscription lundi 24 avril 2006 Statut Membre Dernière intervention 3 avril 2008
16 nov. 2007 à 09:45
Youpi!!

En créant un deuxieme projet vide, j'avais bien une fenetre blanche, j'ai donc rajouté petit a petit les éléments de mon projet existant pour voir que... j'avais un WM_PAINT dans ma WindowProcedure principale, qui ne me servait a rien, sauf a m'empecher d'avoir le fond bland!! ;)

donc je l'ai viré maintenant c'est impeccable!

Merci a vous pour l'aide, merci darunia
3
cs_juju12 Messages postés 966 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 4 mars 2010 4
8 nov. 2007 à 17:17
Au risque de te faire t'arracher les cheveux, chez moi, ca marche parfaitement (Visual C++ Express 2005) sans changer une ligne.
Essaie voir en créant un brush blanc(CreateSolidBrush(0xFFFFFF)) toi-même...
0
cs_darunia Messages postés 354 Date d'inscription mercredi 18 décembre 2002 Statut Membre Dernière intervention 24 mars 2011 2
8 nov. 2007 à 17:30
Salut,

Essaye hbrBackground    = (HBRUSH)(COLOR_WINDOW + 1);

D@runia
0
fredsor Messages postés 198 Date d'inscription lundi 24 avril 2006 Statut Membre Dernière intervention 3 avril 2008
8 nov. 2007 à 18:12
Merci a vous, en effet j'ai plus de cheveux là! lol
Avec vos dexu exemples ca ne fonctionne pas  meixu, voici la tete de mon ecran si l'image fonctionne :
Ouhh comme ce gris m'exaspere!!
A noter : que le blanc que l'on voit est dû au WM_CTLCOLOREDIT que je fais sur mes EDIT, et au CTLCOLORSTATIC fais sur les labels...
0

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

Posez votre question
Neo_Fr Messages postés 653 Date d'inscription mardi 6 décembre 2005 Statut Membre Dernière intervention 10 novembre 2014 2
8 nov. 2007 à 20:59
Salut,
Met ca au haut du source:
HBRUSH hBkColor;

Et ca dans ta procedure:

WM_INITDIALOG:
hBkColor = CreateSolidBrush(RGB(255, 255, 255));

WM_CTLCOLORDLG:
return (LRESULT)hBkColor;

Normalement ca devrait marcher..

Neo_Fr
0
fredsor Messages postés 198 Date d'inscription lundi 24 avril 2006 Statut Membre Dernière intervention 3 avril 2008
9 nov. 2007 à 09:09
Euh snif snif pas mieux...
J'ai fais comme tu m'a di, je sais pas si il passe bien dans mon initDialog... :

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
                         hBkColor = CreateSolidBrush(RGB(255, 255, 255));
       case WM_CTLCOLORDLG:
                      return (LRESULT)hBkColor;
          case WM_TIMER:
        { ....
        }
    }

}

et dans le WndMain :
wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = (WNDPROC) WndProc;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
   
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
....

je fais peut etre quelque chose qui ne va pas?
0
Neo_Fr Messages postés 653 Date d'inscription mardi 6 décembre 2005 Statut Membre Dernière intervention 10 novembre 2014 2
9 nov. 2007 à 18:00
Tu compile avec quoi?
Chez moi cette ligne marche nikel sous devcpp:

wincl.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(0, 0, 0));

Neo_Fr
0
cs_juju12 Messages postés 966 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 4 mars 2010 4
9 nov. 2007 à 20:43
Poste voir tout le code parce que là c'est louche...
0
fredsor Messages postés 198 Date d'inscription lundi 24 avril 2006 Statut Membre Dernière intervention 3 avril 2008
10 nov. 2007 à 12:42
Oki je posterais tout mon fichier lundi, mais ca va faire lourd! lol
je compile avec devc++.
a lundi alors, merci
0
fredsor Messages postés 198 Date d'inscription lundi 24 avril 2006 Statut Membre Dernière intervention 3 avril 2008
12 nov. 2007 à 11:41
RE a tous,
voici mon fichier "Affichage.c", enfin surtout sa structure. J'ai "vidé" plein de choses comme vous le constater, pour ne pas que ce soit trop lourd.
Peut etre que ca va deja vous donner une indication... :
#include <windows.h>
#include "Description.h"
#include "Parsing.h"
#include "Affichage.h"
#include "Connexion.h"

#define ID_BUTTON  101
#define ID_EDIT  102
#define ID_STATIC  103

...

// Variable déclarée en global:
WNDPROC OldEditProc=NULL;
WNDPROC OldButtonProc=NULL;
WNDPROC OldListBoxProc=NULL;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

#pragma warning(disable: 4018)
#pragma warning(disable: 4244)

void Initialisation(){...}

// procedure de sous classement des controle EditBox
LRESULT CALLBACK EditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
        ...
    return CallWindowProc(OldEditProc, hwnd, message, wParam, lParam);
}

// Procédure de sous-classement du Bouton:
LRESULT CALLBACK ButtonProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    ...
    return CallWindowProc(OldButtonProc, hwnd, message, wParam, lParam);
}

// Procédure de sous-classement de la listbox
LRESULT CALLBACK ListBoxProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    ...
   return CallWindowProc(OldListBoxProc, hwnd, message, wParam, lParam);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    ...
    switch (message)
    {
            case WM_INITDIALOG:
             {
                             hBkColor = CreateSolidBrush(RGB(255, 255, 255));
                         }
               case WM_CTLCOLORDLG:
                          return (LRESULT)hBkColor;
                     

        case WM_TIMER:
        {
            switch (wParam)
            {
                case IDT_TIMER:    {
                    ...
                }
                break; 
            }
            break;
        }

        case WM_KEYUP:
        {
            GererKeyUp(hWnd,message,wParam,lParam);
            break;
        }

        case WM_CTLCOLOREDIT://Dessin du contrôle EDIT
        {   
                    int i;
            for(i=0;i<GetNombreComposant();i++)
            {
                if (((HWND)lParam==hEdit[i]))
                {
                    SetTextColor((HDC)wParam,couleurTexte[i]);
                    SetBkColor((HDC)wParam,couleurFondTexte[i]);
                    return (BOOL) couleurFond[i];
                }
            }
            return 0;
        }
        case WM_CTLCOLORSTATIC://Dessin des controles "static"
        {
                     int i;
            for(i=0;i<GetNombreComposant();i++)
            {
                if (((HWND)lParam==hLib[i]))
                {
                    SetTextColor((HDC)wParam,couleurTexte[i]);
                    SetBkColor((HDC)wParam,couleurFondTexte[i]);
                    return (BOOL) couleurFond[i];
                }
            }
            // permet de mettre en gris les entetes de tableaux...
            SetTextColor((HDC)wParam,RGB(0,0,0));                    // texte noir
            SetBkColor((HDC)wParam,RGB(192,192,192));                // fond texte gris
            return (LONG) CreateSolidBrush(RGB(192,192,192));        // fond gris
        }
        case WM_CTLCOLORLISTBOX://Dessin des tableaux listbox
        {
                     int i;
            for(i=0;i<GetNombreComposant();i++)
            {       
                if ((HWND)lParam==hTab[i])
                {
                    SetTextColor((HDC)wParam,couleurTexte[i]);
                    SetBkColor((HDC)wParam,couleurFondTexte[i]);
                    return (BOOL) couleurFond[i];
                }
            }           
            return 0;
        }
        case WM_CTLCOLORBTN://Dessin des boutons
        {
             int i;
            for(i=0;i<GetNombreComposant();i++)
            {
                if (((HWND)lParam==hBtn[i]))
                {
                    SetTextColor((HDC)wParam,couleurTexte[i]);
                    SetBkColor((HDC)wParam,couleurFondTexte[i]);
                    return (BOOL) couleurFond[i];
                }   
            }
            return 0;
        }

        case WM_COMMAND:
            wmId    = LOWORD(wParam);
            wmEvent = HIWORD(wParam);  

        switch (wmId)
        {
              
                  
            case ID_BUTTON:                        // en cas d'action sur un bouton
            {
                ...
            }
        }
        break;
        case WM_USER:
        {
                     ...
        }
       
        case WM_CREATE:
        {
                         ...
        }   
       
        break;

        case WM_PAINT:
            {
            RECT rt;
            hdc = BeginPaint(hWnd, &ps);
            GetClientRect(hWnd, &rt);
            FillRect(hdc, &rt, (HBRUSH) (1));
            EndPaint(hWnd, &ps);
            break;
        }
            case WM_DESTROY:
            DestroyWindow(hWnd);        // destruction de la fenetre
            PostQuitMessage(0);            // exit
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
            break;
    }           
    return 0;
}

char szClassName[ ] = "GV3 Mobile";
int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    char** tableau=NULL;
    LancerParsing(tableau);
                   
    hinst=hThisInstance;

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = (WNDPROC) WndProc;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
   
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;
       
    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "GV3 Mobile",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           500,                 /* The programs width */
           600,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );
 

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);
    UpdateWindow(hwnd);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}

Bon courage a ceux qui sont motivés pour le lire, et encore merci!
0
cs_darunia Messages postés 354 Date d'inscription mercredi 18 décembre 2002 Statut Membre Dernière intervention 24 mars 2011 2
13 nov. 2007 à 17:44
Ca a peut etre rien a voir, mais comment sont definis __WIN32_WINDOWS et __WIN32_WINNT ?

D@runia
0
fredsor Messages postés 198 Date d'inscription lundi 24 avril 2006 Statut Membre Dernière intervention 3 avril 2008
13 nov. 2007 à 21:09
Euh je t'aouve là Darunia que tu me pose une colle...
je suppose qu'ils sont définis automatiquement, a partir du moment ou je créé un projet vide Appli Win32 Windows?
0
cs_darunia Messages postés 354 Date d'inscription mercredi 18 décembre 2002 Statut Membre Dernière intervention 24 mars 2011 2
14 nov. 2007 à 08:56
Regarde dans ton stdafx.h si tu en as un.

[mailto:D@runia D@runia]
0
Rejoignez-nous