c:\program files\microsoft visual studio\vc98\atl\include\atlwin.h(65) : error C2065: '_Module' : undeclared identifier c:\program files\microsoft visual studio\vc98\atl\include\atlwin.h(2912) : error C2228: left of '.GetModuleInstance' must have class/struct/union type c:\program files\microsoft visual studio\vc98\atl\include\atlwin.h(2974) : error C2228: left of '.GetModuleInstance' must have class/struct/union type D:\test\option2\op.cpp(8) : error C2653: 'WTL' : is not a class or namespace name D:\test\option2\op.cpp(8) : error C2065: 'CButton' : undeclared identifier D:\test\option2\op.cpp(9) : fatal error C1903: unable to recover from previous error(s); stopping compilation
就是想了解 对应的 vc实现方法下面付上vb工程代码
创建过程
1、新建exe工程 不添加任何控件
2、动态创建控件 并设定单选控件的 容器 为 frame控件源代码Sub CreateControl()
' 创建新frame 控件
Set Frame1 = Controls.Add("VB.Frame", "Frame1")
' 将控件移动到你所需要的地方
Frame1.Move 50, 50, 3200, 3300
' 创建时,所有的控件都是不可见的
Frame1.Visible = True
'单选按钮1
Set Option1 = Controls.Add("VB.OptionButton", "Option1")
Option1.Move 222, 222, 1200, 300
Option1.Visible = True
Option1.Caption = "Option1"
'单选按钮2
Set Option2 = Controls.Add("VB.OptionButton", "Option2")
Option2.Move 222, 555, 1200, 300
Option2.Visible = True
Option2.Caption = "Option2"
'单选按钮3
Set Option3 = Controls.Add("VB.OptionButton", "Option3")
Option3.Move 222, 888, 1200, 300
Option3.Visible = True
Option3.Caption = "Option3"
'设定按钮 属于的容器
Set Option1.Container = Frame1
Set Option2.Container = Frame1
Set Option3.Container = Frame1
End Sub
Private Sub Form_Load()
CreateControl
End Sub
typedef CWinTraitsOR<BS_GROUPBOX, 0> _GroupTraits;
typedef CWinTraitsOR<BS_AUTORADIOBUTTON ,0> _OptionTraits;class CGroup : public CWindowImpl<CGroup, WTL::CButton ,_GroupTraits>
{
public:
DECLARE_EMPTY_MSG_MAP()
};class COption : public CWindowImpl<COption, WTL::CButton,_OptionTraits>
{
public:
DECLARE_EMPTY_MSG_MAP()
};class CMainDlg : public CDialogImpl<CMainDlg>
{
CGroup m_group1,m_group2;
COption m_opt1[5];
COption m_opt2[5];
public:
enum { IDD = IDD_MAINDLG }; BEGIN_MSG_MAP(CMainDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
END_MSG_MAP()
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
RECT rtGroup = { 20,10,120, 120};
m_group1.Create(m_hWnd,rtGroup); CString strCap;
RECT rt = { 5, 10, 90, 30};
for ( int i = 0; i < 5; i++)
{
m_opt1[i].Create(m_group1,rt);
strCap.Format("Option%d",i+i);
m_opt1[i].SetWindowText(strCap);
::OffsetRect(&rt,0,25);
} ::OffsetRect(&rtGroup,120,0);
m_group2.Create(m_hWnd,rtGroup); ::SetRect(&rt,5,10,90,30);
for ( int i = 0; i < 5; i++)
{
m_opt2[i].Create(m_group2,rt);
strCap.Format("Option%d",i+i);
m_opt2[i].SetWindowText(strCap);
::OffsetRect(&rt,0,25);
}
return TRUE;
} LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
EndDialog(wID);
return 0;
}
};
#include "atlbase.h"
#include "atlwin.h"
c:\program files\microsoft visual studio\vc98\atl\include\atlwin.h(2912) : error C2228: left of '.GetModuleInstance' must have class/struct/union type
c:\program files\microsoft visual studio\vc98\atl\include\atlwin.h(2974) : error C2228: left of '.GetModuleInstance' must have class/struct/union type
D:\test\option2\op.cpp(8) : error C2653: 'WTL' : is not a class or namespace name
D:\test\option2\op.cpp(8) : error C2065: 'CButton' : undeclared identifier
D:\test\option2\op.cpp(9) : fatal error C1903: unable to recover from previous error(s); stopping compilation
#include "atlbase.h"
#include "atlwin.h"
#include "atlapp.h"
#include "atlctrls.h"前三个错误 还是在
#include <atlctrls.h>
#include <atldlgs.h>
typedef CWinTraitsOR<BS_AUTORADIOBUTTON ,0> _OptionTraits;class CGroup : public CWindowImpl<CGroup, CWindow ,_GroupTraits>
{
public:
DECLARE_EMPTY_MSG_MAP()
HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
DWORD dwStyle = 0, DWORD dwExStyle = 0,
ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
{
return CWindow::Create(_T("BUTTON"), hWndParent, rect.m_lpRect, szWindowName, _GroupTraits::GetWndStyle(0), _GroupTraits::GetWndExStyle(0), MenuOrID.m_hMenu, lpCreateParam);
}};class COption : public CWindowImpl<COption, CWindow,_OptionTraits>
{
public:
DECLARE_EMPTY_MSG_MAP() HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
DWORD dwStyle = 0, DWORD dwExStyle = 0,
ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
{
return CWindow::Create(_T("BUTTON"), hWndParent, rect.m_lpRect, szWindowName, _OptionTraits::GetWndStyle(0), _OptionTraits::GetWndExStyle(0), MenuOrID.m_hMenu, lpCreateParam);
}
};
他在 vb中 能正常象以上方法分组但vc中 对group风格不起作用也不象 ms fm2.0 一样有setGroupName的方法
(但他有其他功能 所以我仍然想引用他)我把工程代码 贴这里 你有空帮忙看看(打开前请先注册按钮控件)http://xianexs.mail.qq.com/cgi-bin/downloadfilepart/svrid253/option3.rar?svrid=253&fid=bb06d74dc1d46a2c72456ca8768be21093e481ece70aaf07&&txf_fid=&&txf_sid=(提取码 27902994)
BOOL COption3Dlg::OnInitDialog() 函数中非常感激
class COption3Dlg : public CDialog
{
CButton group,opt1,opt2;
//......
};BOOL COption3Dlg::OnInitDialog()
{
//...
// TODO: Add extra initialization here
CRect rect4(90,1,350,160);
CRect rect2(50,10,120,60);
CRect rect3(150,10,220,60); group.Create(NULL,BS_GROUPBOX | WS_CHILD | WS_VISIBLE,rect4,this,12345);
opt1.Create(NULL,WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTORADIOBUTTON ,rect2,&group,12346);
opt2.Create(NULL,WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTORADIOBUTTON ,rect3,&group,12347); return TRUE;
}
你的好像是和我那个代码一样 只是表达方式相反
我是用指针 指向控件对象不过结果一样的 还是没有实现分组
option按钮 可以两个同时 而且选择后,
我按住一个后 另外一个 仍然不会改变状态。
联系过此控件的开发者 说控件会自动告诉容器所处状态,进行互斥运算
可他不用vc 也没给解决方法。遗憾现在就是想知道 option 和 frame 如何通过代码发生关系
高手再继续帮忙呀 3q
这个控件 WS_GROUP风格不起作用
真郁闷。