⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mybacklight.cpp

📁 管理手机背景灯状态的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
	switch (uMsg)
	{
		case WM_INITDIALOG:        
			// get current slection
			GetFromRegistry(eBatt,&dwValueChecked,&dwValueUnchecked); 

			dwValue = (dwValueChecked>0?dwValueChecked:dwValueUnchecked)/60;

			hwndSlider = GetDlgItem(hwndDlg,IDC_SLIDER1);
			SendMessage(hwndSlider,TBM_SETRANGE,TRUE,MAKELONG(1, 15));	// range
			SendMessage(hwndSlider,TBM_SETTICFREQ,2,0L);				// tick freq.
			SendMessage(hwndSlider,TBM_SETPAGESIZE,0L,2);				// page up/dn size
			SendMessage(hwndSlider,TBM_SETPOS,TRUE,dwValue);   

			hwndCheck = GetDlgItem(hwndDlg,IDC_CHECK1);
			SendMessage(hwndCheck,BM_SETCHECK,(WPARAM)(dwValueChecked>0?BST_CHECKED:BST_UNCHECKED),0);

			wsprintf(szStatic,_T("%d min(s)"),dwValue);
			SendMessage(GetDlgItem(hwndDlg,IDC_STATIC1),WM_SETTEXT,0,(LPARAM)szStatic);

			GetFromRegistry(eBrightness,&dwValue,NULL);            // get current slection

			hwndSlider = GetDlgItem(hwndDlg,IDC_SLIDER2);
			SendMessage(hwndSlider,TBM_SETRANGE,TRUE,MAKELONG(1, 15));	// range
			SendMessage(hwndSlider,TBM_SETTICFREQ,2,0L);				// tick freq.
			SendMessage(hwndSlider,TBM_SETPAGESIZE,0L,2);				// page up/dn size
			SendMessage(hwndSlider,TBM_SETPOS,TRUE,dwValue);

			wsprintf(szStatic,_T("%d"),dwValue);
			SendMessage(GetDlgItem(hwndDlg,IDC_STATIC2),WM_SETTEXT,0,(LPARAM)szStatic);

			// lParam contains the PROPSHEETPAGE struct; store the HWND into the dword at the end of the struct
			ppsp = (LPPROPSHEETPAGE)lParam;
			*((HWND*)(ppsp + 1)) = hwndDlg;

			return TRUE;
		
		
		case WM_HSCROLL:            // track bar message
			switch LOWORD(wParam) 
			{
				case TB_BOTTOM:
				case TB_THUMBPOSITION:
				case TB_LINEUP:
				case TB_LINEDOWN:
				case TB_PAGEUP:
				case TB_PAGEDOWN:
				case TB_TOP:
					hwndSlider = GetDlgItem(hwndDlg,IDC_SLIDER1);
					if (hwndSlider == (HWND)lParam)
					{
						// The timeout minutes slider
						dwValue = SendMessage(hwndSlider,TBM_GETPOS,0,0);
						wsprintf(szStatic,_T("%d min(s)"),dwValue);
						SendMessage(GetDlgItem(hwndDlg,IDC_STATIC1),WM_SETTEXT,0,(LPARAM)szStatic);
					}
					else
					{
						// The brightness slider
						hwndSlider = GetDlgItem(hwndDlg,IDC_SLIDER2);
						dwValue = SendMessage(hwndSlider,TBM_GETPOS,0,0);
						wsprintf(szStatic,_T("%d"),dwValue);
						SendMessage(GetDlgItem(hwndDlg,IDC_STATIC2),WM_SETTEXT,0,(LPARAM)szStatic);
					}

					return TRUE;
				default:
					// Default case
					return FALSE;
			}
			break;
	}

	return FALSE;
}


////////////////////////////////////////////////////////
//	The DialogProc for the On AC Power property page
//
////////////////////////////////////////////////////////
int CALLBACK ACPowerPageProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
	HWND	hwndSlider;
	HWND	hwndCheck;
	DWORD	dwValueChecked;
	DWORD	dwValueUnchecked;
	DWORD	dwValue;
	TCHAR	szStatic[16];
	LPPROPSHEETPAGE ppsp;

	switch (uMsg)
	{
		case WM_INITDIALOG:        
			// get current slection
			GetFromRegistry(eACPower,&dwValueChecked,&dwValueUnchecked);
			dwValue = (dwValueChecked>0?dwValueChecked:dwValueUnchecked)/60;

			hwndSlider = GetDlgItem(hwndDlg,IDC_SLIDER1);
			SendMessage(hwndSlider,TBM_SETRANGE,TRUE,MAKELONG(1, 15));	// range
			SendMessage(hwndSlider,TBM_SETTICFREQ,2,0L);				// tick freq.
			SendMessage(hwndSlider,TBM_SETPAGESIZE,0L,2);				// page up/dn size
			SendMessage(hwndSlider,TBM_SETPOS,TRUE,dwValue);

			hwndCheck = GetDlgItem(hwndDlg,IDC_CHECK1);
			SendMessage(hwndCheck,BM_SETCHECK,(WPARAM)(dwValueChecked>0?BST_CHECKED:BST_UNCHECKED),0);

			wsprintf(szStatic,_T("%d min(s)"),dwValue);
			SendMessage(GetDlgItem(hwndDlg,IDC_STATIC1),WM_SETTEXT,0,(LPARAM)szStatic);

			// lParam contains the PROPSHEETPAGE struct; store the HWND into the dword at the end of the struct
			ppsp = (LPPROPSHEETPAGE)lParam;
			*((HWND*)(ppsp + 1)) = hwndDlg;

			return TRUE;

		case WM_HSCROLL:            // track bar message
			switch LOWORD(wParam) 
			{
				// Breaks 
				case TB_BOTTOM:
				case TB_THUMBPOSITION:
				case TB_LINEUP:
				case TB_LINEDOWN:
				case TB_PAGEUP:
				case TB_PAGEDOWN:
				case TB_TOP:
					dwValue = SendMessage(GetDlgItem(hwndDlg,IDC_SLIDER1),TBM_GETPOS,0,0);
					wsprintf(szStatic,_T("%d min(s)"),dwValue);
					SendMessage(GetDlgItem(hwndDlg,IDC_STATIC1),WM_SETTEXT,0,(LPARAM)szStatic);
					return TRUE;
				default:
					// Default case
					return FALSE;
			}
			break;
	}

	return FALSE;
}


////////////////////////////////////////////////////////
//	This callback is called when each property page gets
//  created and when it gets released.
////////////////////////////////////////////////////////
UINT CALLBACK PropSheetPageProc(HWND hwnd,UINT uMsg,LPPROPSHEETPAGE ppsp)
{
	HWND	hwndSlider;
	HWND	hwndCheck;
	HWND	hwndDlg;
	DWORD	dwValueChecked=0;
	DWORD	dwValueUnchecked=0;
	DWORD	dwBrightness;

	// Get the HWND of this property page that was tucked at the
	// end of the propsheetpage struct in the WM_INITDIALOG for this page
	hwndDlg = *((HWND*)(ppsp + 1));

	switch(uMsg) {
	case PSPCB_CREATE:
		//Return any non zero value to indicate success
		return 1;
		break;

	case PSPCB_RELEASE:
		//Make this a code block so declaration of iPage is local
		{
			int iPage = (int)ppsp->lParam;
			switch (iPage)
			{
				case ID_BATT:
					dwBrightness = SendMessage(GetDlgItem(hwndDlg,IDC_SLIDER2),TBM_GETPOS,0,0);
					SetToRegistry(eBrightness,dwBrightness,0);

				// Break intentionally left out so code falls through
				case ID_AC:
					hwndCheck = GetDlgItem(hwndDlg,IDC_CHECK1);
					hwndSlider = GetDlgItem(hwndDlg,IDC_SLIDER1);

					if (BST_UNCHECKED == SendMessage(hwndCheck,BM_GETCHECK,0,0))
						dwValueUnchecked = 60 * SendMessage(hwndSlider,TBM_GETPOS,0,0);
					else
						dwValueChecked = 60 * SendMessage(hwndSlider,TBM_GETPOS,0,0);

					SetToRegistry(iPage==ID_BATT?eBatt:eACPower,dwValueChecked,dwValueUnchecked);

					break;

				default:
					// We should never see this case.  If we do we want to know in debug builds.
					ASSERT(false);
					break;
			}

			// Signal the driver that the backlight settings
			// have changed so it reloads them from the registry
			HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, _T("BackLightChangeEvent"));
			if (hEvent != NULL)
				SetEvent(hEvent);
			CloseHandle(hEvent);

			// return value is ignored for this message
			return 0;
		}
		break;
	default:
		// We should never see this case.  If we do we want to know in debug builds.
		ASSERT(false);
		break;
	}
	//return for default case above
	return (UINT)-1;
}


////////////////////////////////////////////////////////
//	The PropSheetProc for the property sheet.
//
////////////////////////////////////////////////////////
int CALLBACK PropSheetProc(HWND hwndDlg,UINT uMsg,LPARAM lParam)
{
	switch (uMsg)
	{
		// Returning COMCTL32_VERSION to this message makes the
		// style of the property sheet to be that of the native
		// Pocket PC ones
		case PSCB_GETVERSION:
			return COMCTL32_VERSION;
		
		// The text copied into the lParam on receipt of this message
		// is displayed as the title of the propertysheet
		case PSCB_GETTITLE:
			wcscpy((TCHAR*)lParam,TEXT("Backlight Settings"));
			break;
		
		// The text copied into the lParam on receipt of this message
		// gets displayed as the link text at the bottom of the
		// propertysheet
		case PSCB_GETLINKTEXT:
			wcscpy((TCHAR*)lParam,TEXT("Go to <file:ctlpnl.exe cplmain.cpl,2,1{another}> applet."));
			break;
			
		default:
			break;
	}
	
	return 0;
}


////////////////////////////////////////////////////////
//	Called to display this applet as a property sheet
//
////////////////////////////////////////////////////////
BOOL CreatePropertySheet(HWND hwndParent, int iApplet)
{
	BOOL bReturn = FALSE;

	PROPSHEETHEADER psh;
	PROPSHEETPAGE ppsp;
	HPROPSHEETPAGE hpsp[2];

	int nPages=2;

	// Set all values for first property page
	ppsp.dwSize = sizeof(PROPSHEETPAGE)+sizeof(HWND); // Extra space at end of struct to tuck page's hwnd in when it's created
	ppsp.dwFlags = PSP_DEFAULT|PSP_USETITLE|PSP_USECALLBACK;
	ppsp.hInstance = g_hInstance;
	ppsp.pszTemplate = (LPTSTR)MAKEINTRESOURCE(IDD_PROPPAGE0);
	ppsp.hIcon = NULL;
	ppsp.pszTitle = TEXT("On Battery Power");
	ppsp.pfnDlgProc = BattPageProc;
	ppsp.lParam = (LONG)ID_BATT;
	ppsp.pfnCallback = PropSheetPageProc;
	ppsp.pcRefParent = NULL;

	hpsp[0] = CreatePropertySheetPage(&ppsp);
	if (NULL == hpsp[0]) {
		//Fail out of function
		return bReturn;
	}

	// Set all values for second perperty page
	ppsp.dwSize = sizeof(PROPSHEETPAGE)+sizeof(HWND); // Extra space at end of struct to tuck page's hwnd in when it's created
	ppsp.dwFlags = PSP_DEFAULT|PSP_USETITLE|PSP_USECALLBACK;
	ppsp.hInstance = g_hInstance;
	ppsp.pszTemplate = (LPTSTR)MAKEINTRESOURCE(IDD_PROPPAGE1);
	ppsp.hIcon = NULL;
	ppsp.pszTitle = TEXT("On AC Power");
	ppsp.pfnDlgProc = ACPowerPageProc;
	ppsp.lParam = (LONG)ID_AC;
	ppsp.pfnCallback = PropSheetPageProc;
	ppsp.pcRefParent = NULL;

	hpsp[1] = CreatePropertySheetPage(&ppsp);
	if (NULL ==hpsp[1]) {
		//Clean up the page we have created
		DestroyPropertySheetPage(hpsp[0]);

		//Fail out of function
		return bReturn;
	}
	
	psh.dwSize				= sizeof(psh);
	psh.dwFlags				= PSH_USECALLBACK|PSH_MAXIMIZE;
	psh.hwndParent			= hwndParent;
	psh.hInstance			= g_hInstance;
	psh.pszCaption			= NULL;
	psh.phpage				= hpsp;
	psh.nPages				= nPages;
	psh.nStartPage			= iApplet > (nPages-1)? (nPages-1): iApplet;
	psh.pfnCallback			= PropSheetProc;

	if(-1 != PropertySheet(&psh)) {
		bReturn = TRUE;
	}
	else 
	{
		//Clean up PropertySheetPages as they weren't used by the PropertySheet
		DestroyPropertySheetPage(hpsp[0]);
		DestroyPropertySheetPage(hpsp[1]);
	}

	return bReturn;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -