IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

problème tracbar API windows


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 20
    Par défaut problème tracbar API windows
    Bonjour à tous , je développe sous windows avec Dev cpp et j'ai ub souci avec l'api windows , losque je veut créer une trackbar , le code compile parfaitement mais la trackbar ne s'affiche pas . Voila mon code :



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    #include <windows.h>
    #include <commctrl.h> 
     
     
    HINSTANCE This;
     
     
     
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
     
    /*  Make the class name into a global variable  */
    char szClassName[ ] = "WindowsApp";
     
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
     
    {
        This = hThisInstance;                
     
        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 */
     
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* 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) (6);
     
        /* 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 */
               "Windows App",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* 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);
     
        /* 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;
    }
     
     
    /*  This function is called by the Windows function DispatchMessage()  */
     
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         static HWND boutton[2]; 
     
     
        switch (message)                  /* handle the messages */
        {
            case WM_CREATE:   
     
               CreateWindow(TRACKBAR_CLASS,"",WS_CHILD|WS_VISIBLE| TBS_NOTICKS
               ,20,
               20,300,20,hwnd,(HMENU)NULL,This,NULL);   
               break;           
     
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
     
        return 0;
    }

    Voila , alors merci de m'aider.

  2. #2
    Rédacteur
    Avatar de Neitsa
    Homme Profil pro
    Chercheur sécurité informatique
    Inscrit en
    Octobre 2003
    Messages
    1 041
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chercheur sécurité informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 041
    Par défaut
    Bonjour,

    le problème est assez simple à régler. Le contrôle de type TRACKBAR_CLASS est présent uniquement dans la DLL nommée commctl32.dll.

    Tu as bien inclus son en-tête, mais pas appelé la bonne fonction qui permet justement d'avoir cette DLL dans l'espace d'adressage du processus.

    Il suffit pour cela d'appeler la fonction InitCommonControls (ou sa version étendue finissant par Ex) et de ne pas oublier de lier sur comctl32.lib.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    //[...]
     
        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 */
     
    	InitCommonControls();
     
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
     
    //[...]
    P.S : fais attention, ton code n'est pas compatible TCHAR (c-a-d compilable en ANSI ou UNICODE sans problèmes).

  3. #3
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 395
    Par défaut
    Neitsa:
    Citation Envoyé par La Doc de InitCommonControls()
    This function is obsolete. New applications should use the InitCommonControlsEx function.
    moustick1991:
    Qu'est-ce que c'est que ce 6 hard-codé dans le cast en HBRUSH ?
    Ne peux-tu pas utiliser les constantes de couleur système ?
    Remplace-moi ce 6 par COLOR_WINDOW+1, immédiatement!
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 20
    Par défaut
    HAaaaaa merci beaucoup , maintenant ca marche !!!!
    Pour le "6" je sais que c'est hard-codé comme tu dis mais j'avais la flemme Merci quand même je vais modifier ca tout de suite.

    Bon alors j'aurais deux autres questions pour toi et puis jte lâche :

    1 : pourquoi lorsque j'ajoute la case WM_PAINT dans les messages ca ne marche plus ????(la fenêtre s'execute sans erreur mais le control TRACKBAR ne s'affiche plus) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    #include <windows.h>
    #include <commctrl.h> 
     
     
    HINSTANCE This;
     
     
     
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
     
    /*  Make the class name into a global variable  */
    char szClassName[ ] = "WindowsApp";
     
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
     
    {
        This = hThisInstance;                
     
        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 */
     
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* 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) (13 + COLOR_BTNFACE);
     
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
     
         InitCommonControls();
     
     
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows App",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* 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);
     
        /* 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;
    }
     
     
    /*  This function is called by the Windows function DispatchMessage()  */
     
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         static HWND boutton[2]; 
     
     
        switch (message)                  /* handle the messages */
        {
     
             case WM_PAINT:
     
     
     
               break;
     
     
            case WM_CREATE:   
     
               CreateWindow(TRACKBAR_CLASS,"",WS_CHILD|WS_VISIBLE| TBS_NOTICKS
               ,20,
               20,300,20,hwnd,(HMENU)NULL,This,NULL);   
               break;           
     
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
     
        return 0;
    }

    2 : Je n'arrive pas à personnaliser le fond de ma fenêtre , pourais-tu m'indiquer comment on fait ???

  5. #5
    Membre expérimenté Avatar de blackhorus
    Inscrit en
    Février 2003
    Messages
    209
    Détails du profil
    Informations forums :
    Inscription : Février 2003
    Messages : 209
    Par défaut
    En réponse à la question 2, tu peux essayer :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    wincl.hbrBackground = CreateSolidBrush(RGB(0, 0x80, 0));
    à la place de :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     /* Use Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) (13 + COLOR_BTNFACE);

  6. #6
    scr
    scr est déconnecté
    Membre éprouvé
    Inscrit en
    Juin 2005
    Messages
    127
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 127
    Par défaut
    Pour la question 1, si tu implémente l'évènement WM_PAINT, tu désactives l'appel à la fonction standard de dessin. C'est donc à toi d'implémenter le dessin de ta fenêtre.

Discussions similaires

  1. [API windows.h] Problème de type sous Visual 2005
    Par Astraya dans le forum Windows
    Réponses: 3
    Dernier message: 17/07/2007, 22h14
  2. (API Windows) Problème d'affichage de boutons
    Par pioupiou74 dans le forum Windows
    Réponses: 4
    Dernier message: 29/06/2007, 14h52
  3. API windows : problème menu
    Par Gregbeacher dans le forum Windows
    Réponses: 4
    Dernier message: 13/06/2007, 15h35
  4. Problème: CreateProcess() ou API windows?
    Par squale32 dans le forum Windows
    Réponses: 4
    Dernier message: 15/03/2007, 12h29
  5. problème avec "API Windows en C"
    Par Vince-le-fou dans le forum Windows
    Réponses: 2
    Dernier message: 23/11/2005, 15h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo