listbox and metafile selection

ok I have a DIALOG based project.  When In my listbox I have the names of all the emf files located in a certain directory displayed in the listbox.  Now when I dblclick on an item its name is displayed inside of an edit control.  When I dblclick on the item I want the picture to be displayed also.  I have the code to open a metafile.  The code below displayes my metafile inside of a picture box.  Instead of hard coding the name of the file displayed I want to be able to select the name from the listbox that already displays the names of the metafiles (emf).
LVL 2
simongodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MichaelSCommented:
TCHAR szPath[MAX_PATH];

GetDlgItemText(hwndDlg, IDC_YOUREDITCONTROL, (WPARAM)szPath, MAX_PATH);

szPath is a text from your edit control
0
simongodAuthor Commented:
hwndDlg is an undeclared identifier
0
MichaelSCommented:
it should be window handle of your dialog or if you use MFC then just drop it.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

simongodAuthor Commented:
yes i dropped it because I use MFC but when I did I get a new error.  I added your code word for word.  the error is below.

error C2664: 'int __thiscall CWnd::GetDlgItemTextA(int,char *,int) const' : cannot convert parameter 2 from 'unsigned int' to 'char *'
0
leflonCommented:
use classwizard to create a member variable for your edit control (for example m_ctrlEdit)
than you can get the text from the edit control by:
char buf[0x100] = "";
m_ctrlEdit.GetWindowText(buf,0x100);
0
mikeblasCommented:
Maybe you should try finding some books on computer programming.

..B ekiM
0
simongodAuthor Commented:
mabe mikeblas would like to suggest a good book?  Instead of being the problem why not the solution?
0
simongodAuthor Commented:
this is the code that I have for getting the file.

LPCTSTR strFileName = "temp.emf";
      HENHMETAFILE hMetaFile = GetEnhMetaFile(strFileName);

strFileName is the name of the file that I want to be displayed.  How can I change that so when I dblclick on my listbox it will show the picture that I have choosen, using the code that I have above.
0
MichaelSCommented:
Why you assign only 5 points? Usually the easy question is 50 (I mean EE).
0
simongodAuthor Commented:
well i can place more for the question.  I have a lot of questions and want to conserve my pts.
0
MichaelSCommented:
:)
0
simongodAuthor Commented:
Adjusted points to 100
0
simongodAuthor Commented:
In my listbox I already have the files that I want to select from.  I used a function that I made to find all the EMF files on my HD but that code gets rid of the .emf part.  Well I want to select one of those files and have it displayed using the code above to do that.  Here is the function that I have for finding all the emf files.

void CNewDlg::FindFiles(CString csStartDirectory)
{
      HANDLE hFile = FindFirstFile(csStartDirectory + CString(_T("\\*.*")), &fileFindData);
      csFileName = fileFindData.cFileName;

      if (hFile != INVALID_HANDLE_VALUE)
      {
            do
            {
                  csFileName = fileFindData.cFileName;
            
                  // get all .emf files at this level...
                  if (csFileName.Find(_T(".emf")) != -1)
                  {
                        // trim file extension...
                        csFileName = fileFindData.cFileName;
                        csFileName.Replace(_T(".emf"), _T(""));

                        // put trimmed filename into list box...
                        m_selectblock.AddString(csFileName);
                  } // end if
                  else if ((fileFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (csFileName != ".") && (csFileName != ".."))
                  {
                        // FindClose(hFile);
                        csSubDir = csStartDirectory + CString(_T("\\")) + csFileName;
                        FindFiles(csSubDir);
                  } // end else
            } while (FindNextFile(hFile, &fileFindData));
      } // end if
      else
      {
            MessageBox("EMF files not found", "EMF", MB_OK);
      }
} // end FindFiles
0
MichaelSCommented:
something like

CString& MyDialog::GetSelectedText()
{    int iIndex = m_selectblock.GetCurSel();

    if(iIndex == LB_ERR)
        return NULL;

    CString* pString = new CString;
    m_selectblock.GetText(iIndex, pString);
    return pString;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mikeblasCommented:
> mabe mikeblas would like to suggest a good book?  

Most people learn Windows programming with Charles Petzold's "Programming Windows". I think the current edition is the 3rd, but it might be the fourth.

Lots of people learn Visual C++ with David Kruglinski's book. David passed away a couple of summers ago, and Scott Wingo is now listed as a coauthor.

It looks like you really know nothing about programming, though. So you might start with a book that has less prerequisites. I've not read it myself, but you might start with "C++ Primer" by Stanley Lippman.

Or, you might start with a more forgiving environment, like Visual Basic.

..B ekiM
0
simongodAuthor Commented:
thanks to the ones who really helped me
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.