Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Adding File names to list box.

Adding File names to list box.

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Suresh H
    wrote on last edited by
    #1

    Hello All, I have a List Box { IDC_FILE_LIST } and add button { IDC_FILE } When we click on the add button it should popup a window where we can browse some file name with path and it should be added to list box. For that I have used the below code but I am getting errors can anyone please tell me what is wrong in the below code. [code] BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_FILE: OpenFile(hwnd); break; --- ---- Function OpenFile : - void OpenFile(HWND hwnd) { OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileName(&ofn)) { HWND hEdit = GetDlgItem(hwnd, IDC_FILE_LIST); SendDlgItemMessage(hwnd, IDC_FILE_LIST, LB_ADDSTRING, 0, (LPARAM)ofn); } } [\code] Errors : - (134) : error C2065: 'OPENFILENAME' : undeclared identifier (134) : error C2146: syntax error : missing ';' before identifier 'ofn' (134) : error C2065: 'ofn' : undeclared identifier (139) : error C2228: left of '.lStructSize' must have class/struct/union type (140) : error C2228: left of '.hwndOwner' must have class/struct/union type (141) : error C2228: left of '.lpstrFilter' must have class/struct/union type (142) : error C2228: left of '.lpstrFile' must have class/struct/union type (143) : error C2228: left of '.nMaxFile' must have class/struct/union type (144) : error C2228: left of '.Flags' must have class/struct/union type (144) : error C2065: 'OFN_EXPLORER' : undeclared identifier (144) : error C2065: 'OFN_FILEMUSTEXIST' : undeclared identifier (144) : error C2065: 'OFN_HIDEREADONLY' : undeclared identifier (145) : error C2228: left of '.lpstrDefExt' must have class/struct/union type (147) : error C2065: 'GetOpenFileName' : undeclared identifier --------- Thanking you, Suresh HC

    M P 2 Replies Last reply
    0
    • S Suresh H

      Hello All, I have a List Box { IDC_FILE_LIST } and add button { IDC_FILE } When we click on the add button it should popup a window where we can browse some file name with path and it should be added to list box. For that I have used the below code but I am getting errors can anyone please tell me what is wrong in the below code. [code] BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_FILE: OpenFile(hwnd); break; --- ---- Function OpenFile : - void OpenFile(HWND hwnd) { OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileName(&ofn)) { HWND hEdit = GetDlgItem(hwnd, IDC_FILE_LIST); SendDlgItemMessage(hwnd, IDC_FILE_LIST, LB_ADDSTRING, 0, (LPARAM)ofn); } } [\code] Errors : - (134) : error C2065: 'OPENFILENAME' : undeclared identifier (134) : error C2146: syntax error : missing ';' before identifier 'ofn' (134) : error C2065: 'ofn' : undeclared identifier (139) : error C2228: left of '.lStructSize' must have class/struct/union type (140) : error C2228: left of '.hwndOwner' must have class/struct/union type (141) : error C2228: left of '.lpstrFilter' must have class/struct/union type (142) : error C2228: left of '.lpstrFile' must have class/struct/union type (143) : error C2228: left of '.nMaxFile' must have class/struct/union type (144) : error C2228: left of '.Flags' must have class/struct/union type (144) : error C2065: 'OFN_EXPLORER' : undeclared identifier (144) : error C2065: 'OFN_FILEMUSTEXIST' : undeclared identifier (144) : error C2065: 'OFN_HIDEREADONLY' : undeclared identifier (145) : error C2228: left of '.lpstrDefExt' must have class/struct/union type (147) : error C2065: 'GetOpenFileName' : undeclared identifier --------- Thanking you, Suresh HC

      M Offline
      M Offline
      Mila025
      wrote on last edited by
      #2

      Hi, Did you include Windows.h header ?

      ----------- Mila

      S 1 Reply Last reply
      0
      • S Suresh H

        Hello All, I have a List Box { IDC_FILE_LIST } and add button { IDC_FILE } When we click on the add button it should popup a window where we can browse some file name with path and it should be added to list box. For that I have used the below code but I am getting errors can anyone please tell me what is wrong in the below code. [code] BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_FILE: OpenFile(hwnd); break; --- ---- Function OpenFile : - void OpenFile(HWND hwnd) { OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileName(&ofn)) { HWND hEdit = GetDlgItem(hwnd, IDC_FILE_LIST); SendDlgItemMessage(hwnd, IDC_FILE_LIST, LB_ADDSTRING, 0, (LPARAM)ofn); } } [\code] Errors : - (134) : error C2065: 'OPENFILENAME' : undeclared identifier (134) : error C2146: syntax error : missing ';' before identifier 'ofn' (134) : error C2065: 'ofn' : undeclared identifier (139) : error C2228: left of '.lStructSize' must have class/struct/union type (140) : error C2228: left of '.hwndOwner' must have class/struct/union type (141) : error C2228: left of '.lpstrFilter' must have class/struct/union type (142) : error C2228: left of '.lpstrFile' must have class/struct/union type (143) : error C2228: left of '.nMaxFile' must have class/struct/union type (144) : error C2228: left of '.Flags' must have class/struct/union type (144) : error C2065: 'OFN_EXPLORER' : undeclared identifier (144) : error C2065: 'OFN_FILEMUSTEXIST' : undeclared identifier (144) : error C2065: 'OFN_HIDEREADONLY' : undeclared identifier (145) : error C2228: left of '.lpstrDefExt' must have class/struct/union type (147) : error C2065: 'GetOpenFileName' : undeclared identifier --------- Thanking you, Suresh HC

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #3

        include Commdlg.h.

        Prasad Notifier using ATL | Operator new[],delete[][^]

        S 1 Reply Last reply
        0
        • M Mila025

          Hi, Did you include Windows.h header ?

          ----------- Mila

          S Offline
          S Offline
          Suresh H
          wrote on last edited by
          #4

          Hi Mila, Thanks for the response. I have included windows.h and I forgot to include #include "commdlg.h" .

          1 Reply Last reply
          0
          • P prasad_som

            include Commdlg.h.

            Prasad Notifier using ATL | Operator new[],delete[][^]

            S Offline
            S Offline
            Suresh H
            wrote on last edited by
            #5

            Oops I forgot to include #include "commdlg.h" Now the error have gone Thanks a lot Prasad.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups