#include "skygi/skygi.h" /* Include GI Functions */ #define BUTTON_EXIT 1 /* Define value of Button Exit */ #define BUTTON_ENABLE 2 /* Define value for Enable Button */ #define BUTTON_DISABLE 3 /* Define value for Disable Button */ void * EventHandler(HANDLE hWnd, s_gi_msg *msg); /* Prototype our Event Handler */ HANDLE ExitButton; /* Create HANDLE for the ExitButton */ HANDLE EnableButton; /* Create HANDLE for the EnableButton */ HANDLE DisableButton; /* Create HANDLE for DisableButton */ int main() { sCreateApplication *app; /* Create Main Application Struct */ HANDLE MainWin; /* Create HANDLE for the Main Window */ s_gi_msg msg; /* Create Messaging Passing Interface */ if (GI_Initialize() != 0) { /* Initialize GI and check for failure */ fprintf(stderr, "Unable to Init GI"); return -1; } app = GI_ApplicationStructCreate(); /* Create Application Struct */ strcpy(app->ucApplicationName, "Buttons"); /* Set the Title */ app->uiX = 0; /* Set Starting X Coordinate */ app->uiY = 0; /* Set Starting Y Coordinate */ app->uiHeight = 60; /* Set Window Height */ app->uiWidth = 100; /* Set Window Width */ app->uiStyleApplication = 0; /* Set Application Style to Default */ app->uiStyleFrame = 0; /* Set Frame Style to Default */ app->uiStyleTitle = 0; /* Set Title Style to Default */ app->uiStyleMenu = 0; /* Set Menu Style to Default */ app->uiStyleBar = 0; /* Set Bar Style to Default */ app->uiStyleClient = 0; /* Set Client Style to Default */ app->uiBackGroundColor = 0; /* Set Background Color to Default */ app->fwndClient = EventHandler; /* Set Event Handler Name, * The value of fwndClient will * have to be the same as the name * of the Event Handler Function * we prototyped earlier */ MainWin = GI_ApplicationCreate(app); /* Creates Application using * Settings we specified earlier */ ExitButton = GI_WidgetButtonCreate( /* Create Button */ MainWin,/* HANDLE of Parent Window */ "Exit", /* Text to be displayed */ 5, /* X */ 5, /* Y */ 40, /* Width */ 20, /* Height, must always be * 20, style won't allow >20 */ 0, /* Default Style */ BUTTON_EXIT /* ID; this ID will be passed * to the message handler * when the button is pressed */ ); GI_WidgetButtonSetTooltip( /* Create a Tooltip */ ExitButton, /* For ExitButton */ "Click to Exit", /* Text to be displayed */ 20 /* Popup time in Milliseconds */ ); DisableButton = GI_WidgetButtonCreate( /* Create Button */ MainWin, /* HANDLE of Parent Window */ "Disable",/* Text to be displayed */ 50, /* X */ 5, /* Y */ 50, /* Width */ 20, /* Height */ 0, /* Default Style */ BUTTON_DISABLE /* ID */ ); EnableButton = GI_WidgetButtonCreate( /* Create Button */ MainWin, /* HANDLE of Parent Window */ "Enable", /* Text to be displayed */ 50, /* X */ 30, /* Y */ 50, /* Width */ 20, /* Height */ 0, /* Default Style */ BUTTON_ENABLE /* ID */ ); if (GI_ApplicationWindowShow(MainWin) != S_OK) { /* Show Application Window and check return value */ fprintf(stderr, "Unable to Show Application Window"); return -1; } int run; while (1) { /* Endless loop, to make the Window stay open */ run = GI_MessageWait(&msg, NULL); /* Get return value to check for messages */ /* GI_MessageWait() returns 0 on MSG_QUIT */ if (!run) /* If GI_MessageWait returned 0 */ if (msg.win == MainWin) /* Check if MSG_QUIT was sent to MainWin */ break; /* If so, break out of the while loop */ GI_MessageDispatch(msg.win, &msg); } GI_WindowDestroy(MainWin); /* Close Window */ return 0; /* End Program */ } void * EventHandler(HANDLE hWnd, s_gi_msg *msg) { switch (msg->type) { /* Check for messages */ case MSG_DESTROY: /* If message is MSG_DESTROY: */ GI_MessageQuitPost(hWnd); /* Send MSG_QUIT to MainWin */ break; case MSG_COMMAND: /* If message is a command: */ switch (msg->para1) { /* Check type of message */ case BUTTON_EXIT: /* If message is BUTTON_EXIT: */ GI_MessageQuitPost(hWnd); /* Send MSG_QUIT to * MainWin */ break; case BUTTON_ENABLE: GI_WidgetButtonEnable(DisableButton); /* Enable * button */ break; case BUTTON_DISABLE: GI_WidgetButtonDisable(DisableButton); /* Disable * button */ break; } break; } }