C++为什么 setWindowText 不显示任何文本?
C++ why setWindowText doesn't display any text?
我有如下代码,我的问题是为什么在单元格 A[0][0] setWindowText 中什么都不放?
if(LOWORD( wParam ) == 104){
int td;
int td_width=80;
int tr = 0;
int tr_height=20;
for (tr=0;tr<2;tr++) {
for (td=0;td<10;td++) {
HWND A[tr][td];
A[tr][td] = CreateWindowEx( 0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL,
td*td_width, tr*tr_height+50, td_width+1, tr_height+1, hwnd, NULL, hInstance, NULL );
}
SetWindowText(A[0][0], "MK" );
}
}
你在最内层的循环中定义 A[tr][td]。 这会将其范围限制为该循环。 换句话说,在每次迭代中,您都会创建一个全新的数组并仅分配其中一个元素。
这甚至编译有点令人惊讶。 我猜你在其他地方定义了另一个 A 数组,这就是你在 SetWindowText 调用中引用的那个数组。
正如彼得所说,你在错误的位置声明了你的数组。 但更重要的是,您还将数组声明为固定长度,但使用运行时值来指定其边界。这是行不通的,甚至不应该编译。 固定长度数组的边界必须在编译时知道,而不是在运行时知道。
试试这个:
if (LOWORD(wParam) == 104)
{
const int td_width = 80;
const int tr_height = 20;
HWND A[2][10];
for (int tr = 0; tr < 2; ++tr)
{
for (int td = 0; td < 10; ++td)
{
A[tr][td] = CreateWindowEx( 0, TEXT("EDIT"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL, td*td_width, tr*tr_height+50, td_width+1, tr_height+1, hwnd, NULL, hInstance, NULL );
}
}
SetWindowText(A[0][0], TEXT("MK") );
}
相关文章:
- 在处理任何字符大小的模板中使用字符串文本
- 我想使用 "cout" 命令慢慢打印文本,但我真的找不到任何解决方案
- 将文本文件读取到2D数组中,但数组开始为超过数组[39][]的任何内容输出胡言乱语
- 整数文本太大,无法用任何整数类型表示--C++
- 是否有任何方法可以在用户输入文本时读取字符
- 打开任何文本文件
- 为什么此代码只能识别文本文件中的第一行?输入任何大于 1 的数字都会返回"Atomic Number Not Found"
- C 初学者:如何防止表中的文本将任何文本推向其右侧
- 读取 C++ 中的文本文件不显示任何输出
- C++为什么 setWindowText 不显示任何文本?
- 有没有任何方法可以从C++中的文本中提取URL
- 是否有任何中间件/库可以将二进制或文本数据从64位转换为32位
- 使用c++在opencv中检测图像中任何文本的位置
- 使用C++或任何windows脚本语言格式化文本数据
- 制作参数化用户定义文本的任何方法
- 我的C++从文本文件读取的程序无法正常工作,但我没有看到任何代码错误?
- C++ 中任何基数中的整数文本
- C++中的Regex,从正则表达式中获取文本任何部分的字符串
- 读取文本文件的任何头文件与平台无关
- 如何将文件的路径(或任何文本)显示/附加到编辑框中?(C++ Win32 API)