📄 mypanel.cpp
字号:
// MyPanel.cpp : 实现文件
//
#include "stdafx.h"
#include "MyPanel.h"
// CMyPanel
IMPLEMENT_DYNAMIC(CMyPanel, CWnd)
CMyPanel::CMyPanel()
{
}
CMyPanel::~CMyPanel()
{
}
CMyPanel::CMyPanel(HWND hWnd,LPCTSTR tip[],int ItemCount)
{
m_hParent=hWnd;
m_Tip=tip;
m_ItemCount=ItemCount;
}
BEGIN_MESSAGE_MAP(CMyPanel, CWnd)
ON_WM_CREATE()
ON_WM_TIMER()
ON_WM_DESTROY()
END_MESSAGE_MAP()
// CMyPanel 消息处理程序
int CMyPanel::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
RECT rect;
BOOL br;
int i;
m_State=1;
GetWindowRect(&rect);
m_Width=rect.right-rect.left;
m_Height=rect.bottom-rect.top;
m_pButton=new CMyButton(m_hParent);
SetRect(&rect,m_Width-50,0,m_Width,30);
br=m_pButton->Create("收缩",WS_VISIBLE|WS_CHILD|
BS_PUSHBUTTON|BS_OWNERDRAW,rect,this,0x2001);
for(i=0;i<m_ItemCount;++i)
{
m_pStatic[i]=new CMyStatic(m_hParent);
if(0==i) SetRect(&rect,0,i*30,lstrlen(m_Tip[i])*12,i*30+18);
else SetRect(&rect,10,i*30,lstrlen(m_Tip[i])*12,i*30+18);
br=m_pStatic[i]->Create(m_Tip[i],WS_VISIBLE|WS_CHILD|
SS_NOTIFY|SS_OWNERDRAW,rect,this,0x3001+i);
}
return 0;
}
void CMyPanel::OnDestroy()
{
CWnd::OnDestroy();
// TODO: 在此添加消息处理程序代码
delete m_pButton;
for(int i=0;i<m_ItemCount;++i)
delete m_pStatic[i];
}
LRESULT CMyPanel::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: 在此添加专用代码和/或调用基类
if(WM_COMMAND==message)
{
if(0x2001==LOWORD(wParam))
{
m_State=-m_State;
SetTimer(0x101,50,0);
}
}
return CWnd::WindowProc(message, wParam, lParam);
}
void CMyPanel::OnTimer(UINT nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if(0x101==nIDEvent)
{
RECT rect;
int w,h;
if(m_State<0) //收缩
{
GetWindowRect(&rect);
w=rect.right-rect.left;
h=rect.bottom-rect.top;
if(30==h)
{
KillTimer(0x101);
m_pButton->SetWindowText("展开");
::SendMessage(m_hParent,WM_SCALEFINISH,(WPARAM)m_State,0);
}
else //(h>30)
{
h-=30;
SetWindowPos(0,0,0,w,h,SWP_NOMOVE);
::SendMessage(m_hParent,WM_COLLAPSEPANELS,0,
(LPARAM)GetWindowLongPtr(m_hWnd,GWL_ID));
}
}
else //(m_State>0) //展开
{
GetWindowRect(&rect);
w=rect.right-rect.left;
h=rect.bottom-rect.top;
if(h==m_Height)
{
KillTimer(0x101);
m_pButton->SetWindowText("收缩");
::SendMessage(m_hParent,WM_SCALEFINISH,(WPARAM)m_State,0);
}
else //(h<m_Height)
{
h+=30;
SetWindowPos(0,0,0,w,h,SWP_NOMOVE);
::SendMessage(m_hParent,WM_EXPANDPANELS,0,
(LPARAM)GetWindowLongPtr(m_hWnd,GWL_ID));
}
}
}
CWnd::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -