📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "linjunjuan.h"
#include "MainFrm.h"
#include <sys/timeb.h>
#include <time.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_HIDEWINDOW, OnHidewindow)
ON_WM_ACTIVATE()
ON_COMMAND(IDM_CUT, OnCut)
ON_COMMAND(IDM_FIND_REF, OnFindRef)
ON_COMMAND(IDM_PIPEI, OnPipei)
ON_COMMAND(IDM_ORG_MATCH, OnOrgMatch)
ON_COMMAND(IDM_TEST_TIME_ORG, OnTestTimeOrg)
ON_COMMAND(IDM_TEST_TIME_NEW, OnTestTimeNew)
ON_COMMAND(IDM_OUT_MATHC, OnOutMathc)
//}}AFX_MSG_MAP
// ON_MESSAGE(WM_BRIGHT,OnBright)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR,
ID_INDICATOR_X,
ID_INDICATOR_Y,
ID_INDICATOR_ROW,
ID_INDICATOR_COL,// status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
/*
m_pDlgexit=1;
m_pDlg = new CPixel(this);
if (m_pDlg->GetSafeHwnd()==0)
{
m_pDlg->Create();
}*/
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
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
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
RegisterHotKey(m_hWnd,1001,MOD_CONTROL|MOD_SHIFT,'Q');
RegisterHotKey(m_hWnd,1002,MOD_CONTROL|MOD_SHIFT,'q');
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnHidewindow()
{
AfxMessageBox("唤醒热键为: Shift+Q");
CWnd::ShowWindow(SW_HIDE);//隐藏窗口
//以下代码隐藏当前进程
typedef DWORD (WINAPI Fun) (DWORD,DWORD); //定义回调函数原型
HINSTANCE hKernel=LoadLibrary("Kernel32.dll");
if ( hKernel != NULL)
{
Fun * RegQisterServiceProcess=(Fun *)GetProcAddress(hKernel,"RegisterServiceProcess");
( *RegQisterServiceProcess)(NULL,1);
FreeLibrary(hKernel);
}
}
LRESULT CMainFrame::OnBright(WPARAM wParam,LPARAM lParam)
{
/*
pDoc=(CLinjunjuanDoc *)lParam;
if ((pDoc->m_hDIB=ChangeToHDIB(pDoc->orgpic,wParam))==NULL)
return 0L;
pDoc->flagsmall_big=TRUE;
pDoc->UpdateAllViews(NULL);
*/
pDoc=(CLinjunjuanDoc *)lParam;
if (pDoc->m_palDIB != NULL)
{
delete pDoc->m_palDIB;
pDoc->m_palDIB = NULL;
}
if (pDoc->m_hDIB == NULL)
{
return 0L;
}
// Set up document size
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB);
if (::DIBWidth(lpDIB) > INT_MAX ||::DIBHeight(lpDIB) > INT_MAX)
{
::GlobalUnlock((HGLOBAL) pDoc->m_hDIB);
::GlobalFree((HGLOBAL) pDoc->m_hDIB);
pDoc->m_hDIB = NULL;
CString strMsg;
strMsg = "IDS_DIB_TOO_BIG";
MessageBox(NULL, strMsg, MB_ICONINFORMATION | MB_OK);
return 0L;
}
// m_sizeDoc = CSize((int) ::DIBWidth(lpDIB), (int) ::DIBHeight(lpDIB));
::GlobalUnlock((HGLOBAL) pDoc->m_hDIB);
// Create copy of palette
pDoc->m_palDIB = new CPalette;
if (pDoc->m_palDIB == NULL)
{
// we must be really low on memory
::GlobalFree((HGLOBAL) pDoc->m_hDIB);
pDoc->m_hDIB = NULL;
return 0L;
}
if (::CreateDIBPalette(pDoc->m_hDIB,pDoc->m_palDIB) == NULL)
{
// DIB may not have a palette
delete pDoc->m_palDIB;
pDoc->m_palDIB = NULL;
return 0L;
}
pDoc->UpdateAllViews(NULL);
return 0L;
}
void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CMDIFrameWnd::OnActivate(nState, pWndOther, bMinimized);
// m_pDlg->ShowWindow(SW_SHOW);
// m_pDlgexit=FALSE;
// // TODO: Add your message handler code here
}
void CMainFrame::OnCut()
{
CCutDlg dlg;
if(dlg.DoModal()==IDOK)
{//===================================
FILE *fp;
if(dlg.m_firstnum==1)
{
fp=fopen(dlg.m_txtpath,"w");
fprintf(fp," 原始截取模拟SAR图\n");
fprintf(fp,"高度为%dm\n\n",dlg.height);
fclose(fp);
}
int x,y;
//==========================1
Picture temp;
temp.p=fspace_2d(1500,1500);
temp.row=temp.col=1500;
char outsar[512]="";
char outopt[512]="";
char outmoni[512]="";
char outdem[512]="";
strcpy(outsar,dlg.m_sar_c_path);
strcpy(outopt,dlg.m_ref_c_path);
strcpy(outmoni,dlg.m_moni_path);
strcpy(outdem,dlg.m_dim_c_path);
POINT Client_circle;
Picture input_sar ,input_opt,input_dem;
//==========================2
if(dlg.m_sarpath!="")
input_sar.p=InputImageWithName(dlg.m_sarpath,input_sar.row,input_sar.col);
else
{
::MessageBox(NULL,"输入参数不完整","Error",MB_OK);
return;
}
//==========================3
//==============================计算分辨率=========================
float Res;
Res=dlg.height*tan(PI*34.0/180.0)/128.0;
for (int m=0;m<dlg.m_picnum;m++)
{
x=rand()%50;
y=rand()%500;
Client_circle.x=850+x;//col
Client_circle.y=1450+y;//row
//========================存储用于模拟的SAR============
for (int i=0;i<1500;i++)
for (int j=0;j<1500;j++)
{
if((i-1500/2+Client_circle.y)>=0 &&((i-1500/2+Client_circle.y)<3600)&&((j-1500/2+Client_circle.x)>=0)&&((j-1500/2+Client_circle.x)<3600))
temp.p[i][j]=input_sar.p[i-1500/2+Client_circle.y][j-1500/2+Client_circle.x];
else
temp.p[i][j]=0;
}
::writepic(outmoni,temp);
ChangeNameExtension1(outmoni);
int row_ref,col_ref;
row_ref=col_ref=(int)((256+64)*Res/10);
//========================存储SAR参考图=====================
Picture temp_sar_ref;
temp_sar_ref.row=row_ref;
temp_sar_ref.col=col_ref;
temp_sar_ref.p=fspace_2d(row_ref,col_ref);
for (i=0;i<row_ref;i++)
for(int j=0;j<col_ref;j++)
{
temp_sar_ref.p[i][j]=input_sar.p[Client_circle.y-row_ref/2+i][Client_circle.x-col_ref/2+j];
}
::writepic(outsar,temp_sar_ref);
ChangeNameExtension1(outsar);
dspace_2d(temp_sar_ref.p,row_ref,col_ref);
//======================存储OPT参考图====================
if(dlg.m_refpath!="")
{
input_opt.p=InputImageWithName(dlg.m_refpath,input_opt.row,input_opt.col);
Picture temp_opt_ref;
temp_opt_ref.row=row_ref;
temp_opt_ref.col=col_ref;
temp_opt_ref.p=fspace_2d(row_ref,col_ref);
for (i=0;i<row_ref;i++)
for(int j=0;j<col_ref;j++)
{
temp_opt_ref.p[i][j]=input_opt.p[Client_circle.y-row_ref/2+i][Client_circle.x-col_ref/2+j];
}
::writepic(outopt,temp_opt_ref);
ChangeNameExtension1(outopt);
dspace_2d(temp_opt_ref.p,row_ref,col_ref);
dspace_2d(input_opt.p,input_opt.row,input_opt.col);
}
//======================存储DEM参考图====================
if(dlg.m_dimpath!="")
{
FILE *demfile=NULL;
demfile=fopen(dlg.m_dimpath,"r");
input_dem.p=fspace_2d(3601,3601*2);
fread(input_dem.p,3601*3601*2,1,demfile);
fclose(demfile);
Picture temp_dem_ref;
temp_dem_ref.row=row_ref;
temp_dem_ref.col=col_ref*2;
temp_dem_ref.p=fspace_2d(row_ref,col_ref*2);
for (i=0;i<row_ref;i++)
for(int j=0;j<col_ref*2;j++)
{
temp_dem_ref.p[i][j]=input_dem.p[Client_circle.y-row_ref/2+i][Client_circle.x*2-col_ref+j];
}
::writepic(outdem,temp_dem_ref);
ChangeNameExtension1(outdem);
dspace_2d(temp_dem_ref.p,row_ref,col_ref*2);
dspace_2d(input_dem.p,3601,3601*2);
}
//=====================存储文本文件======================
fp=fopen(dlg.m_txtpath,"a");
fprintf(fp,"截图点(中心点)row = %d , 截图点(中心点)col = %d, 图片号码= % d,\n",Client_circle.y,Client_circle.x,m+dlg.m_firstnum);
fclose(fp);
}
dspace_2d(temp.p,1500,1500);
if(dlg.m_sarpath!="")
dspace_2d(input_sar.p,input_sar.row,input_sar.col);
::MessageBox(NULL,"FINISH","NOTICE",MB_OK);
}
}
void CMainFrame::OnFindRef()
{
FILE *fp;
int r[50],c[50];
fp=fopen("c:\\1.txt","r");
fseek( fp, 76, SEEK_SET );
fscanf( fp, "%d", &r[0] );
fseek(fp,27,SEEK_CUR);
fscanf(fp,"%d",&c[0]);
for (int i=1;i<50;i++)
{
fseek(fp,41,SEEK_CUR);
fscanf(fp,"%d",&r[i]);
fseek(fp,27,SEEK_CUR);
fscanf(fp,"%d",&c[i]);
}
fclose(fp);
//===========================================================
CCutDlg dlg;
if(dlg.DoModal()==IDOK)
{//===================================
//==========================1
char outsar[512]="";
char outopt[512]="";
char outmoni[512]="";
char outdem[512]="";
strcpy(outsar,dlg.m_sar_c_path);
strcpy(outopt,dlg.m_ref_c_path);
strcpy(outmoni,dlg.m_moni_path);
strcpy(outdem,dlg.m_dim_c_path);
POINT Client_circle;
Picture input_sar,input_opt,input_dem;
//==========================2
if(dlg.m_sarpath!="")
input_sar.p=InputImageWithName(dlg.m_sarpath,input_sar.row,input_sar.col);
else
{
::MessageBox(NULL,"输入参数不完整","Error",MB_OK);
return;
}
//==========================3
//==============================计算分辨率=========================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -