unable to override OnDropFiles
rwagner -- rwagner@genre.com Monday, January 20, 1997 Robert Wagner@GRN 01/20/97 02:35 PM Environment: Visual C++ 4.2-flat, Win95 Overriding OnDropFiles in the CMainframe class and then opening the file(s) that the user dropped in is pretty straightforward, and I can make this work. However, I am trying to implement dropping a file on a CComboBox control in a dialog box, and find that I cannot. I would like to be able to drop a text file on a CCombobox and then populate the selections from lines in the file. I had ClassWizard provide the override, but it never gets called, even though Windows allows me to drop the file onto this control but noplace else in the dialog; conceivably because I checked 'Accept Files' in the Extended Styles part of Control Properties, which you get by doubleclicking on the control in the Resource Editor. Any ideas or sample code on how to implement this? Thanks Rob
Stuart Downing -- sdowning@fame.com Wednesday, January 22, 1997 [Mini-digest: 5 responses] See... http://www.visionx.com/mfcpro/mfc-l/t7361.htm for a previous discussion of this. ----- Stuart Downing sdowning@fame.com FAME Information Services, Inc. ---------- From: rwagner@genre.com[SMTP:rwagner@genre.com] Sent: Monday, January 20, 1997 9:35 AM To: mfc-l@netcom.com Subject: unable to override OnDropFiles Robert Wagner@GRN 01/20/97 02:35 PM Environment: Visual C++ 4.2-flat, Win95 Overriding OnDropFiles in the CMainframe class and then opening the file(s) that the user dropped in is pretty straightforward, and I can make this work. However, I am trying to implement dropping a file on a CComboBox control in a dialog box, and find that I cannot. I would like to be able to drop a text file on a CCombobox and then populate the selections from lines in the file. I had ClassWizard provide the override, but it never gets called, even though Windows allows me to drop the file onto this control but noplace else in the dialog; conceivably because I checked 'Accept Files' in the Extended Styles part of Control Properties, which you get by doubleclicking on the control in the Resource Editor. Any ideas or sample code on how to implement this? Thanks Rob -----From: Rob HillIve done something similar, but with a treeview , the dropfiles message = goes to the parent of my tree control, not the treecontrol itself. Its = my treecontrol-containing view that processes the dropfiles message, and = then fills the tree control up. Have you tried handling the message in the combo-boxe's parent? Rob. -------------------------------------------------------------------------= -------------- Robert J. Hill Programming Manager=20 Team17 Software Ltd, Longlands House, Wakefield Road, Ossett, W.Yorks, WF5 9JS TEL: 0192 426 7776 FAX: 0192 426 7658 Check out Team17's Home http://www.team17.com=20 Check out our Store on http://one.store.co.uk=20 -------------------------------------------------------------------------= -------------- -----Original Message----- From: rwagner@genre.com [SMTP:rwagner@genre.com] Sent: Monday, January 20, 1997 2:35 PM To: mfc-l@netcom.com Subject: unable to override OnDropFiles Robert Wagner@GRN 01/20/97 02:35 PM Environment: Visual C++ 4.2-flat, Win95 Overriding OnDropFiles in the CMainframe class and then opening the = file(s) that the user dropped in is pretty straightforward, and I can make this work. However, I am trying to implement dropping a file on a CComboBox control = in a dialog box, and find that I cannot. I would like to be able to drop a text file on a CCombobox and then populate the selections from lines in = the file. I had ClassWizard provide the override, but it never gets called, even though Windows allows me to drop the file onto this control but noplace else in the dialog; conceivably because I checked 'Accept Files' in the Extended Styles part of Control Properties, which you get by = doubleclicking on the control in the Resource Editor. Any ideas or sample code on how to implement this? Thanks Rob -----From: Shaju Mathew Hi, I've done an owner-drawn list-box with drag'n drop(your combo-box should be very similar)While my sample adds the program icons in hte combo-box, it should be prettty trivial for you to modify the functionality to add lines from the files.. ///start header file for the list-box // IconListBox.h : header file // This class implements an owner-drawn list box. The user can drag 'n // drop .EXEs/.DLLs from FileManager/Explorer and this listbox will // retrieve the appropriate icons and display them. Once certain rules // are defined for key applications(eg. Netscape, Oracle), we'll // identify them dynamically and add them in this listbox by default. // Instantiated from the CSymptomPropertyPage::OnCreate() override // Overrides of PreCreateWindow(), MeasureItem() and DrawItem() does the job ///////////////////////////////////////////////////////////////////////////// // CIconListBox window #ifndef __ICONLISTBOX_H__ #define __ICONLISTBOX_H__ class CIconListBox : public CListBox { // Construction public: CIconListBox(void); int AddIcon(HICON); // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CIconListBox) public: virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct); virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); protected: virtual BOOL PreCreateWindow(CREATESTRUCT& cs); //}}AFX_VIRTUAL // Implementation public: virtual ~CIconListBox(void); // Generated message map functions protected: //{{AFX_MSG(CIconListBox) afx_msg void OnSelchange(void); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; #endif ///////////////////////////////////////////////////////////////////////////// ///end header //start implementation for the list box // IconListBox.cpp : implementation file // #include "stdafx.h" //#include "glance.h" #include "IconListBox.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CIconListBox CIconListBox::CIconListBox(void) {//nothing to do... } CIconListBox::~CIconListBox(void) { } int CIconListBox::AddIcon(HICON hIcon) {//called by CSymptomPropertyPage members - OnInitDialog()(for default //apps for which we've already a set of rules defined), OnBrowse() //and OnDropFiles() int nIndex = AddString(""); if((LB_ERR != nIndex) && (LB_ERRSPACE != nIndex)) SetItemData(nIndex, (DWORD)hIcon); SetCurSel(nIndex); return(nIndex); } BEGIN_MESSAGE_MAP(CIconListBox, CListBox) //{{AFX_MSG_MAP(CIconListBox) ON_CONTROL_REFLECT(LBN_SELCHANGE, OnSelchange) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CIconListBox message handlers BOOL CIconListBox::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Add your specialized code here and/or call the base class if(!CListBox::PreCreateWindow(cs)) return(FALSE); //cs.dwExStyle |= WS_EX_CLIENTEDGE; cs.style &= ~(LBS_OWNERDRAWVARIABLE | LBS_SORT); cs.style |= LBS_OWNERDRAWFIXED; return(TRUE); //return CListBox::PreCreateWindow(cs); } void CIconListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { // TODO: Add your code to determine the size of specified item //set the height to that of a large icon lpMeasureItemStruct->itemHeight = 36; } void CIconListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your code to draw the specified item CDC dc; dc.Attach(lpDrawItemStruct->hDC); CRect rect = lpDrawItemStruct->rcItem; int nIndex = lpDrawItemStruct->itemID; CBrush *brush = new CBrush(::GetSysColor((lpDrawItemStruct->itemState & ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_WINDOW)); dc.FillRect(rect, brush); delete(brush); if(lpDrawItemStruct->itemState & ODS_FOCUS) dc.DrawFocusRect(rect); if(nIndex != (UINT)-1) dc.DrawIcon(rect.left + 4, rect.top + 2, (HICON)GetItemData(nIndex)); //dc.TextOut(rect.left + 40, rect.top + 8, "Icons"); dc.Detach(); } void CIconListBox::OnSelchange(void) {//overridden for later use // TODO: Add your control notification handler code here //int index = GetCurSel(); //HICON hIcon = (HICON)GetItemData(index); //ShowWindow(SW_HIDE); } //end implementation Here's the how I create it from the parent: int CSymptomPropertyPage::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CPropertyPage::OnCreate(lpCreateStruct) == -1) return -1; DragAcceptFiles();//to activate COleDropTarget // TODO: Add your specialized creation code here //create the owner-drawn icon list-box window m_IconListBox.Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT, /*CRect(380, 150, 480, 210)*/CRect(380, 136, 480, 210), this, IDC_ICONLISTBOX); return 0; } //The CSymptomPropertyPage(::public CPropertyPage) has a dialog template resource in which I've a list-box mapping on to m_IconListBox void CSymptomPropertyPage::OnDropFiles(HDROP hDropInfo) { // TODO: Add your message handler code here and/or call default int nCount = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0); if(1 == nCount)//process one at a time { //IconListBox.ResetContent(); TCHAR szFileName[MAX_PATH]; ::DragQueryFile(hDropInfo, 0, szFileName, MAX_PATH); HICON hIcon = RetrieveIcon(szFileName); m_IconListBox.AddIcon(hIcon); //m_IconListCtrl.AddIcon(hIcon); /*int nIcons = (int)::ExtractIcon(NULL, szFileName, (UINT)-1); if(nIcons) { HICON hIcon; //for(int i = 0; i < nIcons; i++) //{ hIcon = ::ExtractIcon(AfxGetInstanceHandle(), szFileName, 0);//i); m_IconListBox.AddIcon(hIcon); m_IconListCtrl.AddIcon(hIcon); //} } */ //m_IconListBox.SetCurSel(0); //m_IconListCtrl.SetCurSel(0); } DragFinish(hDropInfo); CPropertyPage::OnDropFiles(hDropInfo); } Good luck Shaju_Mathew@hp.com > > Robert Wagner@GRN > 01/20/97 02:35 PM > > Environment: Visual C++ 4.2-flat, Win95 > > Overriding OnDropFiles in the CMainframe class and then opening the file(s) > that the user dropped in is pretty straightforward, and I can make this > work. > > However, I am trying to implement dropping a file on a CComboBox control in > a dialog box, and find that I cannot. I would like to be able to drop a > text file on a CCombobox and then populate the selections from lines in the > file. > > I had ClassWizard provide the override, but it never gets called, even > though Windows allows me to drop the file onto this control but noplace > else in the dialog; conceivably because I checked 'Accept Files' in the > Extended Styles part of Control Properties, which you get by doubleclicking > on the control in the Resource Editor. > > Any ideas or sample code on how to implement this? > > Thanks > Rob > > > > -- *********************************************************************** .---. .---. Shaju Mathew /" " \ WWW / " "\ Off:(916)785-9018 Performance Technology Lab / / "" \(*|*)/ "" \ \ WCSO Group R & D ////// '. V .` \\\\\\ Home:(916)722-4576 Hewlett-Packard Company //// / // : """ : \\ \ \\\\ 8000, Foothills Blvd // / / /`.""" '\ \ \ \\Fax:(916)785-1264 MS 5723, Roseville // //.".\\ \\ CA 95747-5723 -------UU---UU------- '//|||\\` Shaju_Mathew@hp.com *********************************************************************** -----From: "John Boehme" I ran into a similar problem in an application that I wrote. My app provides a standard Win95 folder interface for ftp sites. I wanted to handle the dragging and dropping of files from my computer and have my app send or receive them to ro from the ftp site. I over rode OnDropFiles() in my view and it did not work, never got called. I added the call to DragAcceptFiles() in my InitialUpdate() of my view and it worked. Even though the documentation stated that the drag file capability would apply to any child window that this call is made for. If you need futher code, let me know. Good Luck. John Boehme http://www.iglobal.net/pub/johnandce/ --------- > From: rwagner@genre.com > To: mfc-l@netcom.com > Subject: unable to override OnDropFiles > Date: Monday, January 20, 1997 8:35 AM > > > Robert Wagner@GRN > 01/20/97 02:35 PM > > Environment: Visual C++ 4.2-flat, Win95 > > Overriding OnDropFiles in the CMainframe class and then opening the file(s) > that the user dropped in is pretty straightforward, and I can make this > work. > > However, I am trying to implement dropping a file on a CComboBox control in > a dialog box, and find that I cannot. I would like to be able to drop a > text file on a CCombobox and then populate the selections from lines in the > file. > > I had ClassWizard provide the override, but it never gets called, even > though Windows allows me to drop the file onto this control but noplace > else in the dialog; conceivably because I checked 'Accept Files' in the > Extended Styles part of Control Properties, which you get by doubleclicking > on the control in the Resource Editor. > > Any ideas or sample code on how to implement this? > > Thanks > Rob > >
| Вернуться в корень Архива |