📄 dialog.cpp
字号:
// dialog.cpp : implementation file
//
#include "stdafx.h"
#include "knap1.h"
#include "dialog.h"
#include "dialog1.h"
#include "knap1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// dialog dialog
dialog::dialog(CWnd* pParent /*=NULL*/)
: CDialog(dialog::IDD, pParent)
{
m_bmpBackground1.LoadBitmap(IDB_BITMAPBACKGROUND1);
}
void dialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(dialog)
DDX_Control(pDX, IDC_BUTTON2, m_btnST3);
DDX_Control(pDX, IDC_BUTTON1, m_btnST2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(dialog, CDialog)
//{{AFX_MSG_MAP(dialog)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_WM_PAINT()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// dialog message handlers
extern float v[1000];
extern int w[1000];
extern int x[1000];
extern int m_Num;
extern int m_KnapNum;
int i=1;
void dialog::OnButton1()
{
// TODO: Add your control notification handler code here
dialog1 dialog2;
int num1,num2;
char ch1[10],ch2[10];
CString str;
if(i==1)
AfxMessageBox("请一直输");
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
num1=atoi(ch1);
num2=atoi(ch2);
w[i]=num1;
v[i]=num2;
if(num1<=0)
{
AfxMessageBox("物品应大于0");
GetDlgItem(IDC_EDIT1)->SetWindowText("");
GetDlgItem(IDC_EDIT2)->SetWindowText("");
UpdateData(TRUE);
i--;
}
//// str.Format(" w[%d]=%d",i,w[i]);
//// AfxMessageBox(str);
i++;
GetDlgItem(IDC_EDIT1)->SetWindowText("");
GetDlgItem(IDC_EDIT2)->SetWindowText("");
Sleep(100);
if(i>m_Num)
{
AfxMessageBox("哈哈,总算输完了");
Sleep(100);
dialog2.DoModal();
CDialog::OnCancel();
}
}
void dialog::OnButton2()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
void dialog::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
//CDialog::OnPaint();
CPaintDC dc(this); //对话框的dc
CDC dcMem;
dcMem.CreateCompatibleDC(&dc); //创建与对话框dc兼容的内存dc
CRect rect;
GetClientRect(&rect);
BITMAP bitMap;
m_bmpBackground1.GetBitmap(&bitMap);
CBitmap *pbmpOld=dcMem.SelectObject(&m_bmpBackground1); //将背景位图选入内存dc中
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY); //将内存dc中的位图拉伸显示在对话框的dc中
dc.BitBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,SRCCOPY);
m_Static4.SubclassDlgItem(IDC_STATIC4,this);
m_Static4.SetTextColor(RGB(0,0,255));
m_Static5.SubclassDlgItem(IDC_STATIC5,this);
m_Static5.SetTextColor(RGB(0,0,255));
}
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
BOOL dialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_brush1.CreateSolidBrush(RGB(221,221,221));//画刷颜色
//按钮背景色
m_btnST2.SetActiveFgColor(RGB(250,0,250));
m_btnST2.SetInactiveBgColor(RGB(221,221,221));
m_btnST2.SetInactiveFgColor(RGB(0,0,250));
m_btnST3.SetActiveFgColor(RGB(255,0,255));
m_btnST3.SetInactiveBgColor(RGB(221,221,221));
m_btnST3.SetInactiveFgColor(RGB(0,0,250));
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
HBRUSH dialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
{
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkMode(TRANSPARENT);
pDC->SetBkColor(RGB(221,221,221));
return m_brush1;
}
if(pWnd->GetDlgCtrlID()==IDC_EDIT2)
{
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkMode(TRANSPARENT);
pDC->SetBkColor(RGB(255,0,255));
return m_brush1;
}
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
return hbr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -