Bonjour,
j'aimerais récupérer le nom du fichier qu'un utilisateur choisira grace à openfile et j'aimerais récupérer cette variable ou autre (je ne sais pas comment ça s'appelle ,je débute en c ) je vous passe le code que j'ai trouver sur internet mais lorsque je le compile, j'ai une erreur sur cette ligne carré rouge sur codeblock
Code : Sélectionner tout - Visualiser dans une fenêtre à part
return GetOpenFileName(&ofn);
et le compilateur me dit undefined reference to 'GETOpenFileNameA@4' voici le code en question, merci pour votre attention
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>
#include "resource.h"
 
HINSTANCE hinst;
char szfile[MAX_PATH];
 
BITMAPFILEHEADER* pbminfhead;
BITMAPINFO* pbmpinf;
BYTE* pbitsbmp = 0;
long cxDib, cyDib; // image de fond
HANDLE hheap;
HWND himg; // cadre apercu image
long cximg, cyimg; //
 
void ChargeBmp()
{
  DWORD  dwFileSize, dwRead;
  HANDLE hFile;
  hFile = CreateFile(szfile, GENERIC_READ, FILE_SHARE_READ, NULL,
                     OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
  if(hFile == INVALID_HANDLE_VALUE) return;
  dwFileSize = GetFileSize(hFile, 0);
  pbminfhead = (BITMAPFILEHEADER *) HeapAlloc(hheap, 0, dwFileSize);
  if(pbminfhead == 0) goto flClose;
  dwRead = 0; ReadFile(hFile, pbminfhead, dwFileSize, &dwRead, NULL);
  if((dwRead != dwFileSize)
     || (pbminfhead->bfType != 0x4D42) || (pbminfhead->bfSize != dwFileSize)) {
    HeapFree(hheap, 0, pbminfhead);
    pbminfhead = 0; goto flClose;
  }
  pbmpinf = (BITMAPINFO*) (pbminfhead + 1);
  pbitsbmp = (BYTE*) pbminfhead + pbminfhead->bfOffBits;
  if(pbmpinf->bmiHeader.biSize == sizeof(BITMAPCOREHEADER)) {
    cxDib = ((BITMAPCOREHEADER*) pbmpinf)->bcWidth;
    cyDib = ((BITMAPCOREHEADER*) pbmpinf)->bcHeight;
  }
  else {
    cxDib = pbmpinf->bmiHeader.biWidth;
    cyDib = pbmpinf->bmiHeader.biHeight;
  }
flClose: CloseHandle(hFile);
}
 
DWORD CALLBACK OFNHookProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
{
  switch(mssg) {
    case WM_NOTIFY:
      LPOFNOTIFY lpfn;
      long n;
      lpfn = (LPOFNOTIFY)lParam;
      if(lpfn->hdr.code == CDN_SELCHANGE) {
        SetDlgItemText(hdlg, IDST_FILE, 0);
        InvalidateRect(himg, 0, 1);
        if(pbminfhead) {HeapFree(hheap, 0, pbminfhead); pbminfhead = 0;}
        n = SendMessage(lpfn->hdr.hwndFrom, CDM_GETFILEPATH, MAX_PATH, (long) szfile);
        if(n > 6) {
          if(!stricmp(szfile+n-5, ".bmp")) {
            SetDlgItemText(hdlg, IDST_FILE, szfile);
            ChargeBmp();
            if(pbminfhead) {
              HDC hdc = GetDC(himg);
              StretchDIBits(hdc, 0, 0, cximg, cyimg, 0, 0, cxDib, cyDib, pbitsbmp,
                        pbmpinf, DIB_RGB_COLORS, SRCCOPY);
              ReleaseDC(himg, hdc);
            }
          }
        }
      }
      break;
    case WM_INITDIALOG:
      RECT rc;
      himg = GetDlgItem(hdlg, IDPCT_BMP);
      pbminfhead = 0;
      GetClientRect(himg, &rc);
      cximg = rc.right; cyimg = rc.bottom;
      break;
    case WM_DESTROY:
      if(pbminfhead) HeapFree(hheap, 0, pbminfhead);
  }
  return 0;
}
 
BOOL dlgSelectBitmap(HWND hOwner)
{
  OPENFILENAME ofn;
  memset(&ofn,0,sizeof(ofn));
  ofn.lStructSize = sizeof(OPENFILENAME);
  ofn.nFilterIndex = 1;
  ofn.lpstrFilter = "BMP\0*.bmp\0\0";
  ofn.lpstrFile = szfile;
  ofn.nMaxFile = MAX_PATH;
  ofn.hwndOwner = hOwner;
	ofn.lpstrTitle = "Ouvrir un bitmap";
  ofn.Flags = 0x8006C;
  ofn.hInstance = hinst;
  ofn.lpfnHook = (LPOFNHOOKPROC) OFNHookProc;
  ofn.lpTemplateName = MAKEINTRESOURCE(IDD_BMPSEL);
  szfile[0] = 0;
  return GetOpenFileName(&ofn);
}
 
BOOL CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
{
  switch(mssg) {
    case WM_INITDIALOG:
      SetClassLong(hdlg, GCL_HICON, (long)LoadIcon(hinst, MAKEINTRESOURCE(IDI_APP)));
      return 1;
    case WM_COMMAND:
      switch(wParam) {
        case IDOK:
          SetDlgItemText(hdlg, IDST_FILE, 0);
          if(dlgSelectBitmap(hdlg)) SetDlgItemText(hdlg, IDST_FILE, szfile);
          return 0;
        case IDCANCEL: EndDialog(hdlg, 0);
      }
  }
  return 0;
}
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
{
  hinst = hInstance;
  hheap = GetProcessHeap();
  DialogBox(hInstance, MAKEINTRESOURCE(IDD_APP), NULL, AppDlgProc);
  return 0;
}
heu le code est pour ouvrir une image mais je pense que sa devrais marcher pour ouvrir un .mp3 à vérifier..
Merci pour vos réponse