本程序是VC为平台开发的股票资讯系统

源代码在线查看: singleinstance.cpp

软件大小: 2077 K
上传用户: wyly
关键词: 程序 平台开发 股票
下载地址: 免注册下载 普通下载 VIP

相关代码

				// SingleInstance.cpp : implementation file
				//
				
				#include "stdafx.h"
				#include "StockRefer.h"
				#include "SingleInstance.h"
				
				#ifdef _DEBUG
				#define new DEBUG_NEW
				#undef THIS_FILE
				static char THIS_FILE[] = __FILE__;
				#endif
				
				/////////////////////////////////////////////////////////////////////////////
				// CSingleInstance
				
				CSingleInstance::CSingleInstance()
				{
					m_hMutex = NULL;
				}
				
				CSingleInstance::~CSingleInstance()
				{
					if(m_hMutex != NULL) 
						ReleaseMutex(m_hMutex);
				}
				
				/////////////////////////////////////////////////////////////////////////////
				// CSingleInstance message handlers
				
				BOOL CSingleInstance::Create( UINT nID )
				{
					CString strFullString;
				
					// Create our class name string
					if ( strFullString.LoadString( nID ) ) {
						// Extract the first sub-string
						AfxExtractSubString( m_strClassName, strFullString, 0 );
					}
				
					// Add the word 'Class' to the end
					m_strClassName += _T(" Class");
				
					// Create the mutex
					m_hMutex = CreateMutex( NULL, FALSE, m_strClassName );
					// Check for errors
					if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
						// Reset our mutext handle (just in case)
						m_hMutex = NULL;
						// The mutex already exists, which means an instance is already
						// running. Find the app and pop it up
						HWND hWnd = FindWindowEx( NULL, NULL, m_strClassName, NULL );
						if ( hWnd != NULL ) {
							ShowWindow( hWnd, SW_RESTORE );
							BringWindowToTop( hWnd );
							SetForegroundWindow( hWnd );
						}
						// Return failure
						return FALSE;
					}
				
					// Register the unique window class name so others can find it.
					WNDCLASS wndcls;    memset(&wndcls, 0, sizeof(WNDCLASS));
					wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
					wndcls.lpfnWndProc = AfxWndProc;
					wndcls.hInstance = AfxGetInstanceHandle();
					wndcls.hIcon = LoadIcon( wndcls.hInstance, MAKEINTRESOURCE( nID ) );//or AFX_IDI_STD_FRAME; 
					wndcls.hCursor = LoadCursor( wndcls.hInstance, IDC_ARROW );
					wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
					wndcls.lpszMenuName = NULL;//You may need to fix this
					wndcls.lpszClassName = m_strClassName; // my class name
					// Register name, exit if it fails
					if(!AfxRegisterClass(&wndcls)) {
						AfxMessageBox( _T("Failed to register window class!"), MB_ICONSTOP | MB_OK );
						return FALSE;
					}
				
					// Return success
					return TRUE;
				}
				
				CString CSingleInstance::GetClassName( void ) const
				{
					return m_strClassName;
				}
							

相关资源