📄 ttl_inverterdlg.cpp
字号:
// ttl_inverterDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "ttl_inverter.h"
#include "ttl_inverterDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Cttl_inverterDlg 对话框
Cttl_inverterDlg::Cttl_inverterDlg(CWnd* pParent /*=NULL*/)
: CDialog(Cttl_inverterDlg::IDD, pParent)
, show_which(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void Cttl_inverterDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(Cttl_inverterDlg, CDialog)
ON_WM_PAINT()
ON_WM_TIMER( )
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnBnClickedButton4)
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON6, OnBnClickedButton6)
ON_BN_CLICKED(IDC_BUTTON5, OnBnClickedButton5)
ON_BN_CLICKED(IDC_BUTTON7, OnBnClickedButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnBnClickedButton8)
ON_BN_CLICKED(IDC_BUTTON9, OnBnClickedButton9)
ON_BN_CLICKED(IDC_BUTTON10, OnBnClickedButton10)
END_MESSAGE_MAP()
// Cttl_inverterDlg 消息处理程序
BOOL Cttl_inverterDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO:在此添加额外的初始化代码
timer_on = false;
cnt = 0;
byhand = false;
dis_step = 0;//
return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void Cttl_inverterDlg::OnPaint()
{
CPaintDC dc(this); // 用于绘制的设备上下文
CDC mem_dc;
CBitmap res;
mem_dc.CreateCompatibleDC( &dc );
//int px = 50 ,py = 340;
CBitmap * old_bmp;
float zoom = 580./679;
if( 0 == show_which ){
res.LoadBitmap( IDB_BITMAP3 );
old_bmp = mem_dc.SelectObject( &res );
res.DeleteObject();
dc.StretchBlt( 0,0,580,438*zoom,&mem_dc,0,0,679,438,SRCCOPY );
}
else if( 1 == show_which ){
res.LoadBitmap( IDB_BITMAP1 );
old_bmp = mem_dc.SelectObject( &res );
res.DeleteObject();
dc.StretchBlt( 0,0,580,450*zoom,&mem_dc,0,0,679,450,SRCCOPY );
//dc.StretchBlt( 0,0,377,382,&mem_dc,0,0,754,765,SRCCOPY );
}
else if( 2 == show_which ){
res.LoadBitmap( IDB_BITMAP2 );
old_bmp = mem_dc.SelectObject( &res );
res.DeleteObject();
//dc.StretchBlt( 0,0,377,382,&mem_dc,0,0,754,765,SRCCOPY );
dc.StretchBlt( 0,0,580,450*zoom,&mem_dc,0,0,679,450,SRCCOPY );
}
else if( 3 == show_which || 4 == show_which){
res.LoadBitmap( IDB_BITMAP4 );
old_bmp = mem_dc.SelectObject( &res );
res.DeleteObject();
//dc.StretchBlt( 0,0,377,382,&mem_dc,0,0,754,765,SRCCOPY );
dc.StretchBlt( 0,0,580,450*zoom,&mem_dc,0,0,679,450,SRCCOPY );
}
else if( 5 == show_which ){
res.LoadBitmap( IDB_BITMAP5 );
old_bmp = mem_dc.SelectObject( &res );
res.DeleteObject();
//dc.StretchBlt( 0,0,377,382,&mem_dc,0,0,754,765,SRCCOPY );
dc.StretchBlt( 0,0,580,450*zoom,&mem_dc,0,0,679,450,SRCCOPY );
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标显示。
HCURSOR Cttl_inverterDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void Cttl_inverterDlg::OnBnClickedButton3()
{
if( timer_on )
KillTimer(timer_ID);
show_which = 0;//显示原图
InvalidateRect(NULL,false);
}
void Cttl_inverterDlg::OnBnClickedButton4()
{
EndDialog( 0 );
}
void Cttl_inverterDlg::OnBnClickedButton1()
{
if( timer_on )
KillTimer(timer_ID);
show_which = 5;//显示原图
byhand = false;//自动显示一气合成
InvalidateRect(NULL,false);
SendMessage( WM_PAINT );
cnt = 0;
show_which = 1;//输入高电平图
step = 0;
timer_on = true;
timer_ID = SetTimer(1,100,NULL);
}
void Cttl_inverterDlg::OnBnClickedButton2()
{
if( timer_on )
KillTimer(timer_ID);
show_which = 5;//显示原图
byhand = false;//自动显示一气合成
InvalidateRect(NULL,false);
SendMessage( WM_PAINT );
cnt = 0;
show_which = 2;//输入低电平图
step = 0;
timer_on = true;
timer_ID = SetTimer(1,100,NULL);
}
void Cttl_inverterDlg::OnTimer( UINT )
{
if( 4 == show_which ){
int t_step[] = { 1,4,5 };
ShowOneStep4();
if( byhand ){
if( step >= t_step[dis_step] ){
KillTimer(timer_ID);
timer_on = false;
}
}
else{
//计算当前的步骤:
dis_step = 0;
while( t_step[dis_step] < step ) dis_step++;
if( step > 8 ){
KillTimer(timer_ID);
timer_on = false;
}
}
}
else if( 3 == show_which ){
int t_step[] = { 1,4,5 };
ShowOneStep3();
if( byhand ){
if( step >= t_step[dis_step] ){
KillTimer(timer_ID);
timer_on = false;
}
}
else{
//计算当前的步骤:
dis_step = 0;
while( t_step[dis_step] < step ) dis_step++;
if( step > 5 ){
KillTimer(timer_ID);
timer_on = false;
}
}
}
else if( 2 == show_which ){
int t_step[] = { 1,7,8,11,17,18 };
ShowOneStep2();
if( byhand ){
if( step >= t_step[dis_step] ){
KillTimer(timer_ID);
timer_on = false;
}
}
else{
//计算当前的步骤:
dis_step = 0;
while( t_step[dis_step] < step ) dis_step++;
if( step > 18 ){
KillTimer(timer_ID);
timer_on = false;
}
}
}
else if( 1 == show_which ){
int t_step[] = { 1,15,19,20,21,22,23,24 };
ShowOneStep();
if( byhand ){
if( step >= t_step[dis_step] ){
KillTimer(timer_ID);
timer_on = false;
}
}
else{
//计算当前的步骤:
dis_step = 0;
while( t_step[dis_step] < step ) dis_step++;
if( step > 10 ){
KillTimer(timer_ID);
timer_on = false;
}
}
}
}
void Cttl_inverterDlg::ShowOneStep()
{
CRect block[] = {
CRect(429,26,243,104),//1参数显示-1
CRect(78,10,28,22),//2输入信号-2
CRect(91,45,173,275),//3动态过程显示-3
CRect(262,44,90,48),CRect(262,166,92,75),CRect(262,278,90,97),//-6
CRect(314,1,79,423),//4显示各输入端电流-7
CRect(254,9,47,300),//5显示个器件输入电流-8
CRect(110,22,48,19),//6显示总输入电流-9
CRect(428,166,220,222)//7显示公式-10
};
//动态显示方向:上0下1左2右3,整体4
int dir[] = {
4,//1
5,//2
3,//3
3,3,3,//三个矩形必须同时显示
5,5,5,
5
};
/* int cnt_total[] = {
5,
5,
5,
5,5,5,5,5,5
};
*/ int cnt_total[] = {
1,
1,
1,
1,1,1,1,1,1
};
float zoom = 580./679;
CRect rect;
int sub_step;
int temp;
static int times = 0;
switch( dir[step] ){
case 0: break;
case 1:
//向下
rect.top = block[step].top*zoom;
rect.bottom = rect.top + (block[step].bottom*cnt/cnt_total[step])*zoom;
rect.left = block[step].left*zoom;
rect.right = rect.left + block[step].right*zoom;
InvalidateRect( &rect,false );
cnt++;
if( rect.bottom > (block[step].top + block[step].bottom)*zoom ){
step ++;
cnt = 0;
}
break;
case 2:
//向左
rect.right = ( block[step].left + block[step].right )*zoom;
rect.top = block[step].top*zoom;
rect.left = rect.right - (block[step].right*cnt/cnt_total[step])*zoom;
rect.bottom = rect.top + block[step].bottom*zoom;
InvalidateRect( &rect,false );
cnt++;
if( rect.left < block[step].left*zoom ){
step++;
cnt = 0;
}
break;
case 3:
//右3
for( sub_step = 0;
(step!=3 && sub_step <1) || (step==3 && sub_step <3) ;
sub_step++ ){
rect.left = block[step+sub_step].left*zoom;
rect.right = rect.left + (block[step+sub_step].right*cnt/cnt_total[step+sub_step])*zoom;
rect.top = block[step+sub_step].top*zoom;
rect.bottom = rect.top + block[step+sub_step].bottom*zoom;
InvalidateRect( &rect,false );
}
cnt++;
if( rect.right > (block[step].left + block[step].right)*zoom ){
if( step != 3 )
step++;
else
step += 3;
cnt = 0;
}
break;
case 4:
rect.left = block[step].left*zoom;
rect.right = rect.left + block[step].right*zoom;
rect.top = block[step].top*zoom;
rect.bottom = rect.top + block[step].bottom*zoom;
InvalidateRect( &rect,false );
cnt++;
if( byhand ){
step++;
cnt = 0;
}
else{
if( cnt > cnt_total[step] ){
step++;
cnt = 0;
}
}
case 5:
rect.left = block[step].left*zoom;
rect.right = rect.left + block[step].right*zoom;
rect.top = block[step].top*zoom;
rect.bottom = rect.top + block[step].bottom*zoom;
InvalidateRect( &rect,false );
if( times == 1 ){
temp = show_which;
show_which = 0;
SendMessage( WM_PAINT );
show_which = temp;
}
cnt++;
if( byhand ){
if( times > 2 ){
step++;
cnt = 0;
}
}
else{
if( cnt > cnt_total[step] ){
cnt = 0;
times++;
if( times > 2 ){
times = 0;
step++;
}
}
}
}
}
void Cttl_inverterDlg::ShowOneStep2()
{
CRect block[] = { //输入信号
CRect(429,21,242,106),//1
CRect( 83,9,38,25),//2
CRect( 261,43,91,48),CRect( 261,168,90,78),CRect( 261,278,94,96),//3
CRect( 93,39,169,301),
CRect(316 ,1,79 ,423),
CRect(254,8,38,315),
CRect(139,14,36,22),
CRect(433,160,203,139)//5
};
//动态显示方向:上0下1左2右3,整体4
int dir[] = {
4,//1
5,//2
2,//3
2,2,2,//三个矩形必须同时显示
5,5,5,5,5
};
/*
int cnt_total[] = {
5,
5,
5,
5,5,5,5,5,5,5
};*/
int cnt_total[] = {
1,
1,
1,
1,1,1,1,1,1,1
};
CRect rect;
float zoom = 580./679;
int sub_step;
int temp;
static int times = 0;
switch( dir[step] ){
case 0: break;
case 1:
//向下
rect.top = block[step].top*zoom;
rect.bottom = rect.top + (block[step].bottom*cnt/cnt_total[step])*zoom;
rect.left = block[step].left*zoom;
rect.right = rect.left + block[step].right*zoom;
InvalidateRect( &rect,false );
cnt++;
if( rect.bottom > (block[step].top + block[step].bottom)*zoom ){
step ++;
cnt = 0;
}
break;
case 2:
//向左
for( sub_step = 0;
(step!=2 && sub_step <1) || (step==2 && sub_step <3) ;
sub_step++ ){
rect.right = ( block[step+sub_step].left + block[step+sub_step].right )*zoom;
rect.top = block[step+sub_step].top*zoom;
rect.left = rect.right - (block[step+sub_step].right*cnt/cnt_total[step+sub_step])*zoom;
rect.bottom = rect.top + block[step+sub_step].bottom*zoom;
InvalidateRect( &rect,false );
}
cnt++;
if( rect.left < block[step].left*zoom ){
if( step != 2 )
step++;
else
step += 3;
cnt = 0;
}
break;
case 3:
//右3
for( sub_step = 0;
(step!=3 && sub_step <1) || (step==3 && sub_step <3) ;
sub_step++ ){
rect.left = block[step+sub_step].left*zoom;
rect.right = rect.left + (block[step+sub_step].right*cnt/cnt_total[step+sub_step])*zoom;
rect.top = block[step+sub_step].top*zoom;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -