📄 frmmain.cpp
字号:
// MainFrm.cpp: implementation of the MainFrm class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "FrmMain.h"
#include "LogFile.h"
#include "FrmMainMenu.h"
#include "SystemConfig.h"
#include "ToolKit.h"
#include "FrmExit.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_REGISTANDPRC(FrmMain)
void FrmMain::OtherMsgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
// 响应时钟
case WM_TIMER:
{
this->OnTimer();
}
break;
}
}
FrmMain::FrmMain()
{
this->m_strFile = "FrmMain.ini";
this->m_ClassName = "FrmMain";
this->m_WndStruct.lpszClass = TEXT(this->m_ClassName);
this->m_WndStruct.lpszName = (LPCSTR)SystemConfig::GetConfig()->m_chTitle;
}
FrmMain::~FrmMain()
{
}
void FrmMain::SetControlPropertity()
{
CBaseDialog::SetControlPropertity();
this->m_ctrlMenu = this->GetControlByKey("IDC_BTN_MAIN_MENU"); // 菜单按钮
this->m_ctrlTarget = this->GetControlByKey("IDC_BTN_MAIN_TARGET"); // 目标按钮
this->m_ctrlLink = this->GetControlByKey("IDC_BTN_MAIN_ISLINK"); // 连接按钮
this->m_ctrlZoomIn = this->GetControlByKey("IDC_BTN_MAIN_ZOOMIN"); // 放大按钮
this->m_ctrlZoomOut = this->GetControlByKey("IDC_BTN_MAIN_ZOOMOUT"); // 缩小按钮
this->m_ctrlGPSOK = this->GetControlByKey("IDD_DLG_GPSOK");
this->m_ctrlExit = this->GetControlByKey("IDC_BTN_MAIN_EXIT"); // 退出按钮
this->m_ctrlShowHide= this->GetControlByKey("IDD_DLG_SHOW"); // 显示隐藏按钮
this->m_ctrlTimer = this->GetControlByKey("IDC_BTN_MAIN_TIME"); // 地图比例
this->m_ctrlCountry = this->GetControlByKey("ID_BTN_NAVI_COUNTRY"); // 全国
this->m_ctrlStreet = this->GetControlByKey("IDD_DLG_STREET"); // 街道
this->m_ctrlProvStreet = this->GetControlByKey("IDD_DLG_PROSTREET"); // 省道
this->m_ctrlCountryStreet = this->GetControlByKey("IDC_BTN_MAIN_COUSTREET"); // 国道
this->m_ctrlStart = this->GetControlByKey("IDC_BTN_MAIN_SETSTART"); // 添加开始点
this->m_ctrlEnd = this->GetControlByKey("IDC_BTN_MAIN_SETEND"); // 添加结束点
this->m_ctrlBack = this->GetControlByKey("IDC_BTN_BACK"); // 返回
this->m_ctrlCancel = this->GetControlByKey("IDC_BTN_CANCEL"); // 取消
this->m_ctrlNext = this->GetControlByKey("IDC_BTN_MAIN_NEXT"); // 下一页
this->m_ctrlStreeInfo = this->GetControlByKey("IDC_BTN_MAIN_STREETINFO");
this->m_ctrlLongLat = this->GetControlByKey("IDC_BTN_MAIN_LONGLATPOSIT");
// 显示比例:设置显示比例按钮的字体大小及位置
this->m_ctrlScale = this->GetControlByKey("ID_BTN_NAVI_SCALE");
this->m_ctrlScale->m_CProperty.m_logfont.lfWeight = 700; // 粗体
this->m_ctrlScale->m_CProperty.m_TextFormat = DT_SINGLELINE|DT_TOP|DT_CENTER;
// 设置控件事件
this->SetCtrlEvent(this->m_ctrlMenu, OnMenu);
this->SetCtrlEvent(this->m_ctrlLink, OnLink);
this->SetCtrlEvent(this->m_ctrlExit, OnExit);
this->SetCtrlEvent(this->m_ctrlShowHide, OnHideCtrl);
this->SetCtrlEvent(this->m_ctrlScale, OnScale);
this->SetCtrlEvent(this->m_ctrlCountry, OnCountry);
this->SetCtrlEvent(this->m_ctrlCountryStreet, OnCountryStreet);
this->SetCtrlEvent(this->m_ctrlProvStreet, OnProvStreet);
this->SetCtrlEvent(this->m_ctrlStreet, OnStreet);
this->SetCtrlEvent(this->m_ctrlTarget, OnTarget);
this->SetCtrlEvent(this->m_ctrlBack, OnBack);
this->SetCtrlEvent(this->m_ctrlCancel, OnCancel);
this->SetCtrlEvent(this->m_ctrlNext, OnNext);
// 启动时钟
::SetTimer(this->m_hWnd, 1, 200 ,0);
}
void FrmMain::ShowWnd(CSearchBaseDialog &dialog)
{
this->OnHide();
dialog.m_hBack = &this->m_hWnd;
dialog.OnShow();
}
void FrmMain::OnDraw(HDC *hDC)
{
CBaseDialog::OnDraw(hDC);
// 设置中心点图标
this->DrawCenterPoint();
}
void FrmMain::DrawCenterPoint()
{
HDC hdc = GetDC(this->m_hWnd);
CDC* pDC = CDC::FromHandle(hdc);
int lineToCenter = 5; // 直线起始点距离地图中心的距离
int lineToEnd = 20; // 直线终止点距离地图中心的距离
int cirCleDir = 10; // 圆的半径长度
CRect rect;
GetClientRect(this->m_hWnd, rect);
int xCenter, yCenter;
xCenter = (rect.left + rect.right)/2;
yCenter = (rect.bottom + rect.top)/2;
//CPoint pointCenter;
m_pointCenter.x = xCenter;
m_pointCenter.y = yCenter;
CPen myPen;
myPen.CreatePen(PS_SOLID, 3, RGB(255,0,0));
CPen* oldPen = pDC->SelectObject(&myPen);
pDC->MoveTo(m_pointCenter.x, m_pointCenter.y - lineToEnd);
pDC->LineTo(m_pointCenter.x, m_pointCenter.y - lineToCenter);
pDC->MoveTo(m_pointCenter.x, m_pointCenter.y + lineToCenter);
pDC->LineTo(m_pointCenter.x, m_pointCenter.y + lineToEnd);
pDC->MoveTo(m_pointCenter.x - lineToEnd, m_pointCenter.y);
pDC->LineTo(m_pointCenter.x - lineToCenter, m_pointCenter.y);
pDC->MoveTo(m_pointCenter.x + lineToCenter, m_pointCenter.y);
pDC->LineTo(m_pointCenter.x + lineToEnd, m_pointCenter.y);
CBrush *pBrushCenter = new CBrush;
pBrushCenter->CreateSolidBrush(RGB(0,0,255));
CBrush *oldbrushCenter = pDC->SelectObject( pBrushCenter );
pDC->SelectStockObject(NULL_BRUSH);
pDC->Ellipse(m_pointCenter.x - cirCleDir,
m_pointCenter.y - cirCleDir,
m_pointCenter.x + cirCleDir,
m_pointCenter.y + cirCleDir);
pDC->SelectObject(oldbrushCenter);
pBrushCenter->DeleteObject();
}
// 按钮
void FrmMain::OnMenu(WPARAM wParam, LPARAM lParam)
{
this->ShowWnd(FrmMainMenu::s_FrmMainMenu);
}
// 连接
void FrmMain::OnLink(WPARAM wParam, LPARAM lParam)
{
if (this->m_ctrlLink->m_CProperty.m_strText.GetLength() == strlen("RTLinked"))
{
this->m_ctrlLink->SetText("RTLinking...");
}
else
{
this->m_ctrlLink->SetText("RTLinked");
}
}
// 退出
void FrmMain::OnExit(WPARAM wParam, LPARAM lParam)
{
this->OnHide();
FrmExit::s_FrmExit.m_hBack = &this->m_hWnd;
FrmExit::s_FrmExit.OnShow();
}
// 隐藏
void FrmMain::OnHideCtrl(WPARAM wParam, LPARAM lParam)
{
//BaseControl* controlShow = this->GetControlByKey("IDD_DLG_SHOW");
BaseControl* controls = this->GetControls();
int count = GetControlsCount();
if (m_ctrlShowHide->m_CProperty.m_nImgIndex == 6)
{
for (int i = 0; i < count; i++)
{
if (!this->IsTargetControl(controls[i].m_CProperty.m_strKey))
{
controls[i].ShowWnd(false);
}
}
m_ctrlShowHide->ShowWnd(true);
m_ctrlShowHide->SetImg(7);
}
else
{
for (int i = 0; i < count; i++)
{
if (!this->IsTargetControl(controls[i].m_CProperty.m_strKey))
{
controls[i].ShowWnd(true);
}
}
this->OnScale(false);
m_ctrlShowHide->SetImg(6);
}
}
// 比例
void FrmMain::OnScale(WPARAM wParam, LPARAM lParam)
{
// 如果全国按钮为不可见,则其他按钮为不可见,点击比例按钮后应设置为可见,反之也是这样
this->OnScale(!this->m_ctrlCountry->m_CProperty.m_bIsShow);
}
// 国家
void FrmMain::OnCountry(WPARAM wParam, LPARAM lParam)
{
this->OnScale(false);
this->m_ctrlScale->SetText("60KM");
}
// 国道
void FrmMain::OnCountryStreet(WPARAM wParam, LPARAM lParam)
{
this->OnScale(false);
this->m_ctrlScale->SetText("620M");
}
// 省道
void FrmMain::OnProvStreet(WPARAM wParam, LPARAM lParam)
{
this->OnScale(false);
m_ctrlScale->SetText("310M");
}
// 街区
void FrmMain::OnStreet(WPARAM wParam, LPARAM lParam)
{
this->OnScale(false);
m_ctrlScale->SetText("30M");
}
// 目标
void FrmMain::OnTarget(WPARAM wParam, LPARAM lParam)
{
this->OnTarget(true);
}
// 返回
void FrmMain::OnBack(WPARAM wParam, LPARAM lParam)
{
if (this->m_ctrlStart->m_CProperty.m_nImgIndex == 1)
{
this->OnTarget(false);
}
}
// 取消
void FrmMain::OnCancel(WPARAM wParam, LPARAM lParam)
{
if (this->m_ctrlStart->m_CProperty.m_nImgIndex == 1)
{
this->OnTarget(false);
}
}
// 下一页或上一页
void FrmMain::OnNext(WPARAM wParam, LPARAM lParam)
{
if (this->m_ctrlStart->m_CProperty.m_nImgIndex < 5)
{
this->m_ctrlStart->SetImg(6);
this->m_ctrlEnd->SetImg(7);
this->m_ctrlBack->SetImg(8);
this->m_ctrlCancel->SetImg(9);
this->m_ctrlNext->SetImg(10);
}
else
{
this->m_ctrlStart->SetImg(1);
this->m_ctrlEnd->SetImg(2);
this->m_ctrlBack->SetImg(3);
this->m_ctrlCancel->SetImg(4);
this->m_ctrlNext->SetImg(5);
}
}
void FrmMain::OnScale(bool isShow)
{
this->m_ctrlCountry->ShowWnd(isShow);
this->m_ctrlCountryStreet->ShowWnd(isShow);
this->m_ctrlProvStreet->ShowWnd(isShow);
this->m_ctrlStreet->ShowWnd(isShow);
}
// 点击目标按钮后的控件显示情况
void FrmMain::OnTarget(bool isShow)
{
this->m_ctrlStart->ShowWnd(isShow);
this->m_ctrlEnd->ShowWnd(isShow);
this->m_ctrlBack->ShowWnd(isShow);
this->m_ctrlCancel->ShowWnd(isShow);
this->m_ctrlNext->ShowWnd(isShow);
this->m_ctrlStreeInfo->ShowWnd(isShow);
this->m_ctrlLongLat->ShowWnd(isShow);
}
bool FrmMain::IsTargetControl(CString key)
{
if (key == "IDC_BTN_MAIN_SETSTART" || key == "IDC_BTN_MAIN_SETEND" ||
key == "IDC_BTN_BACK" || key == "IDC_BTN_CANCEL" ||
key == "IDC_BTN_MAIN_NEXT" || key == "IDC_BTN_MAIN_STREETINFO" ||
key == "IDC_BTN_MAIN_LONGLATPOSIT")
{
return true;
}
return false;
}
void FrmMain::OnTimer()
{
CString strTime = ToolKit::GetTime();
this->m_ctrlTimer->SetText(strTime);
UpdateWindow(this->m_hWnd);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -