/****************************************************************************\
*
* FILE: TABCTRL.C
*
* PURPOSE: Code for managing tab control property page dialogs C file.
*
* COMMENTS: This source is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* FUNCTIONS:
* EXPORTS:
* New_TabControl() - Initialize a TABCTRL struct, create tab page dialogs
* and start the message loop
* TabControl_Destroy() - Destroy the tab page dialogs and
* free the list of pointers to the dialogs.
* EXPORTED
* VIA POINTER:
* CenterTabPage() - Center the tab page in the tab control's display area
* StretchTabPage() - Stretch the tab page in the tab control's display area
* Notify() - Handle WM_NOTIFY messages
* LOCALS:
* TabControl_GetClientRect() - Return a Client rectangle for the tab control under
* every possible configuration (tabs, buttons vert etc.)
* TabCtrl_OnKeyDown() - Handle key presses in the tab control (but not the tab pages)
* CreateAccTable() - Creates a table of keyboard accelerators
* TabPage_OnCommand() - Handle the Dialog virtual keys while
* forwarding the rest of the commands to ParentProc.
* TabPage_OnLButtonDown() - Handle WM_LBUTTONDOWN (tab page dialog)
* TabPage_OnSize() - Handle WM_SIZE (tab page dialog)
* TabPage_OnInitDialog() - Handle WM_INITDIALOG (tab page dialog)
* TabPage_DlgProc() - Window Procedure for the tab pages (dialogs)
* TabPageMessageLoop() - Monitor and respond to user keyboard input and system messages (tab page dialog)
* ResetTabPageMessageLoop() - Toggles message loop so that it is active only in the tab page
* TabCtrl_OnSelChanged() - A tab has been pressed, Handle TCN_SELCHANGE notification
*
* Copyright 2006 David MacDermot.
*
*
* History:
* JUNE '06 - Created
* JULY '07 - line 57: Replaced LPTABCTRL this, with LPTABCTRL m_lptc
* and updated the rest of the code and comments
* to reflect the change.
*
\****************************************************************************/
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include "TabCtrl.h"
#include "resource.h"
/****************************************************************************/
// Internal Globals
#define CMD_VK_ESCAPE 101
#define CMD_VK_RETURN 102
static LPTABCTRL m_lptc;
static BOOL stopTabPageMessageLoop=FALSE;
/****************************************************************************/
// Local function prototypes
static VOID TabPageMessageLoop (HWND);
VOID ResetTabPageMessageLoop (HWND);
/****************************************************************************
*
* FUNCTION: TabControl_GetClientRect
*
* PURPOSE: Return a Client rectangle for the tab control under
* every possible configuration (tabs, buttons vert etc.)
*
* PARAMS: HWND hwnd - handle of a tab control
* RECT *prc - pointer to a rectangle structure
*
* RETURNS: VOID
*
* COMMENTS: The rectangle structure is populated as follows:
* prc.left = left, prc.top = top, prc.right = WIDTH, and prc.bottom = HEIGHT
*
* History:
* June '06 - Created
*
\****************************************************************************/
VOID TabControl_GetClientRect(HWND hwnd,RECT* prc)
{
RECT rtab_0;
LONG lStyle = GetWindowLong(hwnd,GWL_STYLE);
// Calculate the tab control's display area
GetWindowRect(hwnd, prc);
ScreenToClient(GetParent(hwnd), (POINT*)&prc->left);
ScreenToClient(hwnd, (POINT*)&prc->right);
TabCtrl_GetItemRect(hwnd,0,&rtab_0); //The tab itself
if((lStyle & TCS_BOTTOM) && (lStyle & TCS_VERTICAL)) //Tabs to Right
{
prc->top = prc->top + 6; //x coord
prc->left = prc->left + 4; //y coord
prc->bottom = prc->bottom - 12; // height
prc->right = prc->right - (12 + rtab_0.right-rtab_0.left); // width
}
else if(lStyle & TCS_VERTICAL) //Tabs to Left
{
prc->top = prc->top + 6; //x coord
prc->left = prc->left + (4 + rtab_0.right-rtab_0.left); //y coord
prc->bottom = prc->bottom - 12; // height
prc->right = prc->right - (12 + rtab_0.right-rtab_0.left); // width
}
else if(lStyle & TCS_BOTTOM) //Tabs on Bottom
{
prc->top = prc->top + 6; //x coord
prc->left = prc->left + 4; //y coord
prc->bottom = prc->bottom - (16 + rtab_0.bottom-rtab_0.top); // height
prc->right = prc->right - 12; // width
}
else //Tabs on top
{
prc->top = prc->top + (6 + rtab_0.bottom-rtab_0.top); //x coord
prc->left = prc->left + 4; //y coord
prc->bottom = prc->bottom - (16 + rtab_0.bottom-rtab_0.top); // height
prc->right = prc->right - 12; // width
}
}
/****************************************************************************
*
* FUNCTION: CenterTabPage
*
* PURPOSE: Center the tab page in the tab control's display area.
*
* PARAMS: HWND hTab - handle tab control
* INT iPage - index of tab page
*
* RETURNS: BOOL - TRUE if successful
*
*
* History:
* June '06 - Created
*
\****************************************************************************/
BOOL CenterTabPage (HWND hTab, INT iPage)
{
RECT rect, rclient;
// Update m_lptc pointer
m_lptc = (LPTABCTRL) GetWindowLong(hTab,GWL_USERDATA);
TabControl_GetClientRect(hTab, &rect); // left, top, width, height
// Get the tab page size
GetClientRect(m_lptc->hTabPages[iPage], &rclient);
rclient.right=rclient.right-rclient.left;// width
rclient.bottom=rclient.bottom-rclient.top;// height
rclient.left= rect.left;
rclient.top= rect.top;
// Center the tab page, or cut it off at the edge of the tab control(bad)
if(rclient.right<rect.right)
rclient.left += (rect.right-rclient.right)/2;
if(rclient.bottom<rect.bottom)
rclient.top += (rect.bottom-rclient.bottom)/2;
// Move the child and put it on top
return SetWindowPos(m_lptc->hTabPages[iPage], HWND_TOP,
rclient.left, rclient.top, rclient.right, rclient.bottom,
0);
}
/****************************************************************************
*
* FUNCTION: StretchTabPage
*
* PURPOSE: Stretch the tab page to fit the tab control's display area.
*
* PARAMS: HWND hTab - handle tab control
* INT iPage - index of tab page
*
* RETURNS: BOOL - TRUE if successful
*
*
* History:
* June '06 - Created
*
\****************************************************************************/
BOOL StretchTabPage (HWND hTab, INT iPage)
{
RECT rect;
// Update m_lptc pointer
m_lptc = (LPTABCTRL) GetWindowLong(hTab,GWL_USERDATA);
TabControl_GetClientRect(hTab, &rect); // left, top, width, height
// Move the child and put it on top
return SetWindowPos(m_lptc->hTabPages[iPage], HWND_TOP,
rect.left, rect.top, rect.right, rect.bottom,
0);
}
/****************************************************************************
*
* FUNCTION: TabCtrl_OnKeyDown
*
* PURPOSE: Handle key presses in the tab control (but not the tab pages).
*
* PARAMS: LPARAM lParam - lParam furnished by parent proc's WM_NOTIFY handler
*
* RETURNS: VOID
*
* History:
* June '06 - Created
*
\******************
Win32_SDK_C_TabControl_source
3星 · 超过75%的资源 需积分: 9 143 浏览量
2009-02-19
20:15:35
上传
评论
收藏 6KB ZIP 举报
feifan_gongzi
- 粉丝: 0
- 资源: 2
- 1
- 2
前往页