win32window.cpp

来自「这是VCF框架的代码」· C++ 代码 · 共 1,196 行 · 第 1/3 页

CPP
1,196
字号
//Win32Window.cpp/*Copyright 2000-2004 The VCF Project.Please see License.txt in the top level directorywhere you installed the VCF.*/#include "vcf/ApplicationKit/ApplicationKit.h"#include "vcf/ApplicationKit/ApplicationKitPrivate.h"#include "vcf/ApplicationKit/Win32Window.h"using namespace VCF;Win32Window::Win32Window():	AbstractWin32Component( NULL ),	internalClose_(false),	owner_(NULL),	activatesPending_(false){}Win32Window::Win32Window( Control* component, Control* owner ):	AbstractWin32Component( component ),	internalClose_(false),	owner_(owner),	activatesPending_(false){}Win32Window::~Win32Window(){}void Win32Window::create( Control* owningControl ){		CreateParams params = createParams();	String className = getClassName();	if ( true != isRegistered() ){		if ( className.empty() ) {			className = "Win32Window::Win32Window";		}		registerWin32Class( className, wndProc_  );	}	Win32ToolKit* toolkit = (Win32ToolKit*)UIToolkit::internal_getDefaultUIToolkit();	HWND parent = NULL;//toolkit->getDummyParent();	if ( NULL != owner_ ){		parent = (HWND)owner_->getPeer()->getHandleID();	}	HICON icon = NULL;	if ( System::isUnicodeEnabled() ) {		hwnd_ = ::CreateWindowExW( params.second,		                             className.c_str(),									 NULL,									 params.first,		                             0,									 0,									 0,									 0,									 parent,									 NULL, ::GetModuleHandleW(NULL), NULL );		icon = LoadIconW( Win32ToolKit::getInstanceHandle(), L"DefaultVCFIcon" );	}	else {		hwnd_ = ::CreateWindowExA( params.second,		                             className.ansi_c_str(),									 NULL,									 params.first,		                             0,									 0,									 0,									 0,									 parent,									 NULL, ::GetModuleHandleA(NULL), NULL );		icon = LoadIconA( Win32ToolKit::getInstanceHandle(), "DefaultVCFIcon" );		//Do we need to destroy the icon????	}	if ( NULL != hwnd_ ){		Win32Object::registerWin32Object( this );		registerForFontChanges();		if ( NULL != icon ) {					SendMessage( hwnd_, WM_SETICON, ICON_BIG, (LPARAM) icon );		}	}	else {		//throw exception	}	setCreated( true );}Win32Object::CreateParams Win32Window::createParams(){	Win32Object::CreateParams result;	result.first = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;	result.first &= ~WS_VISIBLE;		result.second = 0;	return result;}Rect Win32Window::getClientBounds(){	RECT r;	::GetWindowRect( hwnd_, &r );	::GetClientRect( hwnd_, &r );	Rect result( r.left, r.top, r.right, r.bottom );	return result;}void  Win32Window::setClientBounds( Rect* bounds ){	DWORD style = (DWORD)::GetWindowLong( hwnd_, GWL_STYLE );	DWORD exStyle = (DWORD)::GetWindowLong( hwnd_, GWL_EXSTYLE );	RECT r = {0,0,0,0};	r.left = bounds->left_;	r.top = bounds->top_;	r.right = bounds->right_;	r.bottom = bounds->bottom_;	if ( (style & WS_DLGFRAME) || (style & WS_THICKFRAME) ) {		r.left = (r.left - GetSystemMetrics(SM_CXFRAME));		r.top = (r.top - GetSystemMetrics(SM_CYFRAME));		r.right += GetSystemMetrics(SM_CXFRAME);		r.bottom += GetSystemMetrics(SM_CYFRAME);	}	if ( (style & WS_CAPTION) != 0 ) {		int cy = GetSystemMetrics( SM_CYCAPTION );		if ( (exStyle & WS_EX_TOOLWINDOW) != 0 ) {			cy = GetSystemMetrics( SM_CYSMCAPTION );		}		else {			cy = GetSystemMetrics( SM_CYCAPTION );		}		r.top -= cy;	}	::MoveWindow( hwnd_, r.left, r.top,			r.right - r.left, r.bottom - r.top, TRUE );}void Win32Window::setBounds( VCF::Rect* rect ){	AbstractWin32Component::setBounds( rect );}void Win32Window::setVisible( const bool& visible ){	if ( peerControl_->isDesigning() || peerControl_->isLoading() ) {				if ( NULL != GetParent(hwnd_) ) {			if ( visible ){				::ShowWindow( hwnd_, SW_SHOWNOACTIVATE );							}			else{				::ShowWindow( hwnd_, SW_HIDE );			}		}	}	else {		//StringUtils::trace( Format( "Win32Window::setVisible( %d )\n" ) % visible );		if ( true == visible ){						Frame* frame = (Frame*)peerControl_;						switch ( frame->getFrameStyle() ){				case fstToolbarBorderFixed : case fstToolbarBorder : case fstSizeable : case fstFixed :{					::ShowWindow( hwnd_, SW_SHOW );//SW_SHOWNORMAL );					//not sure if we want this here...					::BringWindowToTop( hwnd_ );					//we need this here to repaint the window contents???					//seems kind of funky, but it works					::RedrawWindow( hwnd_, NULL, NULL, RDW_INVALIDATE | RDW_ERASENOW | RDW_ALLCHILDREN);				}				break;								case fstNoBorder : case fstNoBorderFixed : {					::ShowWindow( hwnd_, SW_SHOWNOACTIVATE );					::RedrawWindow( hwnd_, NULL, NULL, RDW_INVALIDATE | RDW_ERASENOW | RDW_ALLCHILDREN);				}				break;			}		}		else{			::ShowWindow( hwnd_, SW_HIDE );		}	}}void Win32Window::handleActivate(){		if ( NULL != peerControl_ ) {		//do nothing if we are in design mode		if ( peerControl_->isDesigning() || peerControl_->isLoading() ) {			return;		}		activatesPending_ = true;				Frame* frame = (Frame*)peerControl_;		if ( peerControl_->isNormal() ) {			frame->activate();		}	}	}bool Win32Window::handleEventMessages( UINT message, WPARAM wParam, LPARAM lParam, LRESULT& wndProcResult, WNDPROC defaultWndProc ){	bool result = false;	wndProcResult = 0;	static bool windowRestoredAlready = true;	switch ( message ) {		case WM_SETTINGCHANGE : {			//settings change!			result = true;			wndProcResult = 0;			::RedrawWindow( hwnd_, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);			return result;		}		break;		case WM_GETMINMAXINFO : {						if ( !peerControl_->isDesigning() ) {				result = false;				wndProcResult = 0;								Size minSize = peerControl_->getMinSize();				Size maxSize = peerControl_->getMaxSize();												MINMAXINFO* info = (MINMAXINFO*)lParam;								if ( minSize.width_ > Control::mmIgnoreMinWidth ) {					info->ptMinTrackSize.x = minSize.width_;				}								if ( minSize.height_ > Control::mmIgnoreMinHeight ) {					info->ptMinTrackSize.y = minSize.height_;				}								if ( maxSize.width_ > Control::mmIgnoreMaxWidth ) {					info->ptMaxTrackSize.x = maxSize.width_;				}								if ( maxSize.height_ > Control::mmIgnoreMaxHeight ) {					info->ptMaxTrackSize.y = maxSize.height_;				}			}		}		break;		case WM_SIZE : {			result = AbstractWin32Component::handleEventMessages( message, wParam, lParam, wndProcResult );			switch ( wParam ) {				case SIZE_MAXIMIZED : {					windowRestoredAlready = false;					Frame* frame = (Frame*)peerControl_;					Window* window = dynamic_cast<Window*>(frame);					if ( NULL != window ) {						WindowEvent e(window,WINDOW_EVENT_MAXIMIZE);						window->WindowMaximize.fireEvent( &e );					}				}				break;				case SIZE_MINIMIZED : {					windowRestoredAlready = false;					Frame* frame = (Frame*)peerControl_;					Window* window = dynamic_cast<Window*>(frame);					if ( NULL != window ) {						WindowEvent e(window,WINDOW_EVENT_MINIMIZE);						window->WindowMinimize.fireEvent( &e );					}				}				break;				case SIZE_RESTORED : {					if ( !windowRestoredAlready ) {						Frame* frame = (Frame*)peerControl_;						Window* window = dynamic_cast<Window*>(frame);						if ( NULL != window ) {							WindowEvent e(window,WINDOW_EVENT_RESTORE);							window->WindowRestore.fireEvent( &e );						}					}					windowRestoredAlready = true;				}				break;			}		}		break;				case VCF_CONTROL_CREATE: {			result = AbstractWin32Component::handleEventMessages( message, wParam, lParam, wndProcResult );			if ( activatesPending_ ) {				activatesPending_ = false;				if ( !(peerControl_->isDesigning() || peerControl_->isLoading()) ) {					::PostMessage( hwnd_, WM_ACTIVATE, MAKEWPARAM (WA_ACTIVE,0), 0 );				}			}		}		break;		case WM_SYSCOMMAND: {						if ( peerControl_->isDesigning() ) {				wndProcResult = 0;				result = true;			}			else {				result = AbstractWin32Component::handleEventMessages( message, wParam, lParam, wndProcResult );			}				}		break;		case WM_NCLBUTTONDOWN: {			handleActivate();			if ( peerControl_->isDesigning() ) {				wndProcResult = 0;				result = false;			}			else {				result = AbstractWin32Component::handleEventMessages( message, wParam, lParam, wndProcResult );				wndProcResult = 0;				result = false;			}					}		break;		case WM_NCACTIVATE : {			if ( NULL != peerControl_ ) {				BOOL active = (BOOL)wParam;								if ( peerControl_->isDesigning() || peerControl_->isLoading() ) {					wndProcResult = TRUE;					result = true;				}				else {					result = AbstractWin32Component::handleEventMessages( message, wParam, lParam, wndProcResult );										Frame* frame = (Frame*)peerControl_;					//StringUtils::trace( Format( "WM_NCACTIVATE, active: %d\n" ) % active );										if ( active ) {						handleActivate();

⌨️ 快捷键说明

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