⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 monqueror一个很具有参考价值的源玛
💻 CPP
字号:
#include <qlist.h>#include <stdio.h>#include <stdlib.h>#include <time.h>#include <string.h>#include <pwd.h>#include <pthread.h>#include <semaphore.h>#include <sys/types.h>#include <sys/wait.h>#include <unistd.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include <minigui/filedlg.h>#include "render_interface.h"#include "mghtmlview.h"#include "html_documentimpl.h"#include "../mglib/mgfont.h"#include "../mghtml/mghtml_settings.h"#include "../include/typedef.h"#include "../net/network.h"#include "menu.h"#include "main.h"#include "optiondialog.h"#define MSG_OPENURL     MSG_USER+10#define MSG_URLREADY    MSG_USER+11using namespace DOM;using namespace khtml;MGHTMLView *frametopview = NULL;						// topmost view of the application.MainWndAttr MainWndAttrib;								// the attribute of the main frame.static HWND hWndToolBar = 0;							// the handle of tools bar.static HWND hWndStatus = 0;								// the handle of status bar.static HWND hWndAddress = 0;							// the handle of address bar.static HWND hMainWnd = 0;								// the handle of main frame.MGHTMLSettings *MG_Settings;							// the global setting.void SetAddressForBar(char * strAddress);void SetStatusForBar(char * strStatus);void GetStatusForBar(char * strStatus,int length);		QList<char> addresslist;static void AboutMonqueror (HWND hwnd){    MessageBox (hwnd,                "Monqueror version 0.5.\n"                "Copyright (C) 2001 ~ 2002 Richard Zhang, David Geng, Michael Tang, Wei Yongming, and others.\n\n"                "Monqueror is an HTML browser runing on MiniGUI version 1.1.x. "                "It is ported from Konqueror version 1.2, which is a famous browser on KDE\n\n"                "Monqueror provides support for HTTP, HTML, and CSS, but it is lack of support for FTP, SSL, "                "and the most important one, JavaScript, etc.\n"                "The code is not stable enough, you may often encounter crash.\n\n"                "Monqueror is free software, covered by the GNU General Public License, "                "and you are welcome to change it and/or distribute copies of it under certain conditions. "                "Please see the file COPYING to know the details.\n\n"                "There is absolutely no warranty for Monqueror.",                "About Monqueror",                MB_OK | MB_ICONINFORMATION);}static int MainWndMsgProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){	TOOLBARITEMINFO   pData;							// information for tool bar	DWORD             WdHt = 0;							// to define the Width(hiword) and the Height(loword)	int i, j;											// temp variable	char tempchar[MAX_PATH];							// for temp string operation	MainWndAttr *MainWndAttrib = NULL;	RECT temprect;	char * addresschar;		MainWndAttrib = (MainWndAttr *)GetWindowAdditionalData(hWnd);	switch (message) 	{		case MSG_TIMER:			if(frametopview)				SendNotifyMessage(frametopview->getHwnd(), MSG_TIMER, wParam, lParam);			break;		case MSG_CREATE:			MainWndAttrib->hMainWnd = hWnd;			j = 0;			if(MainWndAttrib->IsToolBar)			{				char* toolbar_name[] =				{				    "Back", "forward", "Home", "Renew", "Stop", "Option",				};									WdHt = MAKELONG (BMP_H + 1, BMP_W);				GetClientRect(hWnd, &temprect);				hWndToolBar = CreateWindow ("toolbar", " ", WS_CHILD | WS_VISIBLE,							100, 0, j,							temprect.right - temprect.left,							LOWORD(WdHt),							hWnd, WdHt);				for(i = 0; i < TOOLBAR_NUMBER; i++)				{					pData.insPos = i + 1;					pData.id = TOOLBAR_BASE + i;					memset(tempchar, 0, MAX_PATH);					strcpy(tempchar, BMP_PATH);					strcpy(tempchar + strlen(tempchar), toolbar_name[i]);					j = strlen(tempchar);					strcpy(tempchar + j, "nm.bmp");					strcpy(pData.NBmpPath, tempchar);					strcpy(tempchar + j, "mo.bmp");					strcpy(pData.HBmpPath, tempchar);					strcpy(pData.DBmpPath, tempchar);					SendMessage(hWndToolBar, TBM_ADDITEM, wParam, (LPARAM)&pData);				}				j = LOWORD(WdHt);			}			i = 0;			if(MainWndAttrib->IsStatusBar)			{				GetClientRect(hWnd, &temprect);				hWndStatus = CreateWindow("edit", "status", WS_CHILD | WS_VISIBLE | WS_BORDER,						101, 0, temprect.bottom - 20,						temprect.right - temprect.left,						20,						hWnd, 0);				ShowWindow(hWndStatus, SW_SHOW);				i = 20;			}			if(MainWndAttrib->IsAddress)			{				GetClientRect(hWnd, &temprect);				hWndAddress = CreateWindow("edit", MainWndAttrib->strHomePage, WS_CHILD | WS_VISIBLE | WS_BORDER,						102, 0, j,						temprect.right - temprect.left,						20,						hWnd, 0);				ShowWindow(hWndAddress, SW_SHOW);				j += 20;			}			// create the main view of the browser.			GetClientRect(hWnd, &temprect);			frametopview = new MGHTMLView ();			if (!frametopview->createView (0, j, temprect.right - temprect.left, temprect.bottom 				- temprect.top - j - i, true, hWnd))				return -1;						Start_net_thread();			frametopview->setURL(MainWndAttrib->strHomePage);			SetAddressForBar((char *)(frametopview->m_windowurl.url().latin1()));			SendNotifyMessage(frametopview->getHwnd(), MSG_OPENURL, 0, 0);			break;		case MSG_COMMAND:			switch (HIWORD(wParam))			{				case  IDM_BACK:                    SetTimer(hWnd,100,200);					addresschar =addresslist.prev();					if(addresschar != NULL)					{								frametopview->setURL(addresschar);						SetAddressForBar((char *)(frametopview->m_windowurl.url().latin1()));						SendNotifyMessage(frametopview->getHwnd(), MSG_OPENURL, 1, 0);					}					break;				case  IDM_FORWARD:					addresschar =addresslist.next();					if(addresschar != NULL)					{								frametopview->setURL(addresschar);						SetAddressForBar((char *)(frametopview->m_windowurl.url().latin1()));						SendNotifyMessage(frametopview->getHwnd(), MSG_OPENURL, 1, 0);					}					break;				case  IDM_HOME:					frametopview->setURL(MainWndAttrib->strHomePage);					SetAddressForBar((char *)(frametopview->m_windowurl.url().latin1()));					SendNotifyMessage(frametopview->getHwnd(), MSG_OPENURL, 0, 0);					break;				case  IDM_RELOAD:					char address[MAX_PATH];					GetWindowText(hWndAddress, address, MAX_PATH);					frametopview->setURL(address);					SetAddressForBar((char *)(frametopview->m_windowurl.url().latin1()));					SendNotifyMessage(frametopview->getHwnd(), MSG_OPENURL, 0, 0);					break;				case  IDM_STOP:					Cancel_net_thread();					Start_net_thread();					break;				case  IDM_OPTION:					testDialogBox1(hWnd);					break;			}			switch(LOWORD(wParam))			{				case IDM_OPEN:					OpenHTMLFile (hWnd);					break;				case IDM_EXIT:					PostMessage (hWnd, MSG_CLOSE,0,0);					break;				case IDM_ABOUT_THIS:					AboutMonqueror (hWnd);					break;			}							if(HIWORD(wParam) == EN_ENTER && LOWORD(wParam) == 102)							// for address bar input			{						Cancel_net_thread();				Start_net_thread();				char address[MAX_PATH];				GetWindowText(hWndAddress, address, MAX_PATH);				frametopview->setURL(address);				SetAddressForBar((char *)(frametopview->m_windowurl.url().latin1()));				SendNotifyMessage(frametopview->getHwnd(), MSG_OPENURL, 0, 0);			}			if( LOWORD(wParam) < IDM_FAVORATE_END && LOWORD(wParam) >= IDM_FAVORATE)		// for favorate site			{				i = LOWORD(wParam) - 1550;				Cancel_net_thread();				Start_net_thread();				frametopview->setURL(MainWndAttrib->strGlobalMenu[i]);				SetAddressForBar((char *)(frametopview->m_windowurl.url().latin1()));				SendNotifyMessage(frametopview->getHwnd(), MSG_OPENURL, 0, 0);			}			break;        case MSG_CLOSE:			Cancel_net_thread();			delete frametopview;						frametopview = 0;						for (i  = 0; i < FAVORATE_NUMBER; i++)				if(MainWndAttrib->strGlobalMenu[i] != NULL)					free(MainWndAttrib->strGlobalMenu[i]);			if(MainWndAttrib->IsToolBar)				DestroyWindow (hWndToolBar);			if(MainWndAttrib->IsAddress)				DestroyWindow (hWndAddress);			if(MainWndAttrib->IsStatusBar)				DestroyWindow (hWndStatus);			if(MainWndAttrib->strHomePage)				free(MainWndAttrib->strHomePage);			DestroyMainWindow(hWnd);			PostQuitMessage (hWnd);			addresschar = addresslist.first();			while(addresschar != NULL)			{				free(addresschar);				addresschar = addresslist.next();			}            KillTimer(hWnd,100);						return 0;    }    return DefaultMainWinProc(hWnd, message, wParam, lParam);}				 			void InitGlobalInfo(MainWndAttr * MainWndAttrib){	char strConfFile[MAX_PATH + 1];	char strtemp[MAX_PATH + 1];	strncpy (strConfFile, getpwuid(getuid())->pw_dir, MAX_PATH);	if (strConfFile[strlen(strConfFile) - 1] != '/')		strncat(strConfFile, "/", MAX_PATH);	strncat (strConfFile, ".", MAX_PATH);	strncat (strConfFile, CONF_FILENAME, MAX_PATH);	memset(strtemp, 0, MAX_PATH + 1);	if(GetValueFromEtcFile(strConfFile, "homepage", "homepage", strtemp, MAX_PATH) != ETC_OK)	{		sprintf(strtemp, "http://www.minigui.org");	}	MainWndAttrib->strHomePage = (char *)malloc(strlen(strtemp) + 1);	memcpy(MainWndAttrib->strHomePage, strtemp, strlen(strtemp));	MainWndAttrib->strHomePage[strlen(strtemp)] = '\0';		if(GetIntValueFromEtcFile(strConfFile, "MainWndAttr", "startx", &(MainWndAttrib->start_x)) != ETC_OK)	{		MainWndAttrib->start_x = 0;	}	if(GetIntValueFromEtcFile(strConfFile, "MainWndAttr", "starty", &(MainWndAttrib->start_y)) != ETC_OK)	{		MainWndAttrib->start_y = 0;	}	if(GetIntValueFromEtcFile(strConfFile, "MainWndAttr", "width", &(MainWndAttrib->width)) != ETC_OK)	{		MainWndAttrib->width = 1024;	}	if(GetIntValueFromEtcFile(strConfFile, "MainWndAttr", "hight", &(MainWndAttrib->hight)) != ETC_OK)	{		MainWndAttrib->hight = 720;	}	if(GetIntValueFromEtcFile(strConfFile, "MainWndAttr", "IsToolBar", &(MainWndAttrib->IsToolBar)) != ETC_OK)	{		MainWndAttrib->IsToolBar = 1;	}	if(GetIntValueFromEtcFile(strConfFile, "MainWndAttr", "IsStatusBar", &(MainWndAttrib->IsStatusBar)) != ETC_OK)	{		MainWndAttrib->IsStatusBar = 1;	}	if(GetIntValueFromEtcFile(strConfFile, "MainWndAttr", "IsAddress", &(MainWndAttrib->IsAddress)) != ETC_OK)	{		MainWndAttrib->IsAddress = 1;	}	//SetValueToEtcFile(theApp.strEtcFilePath,"KeyPadA","Difficulty", strText);}int MiniGUIMain(int args, const char * arg[]){	MSG Msg;	MAINWINCREATE CreateInfo;	MGHTMLSettings * MG_Settings = new MGHTMLSettings;#ifdef _LITE_VERSION	SetDesktopRect (0, 0, 1024, 768);#endif	InitGlobalInfo(&MainWndAttrib);	CreateInfo.dwStyle = WS_VISIBLE | WS_CAPTION | WS_BORDER;	CreateInfo.dwExStyle = WS_EX_NONE;	CreateInfo.spCaption = "Monqueror -- A MiniGUI-based HTML browser";	CreateInfo.hMenu = createmenu(MainWndAttrib.strGlobalMenu);	CreateInfo.hCursor = GetSystemCursor(IDC_ARROW);	CreateInfo.hIcon = GetSmallSystemIcon (IDI_APPLICATION);	CreateInfo.MainWindowProc = MainWndMsgProc;	CreateInfo.lx = MainWndAttrib.start_x;	CreateInfo.ty = MainWndAttrib.start_y;	CreateInfo.rx = MainWndAttrib.width;	CreateInfo.by = MainWndAttrib.hight;	CreateInfo.iBkColor = COLOR_lightwhite;	CreateInfo.dwAddData = (DWORD)&MainWndAttrib;	CreateInfo.hHosting = HWND_DESKTOP;		hMainWnd = CreateMainWindow(&CreateInfo);	MainWndAttrib.HeadJob = NULL;	MainWndAttrib.iJobNumber = 0;	while (GetMessage (&Msg, hMainWnd)) { 		TranslateMessage (&Msg);		DispatchMessage (&Msg);	}	MainWindowThreadCleanup (hMainWnd);	delete MG_Settings;	return 0;}void OpenHTMLFile(HWND hWnd)			// open a file from menu.{	char currentpath [MAX_PATH + 1];	FILEDLGDATA myWinFileData;	getcwd (currentpath, MAX_PATH);	strcpy (myWinFileData.filepath, currentpath);	myWinFileData.IsSave = FALSE;	if(OpenFileDialog(hWnd, FALSE, &myWinFileData) == IDOK) 	{		if (access (myWinFileData.filefullname, F_OK) < 0) 		{			MessageBox (hWnd, "文件不存在", "Monqueror", MB_OK | MB_ICONSTOP);			return;		}		else if (access (myWinFileData.filefullname, R_OK) < 0) {			MessageBox (hWnd, "文件不可读", "Monqueror", MB_OK | MB_ICONSTOP);			return;		}		frametopview->setURL(myWinFileData.filefullname);//		frametopview->setURL("http://192.168.1.1/index.html");//		SetAddressForBar(frametopview->m_windowurl.url().latin1());		Cancel_net_thread();		Start_net_thread();		SendNotifyMessage(frametopview->getHwnd(), MSG_OPENURL, 0, 0);	}}void SetAddressForBar(char * strAddress){	if(MainWndAttrib.IsAddress)	{		SetWindowText(hWndAddress,strAddress);	}}void SetStatusForBar(char * strStatus){	if(MainWndAttrib.IsStatusBar)	{		SetWindowText(hWndStatus, strStatus);	}}void GetStatusForBar(char * strStatus,int length){	if(MainWndAttrib.IsStatusBar)	{	GetWindowText(hWndStatus, strStatus, length);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -