Carbon DrawOneControl overload?

1 view
Skip to first unread message

Lourens

unread,
Aug 10, 2003, 9:20:13 AM8/10/03
to
Hello,

I've a problem using method DrawOneControl. I'm building an application
using Carbon which consists of the default created main program and a new
thread I created. Using IB I created a simpel window with an StaticText
field, a ProgressBar and a Slider. The thread I created has a connection to
a TCP server and receives information from the server when the server wants
too. The thread then calls a method I created in the main program:

void StatusSetDescription(char *Status) {
SetControlData(TextStatus, kControlEntireControl,
kControlEditTextTextTag, strlen(Status), Status);
DrawOneControl(TextStatus);
}

When I leave out the DrawOneControl call, the static text fields gets
updated ones. When I leave it in it gets (I guess) updated everytime. But it
is flickering a lot and also a few order controls on the window don't get
drawn or get drawn on the wrong places. Once in a while (but not always) the
application even crashes on a SIGBUS signal. Am I missing something? Is it
correct to use DrawOneControl from another thread? The problem is that I
don't know when or how often the server gives me a status, so I need to
update it everytime. My alternative, I guess, is to use a timer that checks
if the control needs to be redrawn and takes care of this, so that
DrawOneControl doesn't get overloaded. I also read things about InvalRect, I
also tried it but nothing gets redrawn.

I hope anyone has a sollution or a reference to some clear sample code or
documentation.

T.i.a., Lourens


Eric Albert

unread,
Aug 10, 2003, 1:41:30 PM8/10/03
to
In article <3f364622$0$49114$e4fe...@news.xs4all.nl>,
"Lourens" <Lourens-@-CyberFlat-DOT-nl> wrote:

> I've a problem using method DrawOneControl. I'm building an application
> using Carbon which consists of the default created main program and a new
> thread I created. Using IB I created a simpel window with an StaticText
> field, a ProgressBar and a Slider. The thread I created has a connection to
> a TCP server and receives information from the server when the server wants
> too. The thread then calls a method I created in the main program:
>
> void StatusSetDescription(char *Status) {
> SetControlData(TextStatus, kControlEntireControl,
> kControlEditTextTextTag, strlen(Status), Status);
> DrawOneControl(TextStatus);
> }
>
> When I leave out the DrawOneControl call, the static text fields gets
> updated ones. When I leave it in it gets (I guess) updated everytime. But it
> is flickering a lot and also a few order controls on the window don't get
> drawn or get drawn on the wrong places. Once in a while (but not always) the
> application even crashes on a SIGBUS signal. Am I missing something? Is it
> correct to use DrawOneControl from another thread?

Carbon does not support changing the UI from a secondary thread. The
correct way to do this is to post an event to your main thread (you can
safely post events from any thread) which causes your program to update
the control.

Hope this helps,
Eric

--
Eric Albert ejal...@stanford.edu
http://rescomp.stanford.edu/~ejalbert/

Reply all
Reply to author
Forward
0 new messages