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

Windows Discussion :

Problème avec 2 fonctions.


Sujet :

Windows

  1. #1
    Membre habitué Avatar de benjiprog
    Profil pro
    Étudiant
    Inscrit en
    Septembre 2005
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2005
    Messages : 302
    Points : 134
    Points
    134
    Par défaut Problème avec 2 fonctions.
    Bonjour, j'ai un problème concernat un programme dont j'ai pris l'exemple sur le tutoriel de CGi (qui est excellent).
    Voici le code source :
    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
          
    #include <windows.h>  /*Pour les fonctions windows*/
    LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
    int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
                                                    LPSTR lpCmdLine, int nCmdShow)
    {
        HWND hwnd;
        MSG msg;
        WNDCLASS wc;
        wc.style = 0;
        wc.lpfnWndProc = MainWndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = NULL;
        wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
        wc.lpszMenuName =  NULL;
        wc.lpszClassName = "MaWinClass";
        RegisterClass(&wc);
        hwnd = CreateWindow("MaWinClass", "Titre", WS_OVERLAPPEDWINDOW,
                                       CW_USEDEFAULT, CW_USEDEFAULT, 400, 300,
                                                       NULL, NULL, hinstance, NULL);
        if (!hwnd) return FALSE;
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
     
        while (GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        return msg.wParam;
    }
    /***************Fonction de traitement des messages**************/
    LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        switch (uMsg)
        {
     
            /*case WM_KEYDOWN :
        {
            int y;
            char st[]="Bienvenue sur Developpez.com";
            HDC hdc=GetDC(hwnd);
            SetBkMode(hdc, TRANSPARENT);
            for (y=10; y<=200; y+=20)
             TextOut(hdc, 10, y, st, lstrlen (st));
            ReleaseDC(hwnd, hdc);
            return (0);
                 }*/
     
            /*WM_PAINT :
                {
                  int y;
                  char st[] = "Bienvenue sur Developpez.com" ;
                  HDC hdc = GetDC(hwnd);
                  SetBkMode(hdc, TRANSPARENT);
                  for(y=10; y <= 200; y += 20)
                                              TextOut(hdc, 10, y, st , lstrlen(st));
                  ReleaseDC(hwnd, hdc);
                  return 0;
                }*/
     
            case WM_PAINT :
        {
             int y;
             char st[]="Bienvenue sur Developpez.com";
             PAINTSTRUCT ps;
             HDC hdc=BeginPaint(hwnd, &ps);
             SetBkMode(hdc, TRANSPARENT);
             for (y=10; y<=200; y+=20)
                TextOut(hdc, 10, y, st, lstrlen (st));
                 EndPaint(hwnd, &ps);
                 return (0);
           }     
            case WM_CREATE:
        return 0;
            case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
            default:
                return DefWindowProc(hwnd, uMsg, wParam, lParam);
        }
    }
    Après avoir compiler avec Dev C++ j'ai 2 erreurs que je n'arrive pas à résoudre :
    [Linker error] undefined reference to `SetBkMode@8'
    [Linker error] undefined reference to `TextOutA@20'
    ld returned 1 exit status
    Voilà je vous remerci d'avance pour votre aide.
    PS:Et bravo pour cette nouvelle interface graphique.
    Les élèves glandeurs c'est comme le linge, quand il fait beau ca sèche.

  2. #2
    Membre actif Avatar de amaury pouly
    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    157
    Détails du profil
    Informations personnelles :
    Âge : 34
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 157
    Points : 224
    Points
    224
    Par défaut
    Bonjour,
    il faut linker l'exécutable avec
    Gdi32.lib
    Pour Dev-Cpp, il suffit d'aller dans les propriété du projet, onglet Paramètres et dans dans le panel "Editeur de liens" il faut rajouter:
    -lgdi32

  3. #3
    Membre habitué Avatar de benjiprog
    Profil pro
    Étudiant
    Inscrit en
    Septembre 2005
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2005
    Messages : 302
    Points : 134
    Points
    134
    Par défaut
    Je te remerci ca marche mais maintenant c'est avec la fonction GetOpenFileName que j'ai un problème, le même un problème avec le linker.

    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
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    #include <windows.h>
    #define IDM_QUIT 1
    #define IDM_OPEN 2
    LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
    HINSTANCE hinst;
    int WINAPI WinMain (HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
      HWND hwnd;    /*Handle de la fenetre principal*/
      WNDCLASS wc;
      MSG msg;
      
      hinst=hinstance;  /*Handle de l'application (fenetre d'edition)*/
     HMENU hMenu, hSousMenu;  /*Handle du menu et sous menu*/
    
      wc.style = 0;
        wc.lpfnWndProc = MainWndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hinstance;
        wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
        wc.lpszMenuName =  NULL;
        wc.lpszClassName = "MaWinClass";
        
        RegisterClass (&wc);   /*Enregistrement structure au niveau du systeme*/
        
        hSousMenu=CreateMenu ();   /*Creation du sous-menu*/
     AppendMenu(hSousMenu, MF_STRING, IDM_OPEN, "Ouvrir"); /*Sous-menu Ouvrir*/
        AppendMenu(hSousMenu, MF_SEPARATOR, 0, NULL);  /*Séparateur*/
        AppendMenu(hSousMenu, MF_STRING, IDM_QUIT, "Quitter"); /*Sous-menu Quitter*/
        hMenu=CreateMenu (); /*Creation du menu*/
        AppendMenu(hMenu, MF_POPUP, (UINT)hSousMenu, "Fichier");
        
        /*Creation de la fenetre et de ses differents parametres*/
        hwnd = CreateWindow("MaWinClass", "Titre", WS_OVERLAPPEDWINDOW,
                                      CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                                                       NULL, hMenu, hinstance, NULL);
                                                       
        if (!hwnd) return false;
        ShowWindow (hwnd, nCmdShow);  /*Pour rendre fenetre visible*/
     UpdateWindow (hwnd);   /*Rafraichissements*/
     
     while (GetMessage(&msg,NULL,0,0))
     {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
        }
        return msg.wParam;
    }
    /*Fonction de traitement des messages*/
    LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
    {
       static HWND hEdit;
       static bool EditNotChg=true;
       
       switch (umsg)
       {
           case WM_CREATE:
            HFONT hFont;
            hEdit =CreateWindow("edit", "Vous pouvez écrire",
                     WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL,
                                               0, 0, 0, 0, hwnd, NULL, hinst, NULL);
                        hFont = (HFONT)GetStockObject(ANSI_FIXED_FONT);
                        SendMessage(hEdit,WM_SETFONT,(UINT)hFont,true);
                        /*Envoie d'un message pour limiter les marges a 5 pixels*/
         SendMessage(hEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(5,5));
            return (0);
            
             case WM_CLOSE :
             /*Si vous avez fini de saisir du texte demmande de sauvegarde avant de quitter*/
            if (EditNotChg || MessageBox(hwnd,"Voulez-vous sauvegarder les changements" 
                                                  " avant de quitter l'application?", 
                              "Quitter.",MB_YESNO | MB_ICONQUESTION)==IDYES)
            DestroyWindow(hwnd);  /*Fermeture de l'application*/
         return (0); 
          
          case WM_COMMAND :
            if (LOWORD(wParam)==IDM_QUIT) PostMessage(hwnd,WM_CLOSE, 0, 0);
            if (HIWORD(wParam)==EN_CHANGE) EditNotChg=false;
            if (LOWORD(wParam)==IDM_OPEN)
         {
             OPENFILENAME ofn;
             char szFile[MAX_PATH]={0};
             
             ZeroMemory(&ofn, sizeof(OPENFILENAME));
             ofn.lStructSize=sizeof(OPENFILENAME);
             ofn.hwndOwner=hwnd;
             ofn.lpstrFile=szFile;
             ofn.nMaxFile=MAX_PATH;
             ofn.lpstrFilter="Fichier source C\0*.c\0Fichier source CPP\0*.cpp\0";
             ofn.nFilterIndex=1;
             ofn.Flags=OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
             
             if (GetOpenFileName(&ofn)==true)
             {
               HANDLE hf;
               DWORD FileSize,nbcharRead;
               char *buffer;
               
               hf=CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING,
                     FILE_ATTRIBUTE_NORMAL, NULL);
               FileSize=GetFileSize(hf, NULL);
               buffer=(PCHAR)LocalAlloc(LMEM_FIXED, FileSize+1);
               ReadFile(hf, buffer, FileSize, &nbcharRead, NULL);
               buffer[FileSize]=0;
               SendMessage(hEdit,WM_SETTEXT, 0, (LPARAM)buffer);
               LocalFree(buffer);
               CloseHandle(hf);
            }
         }
         return (0);
         
             case WM_SIZE :
            /*Si changement de taille fenetre parent alors changement de taille fenetre enfant*/
            MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), true); 
            return (0);
             
                   case WM_DESTROY :
            PostQuitMessage (0);   /*Fermeture de la fenetre*/
            return (0);
            
          default :
               return DefWindowProc(hwnd, umsg, wParam, lParam);
            }
    }
    Et l'erreur :
    [Linker error] undefined reference to `GetOpenFileNameA@4'
    Les élèves glandeurs c'est comme le linge, quand il fait beau ca sèche.

  4. #4
    Membre habitué Avatar de benjiprog
    Profil pro
    Étudiant
    Inscrit en
    Septembre 2005
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2005
    Messages : 302
    Points : 134
    Points
    134
    Par défaut
    Pourquoi me donne-t-il une erreur de lien?
    Les élèves glandeurs c'est comme le linge, quand il fait beau ca sèche.

  5. #5
    Expert éminent sénior

    Homme Profil pro
    pdg
    Inscrit en
    Juin 2003
    Messages
    5 751
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : pdg

    Informations forums :
    Inscription : Juin 2003
    Messages : 5 751
    Points : 10 667
    Points
    10 667
    Billets dans le blog
    3
    Par défaut
    Lis la doc:
    http://msdn.microsoft.com/library/en...enfilename.asp
    Import library Comdlg32.lib
    il faut linker avec Comdlg32.lib. c.a.d -lcomdlg32 avec devcpp.

  6. #6
    Membre habitué Avatar de benjiprog
    Profil pro
    Étudiant
    Inscrit en
    Septembre 2005
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2005
    Messages : 302
    Points : 134
    Points
    134
    Par défaut
    D'accord je te remerci.
    Les élèves glandeurs c'est comme le linge, quand il fait beau ca sèche.

  7. #7
    Expert éminent sénior

    Homme Profil pro
    pdg
    Inscrit en
    Juin 2003
    Messages
    5 751
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : pdg

    Informations forums :
    Inscription : Juin 2003
    Messages : 5 751
    Points : 10 667
    Points
    10 667
    Billets dans le blog
    3
    Par défaut
    Pense à mettre résolu quand c'est le cas (dans les Outils de la discussion)

Discussions similaires

  1. Problème avec une fonction date.
    Par kmayoyota dans le forum ASP
    Réponses: 8
    Dernier message: 09/09/2004, 12h33
  2. Problème avec la fonction findfirst ()
    Par Angelico dans le forum Windows
    Réponses: 3
    Dernier message: 05/08/2004, 20h40
  3. [Requete SQL en VBA] Problème avec la fonction FLOOR
    Par zubral dans le forum Langage SQL
    Réponses: 4
    Dernier message: 13/07/2004, 13h24
  4. Problème avec les fonctions
    Par jvachez dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 13/01/2004, 12h06
  5. [Postgresql]Problème avec les fonctions ...
    Par fet dans le forum Requêtes
    Réponses: 4
    Dernier message: 02/10/2003, 09h04

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