Click here to Skip to main content
15,886,578 members

onlinewan - Professional Profile



Summary

    Blog RSS
10
Authority
18
Debator
124
Organiser
426
Participant
0
Author
0
Editor
0
Enquirer
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Reputation

Weekly Data. Recent events may not appear immediately. For information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilver
Bypass spam checks when posting contentsilversilversilversilversilversilvergoldSubEditor, Mentor, Protector, Editor
Store personal files in your account areaplatinumplatinumSubEditor, Editor
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Edit a Question in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Edit an Answer in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Delete a Question in Q&AYesSubEditor, Protector, Editor
Delete an Answer in Q&AYesSubEditor, Protector, Editor
Report an ArticlesilversilversilversilverSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubEditor, Mentor, Protector, Editor
Edit other members' articlesSubEditor, Protector, Editor
Create an article without requiring moderationplatinumSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending QuestionProtector
Approve/Disapprove a pending AnswerProtector
Report a forum messagesilversilverbronzeProtector, Editor
Approve/Disapprove a pending Forum MessageProtector
Have the ability to send direct emails to members in the forumsProtector
Create a new tagsilversilversilversilver
Modify a tagsilversilversilversilver

Actions with a green tick can be performed by this member.


 
General带有扩展功能的ListCtrl Pin
onlinewan20-May-10 21:00
onlinewan20-May-10 21:00 
General[MFC]当Explorer进程重启后,确保程序的托盘图标还正常显示在任务栏中 Pin
onlinewan26-Apr-10 20:09
onlinewan26-Apr-10 20:09 
General用VC开发截图小工具 Pin
onlinewan20-Apr-10 21:56
onlinewan20-Apr-10 21:56 
截图对话框源码:
.h
#if !defined(AFX_DLGTEST1_H__CB58A726_ACFB_4A7D_ADE6_D81871CC5421__INCLUDED_)
#define AFX_DLGTEST1_H__CB58A726_ACFB_4A7D_ADE6_D81871CC5421__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DlgTest1.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CDlgTest1 dialog

class CDlgTest1 : public CDialog
{
// Construction
public:
	CDlgTest1(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
	//{{AFX_DATA(CDlgTest1)
	enum { IDD = IDD_DIALOG1 };
		// NOTE: the ClassWizard will add data members here
	//}}AFX_DATA

	static void CapScreenBitmap(CBitmap &memBitmap);

	CBitmap m_Bitmap;		//桌面位图
	CBitmap m_ResultBitmap;	//结果位图

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CDlgTest1)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CDlgTest1)
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

private:
	CPoint m_ptStart;		//截取区域
	CPoint m_ptEnd;			//截取区域

	BOOL m_bSelected;		//是否已经选择了截取区域
	BOOL m_bDoing;
	HCURSOR m_hCursor;
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DLGTEST1_H__CB58A726_ACFB_4A7D_ADE6_D81871CC5421__INCLUDED_)


.cpp
// DlgTest1.cpp : implementation file
//

#include "stdafx.h"
#include "截屏.h"
#include "DlgTest1.h"
#include <cmath>

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

/////////////////////////////////////////////////////////////////////////////
// CDlgTest1 dialog


CDlgTest1::CDlgTest1(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgTest1::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgTest1)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_bSelected = FALSE;
	m_bDoing = FALSE;
}


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


BEGIN_MESSAGE_MAP(CDlgTest1, CDialog)
	//{{AFX_MSG_MAP(CDlgTest1)
	ON_WM_PAINT()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_WM_LBUTTONDOWN()
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgTest1 message handlers

BOOL CDlgTest1::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	Sleep(500);
	CapScreenBitmap(m_Bitmap);

	CRect rect;
	::GetWindowRect(GetDesktopWindow()->m_hWnd, &rect);
	SetWindowPos(&wndTopMost, 0, 0, rect.Width(), rect.Height(), SW_SHOWNA);
	::SetActiveWindow(this->m_hWnd);
	
	m_hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR1);
	SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)m_hCursor);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgTest1::CapScreenBitmap(CBitmap &memBitmap)
{
    CDC *pDC;
    pDC = CDC::FromHandle(::GetDC(GetDesktopWindow()->m_hWnd));
	if(pDC == NULL) return;
    int BitPerPixel = pDC->GetDeviceCaps(BITSPIXEL);
    int Width = pDC->GetDeviceCaps(HORZRES);
    int Height = pDC->GetDeviceCaps(VERTRES);

    CDC memDC;
    if(memDC.CreateCompatibleDC(pDC) == 0) return;
    
    CBitmap *oldmemBitmap;
    if(memBitmap.CreateCompatibleBitmap(pDC, Width, Height) == NULL)
	{
		return;
	}
 
   oldmemBitmap = memDC.SelectObject(&memBitmap);
	if(oldmemBitmap == NULL) return;

   if(memDC.BitBlt(0, 0, Width, Height, pDC, 0, 0, SRCCOPY) == 0) return;
   memDC.SelectObject(oldmemBitmap);
}

void CDlgTest1::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	if ( m_bDoing )
	{
		CRect rect1(min(m_ptStart.x, m_ptEnd.x), min(m_ptStart.y, m_ptEnd.y), max(m_ptStart.x, m_ptEnd.x), max(m_ptStart.y, m_ptEnd.y));
		ScreenToClient(&rect1);

		CPen* pOldPen = NULL;
		CBrush* pOldBrush = NULL;
		pOldPen = dc.SelectObject(CPen::FromHandle(::CreatePen(PS_SOLID, 0, RGB(10,100,130))));
		pOldBrush = (CBrush*)dc.SelectStockObject(NULL_BRUSH);

		dc.Rectangle(&rect1);

		if (pOldPen != NULL)
			dc.SelectObject(pOldPen);
		if (pOldBrush != NULL)
			dc.SelectObject(pOldBrush);


		rect1.left += 2;
		rect1.top += 2;
		rect1.right -= 2;
		rect1.bottom -= 2;
		CDC   dcMem;   
		dcMem.CreateCompatibleDC(this->GetDC());   
		BITMAP   bitmap;
		m_Bitmap.GetBitmap(&bitmap);   
		CBitmap *pbmpOld = dcMem.SelectObject(&m_Bitmap);   
		this->GetDC()->StretchBlt(rect1.left, rect1.top, rect1.Width(), rect1.Height(), &dcMem, 
			rect1.left, rect1.top, rect1.Width(), rect1.Height(), SRCCOPY);
		dcMem.SelectObject(pbmpOld);
// 		this->GetDC()->StretchBlt(0, 0, rect1.Width(), rect1.Height(), &dcMem, 0, 0,   
// 				bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);

	}
	// Do not call CDialog::OnPaint() for painting messages
}

void CDlgTest1::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if ( m_bDoing )
	{
		m_ptEnd = point;
		ClientToScreen(&m_ptEnd);
		this->Invalidate(TRUE);
	}

	
	CDialog::OnMouseMove(nFlags, point);
}

void CDlgTest1::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_bDoing = FALSE;
	m_ptEnd = point;
	ClientToScreen(&m_ptEnd);

	if ( fabs(m_ptStart.x - m_ptEnd.x) < 1 && fabs(m_ptStart.y - m_ptEnd.y) < 1 )
	{
		m_bSelected = FALSE;
		CDialog::OnLButtonUp(nFlags, point);
	}


	CDC *pDC = GetDC();
	CDC memDC;
	memDC.CreateCompatibleDC(pDC);
	CRect rect1(min(m_ptStart.x, m_ptEnd.x) + 2, min(m_ptStart.y, m_ptEnd.y) + 2, 
				max(m_ptStart.x, m_ptEnd.x) - 2, max(m_ptStart.y, m_ptEnd.y) - 2);
	CBitmap *oldmemBitmap;
	if(m_ResultBitmap.CreateCompatibleBitmap(pDC, rect1.Width(), rect1.Height()) == NULL)
	{
		return;
	}

	oldmemBitmap = memDC.SelectObject(&m_ResultBitmap);
	if( memDC.StretchBlt(0, 0, rect1.Width(), rect1.Height(), pDC,
		rect1.left, rect1.top, rect1.Width(), rect1.Height(), SRCCOPY) )
	{

	}
	memDC.SelectObject(oldmemBitmap);

	CDlgTest1::OnOK();	
}

void CDlgTest1::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if ( m_bSelected )
	{
		return;
	}

	m_ptStart = point;
	ClientToScreen(&m_ptStart);
	m_bDoing = TRUE;
	
	CDialog::OnLButtonDown(nFlags, point);
}

int CDlgTest1::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,
                  GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
	HINSTANCE hInst = LoadLibrary("User32.DLL"); 
	if ( hInst ) 
	{
		typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
		MYFUNC fun = NULL;
		fun = (MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
		if ( fun )
			fun(this->GetSafeHwnd(), 0, 150, 2);
		FreeLibrary(hInst); 
	}

	return 0;
}

BOOL CDlgTest1::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE )
	{
		CDialog::OnCancel();
	}
	if ( pMsg->message == WM_RBUTTONUP )
	{
		CDialog::OnCancel();
	}
	
	return CDialog::PreTranslateMessage(pMsg);
}



调用对话框源码:
.h
// 截屏Dlg.h : header file
//

#if !defined(AFX_DLG_H__EFED66EB_A124_4791_B8D8_E64E6E1CF01F__INCLUDED_)
#define AFX_DLG_H__EFED66EB_A124_4791_B8D8_E64E6E1CF01F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "atlbase.h"

const TCHAR	REG_ROOT[]	= _T("Software\\wCutPicTool\\Settings");

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

class CMyDlg : public CDialog
{
// Construction
public:
	CMyDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	//{{AFX_DATA(CMyDlg)
	enum { IDD = IDD_MY_DIALOG };
		// NOTE: the ClassWizard will add data members here
	//}}AFX_DATA

	static BOOL SetRegister(LPCTSTR lpszName, LPCTSTR lpszValue, LPCTSTR lpszKeyName = REG_ROOT);
	static CString GetRegister(LPCTSTR lpszName, LPCTSTR lpszPath = REG_ROOT);
	static void SplitString(LPCTSTR sSource, CStringArray &sDestination, TCHAR cToken);

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMyDlg)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CMyDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnButton1();
	afx_msg void OnButton2();
	afx_msg void OnClose();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DLG_H__EFED66EB_A124_4791_B8D8_E64E6E1CF01F__INCLUDED_)

.cpp
// 截屏Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "截屏.h"
#include "截屏Dlg.h"
#include "DlgTest1.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

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

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

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
		// 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 CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

BOOL CMyDlg::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
	
	// TODO: Add extra initialization here
	CString strAppHandle;
	strAppHandle.Format(_T("%d"), this->m_hWnd);
	SetRegister(_T("AppHandle"), strAppHandle);

	CRect desktopRect;
	::GetWindowRect(GetDesktopWindow()->m_hWnd, &desktopRect);
	
	CString strX = GetRegister(_T("WinPos_X"));
	CString strY = GetRegister(_T("WinPos_Y"));

	if ( strX.IsEmpty() || strY.IsEmpty() )
	{
		return TRUE;
	}

	int nX = atol(strX.IsEmpty() ? _T("10") : strX);
	int nY = atol(strY.IsEmpty() ? _T("10") : strY);

	CRect rect;
	this->GetWindowRect(&rect);
	if ( nX+rect.Width() < desktopRect.right && nY+rect.Height() < desktopRect.bottom )
	{
		rect.right = nX+rect.Width();
		rect.bottom = nY+rect.Height();
		rect.left = nX;
		rect.top = nY;
		MoveWindow(&rect);
	}
//	SetWindowPos(&wndTopMost, rect.left, rect.top, rect.Width(), rect.Height(), SW_SHOWNA);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMyDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	CRect rect;
	this->GetWindowRect(&rect);

	CString strX, strY;
	strX.Format(_T("%d"), rect.left);
	strY.Format(_T("%d"), rect.top);

	SetRegister(_T("WinPos_X"), strX);
	SetRegister(_T("WinPos_Y"), strY);	

	CDialog::OnClose();
}

void CMyDlg::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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMyDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	CDlgTest1 dlg(GetDesktopWindow());

	ShowWindow(SW_MINIMIZE);

	if ( dlg.DoModal() ==IDOK )
	{
		if (OpenClipboard()) 
		{
			//清空剪贴板
			EmptyClipboard();
			SetClipboardData(CF_BITMAP, dlg.m_ResultBitmap);
			//关闭剪贴板
			CloseClipboard();
		}
	}

	ShowWindow(SW_RESTORE);
}

void CMyDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CDlgTest1 dlg(GetDesktopWindow());

	ShowWindow(SW_MINIMIZE);

	if ( dlg.DoModal() ==IDOK )
	{
		CString strExt = _T("所有文件(*.bmp)|*.bmp|");
		CFileDialog dlgSave(FALSE, 
			_T ("xls"), 
			NULL,
			OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,
			(LPCTSTR)strExt);

		CString strFileName;
		if(dlgSave.DoModal() == IDOK)
		{
			strFileName = dlgSave.GetPathName();
			
			FILE *fp = fopen(strFileName, "w+b");

			BITMAP bmp;
			dlg.m_ResultBitmap.GetBitmap(&bmp);
			BITMAPINFOHEADER bih = {0};
			bih.biBitCount = bmp.bmBitsPixel;
			bih.biCompression = BI_RGB;
			bih.biHeight = bmp.bmHeight;
			bih.biPlanes = 1;
			bih.biSize = sizeof(BITMAPINFOHEADER);
			bih.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight;
			bih.biWidth = bmp.bmWidth;
			BITMAPFILEHEADER bfh = {0};
			bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
			bfh.bfSize = bfh.bfOffBits + bmp.bmWidthBytes * bmp.bmHeight;
			bfh.bfType = (WORD)0x4d42;
			fwrite(&bfh, 1, sizeof(BITMAPFILEHEADER), fp);
			fwrite(&bih, 1, sizeof(BITMAPINFOHEADER), fp);
			byte * p = new byte[bmp.bmWidthBytes * bmp.bmHeight];
			GetDIBits(this->GetDC()->m_hDC,
				(HBITMAP) dlg.m_ResultBitmap.m_hObject,
				0,
				bmp.bmHeight,
				p,
				(LPBITMAPINFO) &bih,
				DIB_RGB_COLORS);
			fwrite(p, 1, bmp.bmWidthBytes * bmp.bmHeight, fp);
			delete [] p;
			fclose(fp);
		}
	}

	ShowWindow(SW_RESTORE);
}

// 功能描述:读取注册表信息
CString CMyDlg::GetRegister(LPCTSTR lpszName,LPCTSTR lpszPath)
{
	CString strValue = _T("");
	CString strName = lpszName;
	if(strName.IsEmpty())
		return strValue;
	
	CRegKey regKey;
	try
	{
		if(regKey.Open(HKEY_CURRENT_USER,lpszPath) != ERROR_SUCCESS)
		{//如果不能打开,则退出
			return strValue;
		}
		TCHAR szValue[1024];
		DWORD sl = 1023;
		LONG lReturn = regKey.QueryValue(szValue,lpszName,&sl);
		if( lReturn == ERROR_SUCCESS)
		{
			strValue = szValue;
		}
		regKey.Close();
	}
	catch (...)
	{
		UINT unErro = GetLastError();
		return strValue;
	}
	return strValue;
}

// 功能描述:保存注册表信息
BOOL CMyDlg::SetRegister(LPCTSTR lpszName, LPCTSTR lpszValue,LPCTSTR lpszKeyName)
{
	CString strName = lpszName;
	if(strName.IsEmpty())
		return FALSE;
	
	CRegKey regKey;
	try
	{
		if(regKey.Open(HKEY_CURRENT_USER,lpszKeyName) != ERROR_SUCCESS)
		{//如果不能打开,则新建一个
			if(regKey.Create(HKEY_CURRENT_USER,lpszKeyName) != ERROR_SUCCESS)
			{
				//如果建立不成功,返回FALSE
				return FALSE;
			}
		}
		if(regKey.SetValue(lpszValue,lpszName) != ERROR_SUCCESS)
		{
			return FALSE;
		}
		regKey.Close();
	}
	catch (...)
	{
		regKey.Close();
		return FALSE;
	}
	return TRUE;
}

void CMyDlg::SplitString(LPCTSTR sSource, CStringArray &sDestination, TCHAR cToken)
{
	int     nIndex  = 0;
	BOOL    ret;
	CString subStr;
	sDestination.RemoveAll ();
	while ( TRUE )
	{
		ret = AfxExtractSubString ( subStr , sSource , nIndex , cToken );
		if ( ! ret )
		{
			return;
		}
		if ( ! subStr.IsEmpty () )
		{
			sDestination.Add ( subStr );
		}
		nIndex++;
	}
}

BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class

	return CDialog::PreTranslateMessage(pMsg);
}



主程序实例源码:
.h
// 截屏.h : main header file for the 截屏 application
//

#if !defined(AFX__H__B75C0466_F802_49D4_860E_274339DD06D5__INCLUDED_)
#define AFX__H__B75C0466_F802_49D4_860E_274339DD06D5__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"		// main symbols

/////////////////////////////////////////////////////////////////////////////
// CMyApp:
// See 截屏.cpp for the implementation of this class
//

class CMyApp : public CWinApp
{
public:
	CMyApp();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMyApp)
	public:
	virtual BOOL InitInstance();
	//}}AFX_VIRTUAL

// Implementation

	//{{AFX_MSG(CMyApp)
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX__H__B75C0466_F802_49D4_860E_274339DD06D5__INCLUDED_)

.cpp
// 截屏.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "截屏.h"
#include "截屏Dlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyApp

BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
	//{{AFX_MSG_MAP(CMyApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyApp construction

CMyApp::CMyApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMyApp object

CMyApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CMyApp initialization

BOOL CMyApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif	

	CString strAppHandle;
	HANDLE hMutexHandle = ::CreateMutex(NULL, TRUE, _T("Wanxg_CutPicTool_V1.0"));
	if ( GetLastError() == ERROR_ALREADY_EXISTS )
	{
		strAppHandle = CMyDlg::GetRegister(_T("AppHandle"));
		int nTemp = atoi(strAppHandle);
		HWND hWnd = (HWND)nTemp;
		if ( hWnd != NULL )
		{
			::ShowWindow(hWnd, SW_RESTORE);
			::SetForegroundWindow(hWnd);
			return FALSE;
		}
	}

	CMyDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}



资源文件源码:
.rc
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// Chinese (P.R.C.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#endif //_WIN32

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE DISCARDABLE 
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE DISCARDABLE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE DISCARDABLE 
BEGIN
    "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
    "#define _AFX_NO_OLE_RESOURCES\r\n"
    "#define _AFX_NO_TRACKER_RESOURCES\r\n"
    "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
    "\r\n"
    "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)\r\n"
    "#ifdef _WIN32\r\n"
    "LANGUAGE 4, 2\r\n"
    "#pragma code_page(936)\r\n"
    "#endif //_WIN32\r\n"
    "#include ""res\\截屏.rc2""  // non-Microsoft Visual C++ edited resources\r\n"
    "#include ""l.chs\\afxres.rc""          // Standard components\r\n"
    "#endif\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_ABOUTBOX DIALOG DISCARDABLE  0, 0, 235, 55
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "关于 截屏"
FONT 9, "宋体"
BEGIN
    ICON            IDR_MAINFRAME,IDC_STATIC,11,17,20,20
    LTEXT           "截屏 1.0 版",IDC_STATIC,40,10,119,8,SS_NOPREFIX
    LTEXT           "版权所有 (C) 2010",IDC_STATIC,40,25,119,8
    DEFPUSHBUTTON   "确定",IDOK,178,7,50,14,WS_GROUP
END

IDD_MY_DIALOG DIALOGEX 0, 0, 225, 57
STYLE DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | 
    WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "截图工具"
FONT 9, "宋体"
BEGIN
    PUSHBUTTON      "截图保存到剪切板",IDC_BUTTON1,7,7,90,24
    PUSHBUTTON      "截图保存到文件",IDC_BUTTON2,128,7,90,24
    LTEXT           "注:在截屏时,可以点击鼠标右键取消。",IDC_STATIC,7,42,
                    145,8
END

IDD_DIALOG1 DIALOGEX 0, 0, 187, 96
STYLE WS_CHILD
EXSTYLE WS_EX_TOOLWINDOW
FONT 10, "System"
BEGIN
END


#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 1,0,0,1
 PRODUCTVERSION 1,0,0,1
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "080404B0"
        BEGIN
            VALUE "CompanyName", "\0"
            VALUE "FileDescription", "截屏 Microsoft 基础类应用程序\0"
            VALUE "FileVersion", "1, 0, 0, 1\0"
            VALUE "InternalName", "截屏\0"
            VALUE "LegalCopyright", "版权所有 (C) 2010\0"
            VALUE "LegalTrademarks", "\0"
            VALUE "OriginalFilename", "截屏.EXE\0"
            VALUE "ProductName", "截屏 应用程序\0"
            VALUE "ProductVersion", "1, 0, 0, 1\0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x804, 1200
    END
END

#endif    // !_MAC


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE 
BEGIN
    IDD_ABOUTBOX, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 228
        TOPMARGIN, 7
        BOTTOMMARGIN, 48
    END

    IDD_MY_DIALOG, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 218
        TOPMARGIN, 7
        BOTTOMMARGIN, 50
    END

    IDD_DIALOG1, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 180
        TOPMARGIN, 7
        BOTTOMMARGIN, 89
    END
END
#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Cursor
//

IDC_CURSOR1             CURSOR  DISCARDABLE     "res\\arrow_m.cur"

/////////////////////////////////////////////////////////////////////////////
//
// Icon
//

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME           ICON    DISCARDABLE     "res\\截屏.ico"

/////////////////////////////////////////////////////////////////////////////
//
// String Table
//

STRINGTABLE DISCARDABLE 
BEGIN
    IDS_ABOUTBOX            "关于 截屏(&A)..."
END

#endif    // Chinese (P.R.C.) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE 4, 2
#pragma code_page(936)
#endif //_WIN32
#include "res\截屏.rc2"  // non-Microsoft Visual C++ edited resources
#include "l.chs\afxres.rc"          // Standard components
#endif

/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED

Resource.h
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by 截屏.rc
//
#define IDM_ABOUTBOX                    0x0010
#define IDD_ABOUTBOX                    100
#define IDS_ABOUTBOX                    101
#define IDD_MY_DIALOG                   102
#define IDR_MAINFRAME                   128
#define IDD_DIALOG1                     129
#define IDC_CURSOR1                     135
#define IDC_BUTTON1                     1000
#define IDC_BUTTON2                     1001

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        138
#define _APS_NEXT_COMMAND_VALUE         32771
#define _APS_NEXT_CONTROL_VALUE         1001
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

GeneralCComboBox的下拉列表实现自适应宽度 Pin
onlinewan13-Apr-10 17:02
onlinewan13-Apr-10 17:02 
General给刚刚毕业或即将毕业的同学一封信---从自身经历谈找工作 Pin
onlinewan30-Mar-09 17:48
onlinewan30-Mar-09 17:48 
General计划为什么不能如期完成? Pin
onlinewan26-Mar-09 17:29
onlinewan26-Mar-09 17:29 
General在ARX中利于Automation打开、新建DWG文件 Pin
onlinewan22-Mar-09 15:33
onlinewan22-Mar-09 15:33 
General收藏 [modified] Pin
onlinewan15-Mar-09 16:19
onlinewan15-Mar-09 16:19 
General企业制度与文化 Pin
onlinewan10-Mar-09 23:06
onlinewan10-Mar-09 23:06 
General2005年百度之星程序设计大赛试题初赛题目三 Pin
onlinewan3-Nov-08 19:06
onlinewan3-Nov-08 19:06 
General2005年百度之星程序设计大赛试题初赛题目二 Pin
onlinewan3-Nov-08 19:02
onlinewan3-Nov-08 19:02 
General2005年百度之星程序设计大赛试题初赛题目一 Pin
onlinewan3-Nov-08 18:47
onlinewan3-Nov-08 18:47 
General实现在Word中查找指定内容,将其替换为指定图片 Pin
onlinewan23-Oct-08 15:12
onlinewan23-Oct-08 15:12 
General实现在Excel中查找指定内容,将其替换为指定图片 Pin
onlinewan23-Oct-08 15:04
onlinewan23-Oct-08 15:04 
General【某公司C++笔试题】 [modified] Pin
onlinewan12-Oct-08 22:57
onlinewan12-Oct-08 22:57 
General四道微软面试算法题 [modified] Pin
onlinewan12-Oct-08 16:28
onlinewan12-Oct-08 16:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.