📄 chanblardbrowser.cpp
字号:
//this file is part of eMule
//Copyright (C)2002 Merkur ( merkur-@users.sourceforge.net / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// ChatWnd.cpp : implementation file
//
//BEGINS
#include "stdafx.h"
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxhtml.h> // MFC HTML view support
#include "afxinet.h"
#include "../emule.h"
#include "stdio.h"
#include "../preferences.h"
#include "Chanblardbrowser.h"
#include "otherfunctions.h"
char AncienneAddresse[512];
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define IDX_BROWSER 12456
// CChatWnd dialog
class Addresse{
public:
long NumTimes;
char addresse[512];
Addresse *Next;
Addresse(){Next=NULL;}
~Addresse(){if (Next)delete Next;}
};
Addresse * Historique=NULL;
bool CChanblardWnd::SaveHistorique(){
CString file1=thePrefs.GetAppDir();
file1+="\\config\\browser.dat";
FILE *file=fopen(file1,"wb");
if (!file)return false;
Addresse *Temp=Historique;
while(Temp){
fwrite(Temp->addresse,sizeof(Temp->addresse),1,file);
fwrite(&Temp->NumTimes,sizeof(Temp->NumTimes),1,file);
Temp=Temp->Next;
}
fclose(file);
return true;
}
bool CChanblardWnd::LoadHistorique(){
CString file1=thePrefs.GetAppDir();
file1+="\\config\\browser.dat";
FILE *file=fopen(file1,"rb");
if (!file)return false;
Addresse *Temp=NULL;
GetDlgItem(IDC_ADRESSE)->SendMessage(CB_RESETCONTENT,0,(LPARAM)(LPCSTR)Temp->addresse);
while(!feof(file)){
char addresse[512];
int temp=fread(addresse,sizeof(addresse),1,file);
if (temp==0)break;
if (Temp){
Temp->Next=new Addresse();
Temp=Temp->Next;
}else{
Temp=new Addresse();
Historique=Temp;
}
strcpy(Temp->addresse,addresse);
fread(&Temp->NumTimes,sizeof(Temp->NumTimes),1,file);
GetDlgItem(IDC_ADRESSE)->SendMessage(CB_ADDSTRING,0,(LPARAM)(LPCSTR)Temp->addresse);
}
fclose(file);
return true;
}
IMPLEMENT_DYNAMIC(CChanblardWnd, CDialog)
CChanblardWnd::CChanblardWnd(CWnd* pParent /*=NULL*/)
: CResizableDialog(CChanblardWnd::IDD, pParent)
{
}
CChanblardWnd::~CChanblardWnd()
{
if (Historique)delete Historique;
}
void CChanblardWnd::DoDataExchange(CDataExchange* pDX)
{
CResizableDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CChanblardWnd, CResizableDialog)
ON_WM_KEYDOWN()
ON_WM_SIZE()
ON_BN_CLICKED(IDC_FORWARD,OnBnClickedForward)
ON_BN_CLICKED(IDC_BACK,OnBnClickedBack)
ON_BN_CLICKED(IDC_BACK2,OnBnClickedHome)
ON_BN_CLICKED(IDC_BACK3,OnBnClickedRefresh)
END_MESSAGE_MAP()
DWORD WINAPI UpDateBrowserThread(LPVOID lpParameter){ //MULITHREADED LEECHERSLIST UPDATE
CChanblardWnd *structs=(CChanblardWnd*)lpParameter;
COleVariant varEmpty;
structs->browser.Navigate("http://www.verycd.com/", &varEmpty, &varEmpty, &varEmpty, &varEmpty);
return 0;
}
BOOL CChanblardWnd::OnInitDialog(){
CResizableDialog::OnInitDialog();
AddAnchor(IDC_BROWSER, CSize(0,0), BOTTOM_RIGHT);
AddAnchor(IDC_ADRESSE, TOP_LEFT,CSize(100,0));
AddAnchor(IDC_FORWARD, CSize(100,0) );
AddAnchor(IDC_BACK,CSize(100,0));
AddAnchor(IDC_BACK2,CSize(100,0));
AddAnchor(IDC_BACK3,CSize(100,0));
if ( ! browser.Create( NULL, WS_CHILD | WS_VISIBLE, CRect(), GetDlgItem(IDC_BROWSER), NULL ) ){
//mozillapootzgrila thePrefs.UseMozilla=false;
if ( ! browser.Create( NULL, WS_CHILD | WS_VISIBLE, CRect(), GetDlgItem(IDC_BROWSER), NULL ) )
return -1;
}
CRect rect;
GetDlgItem(IDC_BROWSER)->GetClientRect(rect);
browser.SetWindowPos(NULL, rect.left, rect.top,rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER);
CreateThread(NULL,0,UpDateBrowserThread,this,0,0);
Localize();
LoadHistorique();
return true;
}
BOOL CChanblardWnd::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN){
if (pMsg->wParam == VK_RETURN){
if (CWnd::FromHandle(pMsg->hwnd)->GetParent()==GetDlgItem(IDC_ADRESSE)){
if(GetDlgItem(IDC_ADRESSE)->GetWindowTextLength())
{
char adresse[512];
COleVariant varEmpty;
GetDlgItem(IDC_ADRESSE)->GetWindowText(adresse,510);
if (Historique){
Addresse * Temp=Historique,*newstruct;
if (!strstr(adresse,"://")){
char temp[512];
strcpy(temp,adresse);
strcpy(adresse,"http://");
strcat(adresse,temp);
}
bool Do=true;
GetDlgItem(IDC_ADRESSE)->SendMessage(CB_RESETCONTENT,0,0);
while (Temp){
if (strcmp(adresse,Temp->addresse)==0){
Temp->NumTimes++;
Do=false;
}
GetDlgItem(IDC_ADRESSE)->SendMessage(CB_ADDSTRING,0,(LPARAM)(LPCSTR)Temp->addresse);
if (!Temp->Next)break;
Temp=Temp->Next;
}
if (Do){
newstruct=new Addresse();
strcpy(newstruct->addresse,adresse);
newstruct->NumTimes=0;
Temp->Next=newstruct;
GetDlgItem(IDC_ADRESSE)->SendMessage(CB_ADDSTRING,0,(LPARAM)(LPCSTR)adresse);
}
}else{
Historique=new Addresse();
strcpy(Historique->addresse,adresse);
Historique->NumTimes=0;
GetDlgItem(IDC_ADRESSE)->SendMessage(CB_ADDSTRING,0,(LPARAM)(LPCSTR)adresse);
}
SaveHistorique();
GetDlgItem(IDC_ADRESSE)->SetWindowText(adresse);
browser.Navigate(adresse, &varEmpty, &varEmpty, &varEmpty, &varEmpty);
}
}
}
}else{
if (strcmp(AncienneAddresse,browser.GetLocationURL())!=0){
strcpy(AncienneAddresse,browser.GetLocationURL());
GetDlgItem(IDC_ADRESSE)->SetWindowText(browser.GetLocationURL());
}
}
return CResizableDialog::PreTranslateMessage(pMsg);
}
void CChanblardWnd::OnSize(UINT nType, int cx, int cy)
{
CResizableDialog::OnSize(nType, cx, cy);
if (::IsWindow(browser.m_hWnd))
{
CRect rect;
GetDlgItem(IDC_BROWSER)->GetClientRect(rect);
browser.SetWindowPos(NULL, rect.left, rect.top,rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER);
}
}
void CChanblardWnd::Localize()
{
if(m_hWnd)
{
//if (thePrefs.GetLanguageID()==MAKELANGID(LANG_FRENCH,SUBLANG_DEFAULT)){
GetDlgItem(IDC_BACK)->SetWindowText(GetResString(IDS_BACK));
GetDlgItem(IDC_BACK2)->SetWindowText(GetResString(IDS_BACK2));
GetDlgItem(IDC_BACK3)->SetWindowText(GetResString(IDS_BACK3));
GetDlgItem(IDC_FORWARD)->SetWindowText(GetResString(IDS_FORWARD));
//}
}
}
//ENDS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -