MainDialog.cpp
上传用户:zhoucj12
上传日期:2007-01-02
资源大小:15k
文件大小:3k
- #include "StdAfx.h"
- #include "RichEdit20.h"
- #include "MainDialog.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- CMainDialog::CMainDialog(
- CWnd* in_pParent )
- : CDialog( CMainDialog::IDD, in_pParent )
- {
- //{{AFX_DATA_INIT( CMainDialog )
- //}}AFX_DATA_INIT
- m_hIcon = AfxGetApp()->LoadIcon( IDR_MAINFRAME ) ;
- m_crLink = AfxGetApp()->LoadIcon( IDC_LINKHAND ) ;
- }
- void CMainDialog::DoDataExchange(
- CDataExchange* pDX )
- {
- CDialog::DoDataExchange( pDX ) ;
- //{{AFX_DATA_MAP( CMainDialog )
- DDX_Control( pDX, IDC_RICHEDIT, m_RichEdit ) ;
- DDX_Control( pDX, IDC_RICHEDITEX, m_RichEditEx ) ;
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP( CMainDialog, CDialog )
- //{{AFX_MSG_MAP( CMainDialog )
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_NOTIFY( EN_LINK, IDC_RICHEDITEX, OnRichEditExLink )
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BOOL CMainDialog::OnInitDialog()
- {
- CDialog::OnInitDialog() ;
- SetIcon( m_hIcon, TRUE ) ;
- SetIcon( m_hIcon, FALSE ) ;
-
- m_RichEditEx.SetEventMask( m_RichEdit.GetEventMask() | ENM_LINK ) ;
- m_RichEditEx.AutoURLDetect( TRUE ) ;
-
- return TRUE ;
- }
- void CMainDialog::OnPaint()
- {
- if( IsIconic() )
- {
- CPaintDC l_PaintDC( this ) ;
- SendMessage( WM_ICONERASEBKGND, ( WPARAM )l_PaintDC.GetSafeHdc(), 0 ) ;
- ////////////////////////////////////////////////////////////////////////
- // Center icon in client rectangle
- ////////////////////////////////////////////////////////////////////////
- int l_cIconX = ::GetSystemMetrics( SM_CXICON ) ;
- int l_cIconY = ::GetSystemMetrics( SM_CYICON ) ;
-
- CRect l_rcClient;
-
- GetClientRect( &l_rcClient ) ;
-
- int l_nX = ( l_rcClient.Width() - l_cIconX + 1 ) / 2 ;
- int l_nY = ( l_rcClient.Height() - l_cIconY + 1 ) / 2 ;
- ////////////////////////////////////////////////////////////////////////
- // Draw the icon
- ////////////////////////////////////////////////////////////////////////
- l_PaintDC.DrawIcon( l_nX, l_nY, m_hIcon ) ;
- }
- else
- {
- CDialog::OnPaint() ;
- }
- }
- HCURSOR CMainDialog::OnQueryDragIcon()
- {
- return ( HCURSOR )m_hIcon ;
- }
- void CMainDialog::OnRichEditExLink(
- NMHDR* in_pNotifyHeader,
- LRESULT* out_pResult )
- {
- ENLINK* l_pENLink = ( ENLINK* )in_pNotifyHeader ;
- *out_pResult = 0 ;
- switch( l_pENLink->msg )
- {
- default:
- {
- }
- break ;
- case WM_SETCURSOR:
- {
- if( m_crLink != NULL )
- {
- ::SetCursor( m_crLink ) ;
- *out_pResult = 1 ;
- }
- }
- break ;
- case WM_LBUTTONDOWN:
- {
- CString l_URL ;
- CHARRANGE l_CharRange ;
- m_RichEditEx.GetSel( l_CharRange ) ;
- m_RichEditEx.SetSel( l_pENLink->chrg ) ;
- l_URL = m_RichEdit.GetSelText() ;
- m_RichEditEx.SetSel( l_CharRange ) ;
- CWaitCursor l_WaitCursor ;
- ShellExecute( this->GetSafeHwnd(), _T( "open" ), l_URL, NULL, NULL, SW_SHOWNORMAL ) ;
- *out_pResult = 1 ;
- }
- break ;
- case WM_LBUTTONUP:
- {
- *out_pResult = 1 ;
- }
- break ;
- }
- }