GetOpenFileName

Résolu
piroman14 Messages postés 18 Date d'inscription samedi 14 juin 2008 Statut Membre Dernière intervention 11 novembre 2008 - 24 juil. 2008 à 11:42
piroman14 Messages postés 18 Date d'inscription samedi 14 juin 2008 Statut Membre Dernière intervention 11 novembre 2008 - 24 juil. 2008 à 17:05
Salut!
j'ai un problème avec GetOpenFileName
j'en utilise deux et je n'arrive pas à faire fonctionner le premier des deux
je crois qu'il faut utiliser un identifiant du type IDM_OPEN différent pour chacun des GetOpenFileName mais je ne suis pas sur
voici les deux GetOpenFileName que j'utilise:

I)
case WM_PAINT :
{
        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  BMP\0*.bmp\0";
                ofn.nFilterIndex = 1;
                ofn.Flags =OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  
                if (GetOpenFileName(&ofn)==TRUE)  


  { 
 
     HBITMAP bitmap;
        HDC dc;
        PAINTSTRUCT ps;
  
  bitmap=(HBITMAP)calloc(1,sizeof(HBITMAP));
  
  LoadImage(NULL,szFile,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);


        dc = BeginPaint(hwnd, &ps);


        DrawState(dc,NULL,NULL,(long)bitmap,NULL,10,10,0,0,DST_BITMAP);


        EndPaint(hwnd, &ps);


        DeleteObject(bitmap);


  return 0;


  }
    }
}

II)
case WM_COMMAND:


            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  VTK\0*.vtk\0";
     ofn.nFilterIndex = 1;
     ofn.Flags =OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
   
     if (GetOpenFileName(&ofn)==TRUE)

3 réponses

BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
24 juil. 2008 à 11:55
Salut,
Il n'est pas très judicieux d'appeler cette fonction dans le WM_PAINT car tu va y passer des tonnes de fois. C'est ptet pour ça qu'il ne fonctionne pas. Il faut le faire ailleurs...
Pas besoin d'identifiant pour séparer tes 2 appels.

@+
Buno
----------------------------------------
L'urgent est fait, l'impossible est en cours. Pour les miracles, prévoir un délai...
3
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
24 juil. 2008 à 11:55
case WM_PAINT
ne gérer QUE le dessinage dans cet event, exit boite de dialog comme toute autre intervention utilisateur.

ciao...
BruNews, MVP VC++
3
piroman14 Messages postés 18 Date d'inscription samedi 14 juin 2008 Statut Membre Dernière intervention 11 novembre 2008
24 juil. 2008 à 17:05
Merci pour vos conseils!


Je n'avais pas bien compris l'utilité du WM_PAINT.
Sinon auriez vous une idée pourquoi je n'arrive pas à afficher de bitmap avec mon programme?
Merci par avance de vos conseils, je commence à désepsérer qu'un jour mon programme fonctionne.

  case WM_COMMAND:


            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  BMP\0*.bmp\0";
                ofn.nFilterIndex = 1;
                ofn.Flags =OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  
                if (GetOpenFileName(&ofn)==TRUE)  


    { 
   
    HBITMAP bitmap;
    PAINTSTRUCT ps;
    HDC hdc;
    
    bitmap=(HBITMAP)calloc(1,sizeof(HBITMAP));
    LoadImage(NULL,szFile,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    hdc = BeginPaint(hEdit, &ps);    
    DrawState(hdc,NULL,NULL,(long)bitmap,NULL,10,10,0,0,DST_BITMAP);
    EndPaint(hEdit, &ps);
    DeleteObject(bitmap);
    return 0;


    }
   }


   
0
Rejoignez-nous