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

📄 gui.c

📁 Unreal irc 服务器源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/************************************************************************ *   IRC - Internet Relay Chat, win32/gui.c *   Copyright (C) 2000-2004 David Flynn (DrBin) & Dominick Meglio (codemastr) *    *   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 1, 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. */#define WIN32_VERSION BASE_VERSION PATCH1 PATCH2 PATCH3 PATCH4#include "resource.h"#include "version.h"#include "setup.h"#ifdef INET6#include <winsock2.h>#include <ws2tcpip.h>#endif#include <windows.h>#include <windowsx.h>#include <commctrl.h>#include "struct.h"#include "common.h"#include "sys.h"#include "numeric.h"#include <sys/stat.h>#include <fcntl.h>#include <sys/types.h>#include <io.h>#include <direct.h>#include <errno.h>#include "h.h"#include <richedit.h>#include <commdlg.h>#include "win32.h"__inline void ShowDialog(HWND *handle, HINSTANCE inst, char *template, HWND parent, 			 DLGPROC proc){	if (!IsWindow(*handle)) 	{		*handle = CreateDialog(inst, template, parent, (DLGPROC)proc); 		ShowWindow(*handle, SW_SHOW);	}	else		SetForegroundWindow(*handle);}/* Comments: *  * DrBin did a great job with the original GUI, but he has been gone a long time. * In his absense, it was decided it would be best to continue windows development. * The new code is based on his so it will be pretty much similar in features, my * main goal is to make it more stable. A lot of what I know about GUI coding  * I learned from DrBin so thanks to him for teaching me :) -- codemastr */LRESULT CALLBACK MainDLG(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK LicenseDLG(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK CreditsDLG(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK DalDLG(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK HelpDLG(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK StatusDLG(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK ConfigErrorDLG(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK FromVarDLG(HWND, UINT, WPARAM, LPARAM, unsigned char *, unsigned char **);LRESULT CALLBACK FromFileReadDLG(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK FromFileDLG(HWND, UINT, WPARAM, LPARAM);extern  void      SocketLoop(void *dummy);HINSTANCE hInst;NOTIFYICONDATA SysTray;void CleanUp(void);HTREEITEM AddItemToTree(HWND, LPSTR, int, short);void win_map(aClient *, HWND, short);extern Link *Servers;extern ircstats IRCstats;unsigned char *errors = NULL;extern aMotd *botmotd, *opermotd, *motd, *rules;extern VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv);extern BOOL IsService;void CleanUp(void){	Shell_NotifyIcon(NIM_DELETE ,&SysTray);}void CleanUpSegv(int sig){	Shell_NotifyIcon(NIM_DELETE ,&SysTray);}HWND hStatusWnd;HWND hwIRCDWnd=NULL;HWND hwTreeView;HWND hWndMod;HANDLE hMainThread = 0;UINT WM_TASKBARCREATED, WM_FINDMSGSTRING;FARPROC lpfnOldWndProc;HMENU hContext;OSVERSIONINFO VerInfo;char OSName[256];#ifdef USE_LIBCURLextern char *find_loaded_remote_include(char *url);#endif void TaskBarCreated() {	HICON hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(ICO_MAIN), IMAGE_ICON,16, 16, 0);	SysTray.cbSize = sizeof(NOTIFYICONDATA);	SysTray.hIcon = hIcon;	SysTray.hWnd = hwIRCDWnd;	SysTray.uCallbackMessage = WM_USER;	SysTray.uFlags = NIF_ICON|NIF_TIP|NIF_MESSAGE;	SysTray.uID = 0;	strcpy(SysTray.szTip, WIN32_VERSION);	Shell_NotifyIcon(NIM_ADD ,&SysTray);}LRESULT LinkSubClassFunc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) {	static HCURSOR hCursor;	if (!hCursor)		hCursor = LoadCursor(hInst, MAKEINTRESOURCE(CUR_HAND));	if (Message == WM_MOUSEMOVE || Message == WM_LBUTTONDOWN)		SetCursor(hCursor);	return CallWindowProc((WNDPROC)lpfnOldWndProc, hWnd, Message, wParam, lParam);}LRESULT RESubClassFunc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) {	POINT p;	RECT r;	DWORD start, end;	unsigned char string[500];	if (Message == WM_GETDLGCODE)	   return DLGC_WANTALLKEYS;		if (Message == WM_CONTEXTMENU) 	{		p.x = GET_X_LPARAM(lParam);		p.y = GET_Y_LPARAM(lParam);		if (GET_X_LPARAM(lParam) == -1 && GET_Y_LPARAM(lParam) == -1) 		{			GetClientRect(hWnd, &r);			p.x = (int)((r.left + r.right)/2);			p.y = (int)((r.top + r.bottom)/2);			ClientToScreen(hWnd,&p);		}		if (!SendMessage(hWnd, EM_CANUNDO, 0, 0)) 			EnableMenuItem(hContext, IDM_UNDO, MF_BYCOMMAND|MF_GRAYED);		else			EnableMenuItem(hContext, IDM_UNDO, MF_BYCOMMAND|MF_ENABLED);		if (!SendMessage(hWnd, EM_CANPASTE, 0, 0)) 			EnableMenuItem(hContext, IDM_PASTE, MF_BYCOMMAND|MF_GRAYED);		else			EnableMenuItem(hContext, IDM_PASTE, MF_BYCOMMAND|MF_ENABLED);		if (GetWindowLong(hWnd, GWL_STYLE) & ES_READONLY) 		{			EnableMenuItem(hContext, IDM_CUT, MF_BYCOMMAND|MF_GRAYED);			EnableMenuItem(hContext, IDM_DELETE, MF_BYCOMMAND|MF_GRAYED);		}		else 		{			EnableMenuItem(hContext, IDM_CUT, MF_BYCOMMAND|MF_ENABLED);			EnableMenuItem(hContext, IDM_DELETE, MF_BYCOMMAND|MF_ENABLED);		}		SendMessage(hWnd, EM_GETSEL, (WPARAM)&start, (LPARAM)&end);		if (start == end) 			EnableMenuItem(hContext, IDM_COPY, MF_BYCOMMAND|MF_GRAYED);		else			EnableMenuItem(hContext, IDM_COPY, MF_BYCOMMAND|MF_ENABLED);		TrackPopupMenu(hContext,TPM_LEFTALIGN|TPM_RIGHTBUTTON,p.x,p.y,0,GetParent(hWnd),NULL);		return 0;	}	return CallWindowProc((WNDPROC)lpfnOldWndProc, hWnd, Message, wParam, lParam);}int CloseUnreal(HWND hWnd){	if (MessageBox(hWnd, "Close UnrealIRCd?", "Are you sure?", MB_YESNO|MB_ICONQUESTION) 	    == IDNO)		 return 0;	else 	{		 DestroyWindow(hWnd);		 exit(0);	}}int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){	MSG msg;	unsigned char *s;	HWND hWnd;	WSADATA WSAData;	HICON hIcon;	SERVICE_TABLE_ENTRY DispatchTable[] = 	{		{ "UnrealIRCd", ServiceMain },		{ 0, 0 }	};	DWORD need;		VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);	GetVersionEx(&VerInfo);	GetOSName(VerInfo, OSName);	if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) 	{		SC_HANDLE hService, hSCManager = OpenSCManager(NULL, NULL, GENERIC_EXECUTE);		if ((hService = OpenService(hSCManager, "UnrealIRCd", GENERIC_EXECUTE))) 		{			int save_err = 0;			StartServiceCtrlDispatcher(DispatchTable); 			if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)			{ 				SERVICE_STATUS status;				/* Restart handling, it's ugly but it's as 				 * pretty as it is gonna get :)				 */				if (__argc == 2 && !strcmp(__argv[1], "restartsvc"))				{					QueryServiceStatus(hService, &status);					if (status.dwCurrentState != SERVICE_STOPPED)					{						ControlService(hService,							SERVICE_CONTROL_STOP, &status);						while (status.dwCurrentState == SERVICE_STOP_PENDING)						{							QueryServiceStatus(hService, &status);							if (status.dwCurrentState != SERVICE_STOPPED)								Sleep(1000);						}					}				}				if (!StartService(hService, 0, NULL))					save_err = GetLastError();			}			CloseServiceHandle(hService);			CloseServiceHandle(hSCManager);			if (save_err != ERROR_SERVICE_DISABLED)				exit(0);		} else {			CloseServiceHandle(hSCManager);		}	}	InitCommonControls();	WM_TASKBARCREATED = RegisterWindowMessage("TaskbarCreated");	WM_FINDMSGSTRING = RegisterWindowMessage(FINDMSGSTRING);	atexit(CleanUp);	if(!LoadLibrary("riched20.dll"))		LoadLibrary("riched32.dll");	InitDebug();	if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)    	{		MessageBox(NULL, "Unable to initialize WinSock", "UnrealIRCD Initalization Error", MB_OK);		return FALSE;	}	hInst = hInstance;     	hWnd = CreateDialog(hInstance, "WIRCD", 0, (DLGPROC)MainDLG); 	hwIRCDWnd = hWnd;		TaskBarCreated();	if (InitwIRCD(__argc, __argv) != 1)	{		MessageBox(NULL, "UnrealIRCd has failed to initialize in InitwIRCD()", "UnrealIRCD Initalization Error" ,MB_OK);		return FALSE;	}	ShowWindow(hWnd, SW_SHOW);	hMainThread = (HANDLE)_beginthread(SocketLoop, 0, NULL);	while (GetMessage(&msg, NULL, 0, 0))	{		if (!IsWindow(hStatusWnd) || !IsDialogMessage(hStatusWnd, &msg)) 		{			TranslateMessage(&msg);			DispatchMessage(&msg);		}	}	return FALSE;}LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){	static HCURSOR hCursor;	static HMENU hRehash, hAbout, hConfig, hTray, hLogs;	unsigned char *argv[3];	aClient *paClient;	unsigned char *msg;	POINT p;	if (message == WM_TASKBARCREATED)	{		TaskBarCreated();		return TRUE;	}		switch (message)	{		case WM_INITDIALOG: 		{			ShowWindow(hDlg, SW_HIDE);			hCursor = LoadCursor(hInst, MAKEINTRESOURCE(CUR_HAND));			hContext = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_CONTEXT)),0);			/* Rehash popup menu */			hRehash = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_REHASH)),0);			/* About popup menu */			hAbout = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_ABOUT)),0);			/* Systray popup menu set the items to point to the other menus*/			hTray = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_SYSTRAY)),0);			ModifyMenu(hTray, IDM_REHASH, MF_BYCOMMAND|MF_POPUP|MF_STRING, (UINT)hRehash, "&Rehash");			ModifyMenu(hTray, IDM_ABOUT, MF_BYCOMMAND|MF_POPUP|MF_STRING, (UINT)hAbout, "&About");						SetWindowText(hDlg, WIN32_VERSION);			SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_SMALL, 				(LPARAM)(HICON)LoadImage(hInst, MAKEINTRESOURCE(ICO_MAIN), IMAGE_ICON,16, 16, 0));			SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_BIG, 				(LPARAM)(HICON)LoadImage(hInst, MAKEINTRESOURCE(ICO_MAIN), IMAGE_ICON,32, 32, 0));			return TRUE;		}		case WM_SIZE: 		{			if (wParam & SIZE_MINIMIZED)				ShowWindow(hDlg,SW_HIDE);			return 0;		}		case WM_CLOSE: 			return CloseUnreal(hDlg);		case WM_USER: 		{			switch(LOWORD(lParam)) 			{				case WM_LBUTTONDBLCLK:					ShowWindow(hDlg, SW_SHOW);					ShowWindow(hDlg,SW_RESTORE);					SetForegroundWindow(hDlg);				case WM_RBUTTONDOWN:					SetForegroundWindow(hDlg);					break;				case WM_RBUTTONUP: 				{					unsigned long i = 60000;					MENUITEMINFO mii;					GetCursorPos(&p);					DestroyMenu(hConfig);					hConfig = CreatePopupMenu();					DestroyMenu(hLogs);					hLogs = CreatePopupMenu();					AppendMenu(hConfig, MF_STRING, IDM_CONF, CPATH);

⌨️ 快捷键说明

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