#include "skygi/skygi.h" /* Include GI Functions */ #define ID_UP 1 /* Set ID for Up Button */ #define ID_DOWN 2 /* Set ID for Down Button */ #define ID_EXIT 3 /* Set ID for Exit Button */ unsigned int ProgressBar_Value = 10;/* Set Value for Progress Bar */ void * EventHandler(HANDLE hWnd, s_gi_msg *msg); /* Prototype our Event Handler */ HANDLE UpButton; /* Create our HANDLE for the ++ Button */ HANDLE DownButton; /* Create our HANDLE for the -- Button */ HANDLE ExitButton; /* Create our HANDLE for the Exit Button */ HANDLE ProgressBar; /* Create our HANDLE for the Progress Bar */ int main() { sCreateApplication *app; /* Create our Main Application Struct */ HANDLE MainWin; /* Create our HANDLE for the Main Window */ s_gi_msg msg; /* Create our 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, "Progress Bar Example"); /* 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 = 210; /* 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 */ UpButton = GI_WidgetButtonCreate( /* Create Button */ MainWin, /* HANDLE of Parent Window */ "Up", /* Text to be displayed */ 5, /* X */ 30, /* Y */ 40, /* Width */ 20, /* Height, must always be * 20, style won't allow >20 * for buttons */ 0, /* Default Style */ ID_UP /* ID; this ID will be passed * to the message handler * when the button is pressed */ ); GI_WidgetButtonSetTooltip( /* Create a Tooltip */ UpButton, /* For UpButton */ "++", /* Text to be displayed */ 500 /* Popup time in Milliseconds */ ); DownButton = GI_WidgetButtonCreate( /* Create Button */ MainWin, /* HANDLE of Parent Window */ "Down", /* Text to be displayed */ 50, /* X */ 30, /* Y */ 40, /* Width */ 20, /* Height, must always be * 20, style won't allow >20 * for buttons */ 0, /* Default Style */ ID_DOWN /* ID */ ); GI_WidgetButtonSetTooltip( /* Create a Tooltip */ DownButton, /* For DownButton */ "--", /* Text to be displayed */ 500 /* Popup time in Milliseconds */ ); ExitButton = GI_WidgetButtonCreate( /* Create Button */ MainWin, /* HANDLE of Parent Window */ "Exit", /* Text to be displayed */ 165, /* X */ 30, /* Y */ 40, /* Width */ 20, /* Height */ 0, /* Default Style */ ID_EXIT /* ID */ ); GI_WidgetButtonSetTooltip( /* Create a Tooltip */ ExitButton, /* For ExitButton */ "Exit", /* Text to be displayed */ 500 /* Popup time in Milliseconds */ ); ProgressBar = GI_WidgetProgressCreate( MainWin, /* Parent HANDLE */ "Progress Bar", /* Name */ 5, /* X */ 5, /* Y */ GI_WindowGetWidth(MainWin) - 10, /* Width */ 20, /* Height */ 0 /* Default Style */ ); GI_WidgetProgressSetMax( /* Set Max Value of Progress Bar */ ProgressBar, /* Parent HANDLE */ 20 /* Max Value */ ); GI_WidgetProgressSet( /* Set Value of Progress Bar */ ProgressBar, /* Parent HANDLE */ ProgressBar_Value /* Color Value */ ); 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_WINDOW_SIZED: /* If message is MSG_WINDOW_SIZED */ GI_WindowDimensionSetNotify( /* Resize Progress Bar to Fit Window */ ProgressBar, /* HANDLE to Resize */ FALSE, 5, /* New X */ 5, /* New Y */ GI_WindowGetWidth(hWnd) - 10, /* New Width */ 20 /* New Height */ ); break; case MSG_COMMAND: /* If message is a command: */ switch (msg->para1) { /* Check type of message */ case ID_UP: /* When UpButton is clicked */ if (ProgressBar_Value < 20) { /* Check to make sure ProgressBar doesn't overflow */ GI_WidgetProgressSet( /* Set new Value */ ProgressBar, /* HANDLE */ ++ProgressBar_Value /* Increment Value by 1 */ ); printf("%d\n", ProgressBar_Value); /* Print Value */ GI_WidgetButtonEnable(DownButton); /* Enable DownButton */ } else { GI_WidgetButtonDisable(UpButton); /* Disable UpButton */ } break; case ID_DOWN: /* When DownButton is clicked */ if (ProgressBar_Value > 0) { /* Check to make sure ProgressBar doesn't overflow */ GI_WidgetProgressSet( /* Set new Value */ ProgressBar, /* HANDLE */ --ProgressBar_Value /* Decrement Value by 1 */ ); printf("%d\n", ProgressBar_Value); /* Print Value */ GI_WidgetButtonEnable(UpButton); /* Enable UpButton */ } else { GI_WidgetButtonDisable(DownButton); /* Disable DownButton */ } break; case ID_EXIT: /* When ExitButton is clicked */ GI_MessageQuitPost(hWnd); /* Send MSG_QUIT to * MainWin */ break; } break; } }