开发者

Pattern to update UI state without triggering an event

Most GUI apps have multiple autoprocessing options, say editbox triggers autocomplete, listbox changes icons and product description, radiobutton triggers text updates and so on.

Unfortunately, quite often it's needed to change the state of some of those controls programmaticall开发者_StackOverflow中文版y, at the same time blocking the autotriggers of the linked controls, listbox onselecteditemchange, radiobox onselecteditemchange etc.

Is there a pattern on how you accomplish this? I guess it's possible to add a "m_bDisablEventTrigger" variable on each of the controls, and set it before and after the UI update, but maybe there is a nicer way that can achieve the same thing with less extra ugly code.


You could just disable the desired control (lets say IDC_YOURCONTROL) by using the following:

GetDlgItem(IDC_YOURCONTROL)->EnableWindow(false);

Using this the related triggers for yor control will not be triggered. After your done you can enable your control.


IMHO it's impossible to answer such a question without digging into the particular implementation details. Obviously such patterns exist. The existence of the "master" or "per-control" flags that block some "automatic" behavior is determined solely by the framework used for those "automatic" adjustments.


I do this in my Delphi app. What happens is that whenever a change is made that could affect the control state, a message is posted to that effect. That message will get processed when the app becomes idle, i.e. after any pre-existing messages complete their processing.

The processing of this message then sets the UI state for all controls and the jobs is done. It's all very easy in Delphi of course because the VCL wraps up the underlying Win32 API very conveniently.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜