Esempio n. 1
0
/* Responsible for drawing the description, min && max values
*/
static void SliderDrawTextItems(HWND hWnd, HDC hDC, 
                                ITEMID idDesc, ITEMID idMinV, ITEMID idMaxV,
                                double fValue, BOOL bValueOnly)
{
    char szBuffer[RET_BUFFER_LEN];
    char szBuffer2[RET_BUFFER_LEN / 2], xFormat[RET_BUFFER_LEN / 2];
    RECT rect, rTrect;
    WORD wSize;
    HFONT hOldFont;
    HBRUSH hBrBack1;
    ITEMID idWidget, idVertical, idXFormat;
    ATOMID idUnits;
    short nTextHgt, nTitleHgt, nSlideHgt, nSlideLeft, nTwid;

    GetClientRect(hWnd, &rect);
    GetSliderParam(hWnd, &nTitleHgt, &nTextHgt, &nSlideHgt);
    idWidget = KpsGetWidgetFromWindow(hWnd);
    idVertical = KppGetSlotValue(idWidget, lpSNs->idVerticalSN);
    hBrBack1 = KpsSetWidgetTextColor(idWidget, hDC, NULL);
    SetBkMode(hDC, TRANSPARENT);

    if (!bValueOnly)
    {
        hOldFont = KpsSetWidgetFont(idWidget, hDC, TRUE, 1.0);

        /* DESCRIPTION */
        if (idDesc != lpIDs->idNull)
        {
            wSize = KppGetAtomName(idDesc, szBuffer, RET_BUFFER_LEN);
            SetTextAlign(hDC, TA_CENTER);
            TextOut(hDC, rect.right >> 1, HEIGHTPAD, szBuffer, wSize);
        }
Esempio n. 2
0
LRESULT W_CALLBACK SliderWndProc(HWND hWnd, UINT msg, 
				 WPARAM wParam, LPARAM lParam)
{
    HWND hSBWnd;
    LONG lResult;
    ITEMID idWidget, idVertical, idMin = NULLID, idMax = NULLID;
    ITEMID idDesc, idVisible;
    double fMinV, fMaxV, fValue;
    RECT rCrect;
    double dSliderPos;
    BOOL bCommand = TRUE;
    short nTextHgt, nTitleHgt, nSlideHgt, nSlideLeft;

    switch (msg) {
      case WM_SETFOCUS:
          hSBWnd = GetDlgItem(hWnd, HSLIDERID);
          if (!hSBWnd)
              hSBWnd = GetDlgItem(hWnd, VSLIDERID);
          if (hSBWnd)
              SetFocus(hSBWnd);
          break;

      case WM_HSCROLL:
          hSBWnd = GetDlgItem(hWnd, HSLIDERID);
		  SetFocus(hSBWnd);
          idWidget = KpsGetWidgetFromWindow(hWnd);

          if (hSBWnd)
              dSliderPos = (double) GetScrollPos(hSBWnd, SB_CTL);

          switch (wParam) {
            case SB_LINEUP:
                break;

            case SB_LINEDOWN:
                break;

            case SB_PAGEUP:
                dSliderPos -= 1000;
                break;

            case SB_PAGEDOWN:
                dSliderPos += 1000;
                break;

            case SB_THUMBTRACK:
            case SB_THUMBPOSITION:
                dSliderPos = LOWORD(lParam);
                break;

            default:
                bCommand = FALSE;
                break;
          }
          if (bCommand)
          {
              if (dSliderPos > 10000.0)
                  dSliderPos = 10000.0;
              if (dSliderPos < 0.0)
                  dSliderPos = 0.0;

              GetSliderValue(idWidget, hWnd, wParam, dSliderPos);
          }
          break;
      case WM_VSCROLL:
          hSBWnd = GetDlgItem(hWnd, VSLIDERID);
		  SetFocus(hSBWnd);
          idWidget = KpsGetWidgetFromWindow(hWnd);

          if (hSBWnd)
              dSliderPos = (double) GetScrollPos(hSBWnd, SB_CTL);

          switch (wParam){
            case SB_LINEUP:
                break;
            case SB_LINEDOWN:
                break;
            case SB_PAGEUP:
                dSliderPos -= 1000;
                break;
            case SB_PAGEDOWN:
                dSliderPos += 1000;
                break;
            case SB_THUMBTRACK:
            case SB_THUMBPOSITION:
                dSliderPos = (short) LOWORD(lParam);
                break;

            default:
                bCommand = FALSE;
                break;
          }
          if (bCommand)
          {
              if (dSliderPos < -10000.0)
                  dSliderPos = -10000.0;
              if (dSliderPos > 0.0)
                  dSliderPos = 0.0;

              GetSliderValue(idWidget, hWnd, wParam, dSliderPos);
          }
          break;

      case IDG_RESET:
          idWidget = KpsGetWidgetFromWindow(hWnd);
          idVisible = KppGetSlotValue(idWidget, lpSNs->idVisibleSN);
          if (idVisible != lpIDs->idFalse)
          {
              GetClientRect(hWnd, (LPRECT) & rCrect);
              nSlideLeft = (rCrect.right / 2) - (SLIDERPAD / 2);
              GetSliderParam(hWnd, &nTitleHgt, &nTextHgt, &nSlideHgt);
              idVertical = KppGetSlotValue(idWidget, lpSNs->idVerticalSN);

              if (RetrieveSliderData(idWidget, &idMin, &idMax,
                                     (ITEMID *) NULL,
                                     &fMinV, &fMaxV, &fValue, &idDesc))
              {
                  if (idVertical == lpIDs->idTrue)
                  {
                      hSBWnd = GetDlgItem(hWnd, HSLIDERID);
                      if (hSBWnd)
                          DestroyWindow(hSBWnd);

                      hSBWnd = GetDlgItem(hWnd, VSLIDERID);
                      if (!hSBWnd)
                      {
                          hSBWnd = CreateWindow((LPSTR) "Scrollbar",
                                                (LPSTR) NULL,
                                                WS_CHILD | WS_CLIPSIBLINGS |
                                                SBS_VERT,
                                                nSlideLeft,
                                                nTitleHgt + (2 * HEIGHTPAD),
                                                SLIDERPAD, nSlideHgt,
                                                hWnd, VSLIDERID,
                                                hInstThisDll, (LPSTR) NULL);
                          SetScrollRange(hSBWnd, SB_CTL, -10000, 0, TRUE);
                          SetScrollPos(hSBWnd, SB_CTL, 0, TRUE);
                          ShowWindow(hSBWnd, SW_HIDE);
						  SetProp(hSBWnd, HORIZONTAL, FALSE); 

                          if (!lpOrigSliderProc)
                              lpOrigSliderProc =
                                  (FARPROC) GetClassLong(hSBWnd, GCL_WNDPROC);

                          SetWindowLong(hSBWnd, GWL_WNDPROC,
                                        (LONG) NewSliderProc);
                      }
                      else
                          MoveWindow(hSBWnd, nSlideLeft,
                                     nTitleHgt + (2 * HEIGHTPAD),
                                     SLIDERPAD, nSlideHgt, TRUE);
                  }
                  else
                  {
                      hSBWnd = GetDlgItem(hWnd, VSLIDERID);
                      if (hSBWnd)
                          DestroyWindow(hSBWnd);

                      hSBWnd = GetDlgItem(hWnd, HSLIDERID);
                      if (!hSBWnd)
                      {
                          hSBWnd = CreateWindow((LPSTR) "Scrollbar",
                                                (LPSTR) NULL,
                                                WS_CHILD | WS_CLIPSIBLINGS |
                                                SBS_HORZ,
                                                SLIDERPAD,
                                                nTitleHgt + (2 * HEIGHTPAD),
                                                rCrect.right - (2 * SLIDERPAD),
                                                nSlideHgt,
                                                hWnd, HSLIDERID,
                                                hInstThisDll, (LPSTR) NULL);
                          SetScrollRange(hSBWnd, SB_CTL, 0, 10000, TRUE);
                          ShowWindow(hSBWnd, SW_HIDE);
						  SetProp(hSBWnd, HORIZONTAL, TRUE); 

                          if (!lpOrigSliderProc)
                              lpOrigSliderProc =
                                  (FARPROC) GetClassLong(hSBWnd, GCL_WNDPROC);

                          SetWindowLong(hSBWnd, GWL_WNDPROC,
                                        (LONG) NewSliderProc);
                      }
                      else
                          MoveWindow(hSBWnd, SLIDERPAD, nTitleHgt + (2 * HEIGHTPAD),
                           rCrect.right - (2 * SLIDERPAD), nSlideHgt, TRUE);
                  }
              }
              BringWindowToTop(hWnd);
              hSBWnd = GetDlgItem(hWnd, HSLIDERID);
              if (!hSBWnd)
                  hSBWnd = GetDlgItem(hWnd, VSLIDERID);
              if (hSBWnd)
                  ShowWindow(hSBWnd, SW_SHOW);
          }
          InvalidateRect(hWnd, (LPRECT) NULL, TRUE);
          UpdateWindow(hWnd);
          return (LONG) TRUE;

      case WM_SIZE:
          if (wParam == SIZENORMAL)
              KpsSizeWidget(hWnd, LOWORD(lParam), HIWORD(lParam));
          GetClientRect(hWnd, (LPRECT) &rCrect);
          GetSliderParam(hWnd, &nTitleHgt, &nTextHgt, &nSlideHgt);

          hSBWnd = GetDlgItem(hWnd, VSLIDERID);
          if (hSBWnd != NULL)
          {
              nSlideLeft = (rCrect.right / 2) - (SLIDERPAD / 2);
              MoveWindow(hSBWnd, nSlideLeft, nTitleHgt + (2 * HEIGHTPAD),
                         SLIDERPAD, nSlideHgt, TRUE);
          }
          else
          {
              hSBWnd = GetDlgItem(hWnd, HSLIDERID);
              if (hSBWnd)
              {
                  MoveWindow(hSBWnd, SLIDERPAD, nTitleHgt + (2 * HEIGHTPAD),
                           rCrect.right - (2 * SLIDERPAD), nSlideHgt, TRUE);
              }
          }
          break;

      case WM_PAINT:
          lResult = (LONG) KpsDrawWidget(hWnd);
          hSBWnd = GetDlgItem(hWnd, VSLIDERID);
          if (!hSBWnd)
              hSBWnd = GetDlgItem(hWnd, HSLIDERID);
          if (hSBWnd)
          {
              InvalidateRect(hSBWnd, (LPRECT) NULL, TRUE);
              UpdateWindow(hSBWnd);
          }

          return (LONG) lResult;

      default:
          break;
    }

    return DefWindowProc(hWnd, msg, wParam, lParam);
}
LRESULT CALLBACK Settings( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
#define TIMER_ID_S (UINT) 'S'

	static LONG lSlider[ 3 ];
	static int iPathId[ 3 ] = { IDC_EDIT_TARGET1, IDC_EDIT_TARGET2, IDC_EDIT_TARGET3 };
	static int iButtonId[ 3 ] = { IDC_BUTTON_STOP1, IDC_BUTTON_STOP2, IDC_BUTTON_STOP3 };
	static int iTextId[ 3 ] = { IDC_TEXT_TARGET1, IDC_TEXT_TARGET2, IDC_TEXT_TARGET3 };
	static int iSliderId[ 3 ] = { IDC_SLIDER1, IDC_SLIDER2, IDC_SLIDER3 };
	static HWND hWnd;
	static int iMyId;
	static LPTSTR * lpszStatus;
	static TCHAR lpszWindowText[ 1024 ];

	static HFONT hMyFont = NULL;


	switch (message)
	{
		case WM_INITDIALOG:
		{
			hWnd = ( ( LPHACK_PARAMS ) lParam ) -> myHwnd;
			iMyId =  ( ( LPHACK_PARAMS ) lParam ) -> iMyId;
			lpszStatus = ( ( LPHACK_PARAMS ) lParam ) -> lpszStatus;

			
			HDC hDC = GetDC( hDlg );
			
			hMyFont = MyCreateFont( hDC, TEXT( "Verdana" ), 12, TRUE, FALSE );

			

			ReleaseDC( hDlg, hDC );
		

#ifdef _UNICODE
			if( IS_JAPANESE )
			{
				
				MultiByteToWideChar( CP_UTF8, MB_CUTE,
					IS_JAPANESEo ? S_JPNo_1002 : S_JPN_1002,
					-1, lpszWindowText, 1023 );
				SetWindowText( hDlg, lpszWindowText );
			}
			else if( IS_FRENCH )
			{

				MultiByteToWideChar( CP_UTF8, MB_CUTE,
					S_FRE_1002,
					-1, lpszWindowText, 1023 );
				SetWindowText( hDlg, lpszWindowText );
			}
			else if( IS_SPANISH )
			{

				MultiByteToWideChar( CP_UTF8, MB_CUTE,
					S_SPA_1002,
					-1, lpszWindowText, 1023 );
				SetWindowText( hDlg, lpszWindowText );
			}
			else
#endif
			{
				lstrcpy( lpszWindowText, _T( "Limiter control" ) );
				SetWindowText( hDlg, lpszWindowText );
			}

			for( int i = 0; i < 3; i++ )
			{
				lSlider[ i ] = (long) g_Slider[ i ];
				SetDlgItemText( hDlg, iPathId[ i ], g_szTarget[ i ] );
				TCHAR tmpstr[ 100 ];
				wsprintf( tmpstr, TEXT( "%s #&%d" ),
						( ( g_bHack[ i ] )? TEXT( "Unlimit" ) : TEXT( "Limit" ) ),
						i + 1
				);
				SetDlgItemText( hDlg, iButtonId[ i ], tmpstr );
				EnableWindow( GetDlgItem( hDlg, iButtonId[ i ] ), ( g_dwTargetProcessId[ i ] != TARGET_PID_NOT_SET ) );
				EnableWindow( GetDlgItem( hDlg, iSliderId[ i ] ), ( g_dwTargetProcessId[ i ] != TARGET_PID_NOT_SET ) );
				EnableWindow( GetDlgItem( hDlg, iTextId[ i ] ), ( g_dwTargetProcessId[ i ] != TARGET_PID_NOT_SET ) );

				SendDlgItemMessage( hDlg, iSliderId[ i ], TBM_SETRANGE, TRUE, MAKELONG( 1, 99 ) );
				
				
				SendDlgItemMessage( hDlg, iSliderId[ i ], TBM_SETPOS,   TRUE, lSlider[ i ] );

				for( long lPos = 10L; lPos <= 90L; lPos += 10L )
				{
					SendDlgItemMessage( hDlg, iSliderId[ i ], TBM_SETTIC, 0U, lPos );
				}

				SendDlgItemMessage( hDlg, iTextId[ i ], WM_SETFONT, ( WPARAM ) hMyFont, 0L );
				SetSliderText( hDlg, iTextId[ i ] , lSlider[ i ] );
			}

			if( g_dwTargetProcessId[ 2 ] == (DWORD) -1 || g_bHack[ 3 ] )
			{
				SetDlgItemText( hDlg, iButtonId[ 2 ], TEXT( "(Watching)" ) );
				EnableWindow( GetDlgItem( hDlg, iButtonId[ 2 ] ), FALSE );
				EnableWindow( GetDlgItem( hDlg, iTextId[ 2 ] ), TRUE );
			}

			// Anti-Ukagaka
			SetTimer( hDlg, TIMER_ID_S, 500U, (TIMERPROC) NULL );
			break;
		}

		case WM_CTLCOLORSTATIC:
		{
			for( int i = 0; i < 3; i++ )
			{
				HWND hEdit = GetDlgItem( hDlg, iTextId[ i ] );
				if( (HWND) lParam == hEdit )
				{
					HDC hDC = (HDC) wParam;
					SetBkMode( hDC, TRANSPARENT );
					SetBkColor( hDC, GetSysColor( COLOR_3DFACE ) );
					SetTextColor( hDC, RGB( 0,0,0xaa ) );
					return (BOOL) (HBRUSH) GetSysColorBrush( COLOR_3DFACE );
				}
			}
			return 0L;
		}
		
		
		case WM_HSCROLL:
		{
			if( GetDlgItem( hDlg, IDC_SLIDER1 ) == (HWND) lParam && SliderMoved( wParam ) )
			{
				const RECT minirect = { 20L, 20L + 90L * 0L, 479L, 40L + 90L * 0L };
				lSlider[ 0 ] = SendDlgItemMessage( hDlg, IDC_SLIDER1, TBM_GETPOS, 0U, 0L );
				SetSliderText( hDlg, IDC_TEXT_TARGET1, lSlider[ 0 ] );
				g_Slider[ 0 ] = GetSliderParam( lSlider[ 0 ] );
				if( g_bHack[ 0 ] )
				{
					wsprintf( lpszStatus[ 0 ], TEXT( "Target #1 [ -%d%% ]" ),
						g_Slider[ 0 ] );
					InvalidateRect( hWnd, &minirect, 0 );
				}
			}
			else
			if( GetDlgItem( hDlg, IDC_SLIDER2 ) == (HWND) lParam && SliderMoved( wParam ) )
			{
				const RECT minirect = { 20L, 20L + 90L * 1L, 479L, 40L + 90L * 1L };
				lSlider[ 1 ] = SendDlgItemMessage( hDlg, IDC_SLIDER2, TBM_GETPOS, 0U, 0L );
				SetSliderText( hDlg, IDC_TEXT_TARGET2, lSlider[ 1 ] );
				g_Slider[ 1 ] = GetSliderParam( lSlider[ 1 ] );
				if( g_bHack[ 1 ] )
				{
					wsprintf( lpszStatus[ 0 + 4 * 1 ], TEXT( "Target #2 [ -%d%% ]" ),
						g_Slider[ 1 ] );
					InvalidateRect( hWnd, &minirect, 0 );
				}
			}
			else
			if( GetDlgItem( hDlg, IDC_SLIDER3 ) == (HWND) lParam && SliderMoved( wParam ) )
			{
				const RECT minirect = { 20L, 20L + 90L * 2L, 479L, 40L + 90L * 2L };
				lSlider[ 2 ] = SendDlgItemMessage( hDlg, IDC_SLIDER3, TBM_GETPOS, 0U, 0L );
				SetSliderText( hDlg, IDC_TEXT_TARGET3, lSlider[ 2 ] );
				g_Slider[ 2 ] = GetSliderParam( lSlider[ 2 ] );
				if( g_bHack[ 2 ] )
				{
					wsprintf( lpszStatus[ 0 + 4 * 2 ], TEXT( "Target #3 [ -%d%% ]" ),
						g_Slider[ 2 ] );
					InvalidateRect( hWnd, &minirect, 0 );
				}
			}
			break;
		}
		case WM_COMMAND:
		{
			switch( LOWORD( wParam ) )
			{
				case IDOK:
				{
					TCHAR msg[ 4096 ];
					int i;
					for( i = 0; i < 3; i++ )
					{
						if( g_dwTargetProcessId[ i ] != 0UL )
						{
							wsprintf( msg, TEXT( "g_Slider[ %d ] = %d : %s" ), i, (int) g_Slider[ i ], g_szTarget[ i ] );
							WriteDebugLog( msg );
							SetSliderIni( g_szTarget[ i ], (int) g_Slider[ i ] );
						}
					}

					EndDialog( hDlg, TRUE );
					break;
				}
				case IDCANCEL:
				{
					EndDialog( hDlg, FALSE );
					break;
				}
				case IDC_BUTTON_STOP1:
				{
					if( g_bHack[ 0 ] )
					{
						SendMessage( hWnd, WM_USER_STOP, 0U, 0L );
						SetDlgItemText( hDlg, iButtonId[ 0 ], TEXT( "Limit #&1" ) );
					}
					else
					{
						SendMessage( hWnd, WM_USER_RESTART, 0U, 0L );
						SetDlgItemText( hDlg, iButtonId[ 0 ], TEXT( "Unlimit #&1" ) );
					}
					break;
				}
				case IDC_BUTTON_STOP2:
				{
					if( g_bHack[ 1 ] )
					{
						SendMessage( hWnd, WM_USER_STOP, 1U, 0L );
						SetDlgItemText( hDlg, iButtonId[ 1 ], TEXT( "Limit #&2" ) );
					}
					else
					{
						SendMessage( hWnd, WM_USER_RESTART, 1U, 0L );
						SetDlgItemText( hDlg, iButtonId[ 1 ], TEXT( "Unlimit #&2" ) );
					}
					break;
				}
				case IDC_BUTTON_STOP3:
				{
					if( g_bHack[ 2 ] )
					{
						SendMessage( hWnd, WM_USER_STOP, 2U, 0L );
						SetDlgItemText( hDlg, iButtonId[ 2 ], TEXT( "Limit #&3" ) );
					}
					else
					{
						SendMessage( hWnd, WM_USER_RESTART, 2U, 0L );
						SetDlgItemText( hDlg, iButtonId[ 2 ], TEXT( "Unlimit #&3" ) );
					}
					break;
				}
				default:
				{
					break;
				}
			}
			break; // <-- fixed @ 1.1 beta3
		}

		case WM_TIMER:
		{
			SetWindowText( hDlg, lpszWindowText );
			break;
		}
		case WM_DESTROY:
		{
			DeleteFont( hMyFont );
			hMyFont = NULL;
			KillTimer( hDlg, TIMER_ID_S );
			
			break;
		}
		default:
			return 0L;//FALSE;
	}
    return 1L;//TRUE;
}