我刚刚尝试在DDX_CBWordIndex
我的头文件中添加第二个:
#pragma once
#include "stdafx.h"
template<typename E>
void AFXAPI DDX_RadioEnum(CDataExchange* pDX, int nIDC, E& value)
{
if (pDX == nullptr)
return;
// (1) Prepare the control for data exchange
pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
// (2) Make sure this routine is associated with the first
// radio button in a radio button group
ASSERT(::GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP);
// And verify, that it is indeed a radio button
ASSERT(::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON);
// (3) Iterate over all radio buttons in this group
using value_t = std::underlying_type_t<E>;
value_t rdbtn_index{};
do {
if (::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON) {
// (4) Control is a radio button
if (pDX->m_bSaveAndValidate) {
// (5) Transfer data from UI to class member
if (::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0) {
value = static_cast<E>(rdbtn_index);
}
}
else {
// (6) Transfer data from class member to UI
::SendMessage(hWndCtrl, BM_SETCHECK,
(static_cast<E>(rdbtn_index) == value), 0L);
}
++rdbtn_index;
}
else {
// (7) Not a radio button -> Issue warning
TRACE(traceAppMsg, 0,
"Warning: skipping non-radio button in group.\n");
}
// (8) Move to next control in tab order
hWndCtrl = ::GetWindow(hWndCtrl, GW_HWNDNEXT);
}
// (9) Until there are no more, or we moved to the next group
while (hWndCtrl != nullptr && !(GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP));
}
template<typename E>
void AFXAPI DDX_CBIndexEnum(CDataExchange* pDX, int nIDC, E& value)
{
pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
if (pDX->m_bSaveAndValidate)
value = static_cast<E>(::SendMessage(hWndCtrl, CB_GETCURSEL, 0, 0L));
else
::SendMessage(hWndCtrl, CB_SETCURSEL, static_cast<WPARAM>(value), 0L);
}
void AFXAPI DDX_CBWordIndex(CDataExchange* pDX, int nIDC, WORD& index)
{
pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
if (pDX->m_bSaveAndValidate)
index = (WORD)::SendMessage(hWndCtrl, CB_GETCURSEL, 0, 0L);
else
::SendMessage(hWndCtrl, CB_SETCURSEL, (WPARAM)index, 0L);
}
我正在使用#pragma once
. 但这不会编译:
7>ImportFromCLMExplorerDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)"
(?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>OtherSettingsAutomaticBackupPage.obj 中定义:错误 LNK2005:“void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)”(?DDX_CBWordIndex@@YAXPEAVCDataExchange@ @HAEAG@Z) 已在 AssignHistoryDlg.obj 7>ChristianLifeMinistryPersonalCopiesDlg.obj 中定义:错误 LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已定义在 AssignHistoryDlg.obj 7>ChristianLifeMinistryEditorDlg.obj : 错误 LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>ChristianLifeMinistryStudentMaterialDlg 中定义.obj :错误 LNK2005:“void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)”(?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>ClearAssignmentsDlg.obj 中定义:错误 LNK2005:“void __cdecl DDX_CBWordIndex (class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>InsertDateDlg.obj 中定义:错误 LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int, unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>OptionsDlg.obj 中定义:错误 LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (? DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 中定义 7>OtherSettingsUpdatePage.obj:错误 LNK2005:“void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)”(?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>SpecialEventBethelSpeakerServiceTalkDlg.obj 中定义:错误 LNK2005: “void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)”(?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>SpecialEventVideoconferenceInfoDlg.obj 中定义:错误 LNK2005:“void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>SMCustomizeDlg.obj 中定义:错误 LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short & )"(?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>SpecialEventDlg.obj 中定义:错误 LNK2005:“void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)”(?DDX_CBWordIndex@@YAXPEAVCDataExchange@ @HAEAG@Z) 已在 AssignHistoryDlg.obj 7>SpecialEventManager.obj 中定义:错误 LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已定义在 AssignHistoryDlg.obj 7>UpdateCalendarDlg.obj : 错误 LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已经在 AssignHistoryDlg.obj 中定义错误 LNK2005:“void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)”(?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>SpecialEventManager.obj 中定义:错误 LNK2005:“void __cdecl DDX_CBWordIndex (class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>UpdateCalendarDlg.obj 中定义:错误 LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int, unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 中定义错误 LNK2005:“void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)”(?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>SpecialEventManager.obj 中定义:错误 LNK2005:“void __cdecl DDX_CBWordIndex (class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>UpdateCalendarDlg.obj 中定义:错误 LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int, unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 中定义obj:错误 LNK2005:“void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)”(?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>UpdateCalendarDlg.obj 中定义:错误 LNK2005:“void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 中定义obj:错误 LNK2005:“void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)”(?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 7>UpdateCalendarDlg.obj 中定义:错误 LNK2005:“void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex@@YAXPEAVCDataExchange@@HAEAG@Z) 已在 AssignHistoryDlg.obj 中定义
我不明白为什么它会抱怨,因为该函数只定义一次。