DDX DLL and CComboBoxImpl in WTL
-
Hi All, I seem to be having the most stupid problem (well I am the stupid one) with retrieving the selected value out of a ComboBox. Background info: All my development is within an ATL Com based DLL. I have extended its functionality by including the WTL libraries in the stdafx.h header. The DLL is a set of tools and dlgs that are loaded into the calling application. I have read Michael Dunns intro to WTL articles and found them encouraging... hence trying to use them in my project. However I seem to be having trouble implementing the msg maps and ddx maps etc in the dialogs as they seem to crash the calling application. For the calling application and DLL to work, the dialogs must be of type
CAxDialogImpl
. I have one Dialog that I have managed to use WTL message maps in and it works ok. However other time it doesn't. I cannot get the DDX map to map the values from my ComboBox to my class members:class CTargetDialog : public CAxDialogImpl,//public CUpdateUI, //public CMessageFilter, public CIdleHandler, public CWinDataExchange, public CComObjectRootEx, public CComCoClass { public: CTargetDialog(IApplicationPtr pApp); ~CTargetDialog(); enum { IDD = IDD_TARGETDIALOG }; BEGIN_MSG_MAP(CTargetDialog) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) COMMAND_ID_HANDLER(IDOK, OnOK) COMMAND_ID_HANDLER(IDCANCEL, OnCancel) COMMAND_HANDLER(IDC_COMBO_TARGET, CBN_SELCHANGE, OnSelchangeCombo_target) COMMAND_HANDLER(IDC_COMBO_TARGET, CBN_DROPDOWN, OnDropdownCombo_target) END_MSG_MAP() BEGIN_DDX_MAP(CTargetDialog) DDX_CONTROL(IDC_COMBO_TARGET, m_pComboBox) DDX_TEXT(IDC_COMBO_TARGET, m_szTargetLayer) END_DDX_MAP() // Handler prototypes: // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled); LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnSelchangeCombo_target(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnDropdownCombo_target(WORD wNotifyCode, WORD wID, HWND hWnd
-
Hi All, I seem to be having the most stupid problem (well I am the stupid one) with retrieving the selected value out of a ComboBox. Background info: All my development is within an ATL Com based DLL. I have extended its functionality by including the WTL libraries in the stdafx.h header. The DLL is a set of tools and dlgs that are loaded into the calling application. I have read Michael Dunns intro to WTL articles and found them encouraging... hence trying to use them in my project. However I seem to be having trouble implementing the msg maps and ddx maps etc in the dialogs as they seem to crash the calling application. For the calling application and DLL to work, the dialogs must be of type
CAxDialogImpl
. I have one Dialog that I have managed to use WTL message maps in and it works ok. However other time it doesn't. I cannot get the DDX map to map the values from my ComboBox to my class members:class CTargetDialog : public CAxDialogImpl,//public CUpdateUI, //public CMessageFilter, public CIdleHandler, public CWinDataExchange, public CComObjectRootEx, public CComCoClass { public: CTargetDialog(IApplicationPtr pApp); ~CTargetDialog(); enum { IDD = IDD_TARGETDIALOG }; BEGIN_MSG_MAP(CTargetDialog) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) COMMAND_ID_HANDLER(IDOK, OnOK) COMMAND_ID_HANDLER(IDCANCEL, OnCancel) COMMAND_HANDLER(IDC_COMBO_TARGET, CBN_SELCHANGE, OnSelchangeCombo_target) COMMAND_HANDLER(IDC_COMBO_TARGET, CBN_DROPDOWN, OnDropdownCombo_target) END_MSG_MAP() BEGIN_DDX_MAP(CTargetDialog) DDX_CONTROL(IDC_COMBO_TARGET, m_pComboBox) DDX_TEXT(IDC_COMBO_TARGET, m_szTargetLayer) END_DDX_MAP() // Handler prototypes: // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled); LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnSelchangeCombo_target(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); LRESULT OnDropdownCombo_target(WORD wNotifyCode, WORD wID, HWND hWnd
It looks OK at first glance. What are the compiler errors? --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy
-
It looks OK at first glance. What are the compiler errors? --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy
Thanks for your help, The compiler errors are: For fetching the selected item in the combo box
CString pValueString; int i = this->m_pComboBox.GetDlgItemText(IDC_COMBO_TARGET, pValueString);
error C2664: 'int __thiscall ATL::CWindow::GetDlgItemTextW(int,unsigned short *& ) const' : cannot convert parameter 2 from 'class WTL::CString' to 'unsigned short *& ' A reference that is not to 'const' cannot be bound to a non-lvalue And for OnInit....DoDataExhange(true);
-
Thanks for your help, The compiler errors are: For fetching the selected item in the combo box
CString pValueString; int i = this->m_pComboBox.GetDlgItemText(IDC_COMBO_TARGET, pValueString);
error C2664: 'int __thiscall ATL::CWindow::GetDlgItemTextW(int,unsigned short *& ) const' : cannot convert parameter 2 from 'class WTL::CString' to 'unsigned short *& ' A reference that is not to 'const' cannot be bound to a non-lvalue And for OnInit....DoDataExhange(true);
The first error looks like the compiler is trying to generate a call to the
GetDlgItemText()
that takes aBSTR&
. You probably need to add#define _WTL_USE_CSTRING
before your WTL includes. The second one is you probably forgot to inherit fromCWinDataExchange<>
--Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Laugh it up, fuzzball. -
The first error looks like the compiler is trying to generate a call to the
GetDlgItemText()
that takes aBSTR&
. You probably need to add#define _WTL_USE_CSTRING
before your WTL includes. The second one is you probably forgot to inherit fromCWinDataExchange<>
--Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Laugh it up, fuzzball.Hi Mike, Thanks fro the reply. Here is my inheritance list for my dialog:
class CTargetDialog : public CAxDialogImpl, public CWinDataExchange, public CComObjectRootEx, public CComCoClass
And here is is my listing for stdafx.h#if !defined(AFX_STDAFX_H__63977A7A_D850_4BDE_A636_B409D3974963__INCLUDED_) #define AFX_STDAFX_H__63977A7A_D850_4BDE_A636_B409D3974963__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define STRICT #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0400 #endif #define _WTL_USE_CSTRING #define _ATL_APARTMENT_THREADED #include #include extern CAppModule _Module; #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(push) #pragma warning(disable : 4146) #pragma warning(disable : 4192) #import "C:\arcgis\arcexe83\bin\esriCore.olb" \ raw_interfaces_only, \ raw_native_types, \ no_namespace, \ named_guids, \ exclude("OLE_COLOR", "OLE_HANDLE") #pragma warning(pop) #include "C:\arcgis\arcexe83\ArcObjects Developer Kit\Kits\CATIDs\arccatids.h" #if _ATL_VER < 0x0700 #undef BEGIN_MSG_MAP #define BEGIN_MSG_MAP(x) BEGIN_MSG_MAP_EX(x) #endif class CStaticImpl : public CWindowImpl { DECLARE_EMPTY_MSG_MAP() }; class CComboBoxImpl : public CWindowImpl { DECLARE_EMPTY_MSG_MAP(); };
I have had to reorganize my header files list in the Tools>Options>Directories otherwise I get a redefinition of ISegment error. I have placed the path of the widowsSDK at the bottom of the list and the path to the WTL libraries at the top of the list. I doubt this is the source of my problems though. cheers Bryce -
Hi Mike, Thanks fro the reply. Here is my inheritance list for my dialog:
class CTargetDialog : public CAxDialogImpl, public CWinDataExchange, public CComObjectRootEx, public CComCoClass
And here is is my listing for stdafx.h#if !defined(AFX_STDAFX_H__63977A7A_D850_4BDE_A636_B409D3974963__INCLUDED_) #define AFX_STDAFX_H__63977A7A_D850_4BDE_A636_B409D3974963__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define STRICT #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0400 #endif #define _WTL_USE_CSTRING #define _ATL_APARTMENT_THREADED #include #include extern CAppModule _Module; #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(push) #pragma warning(disable : 4146) #pragma warning(disable : 4192) #import "C:\arcgis\arcexe83\bin\esriCore.olb" \ raw_interfaces_only, \ raw_native_types, \ no_namespace, \ named_guids, \ exclude("OLE_COLOR", "OLE_HANDLE") #pragma warning(pop) #include "C:\arcgis\arcexe83\ArcObjects Developer Kit\Kits\CATIDs\arccatids.h" #if _ATL_VER < 0x0700 #undef BEGIN_MSG_MAP #define BEGIN_MSG_MAP(x) BEGIN_MSG_MAP_EX(x) #endif class CStaticImpl : public CWindowImpl { DECLARE_EMPTY_MSG_MAP() }; class CComboBoxImpl : public CWindowImpl { DECLARE_EMPTY_MSG_MAP(); };
I have had to reorganize my header files list in the Tools>Options>Directories otherwise I get a redefinition of ISegment error. I have placed the path of the widowsSDK at the bottom of the list and the path to the WTL libraries at the top of the list. I doubt this is the source of my problems though. cheers BryceThe inheritance list for the dialogs is like the following... the <CTargetDialog>, were all removed class CTargetDialog : public CAxDialogImpl<CTargetDialog>, public CWinDataExchange<CTargetDialog>, public CComObjectRootEx<CComSingleThreadModel>, public CComCoClass<CTargetDialog>,
-
The first error looks like the compiler is trying to generate a call to the
GetDlgItemText()
that takes aBSTR&
. You probably need to add#define _WTL_USE_CSTRING
before your WTL includes. The second one is you probably forgot to inherit fromCWinDataExchange<>
--Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Laugh it up, fuzzball.Ahhhh found out something interesting. if you try to change the About dialog in a WTL wizard created application, which is dialog based.... the compiler bombs as well. so if you do the following: Add a combo box to the about dialog and label it IDC_COMBO_TARGET aboutdlg.h
// aboutdlg.h : interface of the CAboutDlg class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_ABOUTDLG_H__A290BA10_FE73_4A12_8FCA_FEBA7A47586B__INCLUDED_) #define AFX_ABOUTDLG_H__A290BA10_FE73_4A12_8FCA_FEBA7A47586B__INCLUDED_ class CAboutDlg : public CAxDialogImpl<CAboutDlg>, public CWinDataExchange<CAboutDlg>, public CComObjectRootEx< aboutdlg.cpp `// aboutdlg.cpp : implementation of the CAboutDlg class // ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "resource.h" #include "aboutdlg.h" LRESULT CAboutDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { CenterWindow(GetParent()); return TRUE; } LRESULT CAboutDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND`
-
Ahhhh found out something interesting. if you try to change the About dialog in a WTL wizard created application, which is dialog based.... the compiler bombs as well. so if you do the following: Add a combo box to the about dialog and label it IDC_COMBO_TARGET aboutdlg.h
// aboutdlg.h : interface of the CAboutDlg class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_ABOUTDLG_H__A290BA10_FE73_4A12_8FCA_FEBA7A47586B__INCLUDED_) #define AFX_ABOUTDLG_H__A290BA10_FE73_4A12_8FCA_FEBA7A47586B__INCLUDED_ class CAboutDlg : public CAxDialogImpl<CAboutDlg>, public CWinDataExchange<CAboutDlg>, public CComObjectRootEx< aboutdlg.cpp `// aboutdlg.cpp : implementation of the CAboutDlg class // ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "resource.h" #include "aboutdlg.h" LRESULT CAboutDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { CenterWindow(GetParent()); return TRUE; } LRESULT CAboutDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND`
You need to add the
BEGIN_DDX_MAP
/END_DDX_MAP
map to the class forDoDataExchange()
to work. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Laugh it up, fuzzball. -
You need to add the
BEGIN_DDX_MAP
/END_DDX_MAP
map to the class forDoDataExchange()
to work. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Laugh it up, fuzzball.I left it out deliberatly to test if I could use the GetDialogText(...) call. Which still fails.
LRESULT CAboutDlg::OnSelchangeCombo_target(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { DoDataExhange(true); //gives>error C2065: 'DoDataExhange' : undeclared identifier CString pValueString; //error C2664: 'int __thiscall ATL::CWindow::GetDlgItemTextA(int,unsigned short *& ) const' : cannot //convert parameter 2 from 'class WTL::CString *' to 'unsigned short *& ' //A reference that is not to 'const' cannot be bound to a non-lvalue int i = this->m_pComboBox.GetDlgItemText(IDC_COMBO_TARGET, &pValueString); //works, but how can you find out which was selected //this->m_pComboBox.GetLBText(wNotifyCode, pValueString); //AtlMessageBox(NULL, pValueString.AllocSysString(), _T("Selection"), MB_OK); return 0; }
BEGIN_DDX_MAP(CAboutDlg) //DDX_CONTROL(IDC_STATIC_PIC, m_pPic) DDX_CONTROL(IDC_COMBO_TARGET, m_pComboBox) DDX_TEXT(IDC_COMBO_TARGET, m_szTargetLayer) END_DDX_MAP() I was wondering if you had tested what I described in another post about changing the aboutdlg setting? cheers Bryce -
I left it out deliberatly to test if I could use the GetDialogText(...) call. Which still fails.
LRESULT CAboutDlg::OnSelchangeCombo_target(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { DoDataExhange(true); //gives>error C2065: 'DoDataExhange' : undeclared identifier CString pValueString; //error C2664: 'int __thiscall ATL::CWindow::GetDlgItemTextA(int,unsigned short *& ) const' : cannot //convert parameter 2 from 'class WTL::CString *' to 'unsigned short *& ' //A reference that is not to 'const' cannot be bound to a non-lvalue int i = this->m_pComboBox.GetDlgItemText(IDC_COMBO_TARGET, &pValueString); //works, but how can you find out which was selected //this->m_pComboBox.GetLBText(wNotifyCode, pValueString); //AtlMessageBox(NULL, pValueString.AllocSysString(), _T("Selection"), MB_OK); return 0; }
BEGIN_DDX_MAP(CAboutDlg) //DDX_CONTROL(IDC_STATIC_PIC, m_pPic) DDX_CONTROL(IDC_COMBO_TARGET, m_pComboBox) DDX_TEXT(IDC_COMBO_TARGET, m_szTargetLayer) END_DDX_MAP() I was wondering if you had tested what I described in another post about changing the aboutdlg setting? cheers BryceWell, you misspelled the function - DoDataExchange. ;) I checked again and
GetDlgItemText()
is aCWindow
function, so there is no overload that takes aCString
obviously. Look at the code forDDX_Text
in atlddx.h to see how to use it with aBSTR
. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber "Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain." -- Paul Watson, Linux Zombie -
Well, you misspelled the function - DoDataExchange. ;) I checked again and
GetDlgItemText()
is aCWindow
function, so there is no overload that takes aCString
obviously. Look at the code forDDX_Text
in atlddx.h to see how to use it with aBSTR
. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber "Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain." -- Paul Watson, Linux Zombie