/***************************************************************************** * * Copyright (c) 1999, KL GROUP INC. All Rights Reserved. * http://www.klgroup.com * * This file is provided for demonstration and educational uses only. * Permission to use, copy, modify and distribute this file for * any purpose and without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies, and that the name of KL Group not be used in advertising * or publicity pertaining to this material without the specific, * prior written permission of an authorized representative of * KL Group. * * KL GROUP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. KL GROUP SHALL NOT BE LIABLE FOR ANY * DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ /* panel.c */ #define STRICT #include #include #include "panel.h" #include "resource.h" /* Text Strings for the chart */ char *header_strings[] = { "Michelle's Microchips", NULL }; char *footer_strings[] = { "1963 Quarterly Results", NULL }; /* Label Strings */ char *set_labels[] = { "Expenses", "Revenue", NULL }; char *point_labels[] = { "Q1", "Q2", "Q3", "Q4", NULL }; static HXRT2D hChart; long WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { static HWND hwndChart; static XrtDataHandle my_data; static XrtDataHandle new_data; UINT wCheck; switch (msg) { case XRTN_PALETTECHANGED: SendMessage(XrtGetWindow(hChart), WM_QUERYNEWPALETTE, 0, 0); break; case WM_QUERYNEWPALETTE: case WM_PALETTECHANGED: SendMessage(XrtGetWindow(hChart), msg, wParam, lParam); break; case WM_INITDIALOG: hwndChart = GetDlgItem(hWnd, IDCHART); hChart = XrtCreate(); XrtAttachWindow(hChart, hwndChart); my_data = XrtDataCreateFromFile((LPSTR) "mm63.dat", NULL); XrtSetValues(hChart, XRT_BORDER, XRT_BORDER_PLAIN, XRT_BORDER_WIDTH, 1, XRT_DATA, my_data, XRT_HEADER_STRINGS, header_strings, XRT_FOOTER_STRINGS, footer_strings, XRT_SET_LABELS, set_labels, XRT_POINT_LABELS, point_labels, XRT_XANNOTATION_METHOD, XRT_ANNO_POINT_LABELS, NULL); CheckRadioButton(hWnd, IDBAR, IDPLOT, IDPLOT); SetFocus(hWnd); break; case WM_COMMAND: /* check which button was clicked and set chart properties appropriately */ /* handle commands */ switch(LOWORD(wParam)) { case IDM_EXIT: DestroyWindow(hWnd); break; case IDM_ABOUTDEMO: case IDMHELP: WinHelp(hWnd, "OLCH-DMO.HLP", HELP_CONTEXT, 38); break; case IDM_ABOUTOLECTRACHART: WinHelp(hWnd, "OLCH-DMO.HLP", HELP_CONTEXT, 19); break; case IDBAR: /* change the chart to a bar chart */ CheckRadioButton(hWnd, IDBAR, IDPLOT, wParam); XrtSetValues(hChart, XRT_TYPE, XRT_TYPE_BAR, NULL); break; case IDPLOT: /* change the chart to a plot chart */ CheckRadioButton(hWnd, IDBAR, IDPLOT, wParam); XrtSetValues(hChart, XRT_TYPE, XRT_TYPE_PLOT, NULL); break; case IDTRAN: /* transpose the points and sets of the chart */ wCheck = IsDlgButtonChecked(hWnd, IDTRAN); CheckDlgButton(hWnd, IDTRAN, !wCheck); new_data = XrtDataTranspose(my_data); if (new_data != NULL) { XrtDataDestroy(my_data); my_data = new_data; if (wCheck) { XrtSetValues(hChart, XRT_DATA, my_data, XRT_SET_LABELS, set_labels, XRT_POINT_LABELS, point_labels, NULL); } else { XrtSetValues(hChart, XRT_DATA, my_data, XRT_SET_LABELS, point_labels, XRT_POINT_LABELS, set_labels, NULL); } new_data = (XrtDataHandle) NULL; } break; case IDINV: /* invert the axes of the chart */ wCheck = IsDlgButtonChecked(hWnd, IDINV); CheckDlgButton(hWnd, IDINV, !wCheck); XrtSetValues(hChart, XRT_INVERT_ORIENTATION, !wCheck, NULL); break; } break; case WM_SIZE: { int width; int height; RECT rect; width = LOWORD(lParam); height = HIWORD(lParam); GetWindowRect(hwndChart, &rect); SetWindowPos(hwndChart, NULL, rect.left, rect.top, width - 3, height - rect.top + 42, SWP_NOMOVE); } break; case WM_CLOSE: XrtDataDestroy(my_data); DestroyWindow(hWnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return FALSE; } return TRUE; } int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { static char szAppName[] = "panel"; HWND hWnd; MSG msg; WNDCLASS wc; DLGPROC dlgprc; HACCEL hAccel; if (!hPrevInstance) { wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon (hInstance, "olch2dicon"); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = GetStockObject (WHITE_BRUSH); wc.lpszMenuName = "PanelMenu"; wc.lpszClassName = szAppName; if (!RegisterClass(&wc)) return FALSE; } hAccel = LoadAccelerators(hInstance, "PanelAccelerators"); dlgprc = (DLGPROC) MakeProcInstance((FARPROC)WndProc, hInstance); hWnd = CreateDialog(hInstance, szAppName, 0, dlgprc); ShowWindow(hWnd, nCmdShow); while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(hWnd, hAccel, &msg)) { if (!IsDialogMessage(hWnd, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } // remember to free allocated memory XrtDestroy(hChart); return msg.wParam; }