📄 testdlg.cpp
字号:
// TestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Test.h"
#include "TestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_progress);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_NOTIFY(NM_OUTOFMEMORY, IDC_PROGRESS1, OnOutofmemoryProgress1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
m_fullScreenCX = GetSystemMetrics(SM_CXSCREEN);
m_fullScreenCY = GetSystemMetrics(SM_CYSCREEN);
CRect rect;
this->SetWindowPos(this, 0, 0, m_fullScreenCX, m_fullScreenCY, SWP_SHOWWINDOW);
/*for(int i=0; i<100; i++)
{
m_progress.SetPos(i+1);
Sleep(100);
}*/
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
/*if(hWnd==NULL)
{
::MessageBox(NULL, _T("hWnd is NULL!"), _T("Error"), MB_OK);
}
else
{
::MessageBox(NULL, _T("hWnd is not NULL!"), _T("Error"), MB_OK);
}*/
}
void CTestDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CDC* dc;
dc = this->GetDC();
// Create and select a solid blue brush.
CBrush brushBlue(RGB(0, 0, 255));
CBrush* pOldBrush = dc->SelectObject(&brushBlue);
// Create and select a thick, black pen.
CPen penBlack;
penBlack.CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
CPen* pOldPen = dc->SelectObject(&penBlack);
// Get the client rectangle.
CRect rect;
GetClientRect(rect);
// Shrink the rectangle 20 pixels in each direction.
rect.DeflateRect(20, 20);
// Draw a thick black rectangle filled with blue.
dc->Rectangle(rect);
// Put back the old objects.
dc->SelectObject(pOldBrush);
dc->SelectObject(pOldPen);
dc->SetTextColor(RGB(0, 0, 0));
dc->SetBkMode(TRANSPARENT);
CString text = "Test success!";
dc->ExtTextOut(100, 100, 0, NULL, text, text.GetLength(), NULL);
AfxBeginThread(DrawPexilProc, this);
dc->DeleteDC();
free(dc);
}
UINT CTestDlg::DrawPexilProc(LPVOID pParam)
{
CDialog* dialog = (CDialog*)pParam;
CDC* dc;
dc = dialog->GetDC();
CProgressCtrl myCtrl;
// Create a child progress control.
myCtrl.Create(WS_CHILD|WS_VISIBLE, CRect(10,10,200,30), dialog, 1);
// Set the range to be 0 to 100.
myCtrl.SetRange(0, 100);
for(int i=0; i<10; i++)
{
for(int j=0; j<10; j++)
{
dc->SetPixel(200+10*i+j, 200+10*j, RGB(0, 255, 0));
// Set the position to be half, 50.
myCtrl.SetPos(i*10+j);
Sleep(100);
}
}
dc->DeleteDC();
free(dc);
free(dialog);
return 0;
}
void CTestDlg::OnOutofmemoryProgress1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -