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

📄 appproc.cpp

📁 Windows mobile下的透明控件(皮肤控件) 当前Windows mobile下的皮肤控件还很少
💻 CPP
字号:

#include "AppProc.h"
#include <commctrl.h>
#include <imaging.h>
#include <initguid.h>
#include <imgguids.h>
#include <shlwapi.h>
#include "MainForm.h"

const	WCHAR		g_lszSkinName[CII_MAX][MAX_DIR_STR] =
{
	{L"FormClient.png"},
	{L"EditNormal.png"},
	{L"EditDis.png"},
	{L"BttNormal.png"},
	{L"BttDown.png"},
	{L"BttFocus.png"},
	{L"BttDis.png"},
	{L"CheckBoxNormal.png"},
	{L"CheckBoxCheck.png"},
	{L"CheckBoxNormalDis.png"},
	{L"CheckBoxCheckDis.png"},
	{L"RadioBoxNormal.png"},
	{L"RadioBoxCheck.png"},
	{L"RadioBoxNormalDis.png"},
	{L"RadioBoxCheckDis.png"},
	{L"Label.png"},
	{L"Panel.png"}
};

/*********************************************************************************************
*								CAppProc													 *
*																							 *
*		YCode Y代码 YCtrl Y控件 Windows Mobile 透明控件 2008 YCtrl 1.0						 *
*			作者:卢益贵 QQ:48092788 luyigui.blog.nnsky.com									 *
*																							 *
**********************************************************************************************/
CApp::CApp()
{
	SetCursorBusy();

	m_pForms = new CList;
	m_hOldCursor = NULL;
	GetModuleFileName( 0, (LPWSTR)m_lszExeDir, MAX_DIR_STR);
	int i;
	for( i = lstrlen(m_lszExeDir); i > 0; i-- )
		if( m_lszExeDir[i] == '\\')
		{
			m_lszExeDir[i] = 0;
			break;
		}
	CoInitializeEx(NULL, COINIT_MULTITHREADED);
	for( i = 0; i < CII_MAX; i++ )
		m_pImgSkin[i] = NULL;

	WCHAR wszDir[256] = L"\\Storage Card\\蓝色经典";
	/*HANDLE hf = CreateFile(L"\\Storage Card\\Skin.ini", GENERIC_READ, FILE_SHARE_READ, NULL,  OPEN_EXISTING,
				                   FILE_ATTRIBUTE_NORMAL, NULL);
	if( INVALID_HANDLE_VALUE != hf )
	{
		char szData[256];		
		DWORD Len = 256;
		ReadFile( hf, szData, Len, &Len, NULL );
		if( Len > 0)
		{
			char *pStart = FindText( szData, "DefaultSkin=[" );
			if( pStart )
			{
				pStart += 13;
				char * tmp = pStart;
				while( *tmp )
				{
					if( ']' == *tmp )
						*tmp = 0;
					tmp++;
				}
				MultiByteToWideChar( CP_ACP, 0, pStart, -1, wszDir + 14, 200 );
			}
		}
		CloseHandle( hf );
	}*/

	LoadSkin( wszDir );

	SetCursorDefault();
}

CApp::~CApp()
{
	int i;
	for( i = 0; i < CII_MAX; i++ )
		if( m_pImgSkin[i] )
			m_pImgSkin[i]->Release();

	CForm *pForm;
	while( GetFormCount() )
	{
		pForm = GetForm( 0 );
		delete pForm;
	}

	delete m_pForms;
	CoUninitialize();
}

void CApp::DrawCtrlSkin( HDC hdc, RECT *pRC, CTRLIMGINDEX ciiImgIndex, BOOL bStretch )
{
	if( NULL != m_pImgSkin[ciiImgIndex] )
	{
		if( bStretch )
			m_pImgSkin[ciiImgIndex]->Draw( hdc, pRC, NULL );
		else
		{			
			ImageInfo ii;
			m_pImgSkin[ciiImgIndex]->GetImageInfo( &ii );
			RECT rc;
			rc = *pRC;
			rc.right = rc.left + ii.Width;
			rc.bottom = rc.top + ii.Height;
			m_pImgSkin[ciiImgIndex]->Draw( hdc, &rc, NULL );
		}
	}
}

HRESULT CApp::Run()
{
    MSG msg;

    while( GetMessage( &msg, NULL, 0, 0 ))
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }

    return S_OK;
}

BOOL CApp::CheckMainForm(LPCWSTR lpszClassName, LPCWSTR lpszFormCaption)
{
	HWND hWnd;
	hWnd = FindWindow(lpszClassName, lpszFormCaption);    
    if (hWnd) 
    {
        SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
        return TRUE;
    }else
		return FALSE;
}

void CApp::SetInstance(HINSTANCE hInstance)
{
	m_hInstance = hInstance;
}

HINSTANCE CApp::GetInstance( void )
{
	return m_hInstance;
}

void CApp::LoadSkin( void)
{
	LoadSkin(L"\\Storage Card\\绿色经典");
}

void CApp::LoadSkin( LPCWSTR lpszDir )
{
	int i;

	for( i = 0; i < CII_MAX; i++ )
		if(m_pImgSkin[i])
		{
			m_pImgSkin[i]->Release();
		}

	CString str;

	IImagingFactory *pImgFactory = NULL;
	if ( SUCCEEDED( CoCreateInstance (CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER, 
									  IID_IImagingFactory, (void **)&pImgFactory ) ) )
    {
		for( i = 0; i < CII_MAX; i++ )
		{	
			str = lpszDir;
			str = str + L"\\" + ((LPCWSTR)&g_lszSkinName[i]);
			if( FileExists( str.GetString() ) )
			{
				if( S_OK != pImgFactory->CreateImageFromFile( str.GetString(), &(m_pImgSkin[i])) )
					MessageBox( NULL, str.GetString(), L"皮肤文件打开失败", MB_OK );
			}else
				MessageBox( NULL, str.GetString(), L"以下皮肤文件不存在", MB_OK );
		}
        pImgFactory->Release();
    }
}

void  CApp::AddForm( CForm *pForm )
{
	m_pForms->Add( pForm );
}

void  CApp::DeleteForm( CForm *pForm )
{
	m_pForms->Delete( pForm );
}

int  CApp::GetFormCount( void )
{
	return m_pForms->GetCount();
}

CForm *CApp::GetForm( int nIndex )
{
	return (CForm *)m_pForms->GetItem( nIndex );
}

void CApp::ChangeSkin( LPCWSTR lpszDir )
{
	int i;
	SetCursorBusy();
	LoadSkin( lpszDir );	
	for( i = 0; i < GetFormCount() ; i++ )
		((CForm *)GetForm( i ))->ChangeSkin();
	SetCursorDefault();

	CString fn;
	fn = lpszDir;
	for( i = lstrlen(lpszDir) - 1; i > 0; i-- )
	{
		if( ('\\' == lpszDir[i]) && (lstrlen(lpszDir + i + 1) < 120) )
		{
			fn += L"Skin.Ini";
			HANDLE hf = CreateFile(fn.GetString(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS | CREATE_NEW | OPEN_EXISTING,
				                   FILE_ATTRIBUTE_NORMAL, NULL);
			if( INVALID_HANDLE_VALUE != hf )
			{
				char szfn[256] = "DefaultSkin=[";
				DWORD Len;
				WideCharToMultiByte( CP_ACP, 0, lpszDir + i + 1, -1, szfn + 13, 256 - 12, NULL, NULL );
				Len	= strlen( szfn );
				szfn[Len++] = ']';
				szfn[Len] = 0;
				WriteFile( hf, szfn, Len, &Len, NULL );
				SetEndOfFile( hf );
				CloseHandle( hf );
			}
		}
		--fn;
	}
}

LPCWSTR CApp::GetExeDir( void )
{
	
	return m_lszExeDir;	
}

void CApp::SetCursorBusy( void )
{
	m_hOldCursor = SetCursor( LoadCursor( m_hInstance, IDC_WAIT ) );
}

void CApp::SetCursorDefault( void )
{
	if(	m_hOldCursor )
		SetCursor( m_hOldCursor );
	else
		SetCursor( LoadCursor( m_hInstance, IDC_NO ) );
}

void CApp::Terminate( void )
{
	PostMessage( NULL, WM_QUIT, 0, 0 );
}

CApp		*g_pApp;


/*********************************************************************************************
*								WinMain														 *
*																							 *
*		YCode Y代码 YCtrl Y控件 Windows Mobile 透明控件 2008 YCtrl 1.0						 *
*			作者:卢益贵 QQ:48092788 luyigui.blog.nnsky.com									 *
*																							 *
**********************************************************************************************/
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd )
{
	
	g_pApp = new CApp;

	g_pApp->SetCursorBusy();
	g_pApp->SetInstance( hInstance );
	

	if( FALSE == g_pApp->CheckMainForm( GetMainFormClassName(), GetMainFormCaption() ) )
	{
		CMainForm	*pMainForm;
		pMainForm = new CMainForm();
		pMainForm->SetOnMinQuit( TRUE );
		pMainForm->Show( nShowCmd );

		g_pApp->SetCursorDefault();
		g_pApp->Run();

		delete pMainForm;
	}else
		g_pApp->SetCursorDefault();	

	delete g_pApp;
	return 0;
}
  
  
 

⌨️ 快捷键说明

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