From e00eb376f45ead6e5c5eccd79810d16ce72999b0 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 6 Jan 2011 15:01:31 +0000 Subject: modification bouton acceleration --- Horloge/HorlogeDlg.cpp | 117 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-) (limited to 'Horloge/HorlogeDlg.cpp') diff --git a/Horloge/HorlogeDlg.cpp b/Horloge/HorlogeDlg.cpp index 5ec075a..8f83b07 100644 --- a/Horloge/HorlogeDlg.cpp +++ b/Horloge/HorlogeDlg.cpp @@ -14,6 +14,9 @@ static char THIS_FILE[] = __FILE__; #endif + +UINT g_uTBBC = RegisterWindowMessage(L"TaskbarButtonCreated"); // for taskbar shell integration + ///////////////////////////////////////////////////////////////////////////// // CHorlogeDlg dialog @@ -24,6 +27,7 @@ CHorlogeDlg::CHorlogeDlg(CWnd* pParent /*=NULL*/) m_busnumber = _T(""); m_big_speed = FALSE; m_filename = _T(""); + m_pTaskBarlist = NULL; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); @@ -46,6 +50,7 @@ void CHorlogeDlg::DoDataExchange(CDataExchange* pDX) DDX_Text(pDX, IDC_FILENAME, m_filename); //}}AFX_DATA_MAP DDX_Control(pDX, IDC_FILEPROGRESS, file_progress); + DDX_Control(pDX, IDC_SPIN1, m_speed_spin); } BEGIN_MESSAGE_MAP(CHorlogeDlg, CDialog) @@ -67,7 +72,11 @@ BEGIN_MESSAGE_MAP(CHorlogeDlg, CDialog) ON_BN_CLICKED(IDC_FILE, OnFile) ON_BN_CLICKED(IDC_NORMAL_SPEED, OnNormalSpeed) ON_LBN_DBLCLK(IDC_APPLIST, OnDblclkApplist) + ON_REGISTERED_MESSAGE( g_uTBBC, CHorlogeDlg::OnCreateThumbToolBar ) //}}AFX_MSG_MAP +// ON_BN_DOUBLECLICKED(IDC_FORWARD, &CHorlogeDlg::OnBnDoubleclickedForward) +// ON_BN_DOUBLECLICKED(IDC_BACKWARD, &CHorlogeDlg::OnBnDoubleclickedBackward) +ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, &CHorlogeDlg::OnDeltaposSpin1) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// @@ -82,8 +91,6 @@ BOOL CHorlogeDlg::OnInitDialog() //SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon - ((CButton*)GetDlgItem(IDC_FORWARD))->SetIcon( AfxGetApp()->LoadIcon(IDI_FORWARD)); - ((CButton*)GetDlgItem(IDC_BACKWARD))->SetIcon(AfxGetApp()->LoadIcon(IDI_BACKWARD)); ((CButton*)GetDlgItem(IDC_PAUSE))->SetIcon(AfxGetApp()->LoadIcon(IDI_PAUSE)); ((CButton*)GetDlgItem(IDC_START))->SetIcon(AfxGetApp()->LoadIcon(IDI_START)); ((CButton*)GetDlgItem(IDC_NORMAL_SPEED))->SetIcon(AfxGetApp()->LoadIcon(IDI_NORMAL_SPEED)); @@ -119,7 +126,92 @@ BOOL CHorlogeDlg::OnInitDialog() return TRUE; // return TRUE unless you set the focus to a control } +LRESULT CHorlogeDlg::OnCreateThumbToolBar( WPARAM, LPARAM ) +{ + AddThumbarButtons(); + return 0; +} + +void CHorlogeDlg::AddThumbarButtons() +{ + // Initialize the pointer. You can also do this in the constructor. + // Remember to release after use + if( NULL == m_pTaskBarlist ) + { + CoCreateInstance( CLSID_TaskbarList, NULL, CLSCTX_ALL, + IID_ITaskbarList3, (void**)&m_pTaskBarlist); + } + + m_pTaskBarlist->HrInit(); + + // We mention that, we're specifying bitmap, tooltpi and other flags. + // This is mask, only specified parameters will be taken from structure + THUMBBUTTONMASK dwMask = THB_BITMAP | THB_TOOLTIP | THB_FLAGS; + + // Create the images from a single bitmap which contains + // buttons seperated 16pix width. Like we handle toolbar buttons + CImageList ImageList; + ImageList.Create( MAKEINTRESOURCE( IDB_BITMAP_PAUSE), 16, 2, RGB( 0xFF,0,0xFF)); + + // Prepare the thumbar buttons + THUMBBUTTON thbButtons[2]; + thbButtons[0].dwMask = dwMask; + // This can be any integer required on handling button events + thbButtons[0].iId = IDB_THB_BUTTON_START; + thbButtons[0].iBitmap = 0; + lstrcpy( thbButtons[0].szTip, TEXT("Start")); + thbButtons[0].dwFlags = THBF_ENABLED | THBF_DISMISSONCLICK; + + thbButtons[1].dwMask = dwMask; + thbButtons[1].iId = IDB_THB_BUTTON_PAUSE; + thbButtons[1].iBitmap = 1; + thbButtons[1].dwFlags = THBF_ENABLED/*THBF_DISABLED*/ | THBF_DISMISSONCLICK; + lstrcpy( thbButtons[1].szTip, TEXT("Pause")); + + // Declare the image list that contains the button images. + m_pTaskBarlist->ThumbBarSetImageList(m_hWnd, ImageList.GetSafeHandle()); + + // Attach the toolbar to the thumbnail. + m_pTaskBarlist->ThumbBarAddButtons(m_hWnd, ARRAYSIZE(thbButtons), thbButtons); + + // In this program we're using the interface later, so not releasing now. + // It's Ok to release if finished using. We can create again when necessary +} + + +BOOL CHorlogeDlg::OnCommand(WPARAM wParam, LPARAM lParam) +{ + UINT CommandID = LOWORD( wParam ); + if( IDB_THB_BUTTON_START == CommandID ) + { + OnStart(); + } + else if( IDB_THB_BUTTON_PAUSE == CommandID ) + { + OnPause(); + } + else + return CDialog::OnCommand(wParam, lParam); +} + +void CHorlogeDlg::OnBnClickedButton1() +{ + + THUMBBUTTONMASK dwMask = THB_FLAGS; + + THUMBBUTTON thbButtons[2] = { }; + thbButtons[0].dwMask = dwMask; + thbButtons[0].iId = IDB_THB_BUTTON_START; + thbButtons[0].dwFlags = THBF_DISABLED| THBF_DISMISSONCLICK; + + thbButtons[1].dwMask = dwMask; + thbButtons[1].iId = IDB_THB_BUTTON_PAUSE; + thbButtons[1].dwFlags = THBF_ENABLED | THBF_DISMISSONCLICK; + + m_pTaskBarlist->ThumbBarUpdateButtons( m_hWnd, ARRAYSIZE(thbButtons), thbButtons ); + +} // 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. @@ -259,17 +351,21 @@ void CHorlogeDlg::OnBackward() bus->SendMsg("SetClock Rate=%.2f",rate); } + void CHorlogeDlg::OnForward() { rate += 0.5; m_Speed.Format(TEXT("%.2f"), rate ); bus->SendMsg("SetClock Rate=%.2f",rate); } + + void CHorlogeDlg::OnNormalSpeed() { rate = 1.0; m_Speed.Format(TEXT("%.2f"), rate ); bus->SendMsg("SetClock Rate=%.2f",rate); + m_speed_spin.SetPos( 0 ); } @@ -345,3 +441,20 @@ void CHorlogeDlg::OnFile() } } + + +void CHorlogeDlg::OnDeltaposSpin1(NMHDR *pNMHDR, LRESULT *pResult) +{ + LPNMUPDOWN pNMUpDown = reinterpret_cast(pNMHDR); + if ( rate <= 0.5 && pNMUpDown->iDelta < 0 ) + { + *pResult = 1; + } + else + { + rate += 0.5 * pNMUpDown->iDelta; + m_Speed.Format(TEXT("%.2f"), rate ); + bus->SendMsg("SetClock Rate=%.2f",rate); + *pResult = 0; + } +} -- cgit v1.1