Beispiel #1
0
    int SImgX_WIC::LoadFromMemory(void *pBuf,size_t bufLen )
    {
        SASSERT(m_pImgArray == NULL);

        IWICImagingFactory*    factory    = SImgDecoderFactory_WIC::s_wicImgFactory;
        CAutoRefPtr<IWICBitmapDecoder>     decoder;
        CAutoRefPtr<IWICStream> stream ;

        if(FAILED(factory->CreateStream(&stream))) return 0;

        if(FAILED(stream->InitializeFromMemory((BYTE*)pBuf,(DWORD)bufLen))) return 0;

        if(FAILED(factory->CreateDecoderFromStream(stream,NULL,WICDecodeMetadataCacheOnDemand,&decoder))) return 0;

        return _DoDecode(decoder);
    }
Beispiel #2
0
HRESULT RichEditOleBase::Draw(
    DWORD dwDrawAspect, 
    LONG lindex,  
    void *pvAspect, 
    DVTARGETDEVICE *ptd, 
    HDC hdcTargetDev,
    HDC hdcDraw, 
    LPCRECTL lprcBounds,
    LPCRECTL lprcWBounds,
    BOOL ( STDMETHODCALLTYPE *pfnContinue )(ULONG_PTR dwContinue), 
    ULONG_PTR dwContinue)
{
    InvertBorder(hdcDraw, (RECT*)lprcBounds);

    m_rcObj = (RECT*)lprcBounds;
    m_rcObj.InflateRect(-1,-1,-1,-1); // 四周留一个像素给RichEdit画反色框
    m_oleWindow.SetOleWindowRect(m_rcObj);

    CAutoRefPtr<IRegion> rgn;
    GETRENDERFACTORY->CreateRegion(&rgn);
    rgn->CombineRect((RECT*)lprcBounds,RGN_AND);

    CAutoRefPtr<IRenderTarget> pRT;
    GETRENDERFACTORY->CreateRenderTarget(&pRT, m_rcObj.Width(), m_rcObj.Height());

    // 画背景
    HDC hdc = pRT->GetDC(0);
    ::BitBlt(hdc, 0, 0, m_rcObj.Width(), m_rcObj.Height(),
        hdcDraw, m_rcObj.left, m_rcObj.top, 
        SRCCOPY);

    // 画richedit
    m_oleWindow.RedrawRegion(pRT, rgn);

    // 贴到目标DC
    ::BitBlt(hdcDraw, m_rcObj.left, m_rcObj.top, m_rcObj.Width(), m_rcObj.Height(),
        hdc, 0, 0, 
        SRCCOPY);

    pRT->ReleaseDC(hdc);

    return S_OK;
}
Beispiel #3
0
    int SImgX_WIC::_DoDecode( IWICBitmapDecoder * pDecoder )
    {
        SASSERT(m_uImgCount == 0);
        
        IWICImagingFactory*    factory    = SImgDecoderFactory_WIC::s_wicImgFactory;
        CAutoRefPtr<IWICFormatConverter> converter;
        if(FAILED(factory->CreateFormatConverter(&converter))) 
            return 0;

        if(FAILED(pDecoder->GetFrameCount(&m_uImgCount)))  
            return 0;

        m_pImgArray = new SImgFrame_WIC[m_uImgCount];
        for(UINT i = 0; i< m_uImgCount ;i++)
        {
            CAutoRefPtr<IWICBitmapFrameDecode> frame;
            if(SUCCEEDED(pDecoder->GetFrame(i,&frame)))
            {
//                 CAutoRefPtr<IWICMetadataQueryReader> pMetaReader;
//                 pDecoder->GetMetadataQueryReader(&pMetaReader);
//                 if(pMetaReader)
//                 {
//                     PROPVARIANT propValue;
//                     PropVariantInit(&propValue);
//                     HRESULT hr=pMetaReader->GetMetadataByName(L"/grctlext/Delay", &propValue);
//                     if(SUCCEEDED(hr))
//                     {
//                         m_pImgArray[i].SetFrameDelay(propValue.intVal);
//                     }
//                     PropVariantClear(&propValue);
//                 }
                converter->Initialize(frame,
                    m_bPremultiplied?GUID_WICPixelFormat32bppPBGRA:GUID_WICPixelFormat32bppBGRA,
                    WICBitmapDitherTypeNone,NULL,
                    0.f,WICBitmapPaletteTypeCustom);
                CAutoRefPtr<IWICBitmapSource> bmp;
                converter->QueryInterface(IID_PPV_ARGS(&bmp));
                m_pImgArray[i].SetWICBitmapSource(bmp);
            }
        }
        return m_uImgCount;
    }
Beispiel #4
0
	bool initSysResource()
	{
		//加载系统资源
		if(hSysResource == 0) return false;

		BOOL bLoaded = FALSE;
		CAutoRefPtr<IResProvider> sysSesProvider;
		CreateResProvider(RES_PE,(IObjRef**)&sysSesProvider);
		bLoaded = sysSesProvider->Init((WPARAM)hSysResource,0);

		if(bLoaded == TRUE)
		{
			pSouiApp->LoadSystemNamedResource(sysSesProvider);

			//采用hook绘制菜单的边框
			CMenuWndHook::InstallHook(hInstance,_T("_skin.sys.menu.border"));
		}

		return (bLoaded == TRUE);
	}
Beispiel #5
0
    void SScrollText::UpdateScrollInfo(CSize size)
    {
        CAutoRefPtr<IRenderTarget> pRT;
        GETRENDERFACTORY->CreateRenderTarget(&pRT,0,0);
        BeforePaintEx(pRT);
        SIZE sz;
        pRT->MeasureText(m_strText,m_strText.GetLength(),&sz);

        if(sz.cx - size.cx>0)
        {
            m_nScrollWidth = sz.cx;
			if (m_nRollType==1)
			{
				m_nOffset=-size.cx;
			}
			OnShowWindow(IsVisible(TRUE), 0);
        }
        else
        {
            m_nOffset = 0;
            m_nScrollWidth = 0;
        }
    }
Beispiel #6
0
void SItemPanel::Draw(IRenderTarget *pRT,const CRect & rc)
{
    m_style.m_crBg=m_crBk;
    if((m_dwState & WndState_Hover) && m_crHover != CR_INVALID) m_style.m_crBg=m_crHover;
    if((m_dwState & WndState_Check) && m_crSelBk != CR_INVALID) m_style.m_crBg=m_crSelBk;

    //不继承宿主的字体,从系统字体开始
    SPainter painter;
    BeforePaint(pRT,painter);

    CAutoRefPtr<IRegion> rgn;
    pRT->GetClipRegion(&rgn);
    
    pRT->OffsetViewportOrg(rc.left,rc.top);
    if(rgn)
    {
        rgn->Offset(-rc.TopLeft());
    }
    BuildWndTreeZorder();
    RedrawRegion(pRT,rgn);
    pRT->OffsetViewportOrg(-rc.left,-rc.top);
    
    AfterPaint(pRT,painter);
}
Beispiel #7
0
void SItemPanel::OnRedraw(const CRect &rc)
{
    if(m_pFrmHost->IsUpdateLocked()) return;

    CRect rcItem=GetItemRect();
    if(!rcItem.IsRectNull() && m_pFrmHost->IsVisible(TRUE))
    {
        if(m_pItemContainer->IsItemRedrawDelay())
        {
            CRect rc2(rc);
            rc2.OffsetRect(rcItem.TopLeft());
            rc2.IntersectRect(rc2,rcItem);
            m_pFrmHost->InvalidateRect(rc2);
        }else
        {
            IRenderTarget *pRT=OnGetRenderTarget(rc,OLEDC_PAINTBKGND);
            CAutoRefPtr<IRegion> rgn;
            GETRENDERFACTORY->CreateRegion(&rgn);
            rgn->CombineRect(&rc,RGN_COPY);
            RedrawRegion(pRT,rgn);
            OnReleaseRenderTarget(pRT,rc,OLEDC_PAINTBKGND);
        }
    }
}
Beispiel #8
0
//定义唯一的一个R,UIRES对象,ROBJ_IN_CPP是resource.h中定义的宏。
ROBJ_IN_CPP


int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
{
    HRESULT hRes = OleInitialize(NULL);
    SASSERT(SUCCEEDED(hRes));

    int nRet = 0;
    
    SComMgr *pComMgr = new SComMgr;

    HMODULE hSci = LoadLibrary(_T("SciLexer.dll"));
	if(!hSci){
		MessageBox(GetActiveWindow(),_T("Load SciLexer.dll failed! \nCopying third-part/SciLexer/bin/SciLexer.dll to the running folder should resolve the problem!!"),_T("error"),MB_OK|MB_ICONSTOP);
		return -1;
	}

    //将程序的运行路径修改到项目所在目录所在的目录
    TCHAR szCurrentDir[MAX_PATH] = { 0 };
    GetModuleFileName(NULL, szCurrentDir, sizeof(szCurrentDir));
    LPTSTR lpInsertPos = _tcsrchr(szCurrentDir, _T('\\'));
    _tcscpy(lpInsertPos + 1, _T("..\\demos\\uieditor\\"));
    SetCurrentDirectory(szCurrentDir);
    {
        BOOL bLoaded=FALSE;
        CAutoRefPtr<SOUI::IImgDecoderFactory> pImgDecoderFactory;
        CAutoRefPtr<SOUI::IRenderFactory> pRenderFactory;

        bLoaded = pComMgr->CreateRender_GDI((IObjRef**)&pRenderFactory); //SRenderFactory_GDI
        SASSERT_FMT(bLoaded,_T("load interface [render] failed!"));

        bLoaded=pComMgr->CreateImgDecoder((IObjRef**)&pImgDecoderFactory);//SImgDecoderFactory_GDIP
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("imgdecoder"));

        pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);//SImgDecoderFactory_GDIP
        SApplication *theApp = new SApplication(pRenderFactory, hInstance);


		//向app注册自定义类
		theApp->RegisterWndFactory(TplSWindowFactory<SMyButton>());
		theApp->RegisterWndFactory(TplSWindowFactory<SMoveWnd>());
		theApp->RegisterWndFactory(TplSWindowFactory<SFreeMoveWindow>());
		theApp->RegisterWndFactory(TplSWindowFactory<SToolbox>());



		theApp->RegisterWndFactory(TplSWindowFactory<STurn3dView>());

		// extened controls
		theApp->RegisterWndFactory(TplSWindowFactory<SChromeTabCtrl>());//注册ChromeTabCtrl
		theApp->RegisterWndFactory(TplSWindowFactory<SImageMaskWnd>());//注册SImageMaskWnd
		theApp->RegisterWndFactory(TplSWindowFactory<SButtonEx>());
		theApp->RegisterWndFactory(TplSWindowFactory<SWindowEx>());
		theApp->RegisterWndFactory(TplSWindowFactory<SImRichEdit>());
		theApp->RegisterWndFactory(TplSWindowFactory<SImagePlayer>());
		theApp->RegisterWndFactory(TplSWindowFactory<SText>());
		theApp->RegisterWndFactory(TplSWindowFactory<SImageEx>());
		theApp->RegisterWndFactory(TplSWindowFactory<SSplitBar>());
		theApp->RegisterWndFactory(TplSWindowFactory<SImageSwitcher>());

		theApp->RegisterWndFactory(TplSWindowFactory<STabPage2>());//注册STabPage2
		theApp->RegisterWndFactory(TplSWindowFactory<STabCtrl2>());//注册STabCtrl2
		theApp->RegisterWndFactory(TplSWindowFactory<SAnimImg>());//注册SAnimImg
		theApp->RegisterWndFactory(TplSWindowFactory<SGifPlayer>());//注册gif

		theApp->RegisterWindowClass<SListBoxDrop>();
		theApp->RegisterWindowClass<CDropWnd>();

        theApp->RegisterWndFactory(TplSWindowFactory<SPropertyGrid>());//注册属性表控件
        theApp->RegisterWndFactory(TplSWindowFactory<SScrollText>());
        theApp->RegisterWndFactory(TplSWindowFactory<SRotateWindow>());

		//extened skins
		theApp->RegisterSkinFactory(TplSkinFactory<SColorMask>());
		theApp->RegisterSkinFactory(TplSkinFactory<SSkinMutiFrameImg>());
		theApp->RegisterSkinFactory(TplSkinFactory<SSkinVScrollbar>());
		theApp->RegisterSkinFactory(TplSkinFactory<SSkinNewScrollbar>());
		theApp->RegisterSkinFactory(TplSkinFactory<SSkinGif>());
		theApp->RegisterSkinFactory(TplSkinFactory<SSkinAPNG>());
        {
			#ifdef _DEBUG
				HMODULE hSysRes = LoadLibrary(_T("soui-sys-resourced.dll"));		

			#else
				HMODULE hSysRes = LoadLibrary(_T("soui-sys-resource.dll"));		
			#endif

            CAutoRefPtr<IResProvider> sysResProvider;
            CreateResProvider(RES_PE, (IObjRef**)&sysResProvider);
            sysResProvider->Init((WPARAM)hSysRes, 0);
            theApp->LoadSystemNamedResource(sysResProvider);
			FreeLibrary(hSysRes);
        }

		

        CAutoRefPtr<IResProvider>   pResProvider;
#if (RES_TYPE == 0)
        CreateResProvider(RES_FILE, (IObjRef**)&pResProvider);
        if (!pResProvider->Init((LPARAM)_T("uires"), 0))
        {
            SASSERT(0);
            return 1;
        }
#else 
        CreateResProvider(RES_PE, (IObjRef**)&pResProvider);
        pResProvider->Init((WPARAM)hInstance, 0);
#endif
		//如果需要在代码中使用R::id::namedid这种方式来使用控件必须要这一行代码:2016年2月2日,R::id::namedXmlID是由uiresbuilder 增加-h .\res\resource.h idtable 这3个参数后生成的。
		//theApp->InitXmlNamedID(namedXmlID,ARRAYSIZE(namedXmlID),TRUE);
		//theApp->Init(_T("XML_INIT"));  //这一句不在需要了 在AddResProvider时自动执行初始化
		

		theApp->AddResProvider(pResProvider, L"uidef:UIDESIGNER_XML_INIT");   // theApp->AddResProvider(pResProvider, L"uidef:xml_init");



		//设置真窗口处理接口
		CSouiRealWndHandler * pRealWndHandler = new CSouiRealWndHandler();
		theApp->SetRealWndHandler(pRealWndHandler);
		pRealWndHandler->Release();

        ////加载LUA脚本模块。
        //CAutoRefPtr<IScriptModule> pScriptLua;
        //bLoaded=pComMgr->CreateScrpit_Lua((IObjRef**)&pScriptLua);
        //SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("script_lua"));

        ////加载多语言翻译模块。
        //CAutoRefPtr<ITranslatorMgr> trans;
        //bLoaded=pComMgr->CreateTranslator((IObjRef**)&trans);
        //SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("translator"));
        //if(trans)
        //{//加载语言翻译包
        //    theApp->SetTranslator(trans);
        //    pugi::xml_document xmlLang;
        //    if(theApp->LoadXmlDocment(xmlLang,_T("lang_cn"),_T("translator")))
        //    {
        //        CAutoRefPtr<ITranslator> langCN;
        //        trans->CreateTranslator(&langCN);
        //        langCN->Load(&xmlLang.child(L"language"),1);//1=LD_XML
        //        trans->InstallTranslator(langCN);
        //    }
        //}
        
        // BLOCK: Run application
        {			
            CMainDlg dlgMain;
            dlgMain.Create(GetActiveWindow());
            dlgMain.SendMessage(WM_INITDIALOG);
            dlgMain.CenterWindow(dlgMain.m_hWnd);
            dlgMain.ShowWindow(SW_SHOWNORMAL);	
			SStringT uideffile = lpstrCmdLine;		
			if (!uideffile.IsEmpty())
			{
				uideffile.Trim(_T('\"'));
				uideffile += _T("uires.idx");
#ifdef _DEBUG
				SMessageBox(NULL, uideffile, NULL, MB_OK);
#endif
				if(FileIsExist(uideffile))
					dlgMain.OpenProject(uideffile);
			}
            nRet = theApp->Run(dlgMain.m_hWnd);
        }

        delete theApp;
    }
	FreeLibrary(hSci);
    
    delete pComMgr;
    
    OleUninitialize();
    return nRet;
}
Beispiel #9
0
void SQrCtrl::CreateQrImg( SStringT strContent )
{
	CQR_Encode qrEncode;
	int nLevel = 3;
	int nVersion = 0;
	bool bAutoExtent = true;
	int nMaskingNo = -1;
	SStringA strContentA = S_CT2A(strContent, CP_UTF8);
	if (qrEncode.EncodeData(nLevel, nVersion, bAutoExtent, nMaskingNo, strContentA, strContentA.GetLength()))
	{

		if (m_pSkin == NULL)
		{
			int qrSize = qrEncode.m_nSymbleSize + (QR_MARGIN * 2);
			CAutoRefPtr<IBitmap> bmp;
			GETRENDERFACTORY->CreateBitmap(&bmp);
			bmp->Init(qrSize, qrSize);
			LPDWORD pBits = (LPDWORD)bmp->LockPixelBits();
			memset(pBits, 0xFF, qrSize*qrSize * 4);
			int nLineWid = qrSize;
			LPDWORD pLine = pBits + QR_MARGIN*nLineWid;
			for (int i = 0; i < qrEncode.m_nSymbleSize; i++)
			{
				LPDWORD pLineData = pLine + QR_MARGIN;
				for (int j = 0; j < qrEncode.m_nSymbleSize; j++)
				{
					if (qrEncode.m_byModuleData[i][j])
					{
						pLineData[j] = RGBA(0, 0, 0, 255);
					}
				}
				pLine += qrSize;
			}
			bmp->UnlockPixelBits(pBits);
			SetImage(bmp);
		}
		else
		{
			int qrSize = qrEncode.m_nSymbleSize + 2;
			CAutoRefPtr<IBitmap> bmp;
			GETRENDERFACTORY->CreateBitmap(&bmp);
			SIZE skinSize = m_pSkin->GetSkinSize();
			CRect rcWind = GetWindowRect();

			bmp->Init(rcWind.Width(), rcWind.Height());

			CAutoRefPtr<IBitmap> qrbmp;
			GETRENDERFACTORY->CreateBitmap(&qrbmp);
			qrbmp->Init(qrSize, qrSize);
			LPDWORD pBits = (LPDWORD)qrbmp->LockPixelBits();
			memset(pBits, 0x00, qrSize*qrSize * 4);
			int nLineWid = qrSize;
			LPDWORD pLine = pBits + nLineWid;
			for (int i = 0; i < qrEncode.m_nSymbleSize; i++)
			{
				LPDWORD pLineData = pLine + 1;
				for (int j = 0; j < qrEncode.m_nSymbleSize; j++)
				{
					if (qrEncode.m_byModuleData[i][j])
					{
						pLineData[j] = RGBA(0xFF, 0xFF, 0xFF, 0xFF);
					}
				}
				pLine += qrSize;
			}
			qrbmp->UnlockPixelBits(pBits);
			MakeCacheApha(m_pSkin, bmp, qrbmp);
			SetImage(bmp);
		}
	}
}
Beispiel #10
0
void SQrCtrl::MakeCacheApha( ISkinObj *pSkin, IBitmap *_pBitCache, IBitmap *_pBitMask )
{
	CAutoRefPtr<IRenderTarget> pRTDst;
	GETRENDERFACTORY->CreateRenderTarget(&pRTDst, 0, 0);
	CAutoRefPtr<IRenderObj> pOldBmp;
	pRTDst->SelectObject(_pBitCache, &pOldBmp);
	CRect rc(CPoint(0, 0), _pBitCache->Size());
	pSkin->Draw(pRTDst, &rc, 0);
	CAutoRefPtr<IBitmap> bmp;
	GETRENDERFACTORY->CreateBitmap(&bmp);
	if (m_QrRect.IsRectEmpty())
	{
		bmp = _pBitMask;
	}
	else
	{
		bmp->Init(m_QrRect.Width(),	m_QrRect.Height());
		pRTDst->SelectObject(bmp, NULL);
		CRect rcSrc(CPoint(0, 0), _pBitMask->Size());
		rc = CRect(CPoint(0, 0), bmp->Size());
		pRTDst->DrawBitmapEx(rc, _pBitMask, rcSrc, MAKELONG(EM_STRETCH, m_fl));
		pRTDst->SelectObject(pOldBmp);
	}


	int nDesLinePixels = _pBitCache->Width();
	int nDesRowPixels = _pBitCache->Height();
	int nline = bmp->Height();
	int nRow = bmp->Width();
	if ((nDesRowPixels < nRow + m_QrRect.top) || (nDesLinePixels < nline + m_QrRect.left))
		return;
	LPDWORD pBitCache = (LPDWORD)_pBitCache->LockPixelBits();
	LPDWORD pBitMask = (LPDWORD)bmp->LockPixelBits();
	LPDWORD pDst = pBitCache;
	LPDWORD pSrc = pBitMask;
	LPDWORD pLine = pDst + m_QrRect.top * nDesLinePixels;
	for (int line = 0; line < nline; line++)
	{
		LPDWORD pLineData = pLine + m_QrRect.left;
		for (int row = 0; row < nRow; row++)
		{
			LPBYTE byAlpha = (LPBYTE)(pSrc + row);
			if (byAlpha[3] == 0)
			{
				LPDWORD pByteAlpha = (pLineData + row);
				*pByteAlpha =RGBA(0,0,0,0);
			}
		}
		pSrc += nRow;
		pLine += nDesLinePixels;
	}
	_pBitCache->UnlockPixelBits(pBitCache);
	bmp->UnlockPixelBits(pBitMask);
}
Beispiel #11
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpstrCmdLine*/, int /*nCmdShow*/)
{
    HRESULT hRes = OleInitialize(NULL);
    SASSERT(SUCCEEDED(hRes));
    
    int nRet = 0; 
    
    SComMgr * pComMgr = new SComMgr;
    //将程序的运行路径修改到项目所在目录所在的目录
    TCHAR szCurrentDir[MAX_PATH]={0};
    GetModuleFileName( NULL, szCurrentDir, sizeof(szCurrentDir) );
    LPTSTR lpInsertPos = _tcsrchr( szCurrentDir, _T('\\') );
    _tcscpy(lpInsertPos+1,_T("\\..\\360"));
    //SetCurrentDirectory(szCurrentDir);
        
    {

        CAutoRefPtr<SOUI::IImgDecoderFactory> pImgDecoderFactory;
        CAutoRefPtr<SOUI::IRenderFactory> pRenderFactory;
        pComMgr->CreateRender_GDI((IObjRef**)&pRenderFactory);
        pComMgr->CreateImgDecoder((IObjRef**)&pImgDecoderFactory);

        pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);

        SApplication *theApp=new SApplication(pRenderFactory,hInstance);

        CAutoRefPtr<ITranslatorMgr> trans;
        pComMgr->CreateTranslator((IObjRef**)&trans);
        if(trans)
        {
            theApp->SetTranslator(trans);
            pugi::xml_document xmlLang;
            if(xmlLang.load_file(L"Translator/lang_cn.xml"))
            {
                CAutoRefPtr<ITranslator> langCN;
                trans->CreateTranslator(&langCN);
                langCN->Load(&xmlLang.child(L"language"),1);//1=LD_XML
                trans->InstallTranslator(langCN);
            }
        }
        	
        CAutoRefPtr<IResProvider>   pResProvider;
#if (RES_TYPE == 0)
        CreateResProvider(RES_FILE,(IObjRef**)&pResProvider);
        if(!pResProvider->Init((LPARAM)_T("uires"),0))
        {
            SASSERT(0);
            return 1;
        }
#else 
        CreateResProvider(RES_PE,(IObjRef**)&pResProvider);
        pResProvider->Init((WPARAM)hInstance,0);
#endif

        theApp->AddResProvider(pResProvider);
        
		TCHAR xx[MAX_PATH];
		GetCurrentDirectory(MAX_PATH, xx);

        //加载系统资源
        HMODULE hSysResource=LoadLibrary(SYS_NAMED_RESOURCE);
        if(hSysResource)
        {
            CAutoRefPtr<IResProvider> sysSesProvider;
            CreateResProvider(RES_PE,(IObjRef**)&sysSesProvider);
            sysSesProvider->Init((WPARAM)hSysResource,0);
            theApp->LoadSystemNamedResource(sysSesProvider);
        }

        theApp->Init(_T("XML_INIT")); 

        // BLOCK: Run application
        {
            CMainDlg dlgMain;  
            dlgMain.Create(GetActiveWindow(),0,0,0,0);
            dlgMain.SendMessage(WM_INITDIALOG);
            dlgMain.CenterWindow(dlgMain.m_hWnd);
            dlgMain.ShowWindow(SW_SHOWNORMAL);
            nRet=theApp->Run(dlgMain.m_hWnd);
        }

        delete theApp;
    }


    delete pComMgr;
    OleUninitialize();
    return nRet;
}
Beispiel #12
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
{
    HRESULT hRes = OleInitialize(NULL);
    SASSERT(SUCCEEDED(hRes));

    int nRet = 0;
    
    SComMgr *pComMgr = new SComMgr(_T("imgdecoder-gdip"));

    {
        BOOL bLoaded=FALSE;
        CAutoRefPtr<SOUI::IImgDecoderFactory> pImgDecoderFactory;
        CAutoRefPtr<SOUI::IRenderFactory> pRenderFactory;
        bLoaded = pComMgr->CreateRender_GDI((IObjRef**)&pRenderFactory);
        SASSERT_FMT(bLoaded,_T("load interface [render] failed!"));
        bLoaded=pComMgr->CreateImgDecoder((IObjRef**)&pImgDecoderFactory);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("imgdecoder"));

        pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);
        SApplication *theApp = new SApplication(pRenderFactory, hInstance);
        
        theApp->RegisterWndFactory(TplSWindowFactory<SEdit2>());
        theApp->RegisterWndFactory(TplSWindowFactory<SImgCanvas>());
        theApp->RegisterWndFactory(TplSWindowFactory<SFolderTreeList>());

        HMODULE hSysResource=LoadLibrary(SYS_NAMED_RESOURCE);
        if(hSysResource)
        {
            CAutoRefPtr<IResProvider> sysSesProvider;
            CreateResProvider(RES_PE,(IObjRef**)&sysSesProvider);
            sysSesProvider->Init((WPARAM)hSysResource,0);
            theApp->LoadSystemNamedResource(sysSesProvider);
        }

        CAutoRefPtr<IResProvider>   pResProvider;
#if (RES_TYPE == 0)
        //将程序的运行路径修改到项目所在目录所在的目录
        SStringT strPath = theApp->GetAppDir();
        strPath += _T("..\\SoTool\\uires");
        SetCurrentDirectory(strPath);

        CreateResProvider(RES_FILE, (IObjRef**)&pResProvider);
        if (!pResProvider->Init((LPARAM)_T("uires"), 0))
        {
            SASSERT(0);
            return 1;
        }
#else 
        CreateResProvider(RES_PE, (IObjRef**)&pResProvider);
        pResProvider->Init((WPARAM)hInstance, 0);
#endif

        theApp->AddResProvider(pResProvider);

        
        // BLOCK: Run application
        {
            CMainDlg dlgMain;
            dlgMain.Create(GetActiveWindow());
            dlgMain.SendMessage(WM_INITDIALOG);
            dlgMain.CenterWindow(dlgMain.m_hWnd);
            dlgMain.ShowWindow(SW_SHOWNORMAL);
            nRet = theApp->Run(dlgMain.m_hWnd);
        }

        delete theApp;
    }
    
    delete pComMgr;
    
    OleUninitialize();
    return nRet;
}
Beispiel #13
0
ROBJ_IN_CPP

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpstrCmdLine*/, int /*nCmdShow*/)
{
    
    //必须要调用OleInitialize来初始化运行环境
    HRESULT hRes = OleInitialize(NULL);
    SASSERT(SUCCEEDED(hRes));


    //LoadLibrary(L"E:\\soui.taobao\\richedit\\Debug\\riched20.dll");
    
    /* XML预编译前面加载效率比较
    pugi::xml_document doc;
    
    LARGE_INTEGER perf;
    QueryPerformanceFrequency(&perf);
    LARGE_INTEGER t1,t2;
    QueryPerformanceCounter(&t1);
    doc.load_file(L"e:\\play.xml",pugi::parse_default,pugi::encoding_utf8);
    QueryPerformanceCounter(&t2);
    doc.save_file(L"e:\\play1.xml");
    
    
    doc.save_bin(L"e:\\paly.xml.bin");
    pugi::xml_document doc2;
    LARGE_INTEGER t21,t22;
    QueryPerformanceCounter(&t21);
    doc2.load_bin_file(L"e:\\paly.xml.bin");
    QueryPerformanceCounter(&t22);
    doc2.save_file(L"e:\\play2.xml");
    
    LONGLONG SP1 = (t2.QuadPart-t1.QuadPart)*1000000/perf.QuadPart;        
    LONGLONG SP2 = (t22.QuadPart-t21.QuadPart)*1000000/perf.QuadPart;
    
    SStringW str;
    str.Format(L"!!!!!sp2=%d,sp1=%d\n",(int)SP2,(int)SP1);
    MessageBoxW(GetActiveWindow(),str,L"span",MB_OK);
    return 0;    
    */
    int nRet = 0; 

    //使用imgdecoder-png图片解码模块演示apng动画
    SComMgr *pComMgr = new SComMgr(_T("imgdecoder-png"));
    

    {

        int nType=MessageBox(GetActiveWindow(),_T("选择渲染类型:\n[yes]: Skia\n[no]:GDI\n[cancel]:Quit"),_T("select a render"),MB_ICONQUESTION|MB_YESNOCANCEL);
        if(nType == IDCANCEL)
        {
            nRet = -1;
            goto exit;
        }


        //定义一组类SOUI系统中使用的类COM组件
        //CAutoRefPtr是一个SOUI系统中使用的智能指针类
        CAutoRefPtr<IImgDecoderFactory> pImgDecoderFactory; //图片解码器,由imagedecoder-wid.dll模块提供
        CAutoRefPtr<IRenderFactory> pRenderFactory;         //UI渲染模块,由render-gdi.dll或者render-skia.dll提供
        CAutoRefPtr<ITranslatorMgr> trans;                  //多语言翻译模块,由translator.dll提供
        CAutoRefPtr<IScriptFactory> pScriptLua;              //lua脚本模块,由scriptmodule-lua.dll提供
        CAutoRefPtr<ILog4zManager>  pLogMgr;                //log4z对象
        
        BOOL bLoaded=FALSE;
        //从各组件中显式创建上述组件对象
        
        
        if(nType == IDYES)
            bLoaded = pComMgr->CreateRender_Skia((IObjRef**)&pRenderFactory);
        else
            bLoaded = pComMgr->CreateRender_GDI((IObjRef**)&pRenderFactory);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),nType==IDYES?_T("render_skia"):_T("render_gdi"));
        bLoaded=pComMgr->CreateImgDecoder((IObjRef**)&pImgDecoderFactory);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("imgdecoder"));
        bLoaded=pComMgr->CreateTranslator((IObjRef**)&trans);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("translator"));

        if(pComMgr->CreateLog4z((IObjRef**)&pLogMgr))
        if(pLogMgr){
            pLogMgr->createLogger("soui");//support output soui trace infomation to log
            pLogMgr->start();
        }
        
        //为渲染模块设置它需要引用的图片解码模块
        pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);

        //定义一个唯一的SApplication对象,SApplication管理整个应用程序的资源
        SApplication *theApp=new SApplication(pRenderFactory,hInstance);
        
        theApp->SetLogManager(pLogMgr);
        LOGF("demo","test "<<100 << L"wchar");
        SLOGFMTE("log output using ansi format,str=%s, tick=%u","test",GetTickCount());
        SLOGFMTE(L"log output using unicode format,str=%s, tick=%u",L"中文",GetTickCount());
        
        //控件注册要放到AddResProvider前: 2016年3月8日
        
        //向SApplication系统中注册由外部扩展的控件及SkinObj类
        SWkeLoader wkeLoader;
        if(wkeLoader.Init(_T("wke.dll")))        
        {
            theApp->RegisterWndFactory(TplSWindowFactory<SWkeWebkit>());//注册WKE浏览器
        }
        theApp->RegisterWindowClass<SMatrixWindow>();//
        theApp->RegisterWindowClass<SFreeMoveWindow>();//
        theApp->RegisterWindowClass<SClock>();//
        theApp->RegisterWindowClass<SGifPlayer>();//theApp中增加方法:RegisterWindowClass,替换RegisterWndFactory(TplSWindowFactory<SGifPlayer>())
        theApp->RegisterSkinFactory(TplSkinFactory<SSkinGif>());//注册SkinGif
        theApp->RegisterSkinFactory(TplSkinFactory<SSkinAPNG>());//注册SSkinAPNG
        theApp->RegisterSkinFactory(TplSkinFactory<SSkinVScrollbar>());//注册纵向滚动条皮肤

        theApp->RegisterWndFactory(TplSWindowFactory<SIPAddressCtrl>());//注册IP控件
        theApp->RegisterWndFactory(TplSWindowFactory<SPropertyGrid>());//注册属性表控件
        theApp->RegisterWndFactory(TplSWindowFactory<SChromeTabCtrl>());//注册ChromeTabCtrl
        theApp->RegisterWndFactory(TplSWindowFactory<SIECtrl>());//注册IECtrl
        theApp->RegisterWndFactory(TplSWindowFactory<SChatEdit>());//注册ChatEdit
        theApp->RegisterWndFactory(TplSWindowFactory<SScrollText>());//注册SScrollText
        theApp->RegisterWndFactory(TplSWindowFactory<SDesktopDock>());//注册SDesktopDock
        theApp->RegisterWndFactory(TplSWindowFactory<SImageMaskWnd>());//注册SImageMaskWnd
        theApp->RegisterWndFactory(TplSWindowFactory<SRatingBar>());//注册SRatingBar
        if(SUCCEEDED(CUiAnimation::Init()))
        {
            theApp->RegisterWndFactory(TplSWindowFactory<SUiAnimationWnd>());//注册动画控件
        }
        theApp->RegisterWndFactory(TplSWindowFactory<SFlyWnd>());//注册飞行动画控件
        theApp->RegisterWndFactory(TplSWindowFactory<SFadeFrame>());//注册渐显隐动画控件
        theApp->RegisterWndFactory(TplSWindowFactory<SRadioBox2>());//注册RadioBox2
        theApp->RegisterWndFactory(TplSWindowFactory<SCalendar2>());//注册SCalendar2

        SSkinGif::Gdiplus_Startup();
        
        //如果需要在代码中使用R::id::namedid这种方式来使用控件必须要这一行代码:2016年2月2日,R::id::namedXmlID是由uiresbuilder 增加-h .\res\resource.h idtable 这3个参数后生成的。
        theApp->InitXmlNamedID(namedXmlID,ARRAYSIZE(namedXmlID),TRUE);
        
        //将程序的运行路径修改到demo所在的目录
        SStringT strResDir = theApp->GetAppDir();
        strResDir += _T("\\..\\demos\\demo");
        SetCurrentDirectory(strResDir);
        //SOUI系统总是从appdir去查找资源
        theApp->SetAppDir(strResDir);

        //定义一人个资源提供对象,SOUI系统中实现了3种资源加载方式,分别是从文件加载,从EXE的资源加载及从ZIP压缩包加载
        CAutoRefPtr<IResProvider>   pResProvider;
#if (RES_TYPE == 0)//从文件加载
        CreateResProvider(RES_FILE,(IObjRef**)&pResProvider);
        if(!pResProvider->Init((LPARAM)_T("uires"),0))
        {
            CreateResProvider(RES_PE,(IObjRef**)&pResProvider);
            if(!pResProvider->Init((WPARAM)hInstance,0))
            {
                SASSERT(0);
                delete theApp;
                nRet = 1;
                goto exit;
            }
        }
#elif (RES_TYPE==1)//从EXE资源加载
        CreateResProvider(RES_PE,(IObjRef**)&pResProvider);
        pResProvider->Init((WPARAM)hInstance,0);
#elif (RES_TYPE==2)//从ZIP包加载
        bLoaded=pComMgr->CreateResProvider_ZIP((IObjRef**)&pResProvider);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("resprovider_zip"));

        ZIPRES_PARAM param;
        param.ZipFile(pRenderFactory, _T("uires.zip"),"souizip");
        bLoaded = pResProvider->Init((WPARAM)&param,0);
        SASSERT(bLoaded);
#endif
        //将创建的IResProvider交给SApplication对象
        theApp->AddResProvider(pResProvider);

        //创建一个http服务器,用来从资源中加载flash
        CMemFlash   memFlash;

        CHTTPServer flashSvr(&memFlash);
        flashSvr.Start(CMemFlash::HomeDir(),"",82,0);

        if(trans)
        {//加载语言翻译包
            theApp->SetTranslator(trans);
            pugi::xml_document xmlLang;
            if(theApp->LoadXmlDocment(xmlLang,_T("lang_cn"),_T("translator")))
            {
                CAutoRefPtr<ITranslator> langCN;
                trans->CreateTranslator(&langCN);
                langCN->Load(&xmlLang.child(L"language"),1);//1=LD_XML
                trans->InstallTranslator(langCN);
            }
        }
#if defined(DLL_CORE) && !defined(_WIN64)
        //加载LUA脚本模块,注意,脚本模块只有在SOUI内核是以DLL方式编译时才能使用。
        bLoaded=pComMgr->CreateScrpit_Lua((IObjRef**)&pScriptLua);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("scirpt_lua"));
        theApp->SetScriptFactory(pScriptLua);
#endif//DLL_CORE

        
        //加载系统资源
        HMODULE hSysResource=LoadLibrary(SYS_NAMED_RESOURCE);
        if(hSysResource)
        {
            CAutoRefPtr<IResProvider> sysSesProvider;
            CreateResProvider(RES_PE,(IObjRef**)&sysSesProvider);
            sysSesProvider->Init((WPARAM)hSysResource,0);
            theApp->LoadSystemNamedResource(sysSesProvider);
        }
        //采用hook绘制菜单的边框
        CMenuWndHook::InstallHook(hInstance,L"_skin.sys.menu.border");
        
        //加载全局资源描述XML
        //theApp->Init(_T("xml_init")); 不再需要这句,在AddResProvider时自动执行初始化
        
        //演示R.color.xxx,R.string.xxx在代码中的使用。
        COLORREF crRed = GETCOLOR(R.color.red);
        SStringW strTitle = GETSTRING(R.string.title);
        
		SNotifyCenter *pNotifyCenter = new SNotifyCenter;
        {
            //创建并显示使用SOUI布局应用程序窗口,为了保存窗口对象的析构先于其它对象,把它们缩进一层。
            CMainDlg dlgMain;  
            dlgMain.Create(GetActiveWindow(),0,0,800,650);

            dlgMain.GetNative()->SendMessage(WM_INITDIALOG);
            dlgMain.CenterWindow();
            dlgMain.ShowWindow(SW_SHOWNORMAL);

            SmileyCreateHook  smileyHook; //不知道MainDlg里哪块和mhook冲突了,在win10中,如果hook放到dlgmain.create前会导致hook失败。
            nRet=theApp->Run(dlgMain.m_hWnd);
        }
		delete pNotifyCenter;

        theApp->UnregisterWindowClass<SGifPlayer>();
        //应用程序退出
        delete theApp; 
        
        if(pLogMgr)
        {
            pLogMgr->stop();
        }
        
        flashSvr.Shutdown();

        //卸载菜单边框绘制hook
        CMenuWndHook::UnInstallHook();
        CUiAnimation::Free();
                
        SSkinGif::Gdiplus_Shutdown();
    }
exit:
    delete pComMgr;
    

    OleUninitialize();

    return nRet;
}
Beispiel #14
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpstrCmdLine*/, int /*nCmdShow*/)
{
    HRESULT hRes = OleInitialize(NULL);
    SASSERT(SUCCEEDED(hRes));
    
    int nRet = 0; 

    SComLoader imgDecLoader;
    SComLoader renderLoader;
    //将程序的运行路径修改到项目所在目录所在的目录
    TCHAR szCurrentDir[MAX_PATH]={0};
    GetModuleFileName( NULL, szCurrentDir, sizeof(szCurrentDir) );
    LPTSTR lpInsertPos = _tcsrchr( szCurrentDir, _T('\\') );
    _tcscpy(lpInsertPos+1,_T(".."));
    SetCurrentDirectory(szCurrentDir);
        
    {

        CAutoRefPtr<SOUI::IImgDecoderFactory> pImgDecoderFactory;
        CAutoRefPtr<SOUI::IRenderFactory> pRenderFactory;
        imgDecLoader.CreateInstance(COM_IMGDECODER,(IObjRef**)&pImgDecoderFactory);
        renderLoader.CreateInstance(COM_RENDER_GDI,(IObjRef**)&pRenderFactory);

        pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);

        SApplication *theApp=new SApplication(pRenderFactory,hInstance);

        HMODULE hSysResource=LoadLibrary(SYS_NAMED_RESOURCE);
        if(hSysResource)
        {
            CAutoRefPtr<IResProvider> sysSesProvider;
            CreateResProvider(RES_PE,(IObjRef**)&sysSesProvider);
            sysSesProvider->Init((WPARAM)hSysResource,0);
            theApp->LoadSystemNamedResource(sysSesProvider);
        }
        
        	
        CAutoRefPtr<IResProvider>   pResProvider;
        CreateResProvider(RES_PE,(IObjRef**)&pResProvider);
        pResProvider->Init((WPARAM)hInstance,0);

        theApp->AddResProvider(pResProvider);
        
        theApp->RegisterWndFactory(TplSWindowFactory<SIECtrl>());

        theApp->Init(_T("XML_INIT")); 

        // BLOCK: Run application
        {
            CMainDlg dlgMain;  
            dlgMain.Create(GetActiveWindow(),0,0,0,0);
            dlgMain.SendMessage(WM_INITDIALOG);
            dlgMain.CenterWindow(dlgMain.m_hWnd);
            dlgMain.ShowWindow(SW_SHOWNORMAL);
            nRet=theApp->Run(dlgMain.m_hWnd);
        }

        delete theApp;
    }

    OleUninitialize();
    return nRet;
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpstrCmdLine*/, int /*nCmdShow*/)
{
    HRESULT hRes = CoInitialize(NULL);

    SOUI::CAutoRefPtr<SOUI::IRenderFactory> pRenderFactory=NULL;
	SComMgr * pComMgr = new SComMgr;
	///GDI渲染器
	pComMgr->CreateRender_GDI((IObjRef**)&pRenderFactory);
	
	///图片解码器
	SOUI::CAutoRefPtr<SOUI::IImgDecoderFactory> pImgDecoderFactory;
	pComMgr->CreateImgDecoder((IObjRef**)&pImgDecoderFactory);
	pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);
	
	
	SOUI::SApplication *theApp=new SApplication(pRenderFactory,hInstance);

     theApp->RegisterWindowClass<SVideoPlayer>();
	CAutoRefPtr<IResProvider>   pResProvider;
	CreateResProvider(RES_PE,(IObjRef**)&pResProvider);
	if(pResProvider)
	{
	    HMODULE hSysResource=LoadLibrary(_T("kkplayerdemoUI.dll"));
		BOOL ret=pResProvider->Init((WPARAM)hSysResource,0);
	    theApp->AddResProvider(pResProvider);
	}

   
	//加载系统资源
	HMODULE hSysResource=LoadLibrary(SYS_NAMED_RESOURCE);
	if(hSysResource){
		CAutoRefPtr<IResProvider> sysSesProvider;
		CreateResProvider(RES_PE,(IObjRef**)&sysSesProvider);

		sysSesProvider->Init((WPARAM)hSysResource,0);
		theApp->LoadSystemNamedResource(sysSesProvider);
	}

	
	
	CAutoRefPtr<ITranslatorMgr> trans;
	pComMgr->CreateTranslator((IObjRef**)&trans);
	if(trans)
	{
	        theApp->SetTranslator(trans);
            pugi::xml_document xmlLang;
            if(theApp->LoadXmlDocment(xmlLang,_T("lang_cn"),_T("translator"))){
                CAutoRefPtr<ITranslator> langCN;
                trans->CreateTranslator(&langCN);
                langCN->Load(&xmlLang.child(L"language"),1);//1=LD_XML
                trans->InstallTranslator(langCN);
            }
	}


	

	int 	nRet=0;
	
	SOUI::CMainDlg dlgMain;
	dlgMain.Create(NULL,WS_POPUP|WS_CLIPCHILDREN| WS_CLIPSIBLINGS,0,0,0,0,0);
	dlgMain.GetNative()->SendMessage(WM_INITDIALOG);
	dlgMain.CenterWindow(dlgMain.m_hWnd);
	dlgMain.ShowWindow(SW_SHOWNORMAL);
	nRet = theApp->Run(dlgMain.m_hWnd);/**/
}
int CMainFrameWork::InitSoUiFrame()
{
	HRESULT hRes = OleInitialize(NULL);
	SASSERT(SUCCEEDED(hRes));

	int nRet = 0; 

	SComMgr * pComMgr = new SComMgr;
	//将程序的运行路径修改到项目所在目录所在的目录
	TCHAR szCurrentDir[MAX_PATH]={0};
	GetModuleFileName( NULL, szCurrentDir, sizeof(szCurrentDir) );
	LPTSTR lpInsertPos = _tcsrchr( szCurrentDir, _T('\\') );
	_tcscpy(lpInsertPos+1,_T("\\..\\TestProject"));
	SetCurrentDirectory(szCurrentDir);

	{
		CAutoRefPtr<SOUI::IImgDecoderFactory> pImgDecoderFactory;
		CAutoRefPtr<SOUI::IRenderFactory> pRenderFactory;
		pComMgr->CreateRender_GDI((IObjRef**)&pRenderFactory);
		pComMgr->CreateImgDecoder((IObjRef**)&pImgDecoderFactory);

		pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);

		SApplication *theApp=new SApplication(pRenderFactory,g_hInstance);

		CAutoRefPtr<IResProvider>   pResProvider;
#if (RES_TYPE == 0)
		CreateResProvider(RES_FILE,(IObjRef**)&pResProvider);
		if(!pResProvider->Init((LPARAM)_T("uires"),0))
		{
			SASSERT(0);
			return 1;
		}
#else 
		CreateResProvider(RES_PE,(IObjRef**)&pResProvider);
		pResProvider->Init((WPARAM)hInstance,0);
#endif

		theApp->AddResProvider(pResProvider);

		CAutoRefPtr<ITranslatorMgr> trans;
		pComMgr->CreateTranslator((IObjRef**)&trans);
		if(trans)
		{
			theApp->SetTranslator(trans);
			pugi::xml_document xmlLang;
			if(theApp->LoadXmlDocment(xmlLang,_T("lang_cn"),_T("translator")))
			{
				CAutoRefPtr<ITranslator> langCN;
				trans->CreateTranslator(&langCN);
				langCN->Load(&xmlLang.child(L"language"),1);//1=LD_XML
				trans->InstallTranslator(langCN);
			}
		}

		 theApp->RegisterWndFactory(TplSWindowFactory<SIPAddressCtrl>());//注册IP控件

		//加载系统资源
		HMODULE hSysResource=LoadLibrary(SYS_NAMED_RESOURCE);
		if(hSysResource)
		{
			CAutoRefPtr<IResProvider> sysSesProvider;
			CreateResProvider(RES_PE,(IObjRef**)&sysSesProvider);
			sysSesProvider->Init((WPARAM)hSysResource,0);
			theApp->LoadSystemNamedResource(sysSesProvider);
		}

		theApp->Init(_T("XML_INIT")); 

		// BLOCK: Run application
		{
			CMainDlg dlgMain;  
			dlgMain.Create(GetActiveWindow(),0,0,0,0);
			dlgMain.SendMessage(WM_INITDIALOG);
			dlgMain.CenterWindow(dlgMain.m_hWnd);
			dlgMain.ShowWindow(SW_SHOWNORMAL);
			nRet=theApp->Run(dlgMain.m_hWnd);
		}

		delete theApp;
	}

	delete pComMgr;
	OleUninitialize();
}
Beispiel #17
0
void SMenuODWnd::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
    CRect rcItem=lpDrawItemStruct->rcItem;
    rcItem.MoveToXY(0,0);
    SMenuItemData *pdmmi=(SMenuItemData*)lpDrawItemStruct->itemData;

    HDC dc(lpDrawItemStruct->hDC);
    CAutoRefPtr<IRenderTarget> pRT;
    GETRENDERFACTORY->CreateRenderTarget(&pRT,rcItem.Width(),rcItem.Height());

    if(pdmmi)
    {
        MENUITEMINFO mii= {sizeof(MENUITEMINFO),MIIM_FTYPE,0};
        HMENU menuPopup=pdmmi->hMenu;
        GetMenuItemInfo(menuPopup,pdmmi->nID,FALSE,&mii);

        BOOL bDisabled = lpDrawItemStruct->itemState & ODS_GRAYED;
        BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
        BOOL bChecked = lpDrawItemStruct->itemState & ODS_CHECKED;
        BOOL bRadio = mii.fType&MFT_RADIOCHECK;
        m_pItemSkin->Draw(pRT,rcItem,bSelected?1:0);    //draw background

        //draw icon
        CRect rcIcon;
        rcIcon.left=rcItem.left+m_nIconMargin;
        rcIcon.right=rcIcon.left+m_szIcon.cx;
        rcIcon.top=rcItem.top+(rcItem.Height()-m_szIcon.cy)/2;
        rcIcon.bottom=rcIcon.top+m_szIcon.cy;
        if(bChecked)
        {
            if(m_pCheckSkin)
            {
                m_pCheckSkin->Draw(pRT,rcIcon,bRadio?1:0);
            }
        }
        else if(pdmmi->itemInfo.iIcon!=-1 && m_pIconSkin)
        {
            m_pIconSkin->Draw(pRT,rcIcon,pdmmi->itemInfo.iIcon);
        }
        rcItem.left=rcIcon.right+m_nIconMargin;

        //draw text
        CRect rcTxt=rcItem;
        rcTxt.DeflateRect(m_nTextMargin,0);

        COLORREF crOld=pRT->SetTextColor(bDisabled?m_crTxtGray:(bSelected?m_crTxtSel:m_crTxtNormal));


        CAutoRefPtr<IFont> oldFont;
        pRT->SelectObject(m_hFont,(IRenderObj**)&oldFont);
        pRT->DrawText(pdmmi->itemInfo.strText,pdmmi->itemInfo.strText.GetLength(),&rcTxt,DT_SINGLELINE|DT_VCENTER|DT_LEFT);
        pRT->SelectObject(oldFont);

        pRT->SetTextColor(crOld);

        if(bSelected && m_pItemSkin->GetStates()>2)
        {
            //draw select mask
            CRect rcItem=lpDrawItemStruct->rcItem;
            rcItem.MoveToXY(0,0);
            m_pItemSkin->Draw(pRT,rcItem,2);
        }
    }
    else  //if(strcmp("sep",pXmlItem->Value())==0)
    {
        m_pItemSkin->Draw(pRT,rcItem,0);    //draw back
        if(m_pIconSkin)
        {
            rcItem.left += m_pIconSkin->GetSkinSize().cx+m_nIconMargin*2;
        }

        if(m_pSepSkin)
            m_pSepSkin->Draw(pRT,&rcItem,0);
        else
        {
            CAutoRefPtr<IPen> pen1,pen2,oldPen;
            pRT->CreatePen(PS_SOLID,RGBA(196,196,196,255),1,&pen1);
            pRT->CreatePen(PS_SOLID,RGBA(255,255,255,255),1,&pen2);
            pRT->SelectObject(pen1,(IRenderObj**)&oldPen);
            POINT pts[2]={{rcItem.left,rcItem.top},{rcItem.right,rcItem.top}};
            pRT->DrawLines(pts,2);
            pRT->SelectObject(pen2);
            pts[0].y++,pts[1].y++;
            pRT->DrawLines(pts,2);
            pRT->SelectObject(oldPen);
        }
    }
    rcItem=lpDrawItemStruct->rcItem;
    
    HDC hmemdc=pRT->GetDC(0);
    BitBlt(dc,rcItem.left,rcItem.top,rcItem.Width(),rcItem.Height(),hmemdc,0,0,SRCCOPY);
    pRT->ReleaseDC(hmemdc);
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
{
    HRESULT hRes = OleInitialize(NULL);
    SASSERT(SUCCEEDED(hRes));

    int nRet = 0;
    
    SComMgr *pComMgr = new SComMgr;

    //将程序的运行路径修改到项目所在目录所在的目录
    TCHAR szCurrentDir[MAX_PATH] = { 0 };
    GetModuleFileName(NULL, szCurrentDir, sizeof(szCurrentDir));
    LPTSTR lpInsertPos = _tcsrchr(szCurrentDir, _T('\\'));
    _tcscpy(lpInsertPos + 1, _T(".."));
    SetCurrentDirectory(szCurrentDir);
    {
        BOOL bLoaded=FALSE;
        CAutoRefPtr<SOUI::IImgDecoderFactory> pImgDecoderFactory;
        CAutoRefPtr<SOUI::IRenderFactory> pRenderFactory;
        bLoaded = pComMgr->CreateRender_GDI((IObjRef**)&pRenderFactory);
        SASSERT_FMT(bLoaded,_T("load interface [render] failed!"));
        bLoaded=pComMgr->CreateImgDecoder((IObjRef**)&pImgDecoderFactory);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("imgdecoder"));

        pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);
        SApplication *theApp = new SApplication(pRenderFactory, hInstance);
        //从DLL加载系统资源
        HMODULE hModSysResource = LoadLibrary(SYS_NAMED_RESOURCE);
        if (hModSysResource)
        {
            CAutoRefPtr<IResProvider> sysResProvider;
            CreateResProvider(RES_PE, (IObjRef**)&sysResProvider);
            sysResProvider->Init((WPARAM)hModSysResource, 0);
            theApp->LoadSystemNamedResource(sysResProvider);
            FreeLibrary(hModSysResource);
        }else
        {
            SASSERT(0);
        }

        CAutoRefPtr<IResProvider>   pResProvider;
#if (RES_TYPE == 0)
        CreateResProvider(RES_FILE, (IObjRef**)&pResProvider);
        if (!pResProvider->Init((LPARAM)_T("uires"), 0))
        {
            SASSERT(0);
            return 1;
        }
#else 
        CreateResProvider(RES_PE, (IObjRef**)&pResProvider);
        pResProvider->Init((WPARAM)hInstance, 0);
#endif

        theApp->AddResProvider(pResProvider);
        theApp->Init(_T("XML_INIT"));

        
        // BLOCK: Run application
        {
            CMainDlg dlgMain;
            dlgMain.Create(GetActiveWindow());
            dlgMain.SendMessage(WM_INITDIALOG);
            dlgMain.CenterWindow(dlgMain.m_hWnd);
            dlgMain.ShowWindow(SW_SHOWNORMAL);
            nRet = theApp->Run(dlgMain.m_hWnd);
        }

        delete theApp;
    }
    
    delete pComMgr;
    
    OleUninitialize();
    return nRet;
}
Beispiel #19
0
BOOL CmfcdemoApp::InitInstance()
{
	// 如果一个运行在 Windows XP 上的应用程序清单指定要
	// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
	//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// 将它设置为包括所有要在应用程序中使用的
	// 公共控件类。
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

	HRESULT hRes = CoInitialize(NULL);
	SASSERT(SUCCEEDED(hRes));

    {//这一个括号很重要,保证里面声明的局部对象在CoUninitialize()之前释放

        SComLoader imgDecLoader;
        SComLoader renderLoader;
        CAutoRefPtr<IImgDecoderFactory> pImgDecoderFactory;
        CAutoRefPtr<IRenderFactory> pRenderFactory;
        imgDecLoader.CreateInstance(COM_IMGDECODER,(IObjRef**)&pImgDecoderFactory);
        renderLoader.CreateInstance(COM_RENDER_GDI,(IObjRef**)&pRenderFactory);

        pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);

        SApplication *pSouiApp=new SApplication(pRenderFactory,theApp.m_hInstance);

        //加载系统资源
        HMODULE hSysResource=LoadLibrary(SYS_NAMED_RESOURCE);
        if(hSysResource)
        {
            CAutoRefPtr<IResProvider> sysSesProvider;
            CreateResProvider(RES_PE,(IObjRef**)&sysSesProvider);
            sysSesProvider->Init((WPARAM)hSysResource,0);
            pSouiApp->LoadSystemNamedResource(sysSesProvider);
        }

        CAutoRefPtr<IResProvider>   pResProvider;
        CreateResProvider(RES_PE,(IObjRef**)&pResProvider);
        pResProvider->Init((WPARAM)theApp.m_hInstance,0);

        pSouiApp->AddResProvider(pResProvider);    //从资源加载皮肤

        //设置真窗口处理接口
        CSouiRealWndHandler * pRealWndHandler = new CSouiRealWndHandler();
        pSouiApp->SetRealWndHandler(pRealWndHandler);
        pRealWndHandler->Release();

        pSouiApp->Init(_T("uidef"),_T("xml")); //初始化SOUI全局资源

	    CmfcdemoDlg dlg;
	    m_pMainWnd = &dlg;
	    dlg.DoModal();
    	
        delete pSouiApp;

    }

	CoUninitialize();

	return FALSE;
}
Beispiel #20
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpstrCmdLine*/, int /*nCmdShow*/)
{
    //必须要调用OleInitialize来初始化运行环境
    HRESULT hRes = OleInitialize(NULL);
    SASSERT(SUCCEEDED(hRes));
    // LoadLibrary(L"E:\\soui.taobao\\richedit\\Debug\\riched20.dll");
        
    int nRet = 0; 

    //使用imgdecoder-png图片解码模块演示apng动画
    SComMgr *pComMgr = new SComMgr(_T("imgdecoder-png"));
    

    {

        int nType=MessageBox(GetActiveWindow(),_T("选择渲染类型:\n[yes]: Skia\n[no]:GDI\n[cancel]:Quit"),_T("select a render"),MB_ICONQUESTION|MB_YESNOCANCEL);
        if(nType == IDCANCEL)
        {
            nRet = -1;
            goto exit;
        }


        //定义一组类SOUI系统中使用的类COM组件
        //CAutoRefPtr是一个SOUI系统中使用的智能指针类
        CAutoRefPtr<IImgDecoderFactory> pImgDecoderFactory; //图片解码器,由imagedecoder-wid.dll模块提供
        CAutoRefPtr<IRenderFactory> pRenderFactory;         //UI渲染模块,由render-gdi.dll或者render-skia.dll提供
        CAutoRefPtr<ITranslatorMgr> trans;                  //多语言翻译模块,由translator.dll提供
        CAutoRefPtr<IScriptFactory> pScriptLua;              //lua脚本模块,由scriptmodule-lua.dll提供

        BOOL bLoaded=FALSE;
        //从各组件中显式创建上述组件对象
        
        if(nType == IDYES)
            bLoaded = pComMgr->CreateRender_Skia((IObjRef**)&pRenderFactory);
        else
            bLoaded = pComMgr->CreateRender_GDI((IObjRef**)&pRenderFactory);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),nType==IDYES?_T("render_skia"):_T("render_gdi"));
        bLoaded=pComMgr->CreateImgDecoder((IObjRef**)&pImgDecoderFactory);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("imgdecoder"));
        bLoaded=pComMgr->CreateTranslator((IObjRef**)&trans);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("translator"));

        //为渲染模块设置它需要引用的图片解码模块
        pRenderFactory->SetImgDecoderFactory(pImgDecoderFactory);

        //定义一个唯一的SApplication对象,SApplication管理整个应用程序的资源
        SApplication *theApp=new SApplication(pRenderFactory,hInstance);
        //将程序的运行路径修改到demo所在的目录
        SStringT strResDir = theApp->GetAppDir();
        strResDir += _T("\\..\\demo");
        SetCurrentDirectory(strResDir);
        //SOUI系统总是从appdir去查找资源
        theApp->SetAppDir(strResDir);

        //定义一人个资源提供对象,SOUI系统中实现了3种资源加载方式,分别是从文件加载,从EXE的资源加载及从ZIP压缩包加载
        CAutoRefPtr<IResProvider>   pResProvider;
#if (RES_TYPE == 0)//从文件加载
        CreateResProvider(RES_FILE,(IObjRef**)&pResProvider);
        if(!pResProvider->Init((LPARAM)_T("uires"),0))
        {
            SASSERT(0);
            delete theApp;
            nRet = 1;
            goto exit;
        }
#elif (RES_TYPE==1)//从EXE资源加载
        CreateResProvider(RES_PE,(IObjRef**)&pResProvider);
        pResProvider->Init((WPARAM)hInstance,0);
#elif (RES_TYPE==2)//从ZIP包加载
        bLoaded=pComMgr->CreateResProvider_ZIP((IObjRef**)&pResProvider);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("resprovider_zip"));

        ZIPRES_PARAM param;
        param.ZipFile(pRenderFactory, _T("uires.zip"),"souizip");
        bLoaded = pResProvider->Init((WPARAM)&param,0);
        SASSERT(bLoaded);
#endif
        //将创建的IResProvider交给SApplication对象
        theApp->AddResProvider(pResProvider);

        //创建一个http服务器,用来从资源中加载flash
        CMemFlash   memFlash;

        CHTTPServer flashSvr(&memFlash);
        flashSvr.Start(CMemFlash::HomeDir(),"",82,0);

        if(trans)
        {//加载语言翻译包
            theApp->SetTranslator(trans);
            pugi::xml_document xmlLang;
            if(theApp->LoadXmlDocment(xmlLang,_T("lang_cn"),_T("translator")))
            {
                CAutoRefPtr<ITranslator> langCN;
                trans->CreateTranslator(&langCN);
                langCN->Load(&xmlLang.child(L"language"),1);//1=LD_XML
                trans->InstallTranslator(langCN);
            }
        }
#ifdef DLL_CORE
        //加载LUA脚本模块,注意,脚本模块只有在SOUI内核是以DLL方式编译时才能使用。
        bLoaded=pComMgr->CreateScrpit_Lua((IObjRef**)&pScriptLua);
        SASSERT_FMT(bLoaded,_T("load interface [%s] failed!"),_T("scirpt_lua"));
        theApp->SetScriptFactory(pScriptLua);
#endif//DLL_CORE

        //向SApplication系统中注册由外部扩展的控件及SkinObj类
        SWkeLoader wkeLoader;
        if(wkeLoader.Init(_T("wke.dll")))        
        {
            theApp->RegisterWndFactory(TplSWindowFactory<SWkeWebkit>());//注册WKE浏览器
        }
        theApp->RegisterWndFactory(TplSWindowFactory<SGifPlayer>());//注册GIFPlayer
        theApp->RegisterSkinFactory(TplSkinFactory<SSkinGif>());//注册SkinGif
        theApp->RegisterSkinFactory(TplSkinFactory<SSkinAPNG>());//注册SSkinAPNG
        theApp->RegisterSkinFactory(TplSkinFactory<SSkinVScrollbar>());//注册纵向滚动条皮肤

        theApp->RegisterWndFactory(TplSWindowFactory<SIPAddressCtrl>());//注册IP控件
        theApp->RegisterWndFactory(TplSWindowFactory<SPropertyGrid>());//注册属性表控件
        theApp->RegisterWndFactory(TplSWindowFactory<SChromeTabCtrl>());//注册ChromeTabCtrl
        theApp->RegisterWndFactory(TplSWindowFactory<SIECtrl>());//注册IECtrl
        theApp->RegisterWndFactory(TplSWindowFactory<SChatEdit>());//注册ChatEdit
        theApp->RegisterWndFactory(TplSWindowFactory<SScrollText>());//注册SScrollText
        theApp->RegisterWndFactory(TplSWindowFactory<SListCtrlEx>());//注册SListCtrlEx
        theApp->RegisterWndFactory(TplSWindowFactory<SDesktopDock>());//注册SDesktopDock
        theApp->RegisterWndFactory(TplSWindowFactory<SImageMaskWnd>());//注册SImageMaskWnd
        theApp->RegisterWndFactory(TplSWindowFactory<SRatingBar>());//注册SRatingBar
        if(SUCCEEDED(CUiAnimation::Init()))
        {
            theApp->RegisterWndFactory(TplSWindowFactory<SUiAnimationWnd>());//注册动画控件
        }
        theApp->RegisterWndFactory(TplSWindowFactory<SFlyWnd>());//注册飞行动画控件
        theApp->RegisterWndFactory(TplSWindowFactory<SFadeFrame>());//注册渐显隐动画控件
        theApp->RegisterWndFactory(TplSWindowFactory<SRadioBox2>());//注册RadioBox2
        theApp->RegisterWndFactory(TplSWindowFactory<SCalendar2>());//注册SCalendar2
        
        SSkinGif::Gdiplus_Startup();
        
        
        //加载系统资源
        HMODULE hSysResource=LoadLibrary(SYS_NAMED_RESOURCE);
        if(hSysResource)
        {
            CAutoRefPtr<IResProvider> sysSesProvider;
            CreateResProvider(RES_PE,(IObjRef**)&sysSesProvider);
            sysSesProvider->Init((WPARAM)hSysResource,0);
            theApp->LoadSystemNamedResource(sysSesProvider);
        }
        //采用hook绘制菜单的边框
        CMenuWndHook::InstallHook(hInstance,L"_skin.sys.menu.border");
        
        //加载全局资源描述XML
        theApp->Init(_T("xml_init")); 

        {
            //创建并显示使用SOUI布局应用程序窗口,为了保存窗口对象的析构先于其它对象,把它们缩进一层。
            CMainDlg dlgMain;  
            dlgMain.Create(GetActiveWindow(),0,0,800,600);
            dlgMain.GetNative()->SendMessage(WM_INITDIALOG);
            dlgMain.CenterWindow();
            dlgMain.ShowWindow(SW_SHOWNORMAL);
            nRet=theApp->Run(dlgMain.m_hWnd);
        }

        //应用程序退出
        delete theApp; 
        
        flashSvr.Shutdown();

        //卸载菜单边框绘制hook
        CMenuWndHook::UnInstallHook();
        CUiAnimation::Free();
                
        SSkinGif::Gdiplus_Shutdown();
    }
exit:
    delete pComMgr;
    OleUninitialize();

    return nRet;
}