#include //#include #include #include #include //using namespace std; #define IDC_LISTBOX 100 #define IDC_EDITBOX 101 class CMapApp: public CWinApp { private: public: virtual BOOL InitInstance(); }; CMapApp app; class CMapWnd:public CFrameWnd { CListBox* cl; CMapStringToString map; CStatic *det,*det1; std::ifstream in; public: CMapWnd(); //{{AFX_MSG(CMapWnd) afx_msg void Handl_Click(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; BOOL CMapApp::InitInstance() { m_pMainWnd=new CMapWnd; m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return true; } BEGIN_MESSAGE_MAP(CMapWnd,CFrameWnd) //{{AFX_MSG_MAP(CMapWnd) ON_LBN_DBLCLK(IDC_LISTBOX,Handl_Click) //}}AFX_MSG_MAP END_MESSAGE_MAP() void CMapWnd:: Handl_Click() { CRect r1; int i=cl->GetCurSel(); char buf[6]; CString buf2; cl->GetText(i,buf); map.Lookup(buf,buf2); GetClientRect(&r1); r1.InflateRect(-10,-150,-50,-100); det=new CStatic(); det->Create(buf2,WS_CHILD|WS_VISIBLE|SS_LEFT,r1,this); } CMapWnd::CMapWnd() { CRect r,r1; CString str,str1; int i=0; std::string s1,s2; in.open("namesmap.txt"); while(in.good()) { in>>s1; in>>s2; map[_T(s1.c_str())]=_T(s2.c_str()); } Create(NULL,"Sample",WS_OVERLAPPEDWINDOW,CRect(0,0,300,300)); GetClientRect(&r); r.InflateRect(-10,-10,-140,-140); cl=new CListBox(); cl->Create(WS_CHILD|WS_VISIBLE|LBS_STANDARD|LBS_NOTIFY,r,this,IDC_LISTBOX); POSITION pos=map.GetStartPosition(); while(pos!=NULL) { map.GetNextAssoc(pos,str,str1); cl->AddString(str); } cl->SetFocus(); GetClientRect(&r1); r1.InflateRect(-10,-130,-50,-100); det1=new CStatic; det1->Create("State name associated with code",WS_CHILD|WS_VISIBLE|SS_LEFT,r1,this); GetClientRect(&r1); r1.InflateRect(-10,-150,-100,-100); det=new CStatic(); det->Create("",WS_CHILD|WS_VISIBLE|SS_LEFT,r1,this); }