mainfrm.cpp

来自「共享内存的源代码」· C++ 代码 · 共 906 行 · 第 1/2 页

CPP
906
字号
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "DataMan.h"

#include "MainFrm.h"
#include "DataManview.h"
#include ".\mainfrm.h"

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

//for const initialize
const CRect CMainFrame::s_rectDefault(10, 10,500,400);  // static
const char CMainFrame::s_profileHeading[] = "Window size";
const char CMainFrame::s_profileRect[] = "Rect";
const char CMainFrame::s_profileIcon[] = "Icon";
const char CMainFrame::s_profileMax[] = "Max";
const char CMainFrame::s_profileTool[] = "Tool";
const char CMainFrame::s_profileStatus[] = "Status";
const char CMainFrame::s_profileGrids[] = "Grids";
const char CMainFrame::s_profileMirexPath[] = "Micrex-F Path";
const char CMainFrame::s_profileTips_Show[] = "Tips Show";
const char CMainFrame::s_profileOpt_time[] = "Opt_time";
const CXABOUTBUTTON = 80;
/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	ON_MESSAGE(WM_TRAYMESSAGE, OnTrayMessage)
	ON_MESSAGE(WM_SHOWWNDBYPREV, OnShowWndByPrev)
	ON_MESSAGE(WM_MAPCOMPORT, OnCMSSendEvent)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_SIZE()
//	ON_COMMAND(ID_HELP_FIND, OnHelpFind)
	ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnUpdateViewStyles)
	ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnViewStyle)
	//}}AFX_MSG_MAP
	ON_COMMAND(ID_HELP_GETPASSWORD, OnHelpGetpassword)
	ON_COMMAND(ID_HELP_FINDFRAMEWORXCLASS, OnHelpFindframeworxclass)
	ON_WM_DESTROY()
	ON_COMMAND(ID_FILE_CLOSEWINDOW, OnFileClosewindow)
	ON_WM_SYSCOMMAND()

	//定时器
	ON_WM_TIMER()
//	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
//	ON_COMMAND(ID_TOOLS_CONFIG, OnToolsConfig)
//	ON_COMMAND(ID_TOOLS_MONITOR, OnToolsMonitor)
	ON_COMMAND(ID_TOOLS_ADVANCED, OnToolsAdvanced)
	ON_COMMAND(ID_TRAY_OPENDataMan, OnTrayOpenDataMan)//主菜单
	ON_COMMAND(ID_APP_EXIT, OnAppExit)                //退出
	//菜单对TOOLBAR的控制
    ON_COMMAND(ID_VIEW_SHOWTOOLBAR, OnViewToolBar)//菜单激发事件
    //ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWTOOLBAR, OnViewToolBar)

	//增加一个对网络控制选择的项
	ON_COMMAND(ID_TRAY_OPTIMIZATION, OnTrayOptimization)
	ON_UPDATE_COMMAND_UI(ID_TRAY_OPTIMIZATION, OnUpdateTrayOptimization)
	//响应菜单 消除状态栏按钮
	ON_COMMAND(ID_VIEW_STATUS_BAR, OnViewStatusBar)

	//定时刷新设置
	ON_COMMAND(ID_REFRESH_REFRESHONTIME, OnRefreshOnTime)
	ON_UPDATE_COMMAND_UI(ID_REFRESH_REFRESHONTIME, OnRefreshOnTime_UI)

END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
: m_IfRefreshOnTime(true)
, m_Tips_Show_MAIN(false)
, m_optimiz_time_int_main(1)
{
	m_fTrayed = FALSE;
	m_bFirstTime = TRUE;
	CBitmap bmp;
	bmp.LoadBitmap(IDB_BITMAPTRAY);
	m_ilTray.Create(16,16, ILC_COLOR16 | ILC_MASK, 1, 1 );
	m_ilTray.Add(&bmp, RGB(255,0,255));

	//菜单设置
	Is_Optimization = 1;
}

CMainFrame::~CMainFrame()
{
	NOTIFYICONDATA nd;
	nd.cbSize	= sizeof (NOTIFYICONDATA);
	nd.hWnd	= m_hWnd;
	nd.uID	= IDI_TRAYICON;
	Shell_NotifyIcon(NIM_DELETE, &nd);
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	cs.style &= ~FWS_ADDTOTITLE;
	cs.lpszClass = ((CDataManApp*)AfxGetApp())->m_szClassName;

	return CFrameWnd::PreCreateWindow(cs);

}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	InitToolBar();
	if (!m_wndReBar.Create(this) ||
		!m_wndReBar.AddBar(&m_wndToolBar))
	{
		TRACE0("Failed to create rebar\n");
		return -1;      // fail to create
	}

	//Set rebar information
	REBARBANDINFO rbbi;

	rbbi.cbSize = sizeof(rbbi);
	rbbi.fMask = RBBIM_STYLE;
	rbbi.fStyle = RBBS_GRIPPERALWAYS;
	m_wndReBar.GetReBarCtrl().SetBandInfo(0, &rbbi);
	

	ModifyStyle(WS_THICKFRAME,0);
	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT))) 
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}
	// Turn WS_THICKFRAME back on.
	ModifyStyle(0,WS_THICKFRAME);
	//状态栏增加一个网络优化是否按钮
	CRect rc;
	rc.top=30;   
	rc.left=30;   
	rc.bottom=50;   
	rc.right=60;  
	VERIFY(m_wndOptimizationButton.Create(_T("√ Optimize"),
		WS_VISIBLE,rc,this,ID_TRAY_OPTIMIZATION));
	//VERIFY(m_wndOptimizationButton.Create(_T("进入[A]"), 
	//    WS_GROUP |WS_CHILD |WS_VISIBLE |BS_PUSHBUTTON, 
	//	  CRect(10,10,20,20), 
	//	  this, ID_TRAY_OPTIMIZATION ));

	// TODO: Remove this if you don't want tool tips
	//m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
	//	CBRS_TOOLTIPS | CBRS_FLYBY);


	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
	//DockControlBar(&m_wndToolBar);

////////////////
	//对话条
	//if(!m_Dlgbar.Create(this,IDD_DIALOGBAR,CBRS_TOP|CBRS_TOOLTIPS|CBRS_FLYBY,IDD_DIALOGBAR))
	//{
	//	return -1;
	//}

	return 0;
}
//菜单对toolbar的控制
void CMainFrame::OnViewToolBar(void)
{
	//查询用户工具条当前的可见性
	BOOL bVisible = m_wndToolBar.GetStyle()&WS_VISIBLE;
    //根据用户工具条的可见性显示或隐藏工具条
	int nShow = bVisible ? SW_HIDE : SW_SHOWNORMAL ;
	m_wndToolBar.ShowWindow(nShow);

	//重新显示被调整的客户区和工具条
	RecalcLayout();
}
//状态栏增加一个控制优化网络是否按钮
void CMainFrame::RecalcLayout(BOOL bNotify)
{
	CFrameWnd::RecalcLayout(bNotify);

	//状态栏增加一个控制优化网络是否按钮
	CRect rc;
	//rc.top=30;   
	//rc.left=30;   
	//rc.bottom=50;   
	//rc.right=60;  
	if (m_wndStatusBar.m_hWnd) {
		m_wndStatusBar.GetWindowRect(&rc);
		ScreenToClient(&rc);
		rc.right -= CXABOUTBUTTON;
		m_wndStatusBar.SetWindowPos(NULL,rc.left,rc.top,rc.Width(),rc.Height(),
			SWP_NOZORDER);

		rc.left = rc.right;
		rc.right += CXABOUTBUTTON;
		m_wndOptimizationButton.SetWindowPos(NULL,rc.left,rc.top,rc.Width(),rc.Height(),
			SWP_NOZORDER);
	}

	//定时器开启
	SetTimer(1 , 1000 * (m_optimiz_time_int_main==0 ? 0.5 : m_optimiz_time_int_main) , NULL); 
}

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpCreateStruct, CCreateContext* pContext)
{
	if (!CFrameWnd::OnCreateClient(lpCreateStruct,   pContext))
		return FALSE;

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{	
	CFrameWnd::AssertValid();

}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers



void CMainFrame::OnSize(UINT nType, int cx, int cy) 
{
	CFrameWnd::OnSize(nType, cx, cy);

	// TODO: Add your message handler code here
}

BOOL CMainFrame::InitToolBar()
{
	CBitmap bmpTB;
	bmpTB.LoadBitmap(IDB_TOOLBAR);
	
	if (!m_wndToolBar.CreateEx(this) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}
	
	m_ilToolbar.Create (24, 24, ILC_COLOR24 | ILC_MASK,9,2);
	m_ilToolbar.Add(&bmpTB,RGB(255,0,255));
	m_wndToolBar.GetToolBarCtrl().SetImageList (&m_ilToolbar);

	m_wndToolBar.SetButtonText(0,"Programmer");
	m_wndToolBar.SetButtonText(1,"Auto Map");
	m_wndToolBar.SetButtonText(2,"Unmap");
	m_wndToolBar.SetButtonText(3,"Properties");
	m_wndToolBar.SetButtonText(5,"Icons");
	m_wndToolBar.SetButtonText(6,"Small Icon");
	m_wndToolBar.SetButtonText(7,"List");
	m_wndToolBar.SetButtonText(8,"Details");
	m_wndToolBar.SetButtonText(10,"Refresh");
	
	m_wndToolBar.SetSizes(CSize(60,45),CSize(24,24));
	
	m_wndToolBar.SetButtonStyle(5,TBBS_GROUP);

	return TRUE;
	
}

//void CMainFrame::OnHelpFind() 
//{
//	// TODO: Add your command handler code here
//	CWnd *pWnd = FindWindow("TPLCProgrammer", NULL);
//	if (pWnd->GetSafeHwnd()) 
//	{
//		pWnd->ShowWindow(SW_NORMAL);
//		pWnd->SetForegroundWindow();
//		keybd_event(VK_CONTROL, 0, 0, 0);
//		keybd_event(0x4F, 0, 0, 0);
//		keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
//		keybd_event(0x4F, 0, KEYEVENTF_KEYUP, 0);
//	}
//}

void CMainFrame::OnUpdateViewStyles(CCmdUI *pCmdUI)
{
	//CDataManApp *pDataManApp = (CDataManApp *)AfxGetApp();//生成应用程序类的指针
    //if(pDataManApp->IfCMSOpen)
	//{
	//	OnFileClosewindow();
	//	//pDataManApp->IfCMSOpen = false ;
	//	return ;
	//}
	CDataManView* pView = (CDataManView*)GetActiveView();

	if (pView == NULL)
		pCmdUI->Enable(FALSE);
	else
	{
		DWORD dwStyle = pView->GetStyle() & LVS_TYPEMASK;

		// if the command is ID_VIEW_LINEUP, only enable command
		// when we're in LVS_ICON or LVS_SMALLICON mode

		if (pCmdUI->m_nID == ID_VIEW_LINEUP)
		{
			if (dwStyle == LVS_ICON || dwStyle == LVS_SMALLICON)
				pCmdUI->Enable();
			else
				pCmdUI->Enable(FALSE);
		}
		else
		{
			// otherwise, use dots to reflect the style of the view
			pCmdUI->Enable();
			BOOL bChecked = FALSE;

			switch (pCmdUI->m_nID)
			{
			case ID_VIEW_DETAILS:
				bChecked = (dwStyle == LVS_REPORT);
				break;

			case ID_VIEW_SMALLICON:
				bChecked = (dwStyle == LVS_SMALLICON);
				break;

			case ID_VIEW_LARGEICON:
				bChecked = (dwStyle == LVS_ICON);
				break;

			case ID_VIEW_LIST:
				bChecked = (dwStyle == LVS_LIST);
				break;

			default:
				bChecked = FALSE;
				break;
			}

			pCmdUI->SetRadio(bChecked ? 1 : 0);
		}
	}
}

void CMainFrame::OnViewStyle(UINT nCommandID)
{
	CDataManView* pView = (CDataManView*)GetActiveView();
	if (pView != NULL)
	{
		DWORD dwStyle = -1;

		switch (nCommandID)
		{
		case ID_VIEW_LINEUP:
			{
				// ask the list control to snap to grid
				CListCtrl& refListCtrl = pView->GetListCtrl();
				refListCtrl.Arrange(LVA_SNAPTOGRID);
			}
			break;

		// other commands change the style on the list control
		case ID_VIEW_DETAILS:
			dwStyle = LVS_REPORT;
			break;

		case ID_VIEW_SMALLICON:
			dwStyle = LVS_SMALLICON;
			break;

		case ID_VIEW_LARGEICON:
			dwStyle = LVS_ICON;
			break;

		case ID_VIEW_LIST:
			dwStyle = LVS_LIST;
			break;
		}

		// change the style; window will repaint automatically
		if (dwStyle != -1)
			pView->ModifyStyle(LVS_TYPEMASK, dwStyle);
	}
	
	//MessageBox("save Success");
	////CDataManView* pView = (CDataManView*)GetActiveView();
 //   pView->OnToolsOptionsRegInit(pView->MirexFilePath , pView->MirexFilePathsize , pView->m_IfAutoResetList , pView->m_IfAutoSelMicrexF);
		
}

void CMainFrame::OnHelpGetpassword()
{
	// TODO: Add your command handler code here
	CString strBuff;
	int iLen = 0;
	if(::GetWindowText((HWND)0x0050628,strBuff.GetBuffer(100),iLen)!=0)
	{
		strBuff.ReleaseBuffer();
		SetWindowText(strBuff);
	}
	else
	{
		strBuff.ReleaseBuffer();
		AfxMessageBox("Cannot get password.");
	}
	
}

void CMainFrame::OnHelpFindframeworxclass()
{
	// TODO: Add your command handler code here
	CString strClassName = _T("FrameworXClass");

	HWND hWnd = ::FindWindow(strClassName,NULL);
	if (hWnd!=NULL)
	{
		AfxMessageBox(_T("Find it!"));
		::SendMessage(hWnd,WM_SETTEXT,0,(LPARAM)_T("Changed"));
		//::SendMessage(hWnd,WM_CLOSE,0,0);
	}
	else
	{
		AfxMessageBox(_T("No such window found!"));
	}
	
}

⌨️ 快捷键说明

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