# Using GetUserEvent to Respond to User Interface Events

GetUserEvent returns only commit events and events you post through QueueUserEvent. Commit events are generated when the user of the GUI actually commits to an operation such as making a menu selection or typing in a number and pressing <Enter>. The figure below illustrates the event-loop concept of GetUserEvent.

Event Loop Concept

A typical program could use a GetUserEvent loop with the following pseudocode algorithm:

panel_handle = LoadPanel(...);
DisplayPanel(panel_handle,...);
menu_handle = LoadMenuBar(...);
while (GetUserEvent(WAIT, &handle, &control)) {

if (handle ==, PANEL) {

switch (control) {

case PANEL_CONTROL1:

. /* Code that responds to CONTROL1 on */

. /* the panel. */

break;

case PANEL_CONTROL2:

. /* Code that responds to CONTROL2 on */

. /* the panel. */

break;

}

}

if (handle == MENUBAR) {

switch (control) {

case MENUBAR_MENU1_ITEM1:

. /* Code that responds to ITEM1 in */

. /* MENU1 of the menu bar. */

break;

case MENUBAR_MENU1_ITEM2:

. /* Code that responds to ITEM2 in */

. /* MENU1 of the menu bar. */

break;

}

}

If you use GetUserEvent, you can also install callbacks to receive events other than commit events.