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

📄 autohide.h

📁 一款最完整的工业组态软源代码
💻 H
字号:
#if !defined(AFX_AUTOHIDE_H__20010516_C3E9_46AD_95FE_0080AD509054__INCLUDED_)
#define AFX_AUTOHIDE_H__20010516_C3E9_46AD_95FE_0080AD509054__INCLUDED_

#pragma once

/////////////////////////////////////////////////////////////////////////////
// autohide.h - An AutoHide control
//
// Written by Bjarke Viksoe (bjarke@viksoe.dk)
// Copyright (c) 2001 Bjarke Viksoe.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed by any means PROVIDING it is 
// not sold for profit without the authors written consent, and 
// providing that this notice and the authors name is included. 
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability if it causes any damage to you or your
// computer whatsoever. It's free, so don't hassle me about it.
//
// Beware of bugs.
//

#ifndef __cplusplus
   #error ATL requires C++ compilation (use a .cpp suffix)
#endif

#ifndef __ATLAPP_H__
   #error autohide.h requires atlapp.h to be included first
#endif


#define ATL_SIMPLE_AUTOHIDEVIEW_STYLE \
   (WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS)

// Sliding window animation delay
#ifndef AUTOHIDE_DELAY_IN
   #define AUTOHIDE_DELAY_IN  200
   #define AUTOHIDE_DELAY_OUT 100
#endif

// AnimateWindow() constants defined in Platform SDK
#ifndef AW_BLEND
   #define AW_HOR_POSITIVE             0x00000001
   #define AW_HOR_NEGATIVE             0x00000002
   #define AW_HIDE                     0x00010000
   #define AW_ACTIVATE                 0x00020000
   #define AW_SLIDE                    0x00040000
#endif

struct AUTOPANE
{
   HWND hWnd;
   TCHAR szTitle[80];
   RECT rc;
};

#define WM_AUTOHIDE_SETPANE   WM_USER+360
#define WM_AUTOHIDE_VIEWCLOSE WM_USER+361


///////////////////////////////////////////////////////
// CAutoFloatWindow

typedef CWinTraits<WS_OVERLAPPED|WS_CAPTION|WS_THICKFRAME|WS_SYSMENU, WS_EX_TOOLWINDOW> CAutoFloatWinTraits;

template <class T, class TBase = CWindow, class TWinTraits = CAutoFloatWinTraits>
class ATL_NO_VTABLE CAutoFloatWindowImpl : 
   public CWindowImpl< T, TBase, TWinTraits >
{
public:
   DECLARE_WND_CLASS_EX(NULL, CS_DBLCLKS, NULL)

   typedef CAutoFloatWindowImpl< T , TBase, TWinTraits > thisClass;
   BEGIN_MSG_MAP(thisClass)
      MESSAGE_HANDLER(WM_CREATE, OnCreate)
      MESSAGE_HANDLER(WM_NCPAINT, OnNcPaint)
      MESSAGE_HANDLER(WM_PRINT, OnPrint)
      MESSAGE_HANDLER(WM_NCHITTEST, OnHitTest)
      MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
      MESSAGE_HANDLER(WM_NCACTIVATE, OnKillFocus)
      MESSAGE_HANDLER(WM_SIZE, OnSize)
      MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand)
      MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChange)
      MESSAGE_HANDLER(WM_AUTOHIDE_SETPANE, OnSetPane);
   END_MSG_MAP()

   CAutoFloatWindowImpl()
      : m_hwndOwner(NULL)
   {
      ::ZeroMemory(&m_pane, sizeof(m_pane));
   }
   
   HWND m_hwndOwner;
   AUTOPANE m_pane;
   SIZE m_sizeBorder;

   // Operations

   BOOL _AnimateWindow(DWORD dwTime, DWORD dwFlags)
   {
      if( !AtlIsOldWindows() ) {
         typedef BOOL (CALLBACK* LPFNANIMATEWINDOW)(HWND,DWORD,DWORD);
         LPFNANIMATEWINDOW lpfnAnimateWindow = (LPFNANIMATEWINDOW)
            ::GetProcAddress(::GetModuleHandle(_T("user32.dll")), "AnimateWindow");
         if( lpfnAnimateWindow!=NULL ) return lpfnAnimateWindow( m_hWnd, dwTime, dwFlags );
      }
      // For incompatible AnimateWindow() Windows versions
      if( dwFlags & AW_ACTIVATE ) {
         SetWindowPos(HWND_TOP, 0,0,0,0, SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);
      }
      if( dwFlags & AW_HIDE ) {
         SetWindowPos(HWND_TOP, 0,0,0,0, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
      }
      return FALSE;
   }

   void _DrawFrame(HDC hDC) const
   {
      // Repaint frame borders (except the border on the right)
      CDCHandle dc(hDC);
      RECT rcWin;
      GetWindowRect(&rcWin);
      RECT rcTop = { 0,0, (rcWin.right-rcWin.left)-m_sizeBorder.cx, m_sizeBorder.cy };
      dc.FillRect(&rcTop, ::GetSysColorBrush(COLOR_BTNFACE));
      RECT rcBottom = { 0, (rcWin.bottom-rcWin.top)-m_sizeBorder.cy, (rcWin.right-rcWin.left)-m_sizeBorder.cx, (rcWin.bottom-rcWin.top) };
      dc.FillRect(&rcBottom, ::GetSysColorBrush(COLOR_BTNFACE));
      RECT rcLeft = { 0, m_sizeBorder.cy, m_sizeBorder.cx, (rcWin.bottom-rcWin.top)-m_sizeBorder.cy };
      dc.FillRect(&rcLeft, ::GetSysColorBrush(COLOR_BTNFACE));
   }

   // Message handlers

   LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
   {
      BOOL bDummy;
      OnSettingChange(WM_SETTINGCHANGE, 0,0, bDummy);
      return 0;
   }

   LRESULT OnSettingChange(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
   {
      m_sizeBorder.cx = ::GetSystemMetrics(SM_CXSIZEFRAME);
      m_sizeBorder.cy = ::GetSystemMetrics(SM_CYSIZEFRAME);
      return 0;
   }

   LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
   {
      return 1; // handled, no background painting needed
   }

   LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
   {
      LRESULT lRes = DefWindowProc(uMsg, wParam, lParam);
      CWindowDC dc(m_hWnd);
      //HDC hdc = ::GetDCEx(m_hWnd, (HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN);
      //if( wParam>1 ) dc.SelectClipRgn((HRGN)wParam);
      _DrawFrame(dc);
      return lRes;
   }

   LRESULT OnKillFocus(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
   {
      if( (BOOL)wParam==FALSE ) {
         _AnimateWindow(AUTOHIDE_DELAY_OUT, AW_SLIDE|AW_HOR_NEGATIVE|AW_HIDE);
         RECT rc;
         GetWindowRect(&rc);
         ::SendMessage(m_hwndOwner, WM_AUTOHIDE_VIEWCLOSE, rc.right-rc.left,0);
      }
      bHandled = FALSE;
      return 0;
   }

   LRESULT OnHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
   {
      LRESULT lRes = DefWindowProc(uMsg, wParam, lParam);
      switch( lRes ) {
      case HTBOTTOM:
      case HTBOTTOMLEFT:
      case HTLEFT:
      case HTTOPLEFT:
      case HTTOP:
      case HTCAPTION:
         lRes = HTCLIENT;
         break;
      case HTTOPRIGHT:
      case HTBOTTOMRIGHT:
         lRes = HTRIGHT;
         break;
      }
      return lRes;
   }

   LRESULT OnSysCommand(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
   {
      switch( wParam & 0xFFF0 ) {
      case SC_CLOSE:
         ::SetFocus(m_hwndOwner); // Kill focus
         return 0;
      }
      bHandled = FALSE;
      return 0;
   }

   LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
   {
      RECT rc;
      GetClientRect(&rc);
      ::SetWindowPos(m_pane.hWnd, HWND_TOP, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER | SWP_SHOWWINDOW);
      return 0;
   }

   LRESULT OnPrint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
   {
      LRESULT lRes = DefWindowProc(uMsg, wParam, lParam);
      if( lParam & PRF_NONCLIENT ) _DrawFrame((HDC)wParam);
      return lRes;
   }

   LRESULT OnSetPane(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
   {
      ATLASSERT(::IsWindow((HWND)wParam));
      ATLASSERT(lParam!=0);
      if( m_pane.hWnd ) ::ShowWindow(m_pane.hWnd, SW_HIDE);
      m_hwndOwner = (HWND)wParam;
      m_pane = *(reinterpret_cast<AUTOPANE *>(lParam));
      // Re-parent
      ::SetParent(m_pane.hWnd, m_hWnd);
      // Set title
      SetWindowText(m_pane.szTitle);
      // Place view inside pane
      // NOTE: OnSize() also calls ShowWindow() to restore an invisible child
      BOOL bDummy;
      OnSize(WM_SIZE, 0,0, bDummy);
      // Entr

⌨️ 快捷键说明

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