在MFC中,生成一个对话框de程序。定义 CButton *mybutton;和 struct str_dir *p_str_dir; 两个指针为全局。在程序 ::OnInitDialog()中动态生成N个CButton *mybutton= new CButton[N];个按钮。并通过struct str_dir *p_str_dir结构对 mybutton[xyz].SetWindowText(p_str_dir[xyz].m_dir_name);赋值。以上都还能正常运行。但是,当通过自定义de消息响应函数来改变动态生成de按钮上de文本“mybutton[m_xs].SetWindowText(p_str_dir[m_xs+1].m_dir_name);”时,出错!编译提示为“error C2039: 'SetWindowTextA' : is not a member of 'HWND__'
d:\visual studio\vc98\include\windef.h(195) : see declaration of 'HWND__'”请问大家,这是怎么回事??是不是指针是全局de,可是指向de数据在::OnInitDialog()后就没有了?谢谢!
d:\visual studio\vc98\include\windef.h(195) : see declaration of 'HWND__'”请问大家,这是怎么回事??是不是指针是全局de,可是指向de数据在::OnInitDialog()后就没有了?谢谢!
解决方案 »
- vc wps文本 光标移动问题
- 关于用mfc读写bmp文件及相关问题
- vc中如何删除xml指定节点
- 如何访问物理内存?如何确定我的应用程序用了多少物理和虚拟地址?物理和虚拟内存之间的关系如何?
- VC程序打包问题
- 怎么知道从richedit中GetSelText出来的字符是不是汉字?
- 如何用HttpSendRequest函数post一个大文件到cgi
- 关于记事本设置字体的问题
- 请教CClientDC dc(this)中this有什么作用?
- msxml的insertBefore函数的第二个参数到底i应该怎么传递?
- 问一个简单的问题:无法链接的外部符号
- [求教]关于一个程序调用另一个窗口程序的问题-100分
========================为啥是m_xs+1 ??
mybutton[xyz].SetWindowText(p_str_dir[xyz].m_dir_name);
======================知道只是变量,我是说你为啥用m_xs+1,而不是m_xs 。
=================
你能保证吗?我试了可是不行的。
下面的代码一定能满足你的要求。调试通过void CMySeDlg::OnButton1()
{
CButton *mybutton;
struct str_dir *p_str_dir; //两个指针为全局。
int N = 10;
mybutton= new CButton[N];
p_str_dir = new str_dir[N];
RECT rect;
rect.left = 10;
rect.top = 10;
rect.right = 50;
rect.bottom = 50; for(int xyz=0; xyz<N; xyz++)
{
char str[10];
itoa(xyz, str, 10);
p_str_dir[xyz].m_dir_name = "DirName";
strcat(p_str_dir[xyz].m_dir_name.GetBuffer(0), str);
mybutton[xyz].Create(NULL, WS_VISIBLE, rect, this, 1000+xyz);
mybutton[xyz].SetWindowText(p_str_dir[xyz].m_dir_name);
}
}
2)【重复定义 CButton *】嗯~ 有可能的确是重复定义。要试一试。3)在 ::OnButton1() 里当然都是可以di,但是假如你在 ::OnButton2() 里在次通过CButton *mybutton; struct str_dir *p_str_dir; //两个指针为全局
来读取数据,能行吗?? 会不会有作用域de问题?? 有时间我还要来试试。
一开始: CButton *mybutton = NULL;
在OnButton_N中判断
if(mybutton == NULL)
{
Crecte
SetWindowText
}
else
{
SetWindowText
}
c:\program files\microsoft visual studio\vc98\include\windef.h(195) : see declaration of 'HWND__'”“: error C2039: 'ShowWindow' : is not a member of 'HWND__'
c:\program files\microsoft visual studio\vc98\include\windef.h(195) : see declaration of 'HWND__'”“: error C2039: 'SetWindowTextA' : is not a member of 'HWND__'
c:\program files\microsoft visual studio\vc98\include\windef.h(195) : see declaration of 'HWND__'”
PS: 我在::OnInitDialog()里就创建并初始化完成“mybutton[xyz].SetWindowText(p_str_dir[xyz].m_dir_name);”然后我在我自定义de消息响应函数里写上“mybutton[xyz].SetWindowText(p_str_dir[xyz-1].m_dir_name);”也会编译出错,提示跟上面de差不多。
CButton* ptr = new CButton;
ptr->Create(...);
if(ptr->m_hWnd)
ptr->SetWindowText(...);