May 18, 2024, 02:44:44 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Static label controls

Started by Mike Stefanik, February 19, 2006, 02:14:16 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mike Stefanik

February 19, 2006, 02:14:16 AM Last Edit: February 19, 2006, 02:24:05 AM by Mike Stefanik
I notice that when you use SetText with a static label control, it's not erasing the previous text. This code demonstrates it:


#define BUTTON_1 1
#define STATIC_2 2
#define BUTTON_3 3

class dlg:CDialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;

CStatic* m_label;
}

global sub main()
{
dlg d1;
d1.Create(0,0,300,200,0x80C80080,0,"Caption",0);
d1.AddControl(CTBUTTON,"Button1",115,86,70,28,0x5000000B,0x0,BUTTON_1);
d1.AddControl(CTSTATIC,"",25,27,251,18,0x5000010B,0x0,STATIC_2);
d1.AddControl(CTBUTTON,"Button2",115,126,70,28,0x5000000B,0x0,BUTTON_3);

d1.DoModal();
return 0;
}

dlg::OnClose(),int
{
CloseDialog(1);
return true;
}

dlg::OnInitDialog(),int
{
m_label = GetControl(STATIC_2);
CenterWindow();
return true;
}

dlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case BUTTON_1:
if(nNotifyCode = 0)
{
m_label->SetText("abcdefg");
}

case BUTTON_3:
if(nNotifyCode = 0)
{
m_label->SetText("wxyz");
}
}
return true;
}


Click on the first button, then the second and you'll see what I mean.

Edit: One other thing I noticed is that the CWindow base class doesn't have a Refresh (or Redraw, if you prefer) method. I'd like to suggest that method be added, along with an Enable method.
Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Ionic Wind Support Team

Change the style from 0x5000010B to 0x50000000 and the static control will update.

It is a Microsoft design that static controls with SS_SIMPLE set will not automatically repaint on updated text.  Since a static control is meant to be...erm...static.  Meaning unchanging.  But removing the style bits causes a normal invalidation sequence associated with the base window class.

Paul.
Ionic Wind Support Team

Mike Stefanik

February 19, 2006, 10:00:54 AM #2 Last Edit: February 19, 2006, 10:58:53 AM by Mike Stefanik
Ah, that explains it. I sometimes use static controls for displaying status information and had never come across that behavior before. I'd recommend not setting that style by default or making it an option when the static control is created using the dialog editor. It's a little counter-intuitive. To my knowledge, other editors like the one in Visual Studio don't have that kind of behavior (ie: setting the SS_SIMPLE style by default) and the benefit of having Windows use TextOut instead of DrawText for speed has got to be negligible with today's hardware.
Mike Stefanik
www.catalyst.com
Catalyst Development Corporation