begin process at 2010 02 09 23:19:00
  Trouver un code source :
 
dans
 
Accueil > Forum > 

C

 > 

Windows

 > 

Autre

 > 

couleur fond appli win32


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

couleur fond appli win32

jeudi 8 novembre 2007 à 16:56:47 | couleur fond appli win32

fredsor

Membre Club
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?
jeudi 8 novembre 2007 à 17:17:14 | Re : couleur fond appli win32

juju12

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...
jeudi 8 novembre 2007 à 17:30:59 | Re : couleur fond appli win32

darunia

Salut,

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

D@runia
jeudi 8 novembre 2007 à 18:12:32 | Re : couleur fond appli win32

fredsor

Membre Club
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 : Sans titre.bmp
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...

jeudi 8 novembre 2007 à 20:59:22 | Re : couleur fond appli win32

Neo_Fr

Membre Club
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
vendredi 9 novembre 2007 à 09:09:04 | Re : couleur fond appli win32

fredsor

Membre Club
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?
vendredi 9 novembre 2007 à 18:00:39 | Re : couleur fond appli win32

Neo_Fr

Membre Club
Tu compile avec quoi? Chez moi cette ligne marche nikel sous devcpp: wincl.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(0, 0, 0)); Neo_Fr
vendredi 9 novembre 2007 à 20:43:05 | Re : couleur fond appli win32

juju12

Poste voir tout le code parce que là c'est louche...
samedi 10 novembre 2007 à 12:42:13 | Re : couleur fond appli win32

fredsor

Membre Club

Oki je posterais tout mon fichier lundi, mais ca va faire lourd! lol
je compile avec devc++.
a lundi alors, merci

lundi 12 novembre 2007 à 11:41:43 | Re : couleur fond appli win32

fredsor

Membre Club
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!

1 2

Cette discussion est classée dans : messages, wincl, hwnd, window, is


Répondre à ce message

Sujets en rapport avec ce message

insertion d'une phrase [ par chinois57 ] ou doige mettre une phrase du style sa va#include /*  Declare Windows procedure  */LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); /*  Application [ par Arnauti ] Bonjour, je suis nul et j'ai presque jamais fait de C/C++. Enfin, si quelque truc sous dos. Mais j'aimerais créé une aplication mais pas sous dos. Al C++ windows [ par notour ] bonjourj'ai réalyser un programme de cryptage de texte sous page DOS mais pour des raison pratique je souh siouplait la charite pour un pov newbie [ par seichettmorru ] je compile, ca marcheje lance ca me dit "impossible de communiquer avec la carte"j'ai une geforce ti+directx 8.vous etes mon dernier recours:#include probleme de compilation (débutant) [ par cddvdcopy ] je suis débutant, merci de m'éclairer !! ce code marche : #include #define ID_SFC 100 #define ID_RECHERCHE 200 #define ID_EXIT 300 Je debute: [ par phpman ] Bonjour,je debute avec devc++, quand je creer un nouveau projet il me génère le code d'une form windows:#include /* Declare Windows procedure */LRESUL Problème d'initailisation objet IDirect3DDevice9 [ par olivierpot2 ] Bonjour à tous,je débutes en c++ directx et j'avoue que j'ai un peu (beaucoup) de mal...Dans le code suivant je n'arrives pas à initilalisé la variabl tjr aide applications windows [ par chinois57 ] je suis desoler de denouveau vous enbeteer avec sa mais je ne comprend pas comment afficher un message dans une fenetre windows applicatios j'utilise Gestion optimisée du clavier avec l'API Win32 [ par Djazzyman ] Bonjour à tous !Je developpe des petits programmes Windows depuis peu sous Dev C++ 5 (version 4.9.9.2 beta).Jusqu'alors, je me contentais des simples


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,546 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales