开发者

Dynamically generate labels- MFC

开发者 https://www.devze.com 2023-03-18 01:01 出处:网络
In my MFC project, I want to generate the labels dynamically. E开发者_如何学JAVAg: I have to generate 4 edit controls and corresponding labels for them- say \"Label1\" \"Label2\"....

In my MFC project, I want to generate the labels dynamically. E开发者_如何学JAVAg: I have to generate 4 edit controls and corresponding labels for them- say "Label1" "Label2"....

CStatic *label[MAX_THREAD];
for (int i=0; i< dynamic_number ; i++)
{
   label[i] = new CStatic;
   label[i]->Create(L"Name_of_label", WS_CHILD | WS_VISIBLE,
   CRect(10, (10+i*30), 70, (30+i*30)), this);
}

I want "Label1" "Label2"... etc in place of "Name_of_label" I am not very sure how to go about it.

Thanks in advance,


How about something like this:

CString str;
CStatic *label[MAX_THREAD];

for (int i = 0; i < dynamic_number ; i++)
{
    str.Format("Label%d", i);

    label[i] = new CStatic;
    label[i]->Create(str, 
                     WS_CHILD | WS_VISIBLE,
                     CRect(10, (10+i*30), 70, (30+i*30)), 
                     this);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号