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

📄 persistantsize.cpp

📁 用VC實現截取Window的消息
💻 CPP
字号:
#include "stdafx.h"
#include "PersistantSize.h"
#include "SubclassExample.h"

extern CExampleApp theApp;

// Constructor
// All that we do here is save the section name which will be used
// later when persisting the windows position.

CPersistantSize::CPersistantSize(HWND hWnd, LPCTSTR szSection)
	: m_sSection(szSection)
{
	SubclassWindow(hWnd);
	CRect rect;
	if ((rect.left = theApp.GetProfileInt(m_sSection, "Left", -1)) == -1)
		return;
	if ((rect.right = theApp.GetProfileInt(m_sSection, "Right", -1)) == -1)
		return;
	if ((rect.top = theApp.GetProfileInt(m_sSection, "Top", -1)) == -1)
		return;
	if ((rect.bottom = theApp.GetProfileInt(m_sSection, "Bottom", -1)) == -1)
		return;
	MoveWindow(hWnd, rect.left, rect.top, rect.Width(), rect.Height(), TRUE);
}

void CPersistantSize::OnFinalMessage()
{
	delete this;
}

// OnDestroy
// This is the "magic" mechanism that allows us to have peristant sizes.
// This is a message handler for the WM_DESTROY message received by
// the window we've "hooked".

void CPersistantSize::OnDestroy()
{
	HWND hWnd = GetHandle();
	CRect rect;
	GetWindowRect(hWnd, &rect);
	theApp.WriteProfileInt(m_sSection, "Left", rect.left);
	theApp.WriteProfileInt(m_sSection, "Right", rect.right);
	theApp.WriteProfileInt(m_sSection, "Top", rect.top);
	theApp.WriteProfileInt(m_sSection, "Bottom", rect.bottom);
	DefWindowProc();	// Make sure to call the "base" functionality
}

⌨️ 快捷键说明

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