BOOL GraphRefresh (HWND hWnd) { // GraphRefresh PGRAPHSTRUCT pGraph ; pGraph = GraphData (hWnd) ; return (pGraph->bManualRefresh) ; } // GraphRefresh
BOOL ToggleGraphRefresh (HWND hWnd) { // ToggleGraphRefresh PGRAPHSTRUCT pGraph ; pGraph = GraphData (hWnd) ; pGraph->bManualRefresh = !pGraph->bManualRefresh ; return (pGraph->bManualRefresh) ; } // ToggleGraphRefresh
void LegendDeleteItem (HWND hWndLegend, PLINE pLine) { // LegendDeleteItem PLEGEND pLegend ; int iIndex ; int iNextIndex ; int iNumItems ; PGRAPHSTRUCT pGraph ; pLegend = LegendData (hWndLegend) ; if (!pLegend) return ; iNumItems = LBNumItems (pLegend->hWndItems) ; iIndex = LBFind (pLegend->hWndItems, pLine) ; if (iIndex != LB_ERR) { LBDelete (pLegend->hWndItems, iIndex) ; } // no need to do anything if iNumItems is 1 to begin with if (iNumItems != LB_ERR && iNumItems > 1) { if (iIndex == iNumItems - 1) { // deleting the last line, then set selection // to the previous legend line iNextIndex = iIndex - 1 ; } else { // set the selection to the next legend line iNextIndex = iIndex ; } LBSetSelection (pLegend->hWndItems, iNextIndex) ; LegendSetCurrentLine (pLegend, iNextIndex) ; if (pLegend->iLineType == LineTypeChart) { // update the min, max, & avg of the current line pGraph = GraphData (hWndGraph) ; if (!PlayingBackLog()) { // update the min, max, & avg of the current line UpdateValueBarData (pGraph) ; } // update the valuebar display StatusTimer (hWndGraphStatus, TRUE) ; } } } // LegendDeleteItem
void GraphAddAction () { PGRAPHSTRUCT pGraph ; pGraph = GraphData (hWndGraph) ; SizeGraphComponents (hWndGraph) ; LegendSetSelection (hWndGraphLegend, LegendNumItems (hWndGraphLegend) - 1) ; }
void ResetGraphView (HWND hWndGraph) { PGRAPHSTRUCT pGraph ; pGraph = GraphData (hWndGraph) ; if (!pGraph) { return ; } ChangeSaveFileName (NULL, IDM_VIEWCHART) ; if (pGraph->pSystemFirst) { ResetGraph (pGraph) ; } } // ResetGraphView
void UpdateGraphData(BOOL bDisplayFirstIfNecessary) { if (GraphDisplayedNow()) { if (pPlotDlg != NULL) { pPlotDlg->RefreshData(); // ::SetWindowPos(pPlotDlg->GetWndHandle(), HWND_TOPMOST, -1, -1, -1, -1, SWP_NOMOVE | SWP_NOSIZE); // pPlotDlg->SetViewPeriodParameters(); } } else { if (bDisplayFirstIfNecessary) { GraphData(); // ::SetWindowPos(pPlotDlg->GetWndHandle(), HWND_TOPMOST, -1, -1, -1, -1, SWP_NOMOVE | SWP_NOSIZE); // Note: starting up graph will automatically bring in current DB data. } } }
void static OnSelectionChanged (HWND hWnd) { // OnSelectionChanged PLEGEND pLegend ; PGRAPHSTRUCT pGraph ; int iIndex ; pLegend = LegendData (hWnd) ; // set the new selected line iIndex = LBSelection (pLegend->hWndItems) ; if (iIndex == LB_ERR) return ; LegendSetCurrentLine (pLegend, iIndex) ; if (pLegend->iLineType == LineTypeChart) { pGraph = GraphData (hWndGraph) ; if (!PlayingBackLog()) { // update the min, max, & avg of the current line UpdateValueBarData (pGraph) ; } // update the valuebar display StatusTimer (hWndGraphStatus, TRUE) ; // change the Current highlighted line if necessary if (pGraph && pGraph->HighLightOnOff) { WindowInvalidate (hWndGraphDisplay) ; } } } // OnSelectionChanged
HRESULT SaveToImageFile(PlotData **data , unsigned int imageWidth, unsigned int imageHeight , float rangeX, float rangeY , float leftMargin, float bottomMargin , float xTick, float yTick) { HRESULT hr = S_OK; // // Create Factories // IWICImagingFactory *pWICFactory = NULL; ID2D1Factory *pD2DFactory = NULL; IDWriteFactory *pDWriteFactory = NULL; IWICBitmap *pWICBitmap = NULL; ID2D1RenderTarget *pRT = NULL; IDWriteTextFormat *pTextFormat = NULL; ID2D1SolidColorBrush *pSolidBrush = NULL; IWICBitmapEncoder *pEncoder = NULL; IWICBitmapFrameEncode *pFrameEncode = NULL; IWICStream *pStream = NULL; hr = CoCreateInstance( CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, reinterpret_cast<void **>(&pWICFactory) ); if (SUCCEEDED(hr)) { hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory); } if (SUCCEEDED(hr)) { hr = DWriteCreateFactory( DWRITE_FACTORY_TYPE_SHARED, __uuidof(pDWriteFactory), reinterpret_cast<IUnknown **>(&pDWriteFactory) ); } // // Create IWICBitmap and RT // if (SUCCEEDED(hr)) { hr = pWICFactory->CreateBitmap( imageWidth, imageHeight, GUID_WICPixelFormat32bppBGR, WICBitmapCacheOnLoad, &pWICBitmap ); } if (SUCCEEDED(hr)) { hr = pD2DFactory->CreateWicBitmapRenderTarget( pWICBitmap, D2D1::RenderTargetProperties(), &pRT ); } if (SUCCEEDED(hr)) { // // Create text format // static const WCHAR sc_fontName[] = L"Arial"; static const FLOAT sc_fontSize = 20; hr = pDWriteFactory->CreateTextFormat( sc_fontName, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, sc_fontSize, L"", //locale &pTextFormat ); } if (SUCCEEDED(hr)) { pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER); pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER); // // Create a path geometry representing an hour glass // } if (SUCCEEDED(hr)) { hr = pRT->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::Black), &pSolidBrush ); } if (SUCCEEDED(hr)) { // // Render into the bitmap // pRT->BeginDraw(); pRT->Clear(D2D1::ColorF(D2D1::ColorF::White)); D2D1_SIZE_F rtSize = pRT->GetSize(); //static const WCHAR sc_helloWorld[] = L"Hello, World!"; //pRT->DrawText( // sc_helloWorld, // ARRAYSIZE(sc_helloWorld) - 1, // pTextFormat, // D2D1::RectF(0, 0, rtSize.width, rtSize.height), // pBlackBrush); float scaleX = (rtSize.width - leftMargin) / rangeX; float scaleY = (rtSize.height - bottomMargin) / rangeY; // // Reset back to the identity transform // pRT->DrawLine(D2D1::Point2F(leftMargin, 0.0f), D2D1::Point2F(leftMargin, rtSize.height - bottomMargin), pSolidBrush); pRT->DrawLine(D2D1::Point2F(leftMargin, rtSize.height - bottomMargin), D2D1::Point2F(rtSize.width, rtSize.height - bottomMargin), pSolidBrush); pSolidBrush->SetColor(D2D1::ColorF(D2D1::ColorF::LightGray, 0.4f)); size_t countTicks = rangeY / yTick; for(size_t tick = 1; tick <= countTicks; ++tick) { float y = rtSize.height - bottomMargin - static_cast<float>(tick) * yTick * scaleY; pRT->DrawLine(D2D1::Point2F(leftMargin - 3.0f, y), D2D1::Point2F(rtSize.width, y), pSolidBrush); } countTicks = rangeX / xTick; for(size_t tick = 1; tick <= countTicks; ++tick) { float x = leftMargin + static_cast<float>(tick) * xTick * scaleX; pRT->DrawLine(D2D1::Point2F(x, 0.0f), D2D1::Point2F(x, rtSize.height - bottomMargin + 3.0f), pSolidBrush); } //D2D1_MATRIX_3X2_F rotation = D2D1::Matrix3x2F::Rotation(-90.0f); D2D1_MATRIX_3X2_F translation = D2D1::Matrix3x2F::Translation(leftMargin, rtSize.height - bottomMargin); //D2D1_MATRIX_3X2_F scale = D2D1::Matrix3x2F::Scale(D2D1::SizeF(600.0f, 1.0f)); pRT->SetTransform(translation); GraphData(data, pD2DFactory, pRT, pSolidBrush, scaleX, scaleY ); hr = pRT->EndDraw(); } if (SUCCEEDED(hr)) { // // Save image to file // hr = pWICFactory->CreateStream(&pStream); } WICPixelFormatGUID format = GUID_WICPixelFormatDontCare; if (SUCCEEDED(hr)) { static const WCHAR filename[] = L"output.png"; hr = pStream->InitializeFromFilename(filename, GENERIC_WRITE); } if (SUCCEEDED(hr)) { hr = pWICFactory->CreateEncoder(GUID_ContainerFormatPng, NULL, &pEncoder); } if (SUCCEEDED(hr)) { hr = pEncoder->Initialize(pStream, WICBitmapEncoderNoCache); } if (SUCCEEDED(hr)) { hr = pEncoder->CreateNewFrame(&pFrameEncode, NULL); } if (SUCCEEDED(hr)) { hr = pFrameEncode->Initialize(NULL); } if (SUCCEEDED(hr)) { hr = pFrameEncode->SetSize(imageWidth, imageHeight); } if (SUCCEEDED(hr)) { hr = pFrameEncode->SetPixelFormat(&format); } if (SUCCEEDED(hr)) { hr = pFrameEncode->WriteSource(pWICBitmap, NULL); } if (SUCCEEDED(hr)) { hr = pFrameEncode->Commit(); } if (SUCCEEDED(hr)) { hr = pEncoder->Commit(); } SafeRelease(&pWICFactory); SafeRelease(&pD2DFactory); SafeRelease(&pDWriteFactory); SafeRelease(&pWICBitmap); SafeRelease(&pRT); SafeRelease(&pTextFormat); SafeRelease(&pSolidBrush); SafeRelease(&pEncoder); SafeRelease(&pFrameEncode); SafeRelease(&pStream); return hr; }
int NEAR PASCAL CommandHandler(WORD wParam, LONG lParam) { /* if (HIWORD(lParam) == EN_CHANGE) { if (focus(GetDlgCtrlID(LOWORD(lParam))) && players.player_numb > -1) bNeedSaveP = TRUE; else if (courses.course_numb > -1) bNeedSaveC = TRUE; } */ switch (wParam) { case IDOK: SendMessage(hWnd, WM_COMMAND, IDD_RLIST, MAKELONG(0, LBN_DBLCLK)); return NULL; case IDM_CONTENTS: case IDM_SEARCHON: case IDM_USE: MessageBox(hWnd, "Help to come soon!", szAppName, MB_OK | MB_ICONEXCLAMATION); return NULL; case IDM_ABOUT: /* display about dialog box */ lpfnGenericDlgProc = MakeProcInstance((FARPROC)AboutDlgProc, hInst); DialogBox(hInst, "ABOUT", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_HANDICAP: lpfnGenericDlgProc = MakeProcInstance((FARPROC)HandicapDlgProc, hInst); DialogBox(hInst, "HANDICAP", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_P_SEARCH: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; /* fall through */ case IDM_C_SEARCH: if (!get_course(hWnd, &courses, c_index)) return NULL; wWhich = wParam; lpfnGenericDlgProc = MakeProcInstance((FARPROC)SearchDlgProc, hInst); DialogBox(hInst, "SEARCH", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_GRAPH: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; if (!get_course(hWnd, &courses, c_index)) return NULL; if (IDYES == MessageBox(hWnd, "You must have Microsoft Excel\nto use this option. Continue?", szAppName, MB_YESNO | MB_ICONQUESTION)) GraphData(&(players).player[p_index].p_scores, &courses); return NULL; case IDM_NEW_P: /* save current file and clear viewport */ if (bNeedSaveP && IDCANCEL == AskAboutSave(hWnd, szFileTitleP, PLAYER_MARKER)) return FALSE; szFileTitleP[NULL] = '\0'; bNeedSaveP = FALSE; p_index = r_index = r_last = 0; players.player_numb = -1; clear_player(hWnd, hWndRList); DoCaption(hWnd, szFileTitleP, szFileTitleC); return NULL; case IDM_NEW_C: if (bNeedSaveC && IDCANCEL == AskAboutSave(hWnd, szFileTitleC, COURSE_MARKER)) return FALSE; szFileTitleC[NULL] = '\0'; bNeedSaveC = FALSE; c_index = 0; courses.course_numb = -1; clear_course(hWnd); DoCaption(hWnd, szFileTitleP, szFileTitleC); return NULL; case IDM_OPEN_P: /* open an existing file */ of_player.lpstrTitle = "Open Player"; of_player.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; if (!GetOpenFileName(&of_player)) return FALSE; if (ReadFile(hWnd, szFileP, szFileTitleP, szFileTitleC, bNeedSaveP, &players, &courses, PLAYER_MARKER)) { bNeedSaveP = FALSE; p_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); DoCaption(hWnd, szFileTitleP, szFileTitleC); } /* if */ return NULL; case IDM_OPEN_C: /* open an existing file */ of_course.lpstrTitle = "Open Course"; of_course.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; if (!GetOpenFileName(&of_course)) return FALSE; if (ReadFile(hWnd, szFileC, szFileTitleP, szFileTitleC, bNeedSaveC, &players, &courses, COURSE_MARKER)) { bNeedSaveC = FALSE; c_index = 0; show_course(hWnd, &courses, &c_index); DoCaption(hWnd, szFileTitleP, szFileTitleC); } /* if */ return NULL; case IDM_SAVE_P: /* write current file */ if (szFileTitleP[NULL]) { if (!get_player(hWnd, &players, p_index, r_index)) return NULL; if (WriteFile(hWnd, szFileP, &players, &courses, PLAYER_MARKER, p_index, r_index, c_index)) { bNeedSaveP = FALSE; return 1; } /* if */ return NULL; } /* if fall through */ case IDM_SAVEAS_P: /* change file name */ if (!get_player(hWnd, &players, p_index, r_index)) return NULL; of_player.lpstrTitle = "Save Player"; of_player.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if (!GetSaveFileName(&of_player)) return FALSE; if (WriteFile(hWnd, szFileP, &players, &courses, PLAYER_MARKER, p_index, r_index, c_index)) { bNeedSaveP = FALSE; DoCaption(hWnd, szFileTitleP, szFileTitleC); } return NULL; case IDM_SAVE_C: /* write current file */ if (szFileTitleC[NULL]) { if (!get_course(hWnd, &courses, c_index)) return NULL; if (WriteFile(hWnd, szFileC, &players, &courses, COURSE_MARKER, p_index, r_index, c_index)) { bNeedSaveC = FALSE; return 1; } /* if */ return NULL; } /* if fall through */ case IDM_SAVEAS_C: /* change file name */ if (!get_course(hWnd, &courses, c_index)) return NULL; of_course.lpstrTitle = "Save Course"; of_course.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if (!GetSaveFileName(&of_course)) return FALSE; if (WriteFile(hWnd, szFileC, &players, &courses, COURSE_MARKER, p_index, r_index, c_index)) { bNeedSaveC = FALSE; DoCaption(hWnd, szFileTitleP, szFileTitleC); } return NULL; case IDM_PRINT_P: /* Print current file */ if (!get_player(hWnd, &players, p_index, r_index)) return NULL; PrintFile(hInst, hWnd, szFileTitleP[NULL] ? szFileTitleP : szUntitled); return NULL; case IDM_PRINT_C: /* Print current file */ if (!get_course(hWnd, &courses, c_index)) return NULL; PrintFile(hInst, hWnd, szFileTitleC[NULL] ? szFileTitleC : szUntitled); return NULL; case IDM_EXIT: /* Send a close message, and exit the program */ SendMessage(hWnd, WM_CLOSE, NULL, 0L); return NULL; case IDM_UNDO: /* Check for undo status */ SendMessage(GetFocus(), WM_UNDO, 0, 0L); return 0; case IDM_CUT: /* Send cut message */ SendMessage(GetFocus(), WM_CUT, 0, 0L); return 0; case IDM_COPY: /* Send copy message */ SendMessage(GetFocus(), WM_COPY, 0, 0L); return 0; case IDM_PASTE: /* Send paste message */ SendMessage(GetFocus(), WM_PASTE, 0, 0L); return 0; case IDM_CLEAR: /* Send clear message */ SendMessage(GetFocus(), WM_CLEAR, 0, 0L); return 0; case IDM_P_ADD: if (AddPlayer(hWnd, &players, &p_index, &r_index)) bNeedSaveP = TRUE; return NULL; case IDM_R_ADD: if (AddRound(hWnd, &players, &p_index, &r_index, &r_last)) bNeedSaveP = TRUE; return NULL; case IDM_C_ADD: if (AddCourse(hWnd, &courses, &c_index)) bNeedSaveC = TRUE; return NULL; case IDM_P_SORT: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; qsort(players.player, players.player_numb+1, sizeof(players.player[0]), compare_player); bNeedSaveP = TRUE; p_index = r_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); return NULL; case IDM_R_SORT: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; qsort(players.player[p_index].p_scores.history, players.player[p_index].p_scores.round_numb+1, sizeof(players.player[p_index].p_scores.history[0]), compare_round); bNeedSaveP = TRUE; r_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); return NULL; case IDM_C_SORT: if (!get_course(hWnd, &courses, c_index)) return NULL; qsort(courses.course, courses.course_numb, sizeof(courses.course[0]), compare_course); bNeedSaveC = TRUE; c_index = 0; show_course(hWnd, &courses, &c_index); return NULL; case IDM_P_DELETE: if (players.player_numb > -1) { GetDlgItemText(hWnd, IDD_PLAST, (players).player[p_index].p_last, LAST_NAME_LENGTH+1); GetDlgItemText(hWnd, IDD_PFIRST, (players).player[p_index].p_first, FIRST_NAME_LENGTH+1); lstrcpy(szDelete, "Delete : "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_first); lstrcat(szDelete, " "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_last); if (IDYES == MessageBox(hWnd, szDelete, "Delete Player", MB_YESNO | MB_ICONQUESTION)) { bNeedSaveP = TRUE; delete_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); } } /* if */ return NULL; case IDM_R_DELETE: if (players.player[p_index].p_scores.round_numb > -1) { convert_date(&players.player[p_index].p_scores.history[r_index].date, szDate); lstrcpy(szDelete, (LPSTR)"Delete : "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_scores.history[r_index].course_name); lstrcat(szDelete, " "); lstrcat(szDelete, szDate); if (IDYES == MessageBox(hWnd, szDelete, "Delete Round", MB_YESNO | MB_ICONQUESTION)) { delete_round(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); bNeedSaveP = TRUE; } /* if */ } /* if */ return NULL; case IDM_C_DELETE: if (courses.course_numb > -1) { GetDlgItemText(hWnd, IDD_CNAME, (courses).course[c_index].c_name, COURSE_NAME_LENGTH+1); lstrcpy(szc_name, (courses).course[c_index].c_name); lpfnGenericDlgProc = MakeProcInstance((FARPROC)DeleteCourseDlgProc, hInst); DialogBox(hInst, "DELETEC", hWnd, lpfnGenericDlgProc); FreeProcInstance(DeleteCourseDlgProc); /* Release memory */ if (bYesNo == IDYES) { bNeedSaveC = TRUE; delete_course(&courses, &c_index); if (bDeleteRounds && delete_rounds(&players, szc_name)) { bNeedSaveP = TRUE; show_rounds(hWnd, hWndRList, &(players).player[p_index].p_scores, &r_index, &r_last, TRUE); } /* if */ show_course(hWnd, &courses, &c_index); } /* if */ } /* if */ return NULL; case IDD_RLIST: switch(HIWORD(lParam)) { case LBN_DBLCLK: if ((players.player_numb == -1) || (players.player[p_index].p_scores.round_numb == -1)) return NULL; lstrcpy(szNDTitle, "Change Course / Name Date"); convert_date(&players.player[p_index].p_scores.history[r_index].date, szDate); get_date_elements(szDate, szmm, szdd, szyy); lstrcpy(szc_name, (LPSTR)players.player[p_index].p_scores.history[r_index].course_name); lpfnGenericDlgProc = MakeProcInstance((FARPROC)NameDateDlgProc, hInst); DialogBox(hInst, "NAMEDATE", hWnd, lpfnGenericDlgProc); FreeProcInstance(NameDateDlgProc); /* Release memory */ if (bNameDate == IDOK) { bNeedSaveP = TRUE; players.player[p_index].p_scores.history[r_index].date = string_to_date(szmm, szdd, szyy); lstrcpy((LPSTR)players.player[p_index].p_scores.history[r_index].course_name, szc_name); show_rounds(hWnd, hWndRList, &(players).player[p_index].p_scores, &r_index, &r_last, FALSE); } /* if */ return NULL; case LBN_SELCHANGE: if ((int)SendMessage(hWndRList, LB_GETCURSEL, 0, 0L) == r_index) break; if (!get_round(hWnd, &players, p_index, r_index)) { SendMessage(hWndRList, LB_SETCURSEL, r_index, 0L); return NULL; } r_index = (int)SendMessage(hWndRList, LB_GETCURSEL, 0, 0L); if (r_index != LB_ERR && r_index != r_last) { show_round(hWnd, players.player[p_index].p_scores.history[r_index].score); r_last = r_index; } /* if */ return NULL; } /* switch (HIWORD(lParam)) */ return NULL; default: return FALSE; } /* switch (wParam) */ } /* CommandHandler */