Commit d5b0425e authored by 刘乐's avatar 刘乐

增加界面库

parent 53b53a0d
# cmake file for duilib
#Author Qi Gao(monkgau@gmail.com)
#Created: 2012/09/16
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} Root_src)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/Control Control_src)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/Core Core_src)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/Layout Layout_src)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/Utils Utils_src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Control)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Core)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Layout)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Utils)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
add_library(duilib SHARED ${Control_src} ${Core_src} ${Layout_src} ${Utils_src} ${Root_src})
add_definitions(-DUILIB_EXPORTS)
target_link_libraries(duilib comctl32)
set_target_properties(duilib PROPERTIES OUTPUT_NAME "duilib")
add_custom_command(TARGET duilib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${PROJECT_BINARY_DIR}/lib/duilib.dll ${PROJECT_SOURCE_DIR}/bin/duilib.dll)
This diff is collapsed.
#ifndef __UIACTIVEX_H__
#define __UIACTIVEX_H__
#pragma once
struct IOleObject;
namespace DuiLib {
/////////////////////////////////////////////////////////////////////////////////////
//
class CActiveXCtrl;
template< class T >
class CSafeRelease
{
public:
CSafeRelease(T* p) : m_p(p) { };
~CSafeRelease() { if( m_p != NULL ) m_p->Release(); };
T* Detach() { T* t = m_p; m_p = NULL; return t; };
T* m_p;
};
/////////////////////////////////////////////////////////////////////////////////////
//
class DUILIB_API CActiveXUI : public CControlUI, public IMessageFilterUI
{
friend class CActiveXCtrl;
public:
CActiveXUI();
virtual ~CActiveXUI();
LPCTSTR GetClass() const;
LPVOID GetInterface(LPCTSTR pstrName);
UINT GetControlFlags() const;
HWND GetNativeWindow() const;
bool IsDelayCreate() const;
void SetDelayCreate(bool bDelayCreate = true);
bool CreateControl(const CLSID clsid);
bool CreateControl(LPCTSTR pstrCLSID);
HRESULT GetControl(const IID iid, LPVOID* ppRet);
CLSID GetClisd() const;
CDuiString GetModuleName() const;
void SetModuleName(LPCTSTR pstrText);
void SetVisible(bool bVisible = true);
void SetInternVisible(bool bVisible = true);
void SetPos(RECT rc, bool bNeedInvalidate = true);
void Move(SIZE szOffset, bool bNeedInvalidate = true);
bool DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl);
void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
protected:
virtual void ReleaseControl();
virtual bool DoCreateControl();
protected:
CLSID m_clsid;
CDuiString m_sModuleName;
bool m_bCreated;
bool m_bDelayCreate;
IOleObject* m_pUnk;
CActiveXCtrl* m_pControl;
HWND m_hwndHost;
};
} // namespace DuiLib
#endif // __UIACTIVEX_H__
This diff is collapsed.
#ifndef __UIBUTTON_H__
#define __UIBUTTON_H__
#pragma once
namespace DuiLib
{
class DUILIB_API CButtonUI : public CLabelUI
{
public:
CButtonUI();
LPCTSTR GetClass() const;
LPVOID GetInterface(LPCTSTR pstrName);
UINT GetControlFlags() const;
bool Activate();
void SetEnabled(bool bEnable = true);
void DoEvent(TEventUI& event);
LPCTSTR GetNormalImage();
void SetNormalImage(LPCTSTR pStrImage);
LPCTSTR GetHotImage();
void SetHotImage(LPCTSTR pStrImage);
LPCTSTR GetPushedImage();
void SetPushedImage(LPCTSTR pStrImage);
LPCTSTR GetFocusedImage();
void SetFocusedImage(LPCTSTR pStrImage);
LPCTSTR GetDisabledImage();
void SetDisabledImage(LPCTSTR pStrImage);
LPCTSTR GetForeImage();
void SetForeImage(LPCTSTR pStrImage);
LPCTSTR GetHotForeImage();
void SetHotForeImage(LPCTSTR pStrImage);
// Ӧť5״̬ͼ
void SetFiveStatusImage(LPCTSTR pStrImage);
void SetFadeAlphaDelta(BYTE uDelta);
BYTE GetFadeAlphaDelta();
void SetHotBkColor(DWORD dwColor);
DWORD GetHotBkColor() const;
void SetHotTextColor(DWORD dwColor);
DWORD GetHotTextColor() const;
void SetPushedTextColor(DWORD dwColor);
DWORD GetPushedTextColor() const;
void SetFocusedTextColor(DWORD dwColor);
DWORD GetFocusedTextColor() const;
SIZE EstimateSize(SIZE szAvailable);
void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
void PaintText(HDC hDC);
void PaintStatusImage(HDC hDC);
protected:
enum
{
FADE_TIMERID = 11,
FADE_ELLAPSE = 30,
};
UINT m_uButtonState;
DWORD m_dwHotBkColor;
DWORD m_dwHotTextColor;
DWORD m_dwPushedTextColor;
DWORD m_dwFocusedTextColor;
BYTE m_uFadeAlpha;
BYTE m_uFadeAlphaDelta;
TDrawInfo m_diNormal;
TDrawInfo m_diHot;
TDrawInfo m_diHotFore;
TDrawInfo m_diPushed;
TDrawInfo m_diPushedFore;
TDrawInfo m_diFocused;
TDrawInfo m_diDisabled;
};
} // namespace DuiLib
#endif // __UIBUTTON_H__
\ No newline at end of file
#include "stdafx.h"
#include "UICheckBox.h"
namespace DuiLib
{
LPCTSTR CCheckBoxUI::GetClass() const
{
return DUI_CTR_CHECKBOX;
}
LPVOID CCheckBoxUI::GetInterface(LPCTSTR pstrName)
{
if( _tcscmp(pstrName, DUI_CTR_CHECKBOX) == 0 ) return static_cast<CCheckBoxUI*>(this);
return COptionUI::GetInterface(pstrName);
}
void CCheckBoxUI::SetCheck(bool bCheck, bool bTriggerEvent)
{
Selected(bCheck, bTriggerEvent);
}
bool CCheckBoxUI::GetCheck() const
{
return IsSelected();
}
}
#ifndef __UICHECKBOX_H__
#define __UICHECKBOX_H__
#pragma once
namespace DuiLib
{
/// 最普通的单选按钮控件,只有是、否两种结果
/// 派生于COptionUI,只是每组只有一个按钮而已,组名为空,配置文件默认属性举例:
/// <CheckBox name="CheckBox" value="height='20' align='left' textpadding='24,0,0,0' normalimage='file='sys_check_btn.png' source='0,0,20,20' dest='0,0,20,20'' selectedimage='file='sys_check_btn.png' source='20,0,40,20' dest='0,0,20,20'' disabledimage='file='sys_check_btn.png' source='40,0,60,20' dest='0,0,20,20''"/>
class DUILIB_API CCheckBoxUI : public COptionUI
{
public:
LPCTSTR GetClass() const;
LPVOID GetInterface(LPCTSTR pstrName);
void SetCheck(bool bCheck, bool bTriggerEvent=true);
bool GetCheck() const;
};
}
#endif // __UICHECKBOX_H__
This diff is collapsed.
#ifndef __UICOMBO_H__
#define __UICOMBO_H__
#pragma once
namespace DuiLib {
/////////////////////////////////////////////////////////////////////////////////////
//
class CComboWnd;
class DUILIB_API CComboUI : public CContainerUI, public IListOwnerUI
{
friend class CComboWnd;
public:
CComboUI();
LPCTSTR GetClass() const;
LPVOID GetInterface(LPCTSTR pstrName);
void DoInit();
UINT GetControlFlags() const;
CDuiString GetText() const;
void SetEnabled(bool bEnable = true);
CDuiString GetDropBoxAttributeList();
void SetDropBoxAttributeList(LPCTSTR pstrList);
SIZE GetDropBoxSize() const;
void SetDropBoxSize(SIZE szDropBox);
int GetCurSel() const;
bool GetSelectCloseFlag();
void SetSelectCloseFlag(bool flag);
bool SelectItem(int iIndex, bool bTakeFocus = false, bool bTriggerEvent=true);
bool ExpandItem(int iIndex, bool bExpand = true);
int GetExpandedItem() const;
bool SetItemIndex(CControlUI* pControl, int iNewIndex);
bool SetMultiItemIndex(CControlUI* pStartControl, int iCount, int iNewStartIndex);
bool Add(CControlUI* pControl);
bool AddAt(CControlUI* pControl, int iIndex);
bool Remove(CControlUI* pControl, bool bDoNotDestroy=false);
bool RemoveAt(int iIndex, bool bDoNotDestroy=false);
void RemoveAll();
bool Activate();
bool GetShowText() const;
void SetShowText(bool flag);
RECT GetTextPadding() const;
void SetTextPadding(RECT rc);
LPCTSTR GetNormalImage() const;
void SetNormalImage(LPCTSTR pStrImage);
LPCTSTR GetHotImage() const;
void SetHotImage(LPCTSTR pStrImage);
LPCTSTR GetPushedImage() const;
void SetPushedImage(LPCTSTR pStrImage);
LPCTSTR GetFocusedImage() const;
void SetFocusedImage(LPCTSTR pStrImage);
LPCTSTR GetDisabledImage() const;
void SetDisabledImage(LPCTSTR pStrImage);
TListInfoUI* GetListInfo();
UINT GetItemFixedHeight();
void SetItemFixedHeight(UINT nHeight);
int GetItemFont(int index);
void SetItemFont(int index);
UINT GetItemTextStyle();
void SetItemTextStyle(UINT uStyle);
RECT GetItemTextPadding() const;
void SetItemTextPadding(RECT rc);
DWORD GetItemTextColor() const;
void SetItemTextColor(DWORD dwTextColor);
DWORD GetItemBkColor() const;
void SetItemBkColor(DWORD dwBkColor);
LPCTSTR GetItemBkImage() const;
void SetItemBkImage(LPCTSTR pStrImage);
bool IsAlternateBk() const;
void SetAlternateBk(bool bAlternateBk);
DWORD GetSelectedItemTextColor() const;
void SetSelectedItemTextColor(DWORD dwTextColor);
DWORD GetSelectedItemBkColor() const;
void SetSelectedItemBkColor(DWORD dwBkColor);
LPCTSTR GetSelectedItemImage() const;
void SetSelectedItemImage(LPCTSTR pStrImage);
DWORD GetHotItemTextColor() const;
void SetHotItemTextColor(DWORD dwTextColor);
DWORD GetHotItemBkColor() const;
void SetHotItemBkColor(DWORD dwBkColor);
LPCTSTR GetHotItemImage() const;
void SetHotItemImage(LPCTSTR pStrImage);
DWORD GetDisabledItemTextColor() const;
void SetDisabledItemTextColor(DWORD dwTextColor);
DWORD GetDisabledItemBkColor() const;
void SetDisabledItemBkColor(DWORD dwBkColor);
LPCTSTR GetDisabledItemImage() const;
void SetDisabledItemImage(LPCTSTR pStrImage);
int GetItemHLineSize() const;
void SetItemHLineSize(int iSize);
DWORD GetItemHLineColor() const;
void SetItemHLineColor(DWORD dwLineColor);
int GetItemVLineSize() const;
void SetItemVLineSize(int iSize);
DWORD GetItemVLineColor() const;
void SetItemVLineColor(DWORD dwLineColor);
bool IsItemShowHtml();
void SetItemShowHtml(bool bShowHtml = true);
SIZE EstimateSize(SIZE szAvailable);
void SetPos(RECT rc, bool bNeedInvalidate = true);
void Move(SIZE szOffset, bool bNeedInvalidate = true);
void DoEvent(TEventUI& event);
void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
bool DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl);
void PaintText(HDC hDC);
void PaintStatusImage(HDC hDC);
protected:
CComboWnd* m_pWindow;
int m_iCurSel;
bool m_bShowText;
bool m_bSelectCloseFlag;
RECT m_rcTextPadding;
CDuiString m_sDropBoxAttributes;
SIZE m_szDropBox;
UINT m_uButtonState;
TDrawInfo m_diNormal;
TDrawInfo m_diHot;
TDrawInfo m_diPushed;
TDrawInfo m_diFocused;
TDrawInfo m_diDisabled;
TListInfoUI m_ListInfo;
};
} // namespace DuiLib
#endif // __UICOMBO_H__
#include "stdafx.h"
#include "UIDateTime.h"
namespace DuiLib
{
//CDateTimeUI::m_nDTUpdateFlag
#define DT_NONE 0
#define DT_UPDATE 1
#define DT_DELETE 2
#define DT_KEEP 3
class CDateTimeWnd : public CWindowWnd
{
public:
CDateTimeWnd();
void Init(CDateTimeUI* pOwner);
RECT CalPos();
LPCTSTR GetWindowClassName() const;
LPCTSTR GetSuperClassName() const;
void OnFinalMessage(HWND hWnd);
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//LRESULT OnEditChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
protected:
CDateTimeUI* m_pOwner;
HBRUSH m_hBkBrush;
bool m_bInit;
};
CDateTimeWnd::CDateTimeWnd() : m_pOwner(NULL), m_hBkBrush(NULL), m_bInit(false)
{
}
void CDateTimeWnd::Init(CDateTimeUI* pOwner)
{
m_pOwner = pOwner;
m_pOwner->m_nDTUpdateFlag = DT_NONE;
if (m_hWnd == NULL)
{
RECT rcPos = CalPos();
UINT uStyle = WS_CHILD;
Create(m_pOwner->GetManager()->GetPaintWindow(), NULL, uStyle, 0, rcPos);
SetWindowFont(m_hWnd, m_pOwner->GetManager()->GetFontInfo(m_pOwner->GetFont())->hFont, TRUE);
}
if (m_pOwner->GetText().IsEmpty())
::GetLocalTime(&m_pOwner->m_sysTime);
::SendMessage(m_hWnd, DTM_SETSYSTEMTIME, 0, (LPARAM)&m_pOwner->m_sysTime);
::ShowWindow(m_hWnd, SW_SHOWNOACTIVATE);
::SetFocus(m_hWnd);
m_bInit = true;
}
RECT CDateTimeWnd::CalPos()
{
CDuiRect rcPos = m_pOwner->GetPos();
CControlUI* pParent = m_pOwner;
RECT rcParent;
while( pParent = pParent->GetParent() ) {
if( !pParent->IsVisible() ) {
rcPos.left = rcPos.top = rcPos.right = rcPos.bottom = 0;
break;
}
rcParent = pParent->GetClientPos();
if( !::IntersectRect(&rcPos, &rcPos, &rcParent) ) {
rcPos.left = rcPos.top = rcPos.right = rcPos.bottom = 0;
break;
}
}
return rcPos;
}
LPCTSTR CDateTimeWnd::GetWindowClassName() const
{
return _T("DateTimeWnd");
}
LPCTSTR CDateTimeWnd::GetSuperClassName() const
{
return DATETIMEPICK_CLASS;
}
void CDateTimeWnd::OnFinalMessage(HWND hWnd)
{
// Clear reference and die
if( m_hBkBrush != NULL ) ::DeleteObject(m_hBkBrush);
m_pOwner->GetManager()->RemoveNativeWindow(hWnd);
m_pOwner->m_pWindow = NULL;
delete this;
}
LRESULT CDateTimeWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT lRes = 0;
BOOL bHandled = TRUE;
if( uMsg == WM_CREATE ) {
m_pOwner->GetManager()->AddNativeWindow(m_pOwner, m_hWnd);
bHandled = FALSE;
}
else if( uMsg == WM_KILLFOCUS )
{
lRes = OnKillFocus(uMsg, wParam, lParam, bHandled);
}
else if (uMsg == WM_KEYUP && (wParam == VK_DELETE || wParam == VK_BACK))
{
LRESULT lRes = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
m_pOwner->m_nDTUpdateFlag = DT_DELETE;
m_pOwner->UpdateText();
PostMessage(WM_CLOSE);
return lRes;
}
else if (uMsg == WM_KEYUP && wParam == VK_ESCAPE)
{
LRESULT lRes = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
m_pOwner->m_nDTUpdateFlag = DT_KEEP;
PostMessage(WM_CLOSE);
return lRes;
}
// else if( uMsg == OCM_COMMAND ) {
// if( GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE ) lRes = OnEditChanged(uMsg, wParam, lParam, bHandled);
// else if( GET_WM_COMMAND_CMD(wParam, lParam) == EN_UPDATE ) {
// RECT rcClient;
// ::GetClientRect(m_hWnd, &rcClient);
// ::InvalidateRect(m_hWnd, &rcClient, FALSE);
// }
// }
// else if( uMsg == WM_KEYDOWN && TCHAR(wParam) == VK_RETURN ) {
// m_pOwner->GetManager()->SendNotify(m_pOwner, DUI_MSGTYPE_RETURN);
// }
// else if( uMsg == OCM__BASE + WM_CTLCOLOREDIT || uMsg == OCM__BASE + WM_CTLCOLORSTATIC ) {
// if( m_pOwner->GetNativeEditBkColor() == 0xFFFFFFFF ) return NULL;
// ::SetBkMode((HDC)wParam, TRANSPARENT);
// DWORD dwTextColor = m_pOwner->GetTextColor();
// ::SetTextColor((HDC)wParam, RGB(GetBValue(dwTextColor),GetGValue(dwTextColor),GetRValue(dwTextColor)));
// if( m_hBkBrush == NULL ) {
// DWORD clrColor = m_pOwner->GetNativeEditBkColor();
// m_hBkBrush = ::CreateSolidBrush(RGB(GetBValue(clrColor), GetGValue(clrColor), GetRValue(clrColor)));
// }
// return (LRESULT)m_hBkBrush;
// }
else if( uMsg == WM_PAINT) {
if (m_pOwner->GetManager()->IsLayered()) {
m_pOwner->GetManager()->AddNativeWindow(m_pOwner, m_hWnd);
}
bHandled = FALSE;
}
else bHandled = FALSE;
if( !bHandled ) return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
return lRes;
}
LRESULT CDateTimeWnd::OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
LRESULT lRes = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
if (m_pOwner->m_nDTUpdateFlag == DT_NONE)
{
::SendMessage(m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM)&m_pOwner->m_sysTime);
m_pOwner->m_nDTUpdateFlag = DT_UPDATE;
m_pOwner->UpdateText();
}
if ((HWND)wParam != m_pOwner->GetManager()->GetPaintWindow()) {
::SendMessage(m_pOwner->GetManager()->GetPaintWindow(), WM_KILLFOCUS, wParam, lParam);
}
SendMessage(WM_CLOSE);
return lRes;
}
// LRESULT CDateTimeWnd::OnEditChanged(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// {
// if( !m_bInit ) return 0;
// if( m_pOwner == NULL ) return 0;
// // Copy text back
// int cchLen = ::GetWindowTextLength(m_hWnd) + 1;
// LPTSTR pstr = static_cast<LPTSTR>(_alloca(cchLen * sizeof(TCHAR)));
// ASSERT(pstr);
// if( pstr == NULL ) return 0;
// ::GetWindowText(m_hWnd, pstr, cchLen);
// m_pOwner->m_sText = pstr;
// m_pOwner->GetManager()->SendNotify(m_pOwner, DUI_MSGTYPE_TEXTCHANGED);
// return 0;
// }
//////////////////////////////////////////////////////////////////////////
//
CDateTimeUI::CDateTimeUI()
{
::GetLocalTime(&m_sysTime);
m_bReadOnly = false;
m_pWindow = NULL;
m_nDTUpdateFlag=DT_UPDATE;
UpdateText(); // add by:daviyang35 ʼʱʾʱ
m_nDTUpdateFlag = DT_NONE;
}
LPCTSTR CDateTimeUI::GetClass() const
{
return DUI_CTR_DATETIME;
}
LPVOID CDateTimeUI::GetInterface(LPCTSTR pstrName)
{
if( _tcscmp(pstrName, DUI_CTR_DATETIME) == 0 ) return static_cast<CDateTimeUI*>(this);
return CLabelUI::GetInterface(pstrName);
}
UINT CDateTimeUI::GetControlFlags() const
{
return UIFLAG_TABSTOP;
}
HWND CDateTimeUI::GetNativeWindow() const
{
if (m_pWindow) return m_pWindow->GetHWND();
return NULL;
}
SYSTEMTIME& CDateTimeUI::GetTime()
{
return m_sysTime;
}
void CDateTimeUI::SetTime(SYSTEMTIME* pst)
{
m_sysTime = *pst;
Invalidate();
}
void CDateTimeUI::SetReadOnly(bool bReadOnly)
{
m_bReadOnly = bReadOnly;
Invalidate();
}
bool CDateTimeUI::IsReadOnly() const
{
return m_bReadOnly;
}
void CDateTimeUI::UpdateText()
{
if (m_nDTUpdateFlag == DT_DELETE)
SetText(_T(""));
else if (m_nDTUpdateFlag == DT_UPDATE)
{
CDuiString sText;
sText.SmallFormat(_T("%4d-%02d-%02d"),
m_sysTime.wYear, m_sysTime.wMonth, m_sysTime.wDay, m_sysTime.wHour, m_sysTime.wMinute);
SetText(sText);
}
}
void CDateTimeUI::SetPos(RECT rc, bool bNeedInvalidate)
{
CControlUI::SetPos(rc, bNeedInvalidate);
if( m_pWindow != NULL ) {
RECT rcPos = m_pWindow->CalPos();
if (::IsRectEmpty(&rcPos)) ::ShowWindow(m_pWindow->GetHWND(), SW_HIDE);
else {
::SetWindowPos(m_pWindow->GetHWND(), NULL, rcPos.left, rcPos.top, rcPos.right - rcPos.left,
rcPos.bottom - rcPos.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);
}
}
}
void CDateTimeUI::Move(SIZE szOffset, bool bNeedInvalidate)
{
CControlUI::Move(szOffset, bNeedInvalidate);
if( m_pWindow != NULL ) {
RECT rcPos = m_pWindow->CalPos();
if (::IsRectEmpty(&rcPos)) ::ShowWindow(m_pWindow->GetHWND(), SW_HIDE);
else {
::SetWindowPos(m_pWindow->GetHWND(), NULL, rcPos.left, rcPos.top, rcPos.right - rcPos.left,
rcPos.bottom - rcPos.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);
}
}
}
void CDateTimeUI::DoEvent(TEventUI& event)
{
if( !IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND ) {
if( m_pParent != NULL ) m_pParent->DoEvent(event);
else CLabelUI::DoEvent(event);
return;
}
if( event.Type == UIEVENT_SETCURSOR && IsEnabled() )
{
::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_IBEAM)));
return;
}
if( event.Type == UIEVENT_WINDOWSIZE )
{
if( m_pWindow != NULL ) m_pManager->SetFocusNeeded(this);
}
if( event.Type == UIEVENT_SCROLLWHEEL )
{
if( m_pWindow != NULL ) return;
}
if( event.Type == UIEVENT_SETFOCUS && IsEnabled() )
{
if( m_pWindow ) return;
m_pWindow = new CDateTimeWnd();
ASSERT(m_pWindow);
m_pWindow->Init(this);
m_pWindow->ShowWindow();
}
if( event.Type == UIEVENT_KILLFOCUS && IsEnabled() )
{
Invalidate();
}
if( event.Type == UIEVENT_BUTTONDOWN || event.Type == UIEVENT_DBLCLICK || event.Type == UIEVENT_RBUTTONDOWN)
{
if( IsEnabled() ) {
GetManager()->ReleaseCapture();
if( IsFocused() && m_pWindow == NULL )
{
m_pWindow = new CDateTimeWnd();
ASSERT(m_pWindow);
}
if( m_pWindow != NULL )
{
m_pWindow->Init(this);
m_pWindow->ShowWindow();
}
}
return;
}
if( event.Type == UIEVENT_MOUSEMOVE )
{
return;
}
if( event.Type == UIEVENT_BUTTONUP )
{
return;
}
if( event.Type == UIEVENT_CONTEXTMENU )
{
return;
}
CLabelUI::DoEvent(event);
}
}
#ifndef __UIDATETIME_H__
#define __UIDATETIME_H__
#pragma once
namespace DuiLib
{
class CDateTimeWnd;
/// ʱѡؼ
class DUILIB_API CDateTimeUI : public CLabelUI
{
friend class CDateTimeWnd;
public:
CDateTimeUI();
LPCTSTR GetClass() const;
LPVOID GetInterface(LPCTSTR pstrName);
UINT GetControlFlags() const;
HWND GetNativeWindow() const;
SYSTEMTIME& GetTime();
void SetTime(SYSTEMTIME* pst);
void SetReadOnly(bool bReadOnly);
bool IsReadOnly() const;
void UpdateText();
void SetPos(RECT rc, bool bNeedInvalidate = true);
void Move(SIZE szOffset, bool bNeedInvalidate = true);
void DoEvent(TEventUI& event);
protected:
SYSTEMTIME m_sysTime;
int m_nDTUpdateFlag;
bool m_bReadOnly;
CDateTimeWnd* m_pWindow;
};
}
#endif // __UIDATETIME_H__
\ No newline at end of file
This diff is collapsed.
#ifndef __UIEDIT_H__
#define __UIEDIT_H__
#pragma once
namespace DuiLib
{
class CEditWnd;
class DUILIB_API CEditUI : public CLabelUI
{
friend class CEditWnd;
public:
CEditUI();
LPCTSTR GetClass() const;
LPVOID GetInterface(LPCTSTR pstrName);
UINT GetControlFlags() const;
HWND GetNativeWindow() const;
void SetEnabled(bool bEnable = true);
void SetText(LPCTSTR pstrText);
void SetMaxChar(UINT uMax);
UINT GetMaxChar();
void SetReadOnly(bool bReadOnly);
bool IsReadOnly() const;
void SetPasswordMode(bool bPasswordMode);
bool IsPasswordMode() const;
void SetPasswordChar(TCHAR cPasswordChar);
TCHAR GetPasswordChar() const;
bool IsAutoSelAll();
void SetAutoSelAll(bool bAutoSelAll);
void SetNumberOnly(bool bNumberOnly);
bool IsNumberOnly() const;
int GetWindowStyls() const;
HWND GetNativeEditHWND() const;
LPCTSTR GetNormalImage();
void SetNormalImage(LPCTSTR pStrImage);
LPCTSTR GetHotImage();
void SetHotImage(LPCTSTR pStrImage);
LPCTSTR GetFocusedImage();
void SetFocusedImage(LPCTSTR pStrImage);
LPCTSTR GetDisabledImage();
void SetDisabledImage(LPCTSTR pStrImage);
void SetNativeEditBkColor(DWORD dwBkColor);
DWORD GetNativeEditBkColor() const;
void SetSel(long nStartChar, long nEndChar);
void SetSelAll();
void SetReplaceSel(LPCTSTR lpszReplace);
void SetPos(RECT rc, bool bNeedInvalidate = true);
void Move(SIZE szOffset, bool bNeedInvalidate = true);
void SetVisible(bool bVisible = true);
void SetInternVisible(bool bVisible = true);
SIZE EstimateSize(SIZE szAvailable);
void DoEvent(TEventUI& event);
void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
void PaintStatusImage(HDC hDC);
void PaintText(HDC hDC);
protected:
CEditWnd* m_pWindow;
UINT m_uMaxChar;
bool m_bReadOnly;
bool m_bPasswordMode;
bool m_bAutoSelAll;
TCHAR m_cPasswordChar;
UINT m_uButtonState;
DWORD m_dwEditbkColor;
int m_iWindowStyls;
TDrawInfo m_diNormal;
TDrawInfo m_diHot;
TDrawInfo m_diFocused;
TDrawInfo m_diDisabled;
};
}
#endif // __UIEDIT_H__
\ No newline at end of file
#include "stdafx.h"
#include "UIFlash.h"
#include <atlcomcli.h>
#define DISPID_FLASHEVENT_FLASHCALL ( 0x00C5 )
#define DISPID_FLASHEVENT_FSCOMMAND ( 0x0096 )
#define DISPID_FLASHEVENT_ONPROGRESS ( 0x07A6 )
namespace DuiLib
{
CFlashUI::CFlashUI(void)
: m_dwRef(0)
, m_dwCookie(0)
, m_pFlash(NULL)
, m_pFlashEventHandler(NULL)
{
CDuiString strFlashCLSID=_T("{D27CDB6E-AE6D-11CF-96B8-444553540000}");
OLECHAR szCLSID[100] = { 0 };
#ifndef _UNICODE
::MultiByteToWideChar(::GetACP(), 0, strFlashCLSID, -1, szCLSID, lengthof(szCLSID) - 1);
#else
_tcsncpy(szCLSID, strFlashCLSID, lengthof(szCLSID) - 1);
#endif
::CLSIDFromString(szCLSID, &m_clsid);
}
CFlashUI::~CFlashUI(void)
{
if (m_pFlashEventHandler)
{
m_pFlashEventHandler->Release();
m_pFlashEventHandler=NULL;
}
ReleaseControl();
}
LPCTSTR CFlashUI::GetClass() const
{
return DUI_CTR_FLASH;
}
LPVOID CFlashUI::GetInterface( LPCTSTR pstrName )
{
if( _tcscmp(pstrName, DUI_CTR_FLASH) == 0 ) return static_cast<CFlashUI*>(this);
return CActiveXUI::GetInterface(pstrName);
}
HRESULT STDMETHODCALLTYPE CFlashUI::GetTypeInfoCount( __RPC__out UINT *pctinfo )
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE CFlashUI::GetTypeInfo( UINT iTInfo, LCID lcid, __RPC__deref_out_opt ITypeInfo **ppTInfo )
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE CFlashUI::GetIDsOfNames( __RPC__in REFIID riid, __RPC__in_ecount_full(cNames ) LPOLESTR *rgszNames, UINT cNames, LCID lcid, __RPC__out_ecount_full(cNames) DISPID *rgDispId )
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE CFlashUI::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )
{
switch(dispIdMember)
{
case DISPID_FLASHEVENT_FLASHCALL:
{
if (pDispParams->cArgs != 1 || pDispParams->rgvarg[0].vt != VT_BSTR)
return E_INVALIDARG;
return this->FlashCall(pDispParams->rgvarg[0].bstrVal);
}
case DISPID_FLASHEVENT_FSCOMMAND:
{
if( pDispParams && pDispParams->cArgs == 2 )
{
if( pDispParams->rgvarg[0].vt == VT_BSTR &&
pDispParams->rgvarg[1].vt == VT_BSTR )
{
return FSCommand(pDispParams->rgvarg[1].bstrVal, pDispParams->rgvarg[0].bstrVal);
}
else
{
return DISP_E_TYPEMISMATCH;
}
}
else
{
return DISP_E_BADPARAMCOUNT;
}
}
case DISPID_FLASHEVENT_ONPROGRESS:
{
return OnProgress(*pDispParams->rgvarg[0].plVal);
}
case DISPID_READYSTATECHANGE:
{
return this->OnReadyStateChange(pDispParams->rgvarg[0].lVal);
}
}
return S_OK;
}
HRESULT STDMETHODCALLTYPE CFlashUI::QueryInterface( REFIID riid, void **ppvObject )
{
*ppvObject = NULL;
if( riid == IID_IUnknown)
*ppvObject = static_cast<LPUNKNOWN>(this);
else if( riid == IID_IDispatch)
*ppvObject = static_cast<IDispatch*>(this);
else if( riid == __uuidof(_IShockwaveFlashEvents))
*ppvObject = static_cast<_IShockwaveFlashEvents*>(this);
if( *ppvObject != NULL )
AddRef();
return *ppvObject == NULL ? E_NOINTERFACE : S_OK;
}
ULONG STDMETHODCALLTYPE CFlashUI::AddRef( void )
{
::InterlockedIncrement(&m_dwRef);
return m_dwRef;
}
ULONG STDMETHODCALLTYPE CFlashUI::Release( void )
{
::InterlockedDecrement(&m_dwRef);
return m_dwRef;
}
HRESULT CFlashUI::OnReadyStateChange (long newState)
{
if (m_pFlashEventHandler)
{
return m_pFlashEventHandler->OnReadyStateChange(newState);
}
return S_OK;
}
HRESULT CFlashUI::OnProgress(long percentDone )
{
if (m_pFlashEventHandler)
{
return m_pFlashEventHandler->OnProgress(percentDone);
}
return S_OK;
}
HRESULT CFlashUI::FSCommand (_bstr_t command, _bstr_t args)
{
if (m_pFlashEventHandler)
{
return m_pFlashEventHandler->FSCommand(command,args);
}
return S_OK;
}
HRESULT CFlashUI::FlashCall( _bstr_t request )
{
if (m_pFlashEventHandler)
{
return m_pFlashEventHandler->FlashCall(request);
}
return S_OK;
}
void CFlashUI::ReleaseControl()
{
//GetManager()->RemoveTranslateAccelerator(this);
RegisterEventHandler(FALSE);
if (m_pFlash)
{
m_pFlash->Release();
m_pFlash=NULL;
}
}
bool CFlashUI::DoCreateControl()
{
if (!CActiveXUI::DoCreateControl())
return false;
//GetManager()->AddTranslateAccelerator(this);
GetControl(__uuidof(IShockwaveFlash),(LPVOID*)&m_pFlash);
RegisterEventHandler(TRUE);
return true;
}
void CFlashUI::SetFlashEventHandler( CFlashEventHandler* pHandler )
{
if (m_pFlashEventHandler!=NULL)
{
m_pFlashEventHandler->Release();
}
if (pHandler==NULL)
{
m_pFlashEventHandler=pHandler;
return;
}
m_pFlashEventHandler=pHandler;
m_pFlashEventHandler->AddRef();
}
LRESULT CFlashUI::TranslateAccelerator( MSG *pMsg )
{
if(pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST)
return S_FALSE;
if( m_pFlash == NULL )
return E_NOTIMPL;
// 当前Web窗口不是焦点,不处理加速键
BOOL bIsChild = FALSE;
HWND hTempWnd = NULL;
HWND hWndFocus = ::GetFocus();
hTempWnd = hWndFocus;
while(hTempWnd != NULL)
{
if(hTempWnd == m_hwndHost)
{
bIsChild = TRUE;
break;
}
hTempWnd = ::GetParent(hTempWnd);
}
if(!bIsChild)
return S_FALSE;
CComPtr<IOleInPlaceActiveObject> pObj;
if (FAILED(m_pFlash->QueryInterface(IID_IOleInPlaceActiveObject, (LPVOID *)&pObj)))
return S_FALSE;
HRESULT hResult = pObj->TranslateAccelerator(pMsg);
return hResult;
}
HRESULT CFlashUI::RegisterEventHandler( BOOL inAdvise )
{
if (m_pFlash==NULL)
return S_FALSE;
HRESULT hr=S_FALSE;
CComPtr<IConnectionPointContainer> pCPC;
CComPtr<IConnectionPoint> pCP;
hr=m_pFlash->QueryInterface(IID_IConnectionPointContainer,(void **)&pCPC);
if (FAILED(hr))
return hr;
hr=pCPC->FindConnectionPoint(__uuidof(_IShockwaveFlashEvents),&pCP);
if (FAILED(hr))
return hr;
if (inAdvise)
{
hr = pCP->Advise((IDispatch*)this, &m_dwCookie);
}
else
{
hr = pCP->Unadvise(m_dwCookie);
}
return hr;
}
void CFlashUI::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
{
if (_tcscmp(pstrName, _T("homepage")) == 0)
{
}
else if (_tcscmp(pstrName, _T("autonavi"))==0)
{
}
else
CActiveXUI::SetAttribute(pstrName, pstrValue);
}
};
/*
创建日期: 2012/11/05 15:09:48
作者: daviyang35@gmail.com
描述: FlashUI
*/
#ifndef __UIFLASH_H__
#define __UIFLASH_H__
#pragma once
#include "Utils/FlashEventHandler.h"
#include "Utils/flash11.tlh"
namespace DuiLib
{
class DUILIB_API CFlashUI
: public CActiveXUI
, public _IShockwaveFlashEvents
, public ITranslateAccelerator
{
public:
CFlashUI(void);
~CFlashUI(void);
void SetFlashEventHandler(CFlashEventHandler* pHandler);
virtual bool DoCreateControl();
IShockwaveFlash* m_pFlash;
private:
virtual LPCTSTR GetClass() const;
virtual LPVOID GetInterface( LPCTSTR pstrName );
virtual void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount( __RPC__out UINT *pctinfo );
virtual HRESULT STDMETHODCALLTYPE GetTypeInfo( UINT iTInfo, LCID lcid, __RPC__deref_out_opt ITypeInfo **ppTInfo );
virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames( __RPC__in REFIID riid, __RPC__in_ecount_full(cNames ) LPOLESTR *rgszNames, UINT cNames, LCID lcid, __RPC__out_ecount_full(cNames) DISPID *rgDispId);
virtual HRESULT STDMETHODCALLTYPE Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr );
virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void **ppvObject );
virtual ULONG STDMETHODCALLTYPE AddRef( void );
virtual ULONG STDMETHODCALLTYPE Release( void );
HRESULT OnReadyStateChange (long newState);
HRESULT OnProgress(long percentDone );
HRESULT FSCommand (_bstr_t command, _bstr_t args);
HRESULT FlashCall (_bstr_t request );
virtual void ReleaseControl();
HRESULT RegisterEventHandler(BOOL inAdvise);
// ITranslateAccelerator
// Duilib消息分发给WebBrowser
virtual LRESULT TranslateAccelerator( MSG *pMsg );
private:
LONG m_dwRef;
DWORD m_dwCookie;
CFlashEventHandler* m_pFlashEventHandler;
};
}
#endif // __UIFLASH_H__
#include "StdAfx.h"
#include "UIGifAnim.h"
///////////////////////////////////////////////////////////////////////////////////////
DECLARE_HANDLE(HZIP); // An HZIP identifies a zip file that has been opened
typedef DWORD ZRESULT;
typedef struct
{
int index; // index of this file within the zip
char name[MAX_PATH]; // filename within the zip
DWORD attr; // attributes, as in GetFileAttributes.
FILETIME atime,ctime,mtime;// access, create, modify filetimes
long comp_size; // sizes of item, compressed and uncompressed. These
long unc_size; // may be -1 if not yet known (e.g. being streamed in)
} ZIPENTRY;
typedef struct
{
int index; // index of this file within the zip
TCHAR name[MAX_PATH]; // filename within the zip
DWORD attr; // attributes, as in GetFileAttributes.
FILETIME atime,ctime,mtime;// access, create, modify filetimes
long comp_size; // sizes of item, compressed and uncompressed. These
long unc_size; // may be -1 if not yet known (e.g. being streamed in)
} ZIPENTRYW;
#define OpenZip OpenZipU
#define CloseZip(hz) CloseZipU(hz)
extern HZIP OpenZipU(void *z,unsigned int len,DWORD flags);
extern ZRESULT CloseZipU(HZIP hz);
#ifdef _UNICODE
#define ZIPENTRY ZIPENTRYW
#define GetZipItem GetZipItemW
#define FindZipItem FindZipItemW
#else
#define GetZipItem GetZipItemA
#define FindZipItem FindZipItemA
#endif
extern ZRESULT GetZipItemA(HZIP hz, int index, ZIPENTRY *ze);
extern ZRESULT GetZipItemW(HZIP hz, int index, ZIPENTRYW *ze);
extern ZRESULT FindZipItemA(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRY *ze);
extern ZRESULT FindZipItemW(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRYW *ze);
extern ZRESULT UnzipItem(HZIP hz, int index, void *dst, unsigned int len, DWORD flags);
///////////////////////////////////////////////////////////////////////////////////////
namespace DuiLib
{
CGifAnimUI::CGifAnimUI(void)
{
m_pGifImage = NULL;
m_pPropertyItem = NULL;
m_nFrameCount = 0;
m_nFramePosition = 0;
m_bIsAutoPlay = true;
m_bIsAutoSize = false;
m_bIsPlaying = false;
m_pStream = NULL;
}
CGifAnimUI::~CGifAnimUI(void)
{
DeleteGif();
m_pManager->KillTimer( this, EVENT_TIEM_ID );
}
LPCTSTR CGifAnimUI::GetClass() const
{
return DUI_CTR_GIFANIM;
}
LPVOID CGifAnimUI::GetInterface( LPCTSTR pstrName )
{
if( _tcscmp(pstrName, DUI_CTR_GIFANIM) == 0 ) return static_cast<CGifAnimUI*>(this);
return CControlUI::GetInterface(pstrName);
}
void CGifAnimUI::DoInit()
{
InitGifImage();
}
bool CGifAnimUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl)
{
if ( NULL == m_pGifImage )
{
InitGifImage();
}
DrawFrame( hDC );
return true;
}
void CGifAnimUI::DoEvent( TEventUI& event )
{
if( event.Type == UIEVENT_TIMER )
OnTimer( (UINT_PTR)event.wParam );
}
void CGifAnimUI::SetVisible(bool bVisible /* = true */)
{
CControlUI::SetVisible(bVisible);
if (bVisible)
PlayGif();
else
StopGif();
}
void CGifAnimUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{
if( _tcscmp(pstrName, _T("bkimage")) == 0 ) SetBkImage(pstrValue);
else if( _tcscmp(pstrName, _T("autoplay")) == 0 ) {
SetAutoPlay(_tcscmp(pstrValue, _T("true")) == 0);
}
else if( _tcscmp(pstrName, _T("autosize")) == 0 ) {
SetAutoSize(_tcscmp(pstrValue, _T("true")) == 0);
}
else
CControlUI::SetAttribute(pstrName, pstrValue);
}
void CGifAnimUI::SetBkImage(LPCTSTR pStrImage)
{
if( m_sBkImage == pStrImage || NULL == pStrImage) return;
m_sBkImage = pStrImage;
StopGif();
DeleteGif();
Invalidate();
}
LPCTSTR CGifAnimUI::GetBkImage()
{
return m_sBkImage.GetData();
}
void CGifAnimUI::SetAutoPlay(bool bIsAuto)
{
m_bIsAutoPlay = bIsAuto;
}
bool CGifAnimUI::IsAutoPlay() const
{
return m_bIsAutoPlay;
}
void CGifAnimUI::SetAutoSize(bool bIsAuto)
{
m_bIsAutoSize = bIsAuto;
}
bool CGifAnimUI::IsAutoSize() const
{
return m_bIsAutoSize;
}
void CGifAnimUI::PlayGif()
{
if (m_bIsPlaying || m_pGifImage == NULL)
{
return;
}
long lPause = ((long*) m_pPropertyItem->value)[m_nFramePosition] * 10;
if ( lPause == 0 ) lPause = 100;
m_pManager->SetTimer( this, EVENT_TIEM_ID, lPause );
m_bIsPlaying = true;
}
void CGifAnimUI::PauseGif()
{
if (!m_bIsPlaying || m_pGifImage == NULL)
{
return;
}
m_pManager->KillTimer(this, EVENT_TIEM_ID);
this->Invalidate();
m_bIsPlaying = false;
}
void CGifAnimUI::StopGif()
{
if (!m_bIsPlaying)
{
return;
}
m_pManager->KillTimer(this, EVENT_TIEM_ID);
m_nFramePosition = 0;
this->Invalidate();
m_bIsPlaying = false;
}
void CGifAnimUI::InitGifImage()
{
m_pGifImage = LoadGifFromFile(GetBkImage());
if ( NULL == m_pGifImage ) return;
UINT nCount = 0;
nCount = m_pGifImage->GetFrameDimensionsCount();
GUID* pDimensionIDs = new GUID[ nCount ];
m_pGifImage->GetFrameDimensionsList( pDimensionIDs, nCount );
m_nFrameCount = m_pGifImage->GetFrameCount( &pDimensionIDs[0] );
int nSize = m_pGifImage->GetPropertyItemSize( PropertyTagFrameDelay );
m_pPropertyItem = (Gdiplus::PropertyItem*) malloc( nSize );
m_pGifImage->GetPropertyItem( PropertyTagFrameDelay, nSize, m_pPropertyItem );
delete[] pDimensionIDs;
pDimensionIDs = NULL;
if (m_bIsAutoSize)
{
SetFixedWidth(m_pGifImage->GetWidth());
SetFixedHeight(m_pGifImage->GetHeight());
}
if (m_bIsAutoPlay && nSize > 0)
{
PlayGif();
}
}
void CGifAnimUI::DeleteGif()
{
if (m_pStream != NULL )
{
m_pStream->Release();
m_pStream = NULL;
}
if ( m_pGifImage != NULL )
{
delete m_pGifImage;
m_pGifImage = NULL;
}
if ( m_pPropertyItem != NULL )
{
free( m_pPropertyItem );
m_pPropertyItem = NULL;
}
m_nFrameCount = 0;
m_nFramePosition = 0;
}
void CGifAnimUI::OnTimer( UINT_PTR idEvent )
{
if ( idEvent != EVENT_TIEM_ID )
return;
m_pManager->KillTimer( this, EVENT_TIEM_ID );
this->Invalidate();
m_nFramePosition = (++m_nFramePosition) % m_nFrameCount;
long lPause = ((long*) m_pPropertyItem->value)[m_nFramePosition] * 10;
if ( lPause == 0 ) lPause = 100;
m_pManager->SetTimer( this, EVENT_TIEM_ID, lPause );
}
void CGifAnimUI::DrawFrame( HDC hDC )
{
if ( NULL == hDC || NULL == m_pGifImage ) return;
GUID pageGuid = Gdiplus::FrameDimensionTime;
Gdiplus::Graphics graphics( hDC );
graphics.DrawImage( m_pGifImage, m_rcItem.left, m_rcItem.top, m_rcItem.right-m_rcItem.left, m_rcItem.bottom-m_rcItem.top );
m_pGifImage->SelectActiveFrame( &pageGuid, m_nFramePosition );
}
Gdiplus::Image* CGifAnimUI::LoadGifFromFile(LPCTSTR pstrGifPath)
{
LPBYTE pData = NULL;
DWORD dwSize = 0;
do
{
CDuiString sFile = CPaintManagerUI::GetResourcePath();
if( CPaintManagerUI::GetResourceZip().IsEmpty() ) {
sFile += pstrGifPath;
HANDLE hFile = ::CreateFile(sFile.GetData(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
FILE_ATTRIBUTE_NORMAL, NULL);
if( hFile == INVALID_HANDLE_VALUE ) break;
dwSize = ::GetFileSize(hFile, NULL);
if( dwSize == 0 )
{
::CloseHandle(hFile);
break;
}
DWORD dwRead = 0;
pData = new BYTE[ dwSize ];
::ReadFile( hFile, pData, dwSize, &dwRead, NULL );
::CloseHandle( hFile );
if( dwRead != dwSize ) {
delete[] pData;
pData = NULL;
break;
}
}
else {
sFile += CPaintManagerUI::GetResourceZip();
HZIP hz = NULL;
if( CPaintManagerUI::IsCachedResourceZip() ) hz = (HZIP)CPaintManagerUI::GetResourceZipHandle();
else hz = OpenZip((void*)sFile.GetData(), 0, 2);
if( hz == NULL ) break;
ZIPENTRY ze;
int i;
if( FindZipItem(hz, pstrGifPath, true, &i, &ze) != 0 ) break;
dwSize = ze.unc_size;
if( dwSize == 0 ) break;
pData = new BYTE[ dwSize ];
int res = UnzipItem(hz, i, pData, dwSize, 3);
if( res != 0x00000000 && res != 0x00000600) {
delete[] pData;
pData = NULL;
if( !CPaintManagerUI::IsCachedResourceZip() ) CloseZip(hz);
break;
}
if( !CPaintManagerUI::IsCachedResourceZip() ) CloseZip(hz);
}
} while (0);
while (!pData)
{
//读不到图片, 则直接去读取bitmap.m_lpstr指向的路径
HANDLE hFile = ::CreateFile(pstrGifPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
FILE_ATTRIBUTE_NORMAL, NULL);
if( hFile == INVALID_HANDLE_VALUE ) break;
dwSize = ::GetFileSize(hFile, NULL);
if( dwSize == 0 )
{
::CloseHandle(hFile);
break;
}
DWORD dwRead = 0;
pData = new BYTE[ dwSize ];
::ReadFile( hFile, pData, dwSize, &dwRead, NULL );
::CloseHandle( hFile );
if( dwRead != dwSize ) {
delete[] pData;
pData = NULL;
}
break;
}
if (!pData)
{
return NULL;
}
Gdiplus::Image* pImage = LoadGifFromMemory(pData, dwSize);
delete[] pData;
return pImage;
}
Gdiplus::Image* CGifAnimUI::LoadGifFromMemory( LPVOID pBuf,size_t dwSize )
{
HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE, dwSize);
BYTE* pMem = (BYTE*)::GlobalLock(hMem);
memcpy(pMem, pBuf, dwSize);
::GlobalUnlock(hMem);
::CreateStreamOnHGlobal(hMem, TRUE, &m_pStream);
Gdiplus::Image *pImg = Gdiplus::Image::FromStream(m_pStream);
if(!pImg || pImg->GetLastStatus() != Gdiplus::Ok)
{
m_pStream->Release();
m_pStream = NULL;
return 0;
}
return pImg;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment