?
Solved

listbox and metafile selection

Posted on 1999-12-14
16
Medium Priority
?
255 Views
Last Modified: 2013-11-20
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).
0
Comment
Question by:simongod
  • 8
  • 5
  • 2
  • +1
16 Comments
 
LVL 6

Expert Comment

by:MichaelS
ID: 2281383
TCHAR szPath[MAX_PATH];

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

szPath is a text from your edit control
0
 
LVL 2

Author Comment

by:simongod
ID: 2281464
hwndDlg is an undeclared identifier
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 2281475
it should be window handle of your dialog or if you use MFC then just drop it.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 2

Author Comment

by:simongod
ID: 2281491
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
 
LVL 7

Expert Comment

by:leflon
ID: 2281799
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
 
LVL 11

Expert Comment

by:mikeblas
ID: 2282407
Maybe you should try finding some books on computer programming.

..B ekiM
0
 
LVL 2

Author Comment

by:simongod
ID: 2284131
mabe mikeblas would like to suggest a good book?  Instead of being the problem why not the solution?
0
 
LVL 2

Author Comment

by:simongod
ID: 2284143
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
 
LVL 6

Expert Comment

by:MichaelS
ID: 2284181
Why you assign only 5 points? Usually the easy question is 50 (I mean EE).
0
 
LVL 2

Author Comment

by:simongod
ID: 2284210
well i can place more for the question.  I have a lot of questions and want to conserve my pts.
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 2284228
:)
0
 
LVL 2

Author Comment

by:simongod
ID: 2284292
Adjusted points to 100
0
 
LVL 2

Author Comment

by:simongod
ID: 2284300
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
 
LVL 6

Accepted Solution

by:
MichaelS earned 400 total points
ID: 2284321
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
 
LVL 11

Expert Comment

by:mikeblas
ID: 2285694
> 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
 
LVL 2

Author Comment

by:simongod
ID: 2286673
thanks to the ones who really helped me
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question