mgsmes

19
MgsMes.cpp /*----------------------------------------------------------------------+ | name MGS信息接收器 Ver 1.00 | | comment MgsMes | | author Zhang Yi Yun MGS Soft. 2002.06.01. | | 2002.06.03. | +----------------------------------------------------------------------*/ /*----------------------------------------------------------------------+ | MgsMes.CPP 1140 (主程序) | | | | Total 1140 | +----------------------------------------------------------------------*/ /*----------------------------------------------------------------------+ | Ver 1.00 新增功能: | | | | 1. 增加信息接收功能. 2002.06.01. | | 2. 增加信息清除功能. 2002.06.01. | | 3. 增加放入系统图标功能. 2002.06.02. | | 4. 暂停功能. 2002.06.02. | | 5. 信息保存功能. 2002.06.02. | | 6. 信息另存功能. 2002.06.02. | | 7. 应用程序只运行一次功能. 2002.06.02. | | | | Ver 1.10 新增功能: | | 8. 界面直接激活功能. 2004.03.24. | | 9. 改正两个小错误. 2006.05.06. | | | | Ver 1.20 新增功能: | |10. 改进置顶设置取消功能. 2007.07.10. | |11. 支持复制当前行和所有行信息功能. 2007.07.10. | |12. 支持Ctrl+Q退出功能. 2007.07.10. | | | | Ver 2.02 新增功能: | |13. 支持英文版本. 2008.05.09. | |14. 支持界面位置/大小/置顶保存记忆功能.2012.01.01. | |15. 支持界面位置/大小/置顶保存记忆功能.2012.03.10. | |16. 支持繁体版本. 2013.11.30. | | | | Ver 2.03 新增功能: | |17. 支持系统菜单. 2014.02.24. | | | |16. 信息读入功能. 2002.06.02. | | 编程日期: 2002.06.01.-2002.06.03. | +----------------------------------------------------------------------*/ #include <string.h> #include MgsMesp.h CMainFrame *pCMain=NULL; long WndHadShowOn=0; // 记录程序窗口状态(=1 打开, =0 关闭) BOOL MyTaskBarAddIcon(HWND hwnd,UINT uID, HICON hicon, LPSTR lpszTip); BOOL MyTaskBarDeleteIcon(HWND hwnd, UINT uID); long SettingDataChange =0; // 设置数据改动标志 =0 UnChange =1 Change char SettingFileName[256]= MgsMes.CFG ; char SystemDirName[256]= ; char CurrentDirName[256]= E:\\11\\ ; char SoftwareName[ 256] = MGS信息接收器 ; // Ver 2.03 ; char SoftwareNameEN[ 3][256] = { MGS信息接收器 , MGS_MessageReceiver , MGS信息接收器 }; // Ver 1.20 ; // char SoftwareNameEN[ 3][256] = { MGS信息接收器 , MGS_MessageReceiver , MGS信息接收器 }; // Ver 1.20 ; char ErrTmp[256]; char mes[256]; long Language = 0; long LanguageCode = 0x0804; // 中文简体 // 0x0409 美国英语 // 0x0404 中国繁体(台湾) // 0x0804 中国简体(中国) // 0x0C04 中国繁体(香港) // 0x1004 中国繁体(新加坡) CMainApp MainApp; BOOL CMainApp::InitInstance() 第 1 页

Upload: rajivparaj

Post on 17-Sep-2015

232 views

Category:

Documents


8 download

DESCRIPTION

MgsMes

TRANSCRIPT

  • MgsMes.cpp/*----------------------------------------------------------------------+| name MGS Ver 1.00 || comment MgsMes || author Zhang Yi Yun MGS Soft. 2002.06.01. || 2002.06.03. |+----------------------------------------------------------------------*//*----------------------------------------------------------------------+| MgsMes.CPP 1140 () || || Total 1140 |+----------------------------------------------------------------------*//*----------------------------------------------------------------------+| Ver 1.00 : || || 1. . 2002.06.01. || 2. . 2002.06.01. || 3. . 2002.06.02. || 4. . 2002.06.02. || 5. . 2002.06.02. || 6. . 2002.06.02. || 7. . 2002.06.02. || || Ver 1.10 : || 8. . 2004.03.24. || 9. . 2006.05.06. || || Ver 1.20 : ||10. . 2007.07.10. ||11. . 2007.07.10. ||12. Ctrl+Q. 2007.07.10. || || Ver 2.02 : ||13. . 2008.05.09. ||14. //.2012.01.01. ||15. //.2012.03.10. ||16. . 2013.11.30. || || Ver 2.03 : ||17. . 2014.02.24. || ||16. . 2002.06.02. || : 2002.06.01.-2002.06.03. |+----------------------------------------------------------------------*/#include #include "MgsMesp.h"CMainFrame *pCMain=NULL;long WndHadShowOn=0; // (=1 , =0 )BOOL MyTaskBarAddIcon(HWND hwnd,UINT uID, HICON hicon, LPSTR lpszTip);BOOL MyTaskBarDeleteIcon(HWND hwnd, UINT uID); long SettingDataChange =0; // =0 UnChange =1 Change char SettingFileName[256]= "MgsMes.CFG"; char SystemDirName[256]=""; char CurrentDirName[256]="E:\\11\\"; char SoftwareName[ 256] = "MGS"; // Ver 2.03"; char SoftwareNameEN[ 3][256] = { "MGS", "MGS_MessageReceiver", "MGS"}; // Ver 1.20";// char SoftwareNameEN[ 3][256] = { "MGS", "MGS_MessageReceiver", "MGS"}; // Ver 1.20"; char ErrTmp[256]; char mes[256]; long Language = 0; long LanguageCode = 0x0804; // // 0x0409 // 0x0404 () // 0x0804 () // 0x0C04 () // 0x1004 ()CMainApp MainApp;BOOL CMainApp::InitInstance()

    1

  • MgsMes.cpp{extern HWND MGS_hWndFoundWindow; AfxEnableControlContainer(); SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // if( MGS_SearchWindow( SoftwareName, ON) ) return TRUE; pCMain= new CMainFrame(); m_pMainWnd= pCMain; m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); return TRUE;}BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_WM_SIZE() ON_WM_CLOSE()// ON_WM_CHAR()// ON_WM_KEYDOWN() ON_WM_RBUTTONDOWN() ON_WM_PARENTNOTIFY() ON_WM_SYSCOMMAND() ON_MESSAGE( ID_MSG_NOTIFYICON, OnMyIconNotify) ON_MESSAGE( ID_MSG_SHOWAPPICONIC, OnShowAppIconic) ON_COMMAND( IDC_MGSMES, OnMgsMes) ON_COMMAND( ID_FILE_NEW , OnFileNew ) ON_COMMAND( ID_FILE_OPEN, OnFileOpen) ON_COMMAND( ID_FILE_SAVE, OnFileSave) ON_COMMAND( ID_FILE_SAVE_AS, OnFileSaveAs) ON_COMMAND( ID_FILE_EXIT, OnClose) ON_COMMAND( ID_APP_ABOUT, OnMgsMesAbout) //}}AFX_MSG_MAPEND_MESSAGE_MAP()CMainFrame::CMainFrame(){ CRect R(10,10,800,600); mPause= 0; // =0 , =1 mTopMost=0; // =0 OFF, =1 ON R.right = 480+10; R.bottom= 240+10; // LanguageCode= GetSystemDefaultLangID(); if( LanguageCode == 0x0804) Language= 0; // 0x0804 Chinese (PRC) if( LanguageCode == 0x0409) Language= 1; // 0x0409 English if( LanguageCode == 0x0404) Language= 2; // 0x0404 Chinese (Taiwan) // 0x0c04 Chinese (Hong Kong SAR, PRC) // 0x1004 Chinese (Singapore)// if( Language == 2) GBtoBig5( SoftwareNameEN[ 2], SoftwareNameEN[ 0]); if( Language == 2) strcpy( SoftwareNameEN[ 2], SoftwareNameEN[ 1]); strcpy( SoftwareName, SoftwareNameEN[ Language]); Create(NULL, SoftwareName, WS_OVERLAPPEDWINDOW, R); if( ReadSavePos( 0 ) == 0) CenterWindow(); CheckPos( ); mIcon[0]= LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME) ); if( mIcon[0] != NULL) SetIcon( mIcon[0], TRUE); // 16x16}#define ID_MGSMES_Infor 0#define ID_MGSMES_Fansoft 1#define ID_MGSMES_TopMost 2#define ID_MGSMES_Pause 3#define ID_MGSMES_Save 4#define ID_MGSMES_Clear 5

    2

  • MgsMes.cpp // #define ID_MGSMES_Num 6static UINT BASED_CODE Indicators[]={ ID_MGSMES_Infor, ID_MGSMES_Fansoft, ID_MGSMES_TopMost, ID_MGSMES_Pause, ID_MGSMES_Clear, ID_MGSMES_Save,}; char Error_EN[ 3][256]={ "", "Error", "" }; char Name_Fansoft_EN[ 3][256]= { " : www.fansoft.net Email:[email protected]", " WebSite: www.fansoft.net Email:[email protected]", " : www.fansoft.net Email:[email protected]"}; char Name_TopMost_EN[ 3][256] = { " ", "TopMost", " " }; char Name_Pause_EN[ 3][256] = { " ", " Pause" , " " }; char Name_Save_EN[ 3][256] = { " ", " Save" , " " }; char Name_Clear_EN[ 3][256] = { " ", " Clear" , " " }; char Welcome_EN[ 3][8][256]= { { "", " ", "MGS Ver 2.03, 2002.06.-2014.02.", " ", ": .", ": www.fansoft.net Email:[email protected]", " " }, { "Welcome to use!", " ", "MGS Message Receiver, Ver 2.03, 2002.06.-2014.02.", " ", "Development: Zhang Yiyun, Xi'an Jiaotong University.", "WebSite: www.fansoft.net Email:[email protected]", " " }, { "", " ", "MGS Ver 2.03, 2002.06.-2014.02.", " ", ": .", ": www.fansoft.net Email:[email protected]", " " }, };int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){ long i; if( CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; // pMainMenu= new CMenu(); if( Language == 1) pMainMenu->LoadMenu( IDR_MAIN_MENU_EN); else pMainMenu->LoadMenu( IDR_MAIN_MENU_CN); SetMenu( pMainMenu); DrawMenuBar(); CMenu *pMenu; pMenu= GetSystemMenu( FALSE); // // pMenu->EnableMenuItem( SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);// pMenu->AppendMenu( MF_ENABLED, IDC_Copy , "Copy"); pMenu->AppendMenu( MF_ENABLED, IDC_TopMost, "TopMost"); pMenu->AppendMenu( MF_ENABLED, IDC_Pause , "Pause"); pMenu->AppendMenu( MF_ENABLED, IDC_Save , "Save");

    3

  • MgsMes.cpp pMenu->AppendMenu( MF_ENABLED, IDC_Clear , "Clear"); if( Language == 2) { GBtoBig5( Error_EN[ 2], Error_EN[ 0]); GBtoBig5( Name_Fansoft_EN[ 2], Name_Fansoft_EN[ 0]); GBtoBig5( Name_TopMost_EN[ 2], Name_TopMost_EN[ 0]); GBtoBig5( Name_Pause_EN[ 2], Name_Pause_EN[ 0]); GBtoBig5( Name_Save_EN[ 2], Name_Save_EN[ 0]); GBtoBig5( Name_Clear_EN[ 2], Name_Clear_EN[ 0]); for( i=0; iCreate( Style, R,this, IDC_EDIT1); mpCListBox->AddString( Welcome_EN[ Language][0]); // "" mpCListBox->AddString( Welcome_EN[ Language][1]); mpCListBox->AddString( Welcome_EN[ Language][2]); // "MGS Ver 1.20, 2002.06.-2007.07."); mpCListBox->AddString( Welcome_EN[ Language][3]); mpCListBox->AddString( Welcome_EN[ Language][4]); // : ."); mpCListBox->AddString( Welcome_EN[ Language][5]); // : www.fansoft.net Email:[email protected]"); mpCListBox->AddString( Welcome_EN[ Language][6]); return 0;} long Run=0;/*----------------------------------------------------------------------+| name CMainFrame::OnSize() Ver 1.00 || comment CMainFrame::OnSize() || author Zhang Yi Yun MGS Soft. 1998.10.08. || 1998.10.08. |+----------------------------------------------------------------------*/void CMainFrame::OnSize( UINT nType, int cx, int cy){static long StatusBarWid[]= { 0, 260, 35, 35, 35, 35, 60,60}; CRect r; UINT nID, nStyle; int i, cxWidth; CFrameWnd::OnSize(nType, cx, cy); Run++; if( Run < 2 ) return; Run=2; GetClientRect( &r); r.bottom= r.bottom-22; mpCListBox->MoveWindow( &r); GetClientRect( &r); r.top= r.bottom-22; r.left= 0; mStatusBar.MoveWindow( &r); mStatusBar.GetPaneInfo( ID_MGSMES_Infor, nID, nStyle, cxWidth); cxWidth= r.right-18;

    4

  • MgsMes.cpp for(i=1; imessage == WM_KEYDOWN) { switch( pMsg->wParam ) { case 'O': case 'o': case 'S': case 's': case 'q': case 'Q': case 'w': case 'W': if( OnCharDeal( pMsg->wParam) ) return TRUE; break; } } return CFrameWnd::PreTranslateMessage(pMsg);}/*----------------------------------------------------------------------+| name CopyTextToClipboard Ver 1.00 || comment CopyTextToClipboard || author Zhang Yi Yun MGS Soft. 2003.02.14. || 2003.02.14. |+----------------------------------------------------------------------*/void CMainFrame::CopyTextToClipboard( void ){ // Ctrl_Off: , Ctrl_On: All Linesstatic byte KeyBuff[256]; long Key_Ctrl=0, Key_Shift=0; long i, Count, Pos, Len; CString Text, TextBuffer; char *pBuffer= NULL; GetKeyboardState( KeyBuff); Key_Ctrl= OFF; if( KeyBuff[VK_CONTROL] & 128 ) Key_Ctrl= ON; Key_Shift= OFF; if( KeyBuff[VK_SHIFT] & 128 ) Key_Shift= ON; Count= mpCListBox->GetCount(); TextBuffer= ""; if( Key_Ctrl != 0 || Key_Shift != 0) //

    5

  • MgsMes.cpp for( i=0; iGetText( i, Text ); if( Key_Shift != 0) // { Len= Text.GetLength(); Pos= Text.Find( "]" ); // [131,11:42:09] Text= Text.Right( Len-(Pos+1) ); } TextBuffer= TextBuffer+ Text+"\r\n"; } if( Key_Ctrl == 0 && Key_Shift == 0) // { i= mpCListBox->GetCurSel(); if( i< 0) return; Text= ""; mpCListBox->GetText( i, Text ); Len= Text.GetLength(); Pos= Text.Find( "]" ); // [131,11:42:09] Text= Text.Right( Len-(Pos+1) ); // [131,11:42:09] TextBuffer= Text; } SendTextToClipboard( TextBuffer); return;} /*----------------------------------------------------------------------+| name CMGS::OnChar Ver 1.10 || comment key. || author Zhang Yi Yun MGS Soft. 2001.06.02. || 2001.06.02. |+----------------------------------------------------------------------*/long CMainFrame::OnCharDeal( char Ascii){ // ret =1 , =0 # define CTL_O 0x180F# define CTL_Q 0x1011# define CTL_W 0x1117# define CTL_S 0x1F13 byte KeyBuff[256]; long Key_Ctrl; WORD code= 0; GetKeyboardState( KeyBuff); Key_Ctrl= OFF; if( KeyBuff[VK_CONTROL] & 128 ) Key_Ctrl= ON; if( Key_Ctrl ) { if( Ascii == 'o' || Ascii == 'O') code= CTL_O; if( Ascii == 's' || Ascii == 'S') code= CTL_S; if( Ascii == 'q' || Ascii == 'Q') code= CTL_Q; } /*--------------------------------------------------------------+ | | +--------------------------------------------------------------*/ switch ( code ) { case CTL_O : PostMessage( WM_COMMAND, ID_FILE_OPEN, 0); break; case CTL_S : PostMessage( WM_COMMAND, ID_FILE_SAVE, 0); break; case CTL_Q : case CTL_W : PostMessage( WM_COMMAND, ID_FILE_EXIT, 0); break; } if( code ) return( 1); return( 0);}

    6

  • MgsMes.cpp/*----------------------------------------------------------------------+| name CMainFrame::OnParentNotify) Ver 1.00 || comment CMainFrame::OnParentNotify) || author Zhang Yi Yun MGS Soft. 1998.10.08. || 1998.10.08. |+----------------------------------------------------------------------*/void CMainFrame::OnParentNotify( UINT message, LPARAM lParam){extern long RS232_Busy;extern long ChannelNo; CFrameWnd::OnParentNotify(message, lParam); CRect r; CPoint PosCur, PosCen; long Changed= 0; UINT nID, nStyle; int cxWidth; byte KeyBuff[256]; long Key_Ctrl; mStatusBar.GetWindowRect( &r); GetCursorPos( &PosCur); if( !r.PtInRect( PosCur) ) return; ScreenToClient( &PosCur); GetKeyboardState( KeyBuff); Key_Ctrl= OFF; if( KeyBuff[VK_CONTROL] & 128 ) Key_Ctrl= ON; // Clear mStatusBar.GetItemRect( ID_MGSMES_Clear, &r); if( PosCur.x >r.left && PosCur.x < r.right) { if( message == WM_LBUTTONDOWN) { mStatusBar.GetPaneInfo( ID_MGSMES_Clear, nID, nStyle, cxWidth); nStyle= SBPS_NORMAL; mStatusBar.SetPaneInfo( ID_MGSMES_Clear, nID, nStyle, cxWidth); /*--------------------------------------------------------------+ | CTRL, . | +--------------------------------------------------------------*/ if( !Key_Ctrl ) { ClearMsg( ); SetWindowText( SoftwareName); } /*--------------------------------------------------------------+ | CTRL, . | +--------------------------------------------------------------*/ if( Key_Ctrl ) { SetWindowPos( NULL, 0, 0, 480+0, 240+0, SWP_NOMOVE| SWP_NOZORDER); CenterWindow(); ReadSavePos( 1); SetWindowText( "."); OnMgsMes( ); } ::Sleep( 250 ); // mStatusBar.GetPaneInfo( ID_MGSMES_Clear, nID, nStyle, cxWidth); nStyle= SBPS_POPOUT; mStatusBar.SetPaneInfo( ID_MGSMES_Clear, nID, nStyle, cxWidth); } } // Save mStatusBar.GetItemRect( ID_MGSMES_Save, &r); if( PosCur.x >r.left && PosCur.x < r.right) { if( message == WM_LBUTTONDOWN) { mStatusBar.GetPaneInfo( ID_MGSMES_Save, nID, nStyle, cxWidth); nStyle= SBPS_NORMAL; mStatusBar.SetPaneInfo( ID_MGSMES_Save, nID, nStyle, cxWidth);

    7

  • MgsMes.cpp /*--------------------------------------------------------------+ | CTRL, . | +--------------------------------------------------------------*/ if( !Key_Ctrl ) SaveMsg( "MgsMes.Txt"); /*--------------------------------------------------------------+ | CTRL, . | +--------------------------------------------------------------*/ if( Key_Ctrl ) { ReadSavePos( 1); SetWindowText( "."); OnMgsMes( ); } ::Sleep( 250 ); // mStatusBar.GetPaneInfo( ID_MGSMES_Save, nID, nStyle, cxWidth); nStyle= SBPS_POPOUT; mStatusBar.SetPaneInfo( ID_MGSMES_Save, nID, nStyle, cxWidth); } } // Pause mStatusBar.GetItemRect( ID_MGSMES_Pause, &r); if( PosCur.x >r.left && PosCur.x < r.right) { if( message == WM_LBUTTONDOWN) { mPause= (mPause+1)%2; // =0 , =1 } mStatusBar.GetPaneInfo( ID_MGSMES_Pause, nID, nStyle, cxWidth); nStyle= SBPS_NORMAL; if( mPause == 0) nStyle= SBPS_POPOUT; mStatusBar.SetPaneInfo( ID_MGSMES_Pause, nID, nStyle, cxWidth); } // ID_MGSMES_TopMost mStatusBar.GetItemRect( ID_MGSMES_TopMost, &r); if( PosCur.x >r.left && PosCur.x < r.right) { if( message == WM_LBUTTONDOWN) { mTopMost= (mTopMost+1)%2; // =0 OFF, =1 ON if( mTopMost ) { SetWindowPos( &wndTopMost, -1, -1, -1, -1, SWP_NOMOVE| SWP_NOSIZE); } else { SetWindowPos( &wndNoTopMost, -1, -1, -1, -1, SWP_NOMOVE| SWP_NOSIZE);// SetWindowPos( &wndBottom, -1, -1, -1, -1, SWP_NOMOVE| SWP_NOSIZE); } } mStatusBar.GetPaneInfo( ID_MGSMES_TopMost, nID, nStyle, cxWidth); nStyle= SBPS_NORMAL; if( mTopMost == 0) nStyle= SBPS_POPOUT; mStatusBar.SetPaneInfo( ID_MGSMES_TopMost, nID, nStyle, cxWidth); }}/*----------------------------------------------------------------------+| name OnSysCommand Ver 1.00 || comment OnSysCommand || author Zhang Yi Yun MGS Soft. 1997.04.09. || 1997.04.09. |+----------------------------------------------------------------------*/void CMainFrame::OnSysCommand( UINT nID, LPARAM lParam ){ HICON sysIcon; // UINT nStyle; int cxWidth; if( nID== SC_MAXIMIZE || nID==SC_SIZE ) return; if( nID== IDC_TopMost ) { mTopMost= (mTopMost+1)%2; // =0 OFF, =1 ON if( mTopMost ) { SetWindowPos( &wndTopMost, -1, -1, -1, -1, SWP_NOMOVE| SWP_NOSIZE); } else {

    8

  • MgsMes.cpp SetWindowPos( &wndNoTopMost, -1, -1, -1, -1, SWP_NOMOVE| SWP_NOSIZE); } mStatusBar.GetPaneInfo( ID_MGSMES_TopMost, nID, nStyle, cxWidth); nStyle= SBPS_NORMAL; if( mTopMost == 0) nStyle= SBPS_POPOUT; mStatusBar.SetPaneInfo( ID_MGSMES_TopMost, nID, nStyle, cxWidth); } if( nID== IDC_Pause ) { mPause= (mPause+1)%2; // =0 , =1 mStatusBar.GetPaneInfo( ID_MGSMES_Pause, nID, nStyle, cxWidth); nStyle= SBPS_NORMAL; if( mPause == 0) nStyle= SBPS_POPOUT; mStatusBar.SetPaneInfo( ID_MGSMES_Pause, nID, nStyle, cxWidth); } if( nID== IDC_Save ) SaveMsg( "MgsMes.Txt"); if( nID== IDC_Clear ) { ClearMsg( ); SetWindowText( SoftwareName); } if( nID== SC_MINIMIZE ) { ShowWindow( SW_HIDE ); WndHadShowOn = FALSE; sysIcon= LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME) ); MyTaskBarAddIcon(GetSafeHwnd(), 100, sysIcon, _T(SoftwareName)); } else CFrameWnd::OnSysCommand( nID, lParam );}/*----------------------------------------------------------------------+| name SendTextToClipboard Ver 1.00 || comment SendTextToClipboard || author Zhang Yi Yun MGS Soft. 2003.05.09. || 2003.05.09. |+----------------------------------------------------------------------*/long CMainFrame::SendTextToClipboard( CString Text){ //
  • MgsMes.cpp{ MyTaskBarDeleteIcon( GetSafeHwnd(), 100 ); CFrameWnd::OnClose();}/*----------------------------------------------------------------------+| name CMainFrame::OnMgsMes Ver 1.00 || comment || author Zhang Yi Yun MGS Soft. 2002.06.01. || 2002.06.01. |+----------------------------------------------------------------------*/void CMainFrame::OnMgsMes( ){static SYSTEMTIME date; long Count, TimeH, TimeM, TimeS; char Text[1024*6], TextMes[1024*5]; GetSystemTime( &date); TimeH = (date.wHour+8)%24; TimeM = date.wMinute; TimeS = date.wSecond; Count= mpCListBox->GetCount(); if( Count >= 10000) { ClearMsg( ); Count= mpCListBox->GetCount(); } GetWindowText( TextMes, 1024*4); // 2014-04-27 SetWindowText( SoftwareName); sprintf( Text,"[%3d,%02d:%02d:%02d] %s", Count, TimeH, TimeM, TimeS, TextMes); mpCListBox->AddString( Text) ; Count= mpCListBox->GetCount(); if( mPause == 0) mpCListBox->SetCurSel(Count-1);}/*----------------------------------------------------------------------+| name CMainFrame::ClearMsg Ver 1.00 || comment || author Zhang Yi Yun MGS Soft. 1998.10.27. || 1998.10.27. |+----------------------------------------------------------------------*/void CMainFrame::ClearMsg( ){ long i, Count; Count= mpCListBox->GetCount(); if( Count < 256 ) { for( i=Count-1; i>=0; i--) mpCListBox->DeleteString( i ); } else { mpCListBox->ResetContent( ); } mpCListBox->AddString( Welcome_EN[ Language][0]); // "" mpCListBox->AddString( Welcome_EN[ Language][1]); mpCListBox->AddString( Welcome_EN[ Language][2]); // "MGS Ver 1.20, 2002.06.-2007.07."); mpCListBox->AddString( Welcome_EN[ Language][3]); mpCListBox->AddString( Welcome_EN[ Language][4]); // : ."); mpCListBox->AddString( Welcome_EN[ Language][5]); // : www.fansoft.net Email:[email protected]"); mpCListBox->AddString( Welcome_EN[ Language][6]);}/*----------------------------------------------------------------------+| name CMainFrame::ClearMsg Ver 1.00 || comment || author Zhang Yi Yun MGS Soft. 1998.10.27. || 1998.10.27. |+----------------------------------------------------------------------*/void CMainFrame::SaveMsg( char FileName[]){

    10

  • MgsMes.cppextern CString MGSMES_FileText; CString Text= ""; long i, Count; Count= mpCListBox->GetCount(); MGSMES_FileText= ""; for(i=0; iGetText( i, Text ); MGSMES_FileText= MGSMES_FileText+ Text+"\r\n"; } SaveTextFile( MGSMES_FileText, FileName);}/*----------------------------------------------------------------------+| name CMainFrame::CheckPos Ver 1.00 || comment , . || author Zhang Yi Yun MGS Soft. 1998.10.27. || 1998.10.27. |+----------------------------------------------------------------------*/long CMainFrame::CheckPos( long AutoCenter ){ // =0 Ok, =1 CRect R; long xWin, yWin, ret; char ExceedName_EN[ 3][256]= { ", (%ld >%ld)", "Exceed screen range, auto center(%ld >%ld)", ", (%ld >%ld)" }; GetWindowRect( &R); xWin= GetSystemMetrics(SM_CXVIRTUALSCREEN); yWin= GetSystemMetrics(SM_CYVIRTUALSCREEN); ret= 0; if( xWin < R.left) ret= 1; if( xWin < R.left) if( AutoCenter ) { if( Language == 2) GBtoBig5( ExceedName_EN[ 2], ExceedName_EN[ 0]); sprintf( mes, ExceedName_EN[ Language], R.left, xWin); // ", (%ld >%ld)" SetWindowText( mes); OnMgsMes( ); CenterWindow(); } return( ret );}/*----------------------------------------------------------------------+| name CMainFrame::ReadSavePos Ver 1.00 || comment / || author Zhang Yi Yun MGS Soft. 1998.10.27. || 1998.10.27. |+----------------------------------------------------------------------*/long CMainFrame::ReadSavePos( long SaveOn ){extern CString MGSMES_FileText; CString PosText; char RunFileName[256]; char Text[256]= ""; CRect R; long xWid, yWid, xWin, yWin; GetModuleFileName( AfxGetInstanceHandle(), RunFileName, _MAX_PATH ); // FileExtNameDeal( RunFileName, ".CFG", EXT_NAME_SET); if( !SaveOn ) { if( FileExist( RunFileName) == -1) return( 0); ReadTextFile( RunFileName); strcpy( Text, MGSMES_FileText.GetBuffer(256) ); sscanf( Text, "%ld, %ld, %ld, %ld, %ld", &R.left, &R.top, &xWid, &yWid, &mTopMost ); xWin= GetSystemMetrics(SM_CXVIRTUALSCREEN)-24; yWin= GetSystemMetrics(SM_CYVIRTUALSCREEN)-24;// xWin= GetSystemMetrics(SM_CXSCREEN)-24;// yWin= GetSystemMetrics(SM_CYSCREEN)-24;

    11

  • MgsMes.cpp if( xWid < 100 ) xWid= 100; if( xWid > xWin) xWid= xWin; if( yWid < 50 ) yWid= 50; if( yWid > yWin) yWid= yWin; if( R.left-xWid > xWin) R.left= xWin-xWid-10; if( R.top -yWid > yWin) R.top = yWin-yWid-10; if( R.left< 0) R.left= 0; if( R.top < 0) R.top = 0; SetWindowPos( NULL, R.left, R.top, xWid, yWid, SWP_NOZORDER); // ID_MGSMES_TopMost // =0 OFF, =1 ON UINT nID, nStyle; int cxWidth; if( mTopMost ) { SetWindowPos( &wndTopMost, -1, -1, -1, -1, SWP_NOMOVE| SWP_NOSIZE); } else { SetWindowPos( &wndNoTopMost, -1, -1, -1, -1, SWP_NOMOVE| SWP_NOSIZE); } mStatusBar.GetPaneInfo( ID_MGSMES_TopMost, nID, nStyle, cxWidth); nStyle= SBPS_NORMAL; if( mTopMost == 0) nStyle= SBPS_POPOUT; mStatusBar.SetPaneInfo( ID_MGSMES_TopMost, nID, nStyle, cxWidth); } if( SaveOn ) { GetWindowRect( &R); sprintf( Text, "%ld, %ld, %ld, %ld, %ld", R.left, R.top, R.Width(), R.Height(), mTopMost); PosText= Text; SaveTextFile( PosText, RunFileName); } return( 1 );}char *MNFR_pFilterName= "Text files\0*.txt\0All files\0*.*\0";/*----------------------------------------------------------------------+| name CMainFrame::OnFileNew() Ver 1.00 || comment . || author Zhang Yi Yun MGS Soft. 2002.02.18. || 2002.02.18. |+----------------------------------------------------------------------*/void CMainFrame::OnFileNew(){ ClearMsg( );}/*----------------------------------------------------------------------+| name CMainFrame::OnFileNew() Ver 1.00 || comment . || author Zhang Yi Yun MGS Soft. 2002.02.18. || 2002.02.18. |+----------------------------------------------------------------------*/void CMainFrame::OnFileSave(){ SaveMsg( "MgsMes.Txt");}/*----------------------------------------------------------------------+| name CMainFrame::OnFileOpen() Ver 1.00 || comment . || author Zhang Yi Yun MGS Soft. 2002.02.18. || 2002.02.18. |+----------------------------------------------------------------------*/void CMainFrame::OnFileOpen(){extern CString MGSMES_FileText; char FileName[MAX_PATH]; OPENFILENAME ofn; long ret;

    12

  • MgsMes.cpp FileName[0]=0; FillMemory( &ofn, sizeof(OPENFILENAME), 0); ofn.lStructSize= sizeof(OPENFILENAME); ofn.hwndOwner= m_hWnd; ofn.lpstrFilter= MNFR_pFilterName; ofn.nFilterIndex= 1; ofn.lpstrFile= FileName; ofn.nMaxFile= MAX_PATH; ofn.lpstrInitialDir= CurrentDirName; ofn.lpstrTitle= ""; ofn.Flags= OFN_FILEMUSTEXIST; if( GetOpenFileName(&ofn)) { ret= ReadTextFile( FileName); if( ret < 0) { strcpy( ErrTmp, ""); strcat( ErrTmp, FileName); strcat( ErrTmp, ", !"); MessageBox( ErrTmp, " ", MB_OK); } else { ClearMsg( ); mpCListBox->GetText( 0, MGSMES_FileText); } }}/*----------------------------------------------------------------------+| name CMainFrame::OnFileSaveAs() Ver 1.00 || comment . || author Zhang Yi Yun MGS Soft. 2002.02.18. || 2002.02.18. |+----------------------------------------------------------------------*/void CMainFrame::OnFileSaveAs(){ char FileName[MAX_PATH]; char ExtName[64]=".CLT"; OPENFILENAME ofn; char Error[256]; long ret; FileName[0]=0; FillMemory( &ofn, sizeof(OPENFILENAME), 0); ofn.lStructSize= sizeof(OPENFILENAME); ofn.hwndOwner= m_hWnd; ofn.lpstrFilter= MNFR_pFilterName; ofn.nFilterIndex= 1; ofn.lpstrFile= FileName; ofn.nMaxFile= MAX_PATH; ofn.lpstrInitialDir= CurrentDirName; ofn.lpstrTitle= ""; ofn.Flags= OFN_PATHMUSTEXIST; if( GetOpenFileName(&ofn)) { // => Func =1 FileName, ExtName. // FileExtNameDeal( FileName, ExtName, 1); // ? if( FileExist( FileName ) != -1) { strcpy( Error, FileName); strcat( Error, "\n!\n?"); ret= MessageBox( Error, " ",MB_YESNO); if( ret == IDNO) return; } SaveMsg( FileName); }}/*----------------------------------------------------------------------+| name CMainFrame::OnMgsMesAbout() Ver 1.00 || comment MGS. || author Zhang Yi Yun MGS Soft. 2002.03.14. || 2002.03.14. |+----------------------------------------------------------------------*/

    13

  • MgsMes.cppvoid CMainFrame::OnMgsMesAbout( ){ CMgsMesAbout DlgMgsMesAbout(this); DlgMgsMesAbout.DoModal(); CopyTextToClipboard( );}

    /*----------------------------------------------------------------------+| name OnMyIconNotify Ver 1.00 || comment MYWM_NOTIFYICON || author Zhang Yi Yun MGS Soft. 1999.08.11. || 1999.08.11. |+----------------------------------------------------------------------*/void CMainFrame::OnMyIconNotify( WPARAM wParam, LPARAM lParam ){ UINT nID; UINT uMouseMsg; nID = (UINT)wParam; uMouseMsg = (UINT) lParam; if (uMouseMsg == WM_LBUTTONDOWN) // { // WndHadShowOn = (WndHadShowOn+ 1)%2; if( WndHadShowOn ) { // ShowWindow( SW_SHOWNORMAL ); SetActiveWindow( ); SetForegroundWindow(); // , . CheckPos( ); // ShowWindow( SW_MINIMIZE ); // ShowWindow( SW_SHOWNORMAL ); } else { // PostMessage( WM_SYSCOMMAND , SC_MINIMIZE); // ShowWindow( SW_HIDE ); // ShowWindow( SW_MINIMIZE ); // ShowWindow( SW_SHOWNOACTIVATE ); } }}/*----------------------------------------------------------------------+| name OnShowAppIconic Ver 1.00 || comment || author Zhang Yi Yun MGS Soft. 1999.08.11. || 1999.08.11. |+----------------------------------------------------------------------*/void CMainFrame::OnShowAppIconic( WPARAM wParam, LPARAM lParam ){ HICON sysIcon; // sysIcon= LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME) ); MyTaskBarAddIcon(GetSafeHwnd(), 100, sysIcon, _T(SoftwareName)); ShowWindow( SW_HIDE ); WndHadShowOn = FALSE;}/*----------------------------------------------------------------------+| name MyTaskBarAddIcon Ver 1.00 || comment || author Zhang Yi Yun MGS Soft. 1999.08.11. || 1999.08.11. |+----------------------------------------------------------------------*/BOOL MyTaskBarAddIcon(HWND hwnd,UINT uID, HICON hicon, LPSTR lpszTip){ BOOL res; NOTIFYICONDATA tnid; tnid.cbSize = sizeof(NOTIFYICONDATA); tnid.hWnd = hwnd; tnid.uID = uID; tnid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;

    14

  • MgsMes.cpp tnid.uCallbackMessage = ID_MSG_NOTIFYICON; tnid.hIcon = hicon; if (lpszTip) lstrcpyn(tnid.szTip, lpszTip, sizeof(tnid.szTip)); else tnid.szTip[0] = '\0'; res = Shell_NotifyIcon(NIM_ADD, &tnid); if (hicon) DestroyIcon(hicon); return res;}/*----------------------------------------------------------------------+| name MyTaskBarDeleteIcon Ver 1.00 || comment || author Zhang Yi Yun MGS Soft. 1999.08.11. || 1999.08.11. |+----------------------------------------------------------------------*/BOOL MyTaskBarDeleteIcon(HWND hwnd, UINT uID){ BOOL res; NOTIFYICONDATA tnid; tnid.cbSize = sizeof(NOTIFYICONDATA); tnid.hWnd = hwnd; tnid.uID = uID; res = Shell_NotifyIcon(NIM_DELETE, &tnid); return res;}CString MGSMES_FileText= "";/*----------------------------------------------------------------------+| name ReadTextFile() Ver 1.10 || comment . || author Zhang Yi Yun MGS Soft. 2002.03.06. || 2002.03.06. |+----------------------------------------------------------------------*/long ReadTextFile( char FileName[]){ FILE *stream; char Text[256]; long i, j, ret; MGSMES_FileText= ""; stream= fopen(FileName,"rb"); if(stream == NULL) { strcpy( ErrTmp, "()"); strcat( ErrTmp, FileName); strcat( ErrTmp, "."); ::MessageBox(NULL, ErrTmp, " ", MB_OK); ret= -1; return (ret); } j= fseek(stream, 0L, SEEK_SET); for(;;) { j= fread ( Text, 1, 128, stream); for(i=0; i
  • MgsMes.cpp{ FILE *stream; char *pText; long j, ret, Len; Len= CFileText.GetLength(); pText= CFileText.GetBuffer(Len); stream= fopen(FileName,"w+b"); if(stream == NULL) { strcpy( ErrTmp, "()"); strcat( ErrTmp, FileName); strcat( ErrTmp, "."); ::MessageBox(NULL, ErrTmp, " ", MB_OK); ret= -1; return (ret); } j= fseek( stream, 0L, SEEK_SET); ret= 0; j= fwrite ( pText, 1, Len, stream); if( j != Len ) ret= -2; fclose(stream); return 0;}/*----------------------------------------------------------------------+| || name FileExist ver 1.00 || || comment Check File Exist or not. || =-1 not Exist, !=-1 Exist. || author Zhang Yi Yun NHP Corp. 1995.04.19. || 1995.04.19. |+----------------------------------------------------------------------*/long FileExist( char FileName[]){ long ret=0; CFile fbmp; if( !fbmp.Open( FileName, CFile::modeRead| CFile::typeBinary|CFile::shareExclusive)) // { ret= -1; // Open File Error. } else { fbmp.Close(); // ret= 0; } return ( ret );}/*----------------------------------------------------------------------+| || name FileExtNameDeal Ver 1.00 || || comment . || 0=EXT_NAME_DELETE FileName. || 1=EXT_NAME_ADD_IF_NONE,.|| 2=EXT_NAME_GET FileName. || 3=EXT_NAME_SET FileNameExtName. || author Zhang Yi Yun MGS Soft. 1997.10.02. || 1997.10.03. |+----------------------------------------------------------------------*//*----------------------------------------------------------------------+| 1. (9-194.5A.PIC, PIC). 2000.01.20. |+----------------------------------------------------------------------*/void FileExtNameDeal( char FileName[], char ExtName[], long Func ){ // => Func =0 FileName, // => Func =1 FileName, ExtName. // => Func =2 FileName. // => Func =3 FileNameExtName. // => ExtName[] . ExtName[] . long i, j, len; if( Func == EXT_NAME_DELETE || Func == EXT_NAME_SET) // FileName.

    16

  • MgsMes.cpp { len= (long) strlen( FileName); for(i=len-1; i>=0; i--) // { // 1. if( FileName[i]=='.') { FileName[i]= 0; break; } } } // , FileName, ExtName. if( Func == EXT_NAME_ADD_IF_NONE || Func == EXT_NAME_SET) { j=0; for(i=0; i< (long) strlen( FileName); i++) if( FileName[i] == '.' ) j=1; if( j == 0 ) strcat( FileName, ExtName); } // , FileName. if( Func == EXT_NAME_GET) { j=-1; len= (long) strlen( FileName); for(i=0; i= 0 ) { for(i=j; i
  • MgsMes.cpp } return( Found);}/*----------------------------------------------------------------------+| name EnumWindowsProc Ver 1.00 || comment EnumWindowsProc || author Zhang Yi Yun NHP Soft. 2000.05.05. || 2000.05.05. |+----------------------------------------------------------------------*/BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam){ char buffer[256]; long i, Ok, len; GetWindowText( hWnd,buffer,256); len = strlen( MGS_FindWindowName); Ok= 1; for(i=0; i
  • MgsMes.cpp LCMapString( 0x0804, LCMAP_TRADITIONAL_CHINESE, TextGB, -1, pTextBig5, Len*2); // Big5 strcpy( TextBig5, pTextBig5); // delete [] pTextBig5; } return;}//void newlist::OnRButtonDown(UINT nFlags, CPoint point)//{// // TODO: ///// POINT curpoint;// GetCursorPos(&curpoint);// ScreenToClient(&curpoint);//// RECT test;// int i = 0;//// while(iTrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point.x,point.y,GetParent());//// break;// }// else// // ,,// SetCurSel(-1);//// i++;// }//// CListBox::OnRButtonDown(nFlags, point);//}

    19