⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdlgdlg.cpp

📁 ascii->unicode->asc
💻 CPP
字号:
// testDlgDlg.cpp : implementation file
//

#include "stdafx.h"
#include "testDlg.h"
#include "testDlgDlg.h"
#include <Winuser.h>
#include "afxcview.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();


// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL
	public:
		CListView   m_listview;
// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
	
	m_listview.Create("hello", "hello",SW_SHOW, CRect(0,0,100, 100),this,1);
//	m_listview.ShowWindow(SW_SHOW);
	
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDlgDlg dialog

CTestDlgDlg::CTestDlgDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestDlgDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestDlgDlg)
	m_Edit = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

void CTestDlgDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestDlgDlg)
	DDX_Text(pDX, IDC_EDIT1, m_Edit);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestDlgDlg, CDialog)
	//{{AFX_MSG_MAP(CTestDlgDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()	
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
 
/////////////////////////////////////////////////////////////////////////////
// CTestDlgDlg message handlers
//extern "C" BOOL WINAPI SetLayeredWindowAttributes(HWND hwnd,COLORREF crKey,BYTE bAlpha,DWORD dwFlags); 
BOOL CTestDlgDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
//	SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE, 0x00080000 );
	// TODO: Add extra initialization here
//	SetLayeredWindowAttributes(this->GetSafeHwnd(),0,0xff,2);
	
	CEdit *hwnd=(CEdit *)GetDlgItem( IDC_EDIT1);
	m_tip.Create(hwnd);	
	CRect r;
	hwnd->GetClientRect(&r);	
	m_tip.AddTool(hwnd, _T("tooltip"), &r, 1);	
	m_tip.Activate(TRUE);
		

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTestDlgDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CTestDlgDlg::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();
	}
	CDialog::OnPaint();
//	CPaintDC dc(this);
	CDC *dc=GetDC();
	dc->SetBkMode(TRANSPARENT);
	dc->SetTextColor(RGB(255,0,0));
	LOGFONT lf;
	HRESULT hr; 	
    ZeroMemory(&lf, sizeof(lf)); 
    lf.lfHeight = 18; 
	hr =StringCchCopy(lf.lfFaceName, 32, "Times New Roman");
	lf.lfWeight = FW_HEAVY; 
	lf.lfUnderline =TRUE;
    HFONT hfont=CreateFontIndirect(&lf); 
	HFONT hfntPrev = (HFONT)dc->SelectObject(hfont);
	TCHAR dest[MAX_PATH];
	CFile file;
	bool flag=file.Open("c:\\a.txt", /*CFile::modeCreate|*/CFile::modeReadWrite);
	//file.Write(dest, _tcslen(dest));
	file.Read(dest, MAX_PATH);
	file.Close();

	WCHAR dest1[MAX_PATH];
	MultiByteToWideChar( CP_UTF8, 0, (char *) dest, -1,
		(WCHAR *)dest1,MAX_PATH);
	
	::TextOutW(dc->GetSafeHdc(), 0,0,dest1, wcslen(dest1)); 	
	::TextOut(dc->GetSafeHdc(), 0,50,(char *)dest1, wcslen(dest1));
	
	TCHAR dest2[MAX_PATH];
	WideCharToMultiByte( CP_ACP, 0, (WCHAR*) dest1, -1,
		dest2,MAX_PATH,NULL,NULL);
	::TextOut(dc->GetSafeHdc(), 0,100,dest2, strlen(dest2)); 	
//	SelectObject(dc.GetSafeHdc(), hfntPrev); 
	DeleteObject(hfont);	

}

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

void CTestDlgDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	
}

BOOL CTestDlgDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	//m_TitleTip.PreTranslateMessage(pMsg);
	
	m_tip.RelayEvent(pMsg);
	
	
	return CDialog::PreTranslateMessage(pMsg);
}


HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	SetTextColor(pDC->GetSafeHdc() ,RGB(255,0,0));
		// TODO: Return a different brush if the default is not desired
	return hbr;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -