C++調用:
CProgressWnd proWnd(NULL,"Computing covariance",TRUE); proWnd.SetWindowSize(1,300); proWnd.SetStep(1); proWnd.SetRange(0, 100); proWnd.SetText("Quit"); CProgressWnd::SetCurrentWnd(&proWnd); m_vecCovariance.clear(); if(!m_pData->GetCovAndCor(&m_vecCovariance, NULL, true, false,CProgressWnd::GDALCallBack)) { return FALSE; }
CProgressWnd proWnd(NULL,"重投影",TRUE); proWnd.SetWindowSize(1,300); proWnd.SetStep(1); proWnd.SetRange(0, 100); proWnd.SetText("處理中.."); CProgressWnd::SetCurrentWnd(&proWnd); psWarpOptions->pfnProgress = CProgressWnd::GDALCallBack;//GDALTermProgress;
ProgressWnd.h
// ProgressWnd.h : header file // // Written by Chris Maunder (chrismaunder@codeguru.com) // Copyright 1998. // // CProgressWnd is a drop-in popup progress window for use in // programs that a time consuming. Check out the accompanying HTML // doc file for details. // // This code may be used in compiled form in any way you desire. This // file may be redistributed by any means PROVIDING it is not sold for // profit without the authors written consent, and providing that this // notice and the authors name is included. If the source code in // this file is used in any commercial application then an email to // me would be nice. // // This file is provided "as is" with no expressed or implied warranty. // The author accepts no liability if it causes any damage to your // computer, causes your pet cat to fall ill, increases baldness or // makes you car start emitting strange noises when you start it up. // // Expect bugs. // // Please use and enjoy. Please let me know of any bugs/mods/improvements // that you have found/implemented and I will fix/incorporate them into this // file. #ifndef _INCLUDE_PROGRESSWND_H #define _INCLUDE_PROGRESSWND_H ///////////////////////////////////////////////////////////////////////////// // CProgressWnd window class CProgressWnd : public CWnd { // Construction/Destruction public: CProgressWnd(); CProgressWnd(CWnd* pParent, LPCTSTR pszTitle, BOOL bSmooth = FALSE); virtual ~CProgressWnd(); BOOL Create(CWnd* pParent, LPCTSTR pszTitle, BOOL bSmooth = FALSE); BOOL GoModal(LPCTSTR pszTitle =_T("Progress"), BOOL bSmooth = FALSE); protected: void CommonConstruct(); // Operations public: static int __stdcall GDALCallBack(double dfComplete, const char *pszMessage, void *pData); static void SetCurrentWnd(CProgressWnd *pWnd); static int SagaCallback(int MessageID, long Param_1, long Param_2); static CProgressWnd * m_pCurProWnd; CString m_strTitle; BOOL m_bCancelled; void MakebCancelFalse(); void SetRange(int nLower, int nUpper, int nStep = 1); void OnCancelOk() ; // Set range and step size int OffsetPos(int nPos); // Same as CProgressCtrl int StepIt(); // " int SetStep(int nStep); // " int SetPos(int nPos); // " void SetText(LPCTSTR fmt, ...); // Set text in text area void Clear(); // Clear text, reset bar void Hide(); // Hide window void Show(); // Show window BOOL Cancelled() { return m_bCancelled; } // Was "Cancel" hit? void SetWindowSize(int nNumTextLines, int nWindowWidth = 390); void PeekAndPump(BOOL bCancelOnESCkey = TRUE); // Message pumping for modal operation // Implementation protected: void GetPreviousSettings(); void SaveCurrentSettings(); BOOL m_bModal; BOOL m_bPersistantPosition; int m_nPrevPos, m_nPrevPercent; int m_nStep; int m_nMaxValue, m_nMinValue; int m_nNumTextLines; CStatic m_Text; CProgressCtrl m_wndProgress; CButton m_CancelButton; CString m_strCancelLabel; CFont m_font; // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CProgressWnd) public: virtual BOOL DestroyWindow(); //}}AFX_VIRTUAL // Generated message map functions protected: //{{AFX_MSG(CProgressWnd) afx_msg BOOL OnEraseBkgnd(CDC* pDC); //}}AFX_MSG afx_msg void OnCancel(); DECLARE_MESSAGE_MAP() }; #endif /////////////////////////////////////////////////////////////////////////////
ProgressWnd.cpp
// ProgressWnd.cpp : implementation file // // Written by Chris Maunder (chrismaunder@codeguru.com) // Copyright 1998. // // CProgressWnd is a drop-in popup progress window for use in // programs that a time consuming. Check out the header file // or the accompanying HTML doc file for details. // // This code may be used in compiled form in any way you desire. This // file may be redistributed by any means PROVIDING it is not sold for // profit without the authors written consent, and providing that this // notice and the authors name is included. If the source code in // this file is used in any commercial application then an email to // the me would be nice. // // This file is provided "as is" with no expressed or implied warranty. // The author accepts no liability if it causes any damage to your // computer, causes your pet cat to fall ill, increases baldness or // makes you car start emitting strange noises when you start it up. // // Expect bugs. // // Please use and enjoy. Please let me know of any bugs/mods/improvements // that you have found/implemented and I will fix/incorporate them into this // file. // // Updated May 18 1998 - added PeekAndPump function to allow modal operation, // with optional "Cancel on ESC" (Michael <mbh-ep@post5.tele.dk>) // Nov 27 1998 - Removed modal stuff from PeekAndPump // Dec 18 1998 - added WS_EX_TOPMOST to the creation flag #include "stdafx.h" #include "ProgressWnd.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define IDC_CANCEL 10 #define IDC_TEXT 11 #define IDC_PROGRESS 12 LPCTSTR szSection = _T("Settings"); LPCTSTR szEntryX = _T("X"); LPCTSTR szEntryY = _T("Y"); ///////////////////////////////////////////////////////////////////////////// // CProgressWnd CProgressWnd *CProgressWnd::m_pCurProWnd = NULL; CProgressWnd::CProgressWnd() { CommonConstruct(); } CProgressWnd::CProgressWnd(CWnd* pParent, LPCTSTR pszTitle, BOOL bSmooth /* = FALSE */) { CommonConstruct(); m_strTitle = pszTitle; Create(pParent, pszTitle, bSmooth); } void CProgressWnd::CommonConstruct() { m_nNumTextLines = 4; m_nPrevPos = 0; m_nPrevPercent = 0; m_nStep = 1; m_nMinValue = 0; m_nMaxValue = 100; m_strTitle = _T("處理中"); m_strCancelLabel = _T("取消"); m_bCancelled = FALSE; m_bModal = FALSE; m_bPersistantPosition = TRUE; // saves and restores position automatically } CProgressWnd::~CProgressWnd() { if (m_pCurProWnd == this) m_pCurProWnd = NULL; DestroyWindow(); } BOOL CProgressWnd::Create(CWnd* pParent, LPCTSTR pszTitle, BOOL bSmooth /* = FALSE */) { BOOL bSuccess; // Register window class CString csClassName = AfxRegisterWndClass(CS_OWNDC|CS_HREDRAW|CS_VREDRAW, ::LoadCursor(NULL, IDC_APPSTARTING), CBrush(::GetSysColor(COLOR_BTNFACE))); // Get the system window message font for use in the cancel button and text area NONCLIENTMETRICS ncm; ncm.cbSize = sizeof(NONCLIENTMETRICS); VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0)); m_font.CreateFontIndirect(&(ncm.lfMessageFont)); // If no parent supplied then try and get a pointer to it anyway if (!pParent) pParent = AfxGetMainWnd(); // Create popup window bSuccess = CreateEx(WS_EX_DLGMODALFRAME|WS_EX_TOPMOST, // Extended style csClassName, // Classname pszTitle, // Title WS_POPUP|WS_BORDER|WS_CAPTION, // style 0,0, // position - updated soon. 390,130, // Size - updated soon pParent->GetSafeHwnd(), // handle to parent 0, // No menu NULL); if (!bSuccess) return FALSE; // Now create the controls CRect TempRect(0,0,10,10); bSuccess = m_Text.Create(_T(""), WS_CHILD|WS_VISIBLE|SS_NOPREFIX|SS_LEFTNOWORDWRAP, TempRect, this, IDC_TEXT); if (!bSuccess) return FALSE; DWORD dwProgressStyle = WS_CHILD|WS_VISIBLE; #ifdef PBS_SMOOTH if (bSmooth) dwProgressStyle |= PBS_SMOOTH; #endif bSuccess = m_wndProgress.Create(dwProgressStyle, TempRect, this, IDC_PROGRESS); if (!bSuccess) return FALSE; bSuccess = m_CancelButton.Create(m_strCancelLabel, WS_CHILD|WS_VISIBLE|WS_TABSTOP| BS_PUSHBUTTON, TempRect, this, IDC_CANCEL); if (!bSuccess) return FALSE; m_CancelButton.SetFont(&m_font, TRUE); m_Text.SetFont(&m_font, TRUE); // Resize the whole thing according to the number of text lines, desired window // width and current font. SetWindowSize(m_nNumTextLines, 390); // Center and show window if (m_bPersistantPosition) GetPreviousSettings(); else CenterWindow(); Show(); return TRUE; } BOOL CProgressWnd::GoModal(LPCTSTR pszTitle /*=_T("Progress")"*/, BOOL bSmooth /*=FALSE*/) { CWnd *pMainWnd = AfxGetMainWnd(); if (!::IsWindow(m_hWnd) && !Create(pMainWnd, pszTitle, bSmooth)) return FALSE; // Disable main window if (pMainWnd) pMainWnd->EnableWindow(FALSE); // Re-enable this window EnableWindow(TRUE); m_bModal = TRUE; return TRUE; } void CProgressWnd::SetWindowSize(int nNumTextLines, int nWindowWidth /*=390*/) { int nMargin = 10; CSize EdgeSize(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE)); CRect TextRect, CancelRect, ProgressRect; CSize CancelSize; // Set up a default size for the text area in case things go wrong TextRect.SetRect(nMargin,nMargin, nWindowWidth-2*nMargin, 100+2*nMargin); // Get DrawText to tell us how tall the text area will be (while we're at // it, we'll see how big the word "Cancel" is) CDC* pDC = GetDC(); if (pDC) { CFont* pOldFont = pDC->SelectObject(&m_font); CString str = _T("M"); for (int i = 0; i < nNumTextLines-1; i++) str += _T("/nM"); pDC->DrawText(str, TextRect, DT_CALCRECT|DT_NOCLIP|DT_NOPREFIX); TextRect.right = TextRect.left + nWindowWidth; CancelSize = pDC->GetTextExtent(m_strCancelLabel + _T(" ")) + CSize(EdgeSize.cx*4, EdgeSize.cy*3); pDC->SelectObject(pOldFont); ReleaseDC(pDC); } // Work out how big (and where) the cancel button should be CancelRect.SetRect(TextRect.right-CancelSize.cx, TextRect.bottom+nMargin, TextRect.right, TextRect.bottom+nMargin + CancelSize.cy); // Work out how big (and where) the progress control should be ProgressRect.SetRect(TextRect.left, CancelRect.top + EdgeSize.cy, CancelRect.left-nMargin, CancelRect.bottom - EdgeSize.cy); // Resize the main window to fit the controls CSize ClientSize(nMargin + TextRect.Width() + nMargin, nMargin + TextRect.Height() + nMargin + CancelRect.Height() + nMargin); CRect WndRect, ClientRect; GetWindowRect(WndRect); GetClientRect(ClientRect); WndRect.right = WndRect.left + WndRect.Width()-ClientRect.Width()+ClientSize.cx; WndRect.bottom = WndRect.top + WndRect.Height()-ClientRect.Height()+ClientSize.cy; MoveWindow(WndRect); // Now reposition the controls... m_wndProgress.MoveWindow(ProgressRect); m_CancelButton.MoveWindow(CancelRect); m_Text.MoveWindow(TextRect); } void CProgressWnd::Clear() { SetText(_T("")); SetPos(0); m_bCancelled = FALSE; m_nPrevPos = 0; if (::IsWindow(GetSafeHwnd())) UpdateWindow(); } void CProgressWnd::Hide() { if (!::IsWindow(GetSafeHwnd())) return; if (IsWindowVisible()) { ShowWindow(SW_HIDE); ModifyStyle(WS_VISIBLE, 0); } } void CProgressWnd::Show() { if (!::IsWindow(GetSafeHwnd())) return; if (!IsWindowVisible()) { ModifyStyle(0, WS_VISIBLE); ShowWindow(SW_SHOWNA); RedrawWindow(NULL,NULL,RDW_ERASE|RDW_FRAME|RDW_INVALIDATE); } } void CProgressWnd::SetRange(int nLower, int nUpper, int nStep /* = 1 */) { if (!::IsWindow(GetSafeHwnd())) return; // To take advantage of the Extended Range Values we use the PBM_SETRANGE32 // message intead of calling CProgressCtrl::SetRange directly. If this is // being compiled under something less than VC 5.0, the necessary defines // may not be available. #ifdef PBM_SETRANGE32 ASSERT(-0x7FFFFFFF <= nLower && nLower <= 0x7FFFFFFF); ASSERT(-0x7FFFFFFF <= nUpper && nUpper <= 0x7FFFFFFF); m_wndProgress.SendMessage(PBM_SETRANGE32, (WPARAM) nLower, (LPARAM) nUpper); #else ASSERT(0 <= nLower && nLower <= 65535); ASSERT(0 <= nUpper && nUpper <= 65535); m_wndProgress.SetRange(nLower, nUpper); #endif m_nMaxValue = nUpper; m_nMinValue = nLower; m_nStep = nStep; m_wndProgress.SetStep(nStep); } int CProgressWnd::OffsetPos(int nPos) { if (!::IsWindow(GetSafeHwnd())) return m_nPrevPos; Show(); return SetPos(m_nPrevPos + nPos); } int CProgressWnd::StepIt() { if (!::IsWindow(GetSafeHwnd())) return m_nPrevPos; Show(); return SetPos(m_nPrevPos + m_nStep); } int CProgressWnd::SetStep(int nStep) { int nOldStep = m_nStep; m_nStep = nStep; if (!::IsWindow(GetSafeHwnd())) return nOldStep; return m_wndProgress.SetStep(nStep); } int CProgressWnd::SetPos(int nPos) { #ifdef PBM_SETRANGE32 ASSERT(-0x7FFFFFFF <= nPos && nPos <= 0x7FFFFFFF); #else ASSERT(0 <= nPos && nPos <= 65535); #endif if (!::IsWindow(GetSafeHwnd())) return m_nPrevPos; Show(); CString strTitle; int nPercentage; m_nPrevPos = nPos; if (m_nMaxValue > m_nMinValue) nPercentage = (nPos*100)/(m_nMaxValue - m_nMinValue); else nPercentage = 0; if (nPercentage != m_nPrevPercent) { m_nPrevPercent = nPercentage; strTitle.Format(_T("%s [%d%%]"),m_strTitle,nPercentage); SetWindowText(strTitle); } return m_wndProgress.SetPos(nPos); } void CProgressWnd::SetText(LPCTSTR fmt, ...) { if (!::IsWindow(GetSafeHwnd())) return; va_list args; TCHAR buffer[512]; va_start(args, fmt); _vstprintf(buffer, fmt, args); va_end(args); m_Text.SetWindowText(buffer); } BEGIN_MESSAGE_MAP(CProgressWnd, CWnd) //{{AFX_MSG_MAP(CProgressWnd) ON_WM_ERASEBKGND() //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_CANCEL, OnCancel) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CProgressWnd message handlers BOOL CProgressWnd::OnEraseBkgnd(CDC* pDC) { // Fill background with Catchment background colour CBrush backBrush(GetSysColor(COLOR_BTNFACE)); CBrush* pOldBrush = pDC->SelectObject(&backBrush); CRect rect; pDC->GetClipBox(&rect); // Erase the area needed pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY); pDC->SelectObject(pOldBrush); return TRUE; } void CProgressWnd::OnCancelOk() { m_bCancelled = TRUE; Hide(); if (m_bModal) SendMessage(WM_CLOSE); CWnd *pWnd = AfxGetMainWnd(); if (pWnd && ::IsWindow(pWnd->m_hWnd)) pWnd->SetForegroundWindow(); } void CProgressWnd::OnCancel() { m_bCancelled = TRUE; } BOOL CProgressWnd::DestroyWindow() { if (m_bPersistantPosition) SaveCurrentSettings(); if (m_bModal) { m_bModal = FALSE; CWnd *pMainWnd = AfxGetMainWnd(); if (pMainWnd) pMainWnd->EnableWindow(TRUE); } return CWnd::DestroyWindow(); } // Message pumping function that can either be used to pump messages during // long operations. This version will only pass messages to this window (and // all child windows). (Thanks to Michael <mbh-ep@post5.tele.dk> for this) void CProgressWnd::PeekAndPump(BOOL bCancelOnESCkey /*= TRUE*/) { if (m_bModal && ::GetFocus() != m_hWnd) SetFocus(); MSG msg; while (!m_bCancelled && ::PeekMessage(&msg, NULL,0,0,PM_NOREMOVE)) { if (bCancelOnESCkey && (msg.message == WM_CHAR) && (msg.wParam == VK_ESCAPE)) OnCancel(); // Cancel button disabled if modal, so we fake it. if (m_bModal && (msg.message == WM_LBUTTONUP)) { CRect rect; m_CancelButton.GetWindowRect(rect); if (rect.PtInRect(msg.pt)) OnCancel(); } if (!AfxGetApp()->PumpMessage()) { ::PostQuitMessage(0); return; } } } // Retores the previous window size from the registry void CProgressWnd::GetPreviousSettings() { int x = AfxGetApp()->GetProfileInt(szSection, szEntryX, -1); int y = AfxGetApp()->GetProfileInt(szSection, szEntryY, -1); if (x >= 0 && x < GetSystemMetrics(SM_CXSCREEN) && y >= 0 && y < GetSystemMetrics(SM_CYSCREEN)) { SetWindowPos(NULL, x,y, 0,0, SWP_NOSIZE|SWP_NOZORDER); } else CenterWindow(); } // Saves the current window position registry void CProgressWnd::SaveCurrentSettings() { if (!IsWindow(m_hWnd)) return; CRect rect; GetWindowRect(rect); AfxGetApp()->WriteProfileInt(szSection, szEntryX, rect.left); AfxGetApp()->WriteProfileInt(szSection, szEntryY, rect.top); } void CProgressWnd::MakebCancelFalse() { m_bCancelled = false; } int CProgressWnd::SagaCallback(int MessageID, long Param_1, long Param_2) { switch( MessageID ) { case 1://CALLBACK_PROGRESSBAR_SET_POSITION: if (m_pCurProWnd) { m_pCurProWnd->SetPos((double)Param_2 > 0 ? (int)(100.0 * (double)Param_1 / (double)Param_2) : 100); } break; case 0://CALLBACK_PROGRESS_CHECK: if (m_pCurProWnd) { m_pCurProWnd->PeekAndPump(); } break; default: return 0; } return 1; } void CProgressWnd::SetCurrentWnd(CProgressWnd *pWnd) { m_pCurProWnd = pWnd; m_pCurProWnd->SetRange(0, 100); } int CProgressWnd::GDALCallBack(double dfComplete, const char *pszMessage, void *pData) { if (m_pCurProWnd) { m_pCurProWnd->SetPos((int)(100*dfComplete)); } return TRUE; }
本文分享自華爲雲社區《【MySQL技術專欄】MySQL8.0直方圖介紹》,作者:GaussDB 數據庫。 背景 數據庫查詢優化器負責將SQL查詢轉換爲儘可能高效的執行計劃,但因爲數據環境不斷變化導致優化器對查詢數據瞭解的不夠充足,可能無法
每篇一句 大魔王張怡寧:女兒,這堆金牌你拿去玩吧,但我的銀牌不能給你玩。你要想玩銀牌就去找你王浩叔叔吧,他那銀牌多 前言 爲了講述好Spring MVC最爲複雜的數據綁定這塊,我前面可謂是做足了功課,對此部分知識此處給小夥伴留一個學
作者:vivo 互聯網數據庫團隊- Qiu Xinbo 本文主要通過圖示介紹了用主鍵進行分片查詢的過程,介紹了主鍵分頁查詢存在SQL性能問題,如何去創建高效的索引去優化主鍵分頁查詢的SQL性能問題 對於數據分佈不均
JSON簡介: JSON(Java Script Object Notation)是一種輕量級的數據交換格式,通常用於在不同系統之間傳輸數據。它基於 JavaScript 對象語法,但已成爲一種獨立於語言的格式。JSON 數據以鍵值對的形式
一、簡單介紹: CaffeineCache和Guava的Cache是應用廣泛的本地緩存。 在開發中,爲了達到降低依賴、提高訪問速度的目的。會使用它存儲一些維表接口的返回值和數據庫查詢結果,在有些場景下也會在分佈式緩存上再加上一層本地緩存,
鴻蒙原生應用再新丁!新華社 入局鴻蒙 來自 #HarmonyOS# 微博5月27日消息 #鴻蒙千帆起#新華社客戶端完成鴻蒙原生應用核心版本開發,將實現不同使用場景下更加智能、精準、及時的要聞推送,以及主流價值的全場景覆蓋和高效傳播!與此同
在迅速變化的技術領域,本地環境的搭建和調試對於軟件開發的效率和效果至關重要。本文將詳細介紹如何爲Apache DolphinScheduler搭建一個高效的本地開發環境,包括2.x和3.x版本的設置方法。 無論您是初學者還是有經驗的開發者
前言 最近參與的項目中,接口中返回的日期格式不對,發現項目中配置了fastjson作爲spring的數據轉換器,於是使用了fastjson的字段格式化轉換註解 發現不起作用。這讓我很疑惑,然後在fastjson的相關代碼中打斷點發現請
鴻蒙原生應用再新丁!學習強國 入局鴻蒙 來自 #HarmonyOS# 微博5月23日消息 中央宣傳部宣傳輿情研究中心宣佈,將基於HarmonyOS NEXT鴻蒙星河版啓動“學習強國”App鴻蒙原生應用開發!“學習強國”App將爲鴻蒙生態帶
鴻蒙原生應用再新丁!芒果TV 入局鴻蒙 來自 #HarmonyOS# 微博5月21日消息 深受年輕人喜愛的@芒果TV 宣佈完成鴻蒙原生應用Beta版開發🎉芒果TV獨家精品內容結合HarmonyOS NEXT創新能力,將爲用戶帶來更加便捷
1. 背景介紹 1.1. 業務介紹 A平臺與B平臺同屬於同一系統鏈路上,前者主要致力於爲用戶提供註冊入駐服務,後者則專注於提供具體業務操作服務。兩者皆爲運營人員所依賴的在線管理工具。 1.2. 現狀分析 目前這兩個平臺服務於同一業務方,且B
1、查看網絡 docker network ls docker network inspect $container_name 2、docker-compose微服務庫擴容 前提:application.yml配置文件要做相應調整 dock
本文分享自華爲雲社區《通過HPA+CronHPA組合應對業務複雜彈性伸縮場景》,作者:雲容器大未來。 背景 在k8s集羣中,容器水平自動伸縮(HPA),可以根據容器資源的使用量,在設置好的副本範圍內,自動擴縮容工作負載副本數(repli
導讀 本文主要講解了MVEL表達式和責任鏈設計模式相結合一起的消息處理解決方案設計、解耦消息處理節點以及方便代碼維護擴展。通過“訂單拆單消息”的接入作爲具體實踐案例,簡要闡述了MVEL表達式和Apache Chain職責鏈設計模式應用場景。
DevExtreme擁有高性能的HTML5 / JavaScript小部件集合,使您可以利用現代Web開發堆棧(包括React,Angular,ASP.NET Core,jQuery,Knockout等)構建交互式的Web應用程序。從Ang