testdlg - yamaumima/hello.github.io GitHub Wiki

// TestWnDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TestWn.h"
#include "TestWnDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestWnDlg dialog

CTestWnDlg::CTestWnDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestWnDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestWnDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestWnDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestWnDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestWnDlg, CDialog)
	//{{AFX_MSG_MAP(CTestWnDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
	ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
	ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
	ON_BN_CLICKED(IDC_BUTTON12, OnButton12)
	ON_BN_CLICKED(IDC_BUTTON13, OnButton13)
	ON_BN_CLICKED(IDC_BUTTON14, OnButton14)
	ON_BN_CLICKED(IDC_BUTTON15, OnButton15)
	ON_BN_CLICKED(IDC_BUTTON16, OnButton16)
	ON_BN_CLICKED(IDC_BUTTON17, OnButton17)
	ON_BN_CLICKED(IDC_BUTTON18, OnButton18)
	ON_BN_CLICKED(IDC_BUTTON19, OnButton19)
	ON_BN_CLICKED(IDC_BUTTON20, OnButton20)
	ON_BN_CLICKED(IDC_BUTTON21, OnButton21)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestWnDlg message handlers

BOOL CTestWnDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	m_list.CreateEx(WS_EX_CLIENTEDGE,"SysListViEW32",NULL,WS_VISIBLE|WS_CHILD|LVS_SHOWSELALWAYS,
			CRect(10,120,300,270),this,8921);
	m_list.InsertColumn(0,"工号",0,100);
	m_list.InsertColumn(1,"姓名",0,100);
	m_list.InsertColumn(2,"工资",0,100);



	HWND hWnd = ::GetDlgItem(m_hWnd,IDC_EDIT1);
	m_edit.Attach(hWnd);





	hWnd = ::GetDlgItem(m_hWnd,IDC_BUTTON1);
	m_dest.SubclassDlgItem(IDC_BUTTON1,this);
	m_cret.SubclassDlgItem(IDC_BUTTON2,this);
//	m_list.BringWindowToTop();
	// 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
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTestWnDlg::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();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTestWnDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTestWnDlg::OnButton1() 
{
	DestroyWindow();
}

void CTestWnDlg::OnButton2() 
{
/*	if(!m_list)
		m_list.CreateEx(WS_EX_CLIENTEDGE,"SysListViEW32",NULL,WS_VISIBLE|WS_CHILD|LVS_REPORT,
			CRect(10,35,300,300),this,8921);
*/
}

void CTestWnDlg::OnButton3() 
{
	CWnd* pWnd = GetDlgItem(IDOK);

	HWND hWnd = pWnd ->GetSafeHwnd();
	if(hWnd)
		pWnd ->DestroyWindow();
}

void CTestWnDlg::OnButton4() 
{
	HWND hWnd = ::GetDlgItem(m_hWnd,IDOK);	
	CWnd* p = CWnd::FromHandle(hWnd);
	p ->SetWindowText("临时对象");
}

void CTestWnDlg::OnButton5() 
{
	m_edit.SetWindowText("长期有效");
}

void CTestWnDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	m_dest.UnsubclassWindow();
	m_edit.Detach();	
}

void CTestWnDlg::OnButton6() 
{
	DWORD dwStyle = m_list.GetStyle();
	m_list.ModifyStyle(0,LVS_REPORT|LVS_NOSORTHEADER);
}

void CTestWnDlg::OnButton7() 
{ 
	DWORD dwExStyle = m_edit.GetExStyle();
	m_edit.ModifyStyleEx(0,WS_EX_DLGMODALFRAME);
	CRect rect;
	m_edit.GetWindowRect(rect);
	ScreenToClient(rect);
	rect.InflateRect(3,3);
	m_edit.MoveWindow(rect);
	//m_edit.MoveWindow(10,260,400,40);
	Invalidate();
}

void CTestWnDlg::OnButton8() 
{
	SetTimer(1,500,NULL);
	SetTimer(123,16,NULL);	
}

void CTestWnDlg::OnTimer(UINT nID) 
{
	if(nID == 1)
	{
		CString str;
		GetWindowText(str);
		if(str == "Timer....")
			str = "Setting....";
		else
			str = "Timer....";
		SetWindowText(str);
	}
	if(nID == 123)
	{
		CRect rect;
		m_cret.GetWindowRect(rect);
		ScreenToClient(rect);
		rect.OffsetRect(2,0);
		CRect rt;
		GetClientRect(rt);
		if(rect.right >= rt.right )
		{
			KillTimer(123);
			KillTimer(1);
		}
		//	rect.OffsetRect(-rect.left,0);
		m_cret.MoveWindow(rect);
	}
	CDialog::OnTimer(nID);
}

void CTestWnDlg::OnButton9() 
{
	CWnd* pCanc = GetDlgItem(IDCANCEL);
	if(pCanc ->IsWindowVisible())
		pCanc->	ShowWindow(SW_HIDE);	
	else
		pCanc->	ShowWindow(SW_SHOW);	
}

void CTestWnDlg::OnButton10() 
{
	CWnd* pCanc = GetDlgItem(IDCANCEL);

	pCanc ->EnableWindow(!pCanc ->IsWindowEnabled());


}

void CTestWnDlg::OnButton11() 
{
	CWnd* pWnd = FindWindow("HH Parent"	,NULL);
//	if(pWnd && pWnd ->IsIconic())
	if(pWnd && pWnd ->GetStyle()&WS_MINIMIZE)
		pWnd ->ShowWindow(SW_MAXIMIZE);
	

}

void CTestWnDlg::OnButton12() 
{
	///if(IsZoomed())
	if(GetStyle()&WS_MAXIMIZE)
		this ->SetWindowText("是最大化的");
	else
		SetWindowText("非最大化的");
}

void CTestWnDlg::OnButton13() 
{
	CWnd* pCanc = GetDlgItem(IDCANCEL);
	pCanc ->CenterWindow();	
}

void CTestWnDlg::OnButton14() 
{
 	CRect rect;
 	m_cret.GetWindowRect(rect);
 	ScreenToClient(rect);
 	rect.OffsetRect(8,0);
	//m_cret.SetWindowPos(&wndBottom ,110,230,110,440,SWP_NOSIZE|SWP_NOMOVE);
	//m_list.SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
	//Invalidate();
	if(GetExStyle() & WS_EX_TOPMOST)
		SetWindowPos(&wndNoTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
	else
		SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
	
}

void CTestWnDlg::OnButton15() 
{
	//m_list.SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
	m_list.BringWindowToTop();
	Invalidate();
}

void CTestWnDlg::OnButton16() 
{
	CWnd* pWnd = GetTopWindow();
	CString str;
	pWnd ->GetWindowText(str);
	SetWindowText(str);
}

void CTestWnDlg::OnButton17() 
{
	CWnd* pWnd = FindWindow("notepad",NULL);
	if(pWnd)
		//pWnd ->SetForegroundWindow();
		pWnd ->BringWindowToTop();
}

void CTestWnDlg::OnButton18() 
{
	CWnd* pWnd = FindWindow("notepad",NULL);
	if(pWnd)
		pWnd ->FlashWindow(TRUE);
		
}

void CTestWnDlg::OnButton19() 
{
	CWnd* pWnd = m_list.GetParent();	
	if(pWnd == this)
		AfxMessageBox("父窗口是对话框");
}

void CTestWnDlg::OnButton20() 
{
	if(this ->IsChild(&m_list))
	{
		AfxMessageBox("列表控件是该对话框的子窗口");
	}
}

void CTestWnDlg::OnButton21() 
{
	CWnd* pWnd = GetWindow(GW_CHILD);
	CString str;
	while(pWnd)
	{
		pWnd ->GetWindowText(str);
		pWnd = pWnd ->GetWindow(GW_HWNDLAST);
	}
}


// MyList.cpp : implementation file
//

#include "stdafx.h"
#include "TestWn.h"
#include "MyList.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyList

CMyList::CMyList()
{
}

CMyList::~CMyList()
{
}


BEGIN_MESSAGE_MAP(CMyList, CListCtrl)
	//{{AFX_MSG_MAP(CMyList)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyList message handlers