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

📄 rotation.cpp

📁 CIRRUS 93XX系列windows mobile 6.0 BSP
💻 CPP
字号:
#include "windows.h"
#include "resource.h"

#include <cpl.h>
#include <devload.h>


int  ChangeAngle( int  NewAngle)
{
   DEVMODE DevMode;

   int RotationAngles;
   int CurrentAngle;


   //
   // Check for rotation support by getting the rotation angles supported.
   //

   memset (&DevMode, 0, sizeof (DevMode));
   DevMode.dmSize   = sizeof (DevMode);
   DevMode.dmFields = DM_DISPLAYQUERYORIENTATION;

   if (DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(NULL, &DevMode, NULL, CDS_TEST, NULL))
   {
      RotationAngles = DevMode.dmDisplayOrientation;
      //RETAILMSG(1, (L"ChangeDisplaySettingsEx supports these rotation angles %d", RotationAngles));
   }
   else
   {
      RETAILMSG(1, (L"ChangeDisplaySettingsEx failed to get the supported rotation angles."));
      RotationAngles = -1;
   }
   //
   // Get the current rotation angle.
   //
   memset(&DevMode, 0, sizeof (DevMode));
   DevMode.dmSize   = sizeof (DevMode);
   DevMode.dmFields = DM_DISPLAYORIENTATION;

   if (DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(NULL, &DevMode, NULL, CDS_TEST, NULL))
   {
      CurrentAngle = DevMode.dmDisplayOrientation;
      //RETAILMSG(1, (L"ChangeDisplaySettingsEx reports the current rotation as %d", CurrentAngle));
   }
   else
   { 
      RETAILMSG(1, (L"ChangeDisplaySettingsEx failed to get the current rotation angle."));
      CurrentAngle = -1;
   }

   //
   // Rotate to the "new" angle.
   //

   if( NewAngle <0 )
	   return  CurrentAngle; 

   if( CurrentAngle >= 0  &&  (NewAngle !=CurrentAngle)  ) {

      memset(&DevMode, 0, sizeof (DevMode));
      DevMode.dmSize               = sizeof (DevMode);
      DevMode.dmFields             = DM_DISPLAYORIENTATION;
      DevMode.dmDisplayOrientation = NewAngle;

      if (DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx(NULL, &DevMode, NULL, CDS_RESET, NULL))
      {
         //RETAILMSG(1, (L"ChangeDisplaySettingsEx changed rotation angle to %d", NewAngle));
      }
      else
      {
         RETAILMSG(1, (L"ChangeDisplaySettingsEx failed to change the rotation angle to %d", NewAngle));
      }
   }

   return 0;
}







#define DIALOG_CLASS    TEXT("Dialog")

#define MAX_UFN_DEVICE	10


static HINSTANCE g_hInstance;
static int		 g_cInitCount=0;

static HANDLE hDevice;
static int  iCurrentDevice;
static int  iTotlDevice;



BOOL InitListWindow( HWND  hWnd )
{
	int i;

	int iCurrentSelected;
	int iCurrAngle;
	TCHAR cstemp[][10]={L"0",L"90",L"180",L"270"	};

	
	for( i=0; i< 4 ;i++)
	{
		SendDlgItemMessage(  hWnd, IDC_ANGLE, CB_ADDSTRING, 0, (LPARAM)cstemp[i] );
	}							   


	iCurrAngle=ChangeAngle(-1);

	switch( iCurrAngle ) {

	default:
	case DMDO_0:
		iCurrentSelected=0;
		break;
	case DMDO_90:
		iCurrentSelected=1;
		break;
	case DMDO_180:
		iCurrentSelected=2;
		break;
	case DMDO_270:
		iCurrentSelected=3;
		break;
	}

//  iCurrentSelected=SendDlgItemMessage(  hWnd, IDC_COMBO_SELECT, CB_FINDSTRING, 0, (LPARAM)current_device.szName);

	SendDlgItemMessage(  hWnd, IDC_ANGLE, CB_SETCURSEL, iCurrentSelected, 0);

	return TRUE;
}

BOOL TryChangeAngle ( HWND hWnd )
{
	int iDeviceSelected;
//	int iTrueAngle;
	int iAngleCode;

//	TCHAR cstemp[20];

	iDeviceSelected=SendDlgItemMessage(  hWnd, IDC_ANGLE, CB_GETCURSEL, 0, 0);
/*
	if( CB_ERR !=iDeviceSelected )	{

		SendDlgItemMessage(  hWnd, IDC_ANGLE, CB_GETLBTEXT ,  iDeviceSelected, (LPARAM)cstemp);
	}

	iTrueAngle=watoi( cstemp );
*/
	switch( iDeviceSelected ) {

	default:
	case 0:
		iAngleCode=DMDO_0;
		break;
	case 1:
		iAngleCode=DMDO_90;
		break;
	case 2:
		iAngleCode=DMDO_180;
		break;
	case 3:
		iAngleCode=DMDO_270;
		break;
	}

	ChangeAngle( iAngleCode );


	return FALSE;
}

BOOL CALLBACK MainDlgProc( HWND hWnd,  UINT uMsg,   WPARAM wParam,   LPARAM lParam)
{
	switch ( uMsg )
	{
	case WM_INITDIALOG:
		InitListWindow( hWnd );

//		SetWindowText( hWnd, (LPCTSTR)LoadString(g_hInstance, IDS_STRING_TITLE, NULL, 0) );
		break;

	case WM_COMMAND:
		{
			switch( LOWORD ( wParam ) )
			{
			case IDOK:
				{
					TryChangeAngle ( hWnd );

				}
				EndDialog(hWnd, 1 );
				break;
			case IDCANCEL:
				EndDialog(hWnd, 0 );
				break;
			}

		   break;
		}
	default:
		break;
	}


	return FALSE;
}




// --------------------------------------------------------
extern "C" BOOL WINAPI DllEntry(PVOID hmod, ULONG ulReason, PCONTEXT pctx OPTIONAL)
// --------------------------------------------------------
{
   if (ulReason == DLL_PROCESS_ATTACH){
        g_hInstance = (HINSTANCE)hmod;
   }

   return TRUE;


}

// --------------------------------------------------------
extern "C" LONG CALLBACK CPlApplet(HWND hwndCPL, UINT message, LPARAM lParam1, LPARAM lParam2)
// --------------------------------------------------------
{
   static         iInitCount = 0;
   LPNEWCPLINFO   lpncpli;

   switch (message) {
   case CPL_INIT:
      // nothing to do on init
	   if( CreateEvent(   NULL, 0,0,L"Display-Rotation-2006-03-28") )
	   {
		   if( ERROR_ALREADY_EXISTS ==GetLastError( ) )
			   return FALSE;
	   }
	   return TRUE;


   case CPL_GETCOUNT:
      // only one applet in this .CPL
      return (LONG)1;  

   case CPL_NEWINQUIRE:        // third message, sent once per app

      ASSERT(0 == lParam1);
      
      lpncpli = (LPNEWCPLINFO) lParam2;

      lpncpli->dwSize = (DWORD) sizeof(NEWCPLINFO);
      lpncpli->dwFlags = 0;
      lpncpli->dwHelpContext = 0;
      lpncpli->lData = 0;
      lpncpli->hIcon = LoadIcon (g_hInstance,(LPCTSTR) MAKEINTRESOURCE(IDI_ROTATION));
      lpncpli->szHelpFile[0] = '\0';

	  wcscpy(lpncpli->szName,TEXT("Rotation Setting"));
	  lpncpli->szInfo[0]=0;
//      LOADSTRING (IDS_TITLE, lpncpli->szName);
//      LOADSTRING (IDS_INFO, lpncpli->szInfo);

      break;

   case CPL_DBLCLK:
	   {
			HWND hPrevWnd = FindWindow(DIALOG_CLASS, 
				(LPCTSTR)LoadString(g_hInstance, IDS_STRING_TITLE, NULL, 0));
			if (hPrevWnd)
			{
			   // if the window already exists, switch to it because it is almost 
			   // guaranteed to be a previous instance of this applet
			   SetForegroundWindow((HWND)((DWORD)hPrevWnd | 0x00000001));
			   break;
			}

		   DialogBox( g_hInstance, MAKEINTRESOURCE( IDD_ROTATION), NULL, MainDlgProc );
	   }
      break;

   case CPL_STOP:

   case CPL_EXIT:
      // close hwnd
      g_cInitCount--;
      break;

   default:
      break;
   }

   return 0;
}  // CPlApplet

⌨️ 快捷键说明

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