//-------------------------------------------------------------------------------------- // OnSetMinMax // Description: Sets the slider range. // // Handler for WM_SLIDER_SET_MIN_MAX message. //-------------------------------------------------------------------------------------- LRESULT OnSetMinMax(HWND hwnd, LONG posMin, LONG posMax, Slider_Info *pInfo) { pInfo->posMin = posMin; pInfo->posMax = posMax; if (pInfo->posThumb < posMin) { SetSliderPosition(hwnd, posMin, pInfo); } else if (pInfo->posThumb > posMax) { SetSliderPosition(hwnd, posMax, pInfo); } return TRUE; }
void SetControlPosition ( int iControlID, int iPosition ) { switch ( g_pControls[iControlID].sType ) { case WINCONTROL_PROGRESS : SetProgressPosition ( iControlID, iPosition ); break; case WINCONTROL_SLIDER : SetSliderPosition ( iControlID, iPosition ); break; case WINCONTROL_SCROLLBAR : SetScrollBarPosition ( iControlID, iPosition ); break; } }
LRESULT OnSetPosition(HWND hwnd, LONG pos, Slider_Info *pInfo) { if (pos < pInfo->posMin || pos > pInfo->posMax) { return FALSE; } else { SetSliderPosition(hwnd, pos, pInfo); return TRUE; } }
LRESULT OnMouseMove(HWND hwnd, LONG x, LONG /*y*/, Slider_Info *pInfo) { // If the control is selected, update the slider position // and notify the owner window. if (pInfo->bThumbDown) { SetSliderPosition(hwnd, PixelToLogical(hwnd, x, pInfo), pInfo); NotifyParent(hwnd, SLIDER_NOTIFY_DRAG, pInfo); } return 0; }
LRESULT OnLButtonDown(HWND hwnd, LONG x, LONG /*y*/, Slider_Info *pInfo) { // Move the slider to the mouse position. SetSliderPosition(hwnd, PixelToLogical(hwnd, x, pInfo), pInfo); // Set the thumb-down flag. pInfo->bThumbDown = TRUE; // Start capturing mouse moves so we can update the slider position. SetCapture(hwnd); // Notify the owner window that the control was selected. NotifyParent(hwnd, SLIDER_NOTIFY_SELECT, pInfo); return 0; }
int MakeControlSlider ( int iControlID, int iStyle, int iExtendedStyle, int iMin, int iMax, int iX, int iY, int iWidth, int iHeight ) { // Assign the style DWORD dwExtendedStyle = GetExtendedStyle ( iExtendedStyle ); DWORD dwSelectStyle = TBS_HORZ | TBS_NOTICKS | TBS_BOTH; switch ( iStyle ) { case 1 : dwSelectStyle = TBS_HORZ | TBS_NOTICKS | TBS_BOTH; break; case 2 : dwSelectStyle = TBS_VERT | TBS_NOTICKS | TBS_BOTH; break; case 3 : dwSelectStyle = TBS_HORZ; break; case 4 : dwSelectStyle = TBS_VERT; break; case 5 : dwSelectStyle = TBS_HORZ | TBS_AUTOTICKS; break; case 6 : dwSelectStyle = TBS_VERT | TBS_AUTOTICKS; break; case 7 : dwSelectStyle = TBS_ENABLESELRANGE; break; } // Create control MaintainGlobalHWND(); if ( !CreateControl ( iControlID, g_pGlob->hWnd, TRACKBAR_CLASS, dwExtendedStyle, dwSelectStyle, "", iX, iY, iWidth, iHeight ) ) return 0; // Ticks always represented by a line SendMessage ( g_pControls[iControlID].hWnd, TBM_SETTICFREQ, (WPARAM)1, 0 ); // Setup control SetSliderRange ( iControlID, iMin, iMax ); SetSliderPosition ( iControlID, iMin+((iMax-iMin)/2) ); // Subclass to get access to all control messages directly g_pControls [ iControlID ].lOriginalWinProc = SetWindowLong ( g_pControls [ iControlID ].hWnd, GWL_WNDPROC, (LONG)SubClassControlWinProc ); // Update safe rects after new addition UpdateSafeRectsArray(); // Success return 1; }