📄 thtmldlg.cpp
字号:
// ThtmlDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Thtml.h"
#include "ThtmlDlg.h"
#include "iesdk.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CThtmlDlg dialog
CThtmlDlg::CThtmlDlg(CWnd* pParent /*=NULL*/)
: CDialog(CThtmlDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CThtmlDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CThtmlDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CThtmlDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CThtmlDlg, CDialog)
//{{AFX_MSG_MAP(CThtmlDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_SIZE()
ON_NOTIFY(NM_CLICK, IDC_TXT, OnClickTxt)
ON_EN_CHANGE(IDC_TXT, OnChangeTxt)
ON_COMMAND(IDM_FRESH, OnFresh)
ON_COMMAND(IDM_OPEN, OnOpen)
ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeList)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CThtmlDlg message handlers
char * g_phtml;
BOOL CThtmlDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
g_phtml = NULL;
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_strFileName = "d:\\2.htm";
return TRUE; // return TRUE unless you set the focus to a control
}
void CThtmlDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
if( g_phtml != NULL) delete g_phtml;
CDialog::OnClose();
}
void CThtmlDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CThtmlDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
m_bonshown = true;
// this->OnFresh();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CThtmlDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CThtmlDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (!m_bonshown) return;
// TODO: Add your message handler code here
CRichEditCtrl * ptxt = (CRichEditCtrl *)GetDlgItem(IDC_TXT);
ptxt->MoveWindow(0,0,cx,cy,true);
}
void CThtmlDlg::GetTxt(CString &str)
{
CRichEditCtrl * ptxt = (CRichEditCtrl *)GetDlgItem(IDC_TXT);
if( ptxt == NULL ) return;
ptxt->GetWindowText(str);
}
void CThtmlDlg::OnClickTxt(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CThtmlDlg::OnChangeTxt()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
#define MAX_LOADSTRING 100
#define TXT_SIZE 1024*256
#define MAX_HOTPOT_SIZE 256
HOTPOT g_aHotpot[MAX_HOTPOT_SIZE];
char g_szPageTxtRet[TXT_SIZE];
void CThtmlDlg::OnFresh()
{
// TODO: Add your command handler code here
CRichEditCtrl * ptxt = (CRichEditCtrl *)GetDlgItem(IDC_TXT);
CListBox * plist =(CListBox * )GetDlgItem(IDC_LIST);
if( ptxt == NULL || plist == NULL ) return;
for(int nn = plist->GetCount();nn>0;nn--)
plist->DeleteString(nn-1);
FILE * fp;
fp = fopen((LPCTSTR)m_strFileName, "r+b");
if( fp == NULL) return;
fseek(fp,0,SEEK_END);
DWORD len = ftell(fp);
if(g_phtml != NULL)
delete g_phtml;
g_phtml = new char[len];
fseek(fp,0,SEEK_SET);
memset(g_szPageTxtRet,0,1024*64);
if( fread(g_phtml,1,len,fp) == len )
{
ZHtml ohtml(g_phtml,g_szPageTxtRet);
int n = ohtml.ParsePage(g_aHotpot,MAX_HOTPOT_SIZE);
for(int i=0;i<n;i++)
{
char str[124];
memset(str,0,124);
strncpy(str, &g_szPageTxtRet[g_aHotpot[i].hpStart],12);
plist->AddString( str);
}
}
fcloseall();
ptxt->SetWindowText(g_szPageTxtRet);
}
void CThtmlDlg::OnOpen()
{
// TODO: Add your command handler code here
const char szFilter[] = " (*.*)|*.*||";
DWORD dwFlags = OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
CFileDialog fDlg(true, "*.*", NULL, dwFlags, szFilter);
if (fDlg.DoModal() == IDOK)
{
m_strFileName = fDlg.GetPathName();
OnFresh();
}
}
extern int GetSelectOption(HOTPOT * php, char * pdst, int nsize,void * phtml );
void CThtmlDlg::OnSelchangeList()
{
// TODO: Add your control notification handler code here
CRichEditCtrl * ptxt = (CRichEditCtrl *)GetDlgItem(IDC_TXT);
CEdit * pedit = (CEdit * ) GetDlgItem(IDC_EDIT);
CListBox * plist =(CListBox * )GetDlgItem(IDC_LIST);
CEdit * pltxt = (CEdit * ) GetDlgItem(IDC_LINKTXT);
if( !pltxt || !pedit || !ptxt || !plist )return;
int i = plist->GetCurSel();
if( i == -1 ) return;
int start = g_aHotpot[i].hpStart;
int end = g_aHotpot[i].hpEnd ;
ptxt->SetSel(start,end);
char str[124];
memset(str,0,124);
strncpy(str, &g_phtml[g_aHotpot[i].hpJumpTo],120);
pedit->SetWindowText(str);
memset(str,0,124);
strncpy(str, &g_szPageTxtRet[g_aHotpot[i].hpStart],g_aHotpot[i].hpEnd -g_aHotpot[i].hpStart);
pltxt->SetWindowText(str);
CString sstr;
pltxt = (CEdit * ) GetDlgItem(IDC_START);
sstr.Format("%d",g_aHotpot[i].hpStart);
pltxt->SetWindowText((LPCTSTR)sstr);
pltxt = (CEdit * ) GetDlgItem(IDC_END);
sstr.Format("%d",g_aHotpot[i].hpEnd );
pltxt->SetWindowText((LPCTSTR)sstr);
pltxt = (CEdit * ) GetDlgItem(IDC_TYPE);
sstr.Format("%d",g_aHotpot[i].hpStyle );
pltxt->SetWindowText((LPCTSTR)sstr);
pltxt = (CEdit * ) GetDlgItem(IDC_VALUE);
sstr.Format("%d",g_aHotpot[i].hpValue );
pltxt->SetWindowText((LPCTSTR)sstr);
plist =(CListBox * )GetDlgItem(IDC_LISTTEST);
if( !plist ) return;
for(int nn = plist->GetCount();nn>0;nn--)
plist->DeleteString(nn-1);
if(g_aHotpot[i].hpStyle == 2 )
{
char pret[1024];
int ntot = GetSelectOption(&g_aHotpot[i], pret, 1024, g_phtml);
char * ptr = pret;
while(ntot--)
{
plist->AddString(ptr);
ptr += (int)strlen(ptr) + 1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -