📄 cprogressctrldlg.cpp
字号:
// CProgressCtrlDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CProgressCtrl.h"
#include "CProgressCtrlDlg.h"
#include "ColourPicker.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
COLORREF m_clrText;
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CColourPicker m_TextColor;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_BUTTON, m_TextColor);
//}}AFX_DATA_MAP
// DDX_ColourPicker(pDX,IDC_BUTTON,m_clrText);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCProgressCtrlDlg dialog
CCProgressCtrlDlg::CCProgressCtrlDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCProgressCtrlDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCProgressCtrlDlg)
m_bShowPercent = FALSE;
m_range = 500;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_clrBk=RGB(0xE6,0xE6,0xFA);// _T("淡紫色") },
m_clrEnd=RGB(0x00,0x93,0x00);// _T("绿色") },
m_clrText=RGB(0x00,0x00,0x00);// _T("黑色") },
m_clrStart=RGB(0xFF,0xFF,0x00);// _T("黄色") },
m_bClr=TRUE;
m_hIcons[0]=AfxGetApp()->LoadIcon(IDI_ICON1);
m_hIcons[1]=AfxGetApp()->LoadIcon(IDI_ICON2);
m_hIcons[2]=AfxGetApp()->LoadIcon(IDI_ICON3);
m_hIcons[3]=AfxGetApp()->LoadIcon(IDI_ICON4);
m_hIcons[4]=AfxGetApp()->LoadIcon(IDI_ICON5);
m_hIcons[5]=AfxGetApp()->LoadIcon(IDI_ICON6);
m_hIcons[6]=AfxGetApp()->LoadIcon(IDI_ICON7);
m_hIcons[7]=AfxGetApp()->LoadIcon(IDI_ICON8);
m_TrayIcon.m_bHidden=FALSE;
}
void CCProgressCtrlDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCProgressCtrlDlg)
DDX_Control(pDX, IDC_BUTTON_TEXT, m_cClrText);
DDX_Control(pDX, IDC_BUTTON_BGD, m_cClrBkGnd);
DDX_Control(pDX, IDC_BUTTON_END, m_cClrEnd);
DDX_Control(pDX, IDC_BUTTON_START, m_cClrStart);
DDX_Control(pDX, IDC_PROGRESS, m_cProgress);
DDX_Check(pDX, IDC_CHECK1, m_bShowPercent);
DDX_Text(pDX, IDC_EDIT1, m_range);
//}}AFX_DATA_MAP
DDX_ColourPicker(pDX,IDC_BUTTON_TEXT,m_clrText);
DDX_ColourPicker(pDX,IDC_BUTTON_START,m_clrStart);
DDX_ColourPicker(pDX,IDC_BUTTON_END,m_clrEnd);
DDX_ColourPicker(pDX,IDC_BUTTON_BGD,m_clrBk);
}
BEGIN_MESSAGE_MAP(CCProgressCtrlDlg, CDialog)
//{{AFX_MSG_MAP(CCProgressCtrlDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_TEST, OnButtonTest)
ON_WM_CREATE()
ON_COMMAND(ID_HIDEWINDOW, OnHidewindow)
ON_COMMAND(ID_SHOWWINDOW, OnShowwindow)
ON_UPDATE_COMMAND_UI(ID_SHOWWINDOW, OnUpdateShowwindow)
ON_UPDATE_COMMAND_UI(ID_HIDEWINDOW, OnUpdateHidewindow)
ON_WM_TIMER()
ON_WM_SIZE()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_TRAYNOTIFY,OnTrayNotification)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCProgressCtrlDlg message handlers
BOOL CCProgressCtrlDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CCProgressCtrlDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCProgressCtrlDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCProgressCtrlDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CAboutDlg::OnOK()
{
// TODO: Add extra validation here
/// m_bActive=TRUE;
CDialog::OnOK();
}
/*void CCProgressCtrlDlg::Oncolour()
{
// TODO: Add your control notification handler code here
CRect rect;
GetWindowRect(rect);
new CColourPopup(CPoint(rect.left,rect.bottom),RGB(0xFF,0xE4,0xE1),this,10,_T("其它颜色…"));
return ;
}*/
void CCProgressCtrlDlg::OnButtonTest()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_cProgress.SetRange(0,m_range);
m_cProgress.ShowPercent(m_bShowPercent);
m_cProgress.SetStartColor(m_clrStart);
m_cProgress.SetEndColor(m_clrEnd);
m_cProgress.SetBkColor(m_clrBk);
m_cProgress.SetTextColor(m_clrText);
for(int i=0;i<=m_range;i++)
{
PeekAndPump();
m_cProgress.SetPos(i);
Sleep(10);
}
}
BOOL PeekAndPump()
{
static MSG msg;
while(::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
{
if(!AfxGetApp()->PumpMessage()){
::PostQuitMessage(0);
return FALSE;
}
}
return TRUE;
}
int CCProgressCtrlDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if(!m_TrayIcon.CreateTray(this,IDR_TRAYPOPUP,_T("演示托盘(任务栏)应用程序"),m_hIcons,8,400,WM_TRAYNOTIFY))
{
AfxMessageBox(_T("Failed to create tray icon"),MB_OK|MB_ICONSTOP);
return -1;
}
SetTimer(3,400,NULL);
return 0;
}
LRESULT CCProgressCtrlDlg::OnTrayNotification(WPARAM wParam, LPARAM lParam)
{
return m_TrayIcon.OnTrayNotification(wParam,lParam);
}
void CCProgressCtrlDlg::OnHidewindow()
{
// TODO: Add your command handler code here
ShowWindow(SW_SHOWMINIMIZED);
ShowWindow(SW_HIDE);
UpdateWindow();
m_TrayIcon.m_bIsWindowNormal=false;
m_TrayIcon.m_bHidden=TRUE;
}
void CCProgressCtrlDlg::OnShowwindow()
{
// TODO: Add your command handler code here
ShowWindow(SW_RESTORE);
SetForegroundWindow();
m_TrayIcon.m_bIsWindowNormal=true;
m_TrayIcon.m_bHidden=FALSE;
}
void CCProgressCtrlDlg::OnUpdateShowwindow(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_TrayIcon.IsHidden())
pCmdUI->SetCheck(TRUE);
else
pCmdUI->SetCheck(FALSE);
}
void CCProgressCtrlDlg::OnUpdateHidewindow(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_TrayIcon.IsShowing())
pCmdUI->SetCheck(TRUE);
else
pCmdUI->SetCheck(FALSE);
}
void CCProgressCtrlDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
m_TrayIcon.OnTimer1(nIDEvent);
CDialog::OnTimer(nIDEvent);
}
void CCProgressCtrlDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(nType==SIZE_MINIMIZED)
{
OnHidewindow();
}
}
/*void CCProgressCtrlDlg::OnAppExitWindow()
{
// TODO: Add your command handler code here
ShowWindow(SW_SHOWMINIMIZED);
ShowWindow(SW_HIDE);
UpdateWindow();
m_TrayIcon.m_bIsWindowNormal=false;
}*/
void CCProgressCtrlDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
BOOL CCProgressCtrlDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
KillTimer(3);
return CDialog::DestroyWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -