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

📄 pi3win.c

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 C
字号:
/*____________________________________________________________________________*\
 *

 Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.

 These sources, libraries and applications are
 FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
 as long as the following conditions are adhered to.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer. 

 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.

 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.

 *____________________________________________________________________________*|
 *
 * $Source: /cvsroot/pi3web/Pi3Web_200/Source/Win32App/Pi3Win.c,v $
 * $Date: 2003/05/13 18:42:22 $
 *
 Description:

\*____________________________________________________________________________*/
/* $SourceTop:$ */

#include <windowsx.h>
#include <windows.h>
#include "Resource.h"

/*____________________________________________________________________________*\
 *
 Description:
	Definitions and global values
\*____________________________________________________________________________*/
#define MYWM_NOTIFYICON		(WM_APP+101)
static HINSTANCE __hInstance = 0;
static void (* __fnOnWindowingThreadTermination)( void * );
static void *__pWindowingThreadTerminationData;
static int iHaveSystray = 0;

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
BOOL Internal_SendTrayMessage(
		HWND hDlg,
		DWORD dwMessage,
		UINT uID,
		HICON hIcon,
		PSTR pszTip )
{
	BOOL bResult;
	NOTIFYICONDATA tND;
	tND.cbSize		= sizeof(NOTIFYICONDATA);
	tND.hWnd		= hDlg;
	tND.uID			= uID;
	tND.uFlags		= NIF_MESSAGE|NIF_ICON|NIF_TIP;
	tND.uCallbackMessage	= MYWM_NOTIFYICON;
	tND.hIcon		= hIcon;
	if (pszTip)
		{
		strncpy(tND.szTip, pszTip, sizeof(tND.szTip));
		}
	else
		{
		tND.szTip[0] = '\0';
		};

	bResult = Shell_NotifyIcon(dwMessage, &tND);

	if (hIcon)
		{
	    DestroyIcon(hIcon);
		};

	return bResult;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
LRESULT IconDrawItem(LPDRAWITEMSTRUCT lpDI)
{
	HICON hIcon;

	hIcon = (HICON)LoadImage(__hInstance, MAKEINTRESOURCE(lpDI->CtlID),
		IMAGE_ICON, 16, 16, 0);
	if (!hIcon)
		{
		return FALSE;
		}

	DrawIconEx(lpDI->hDC, lpDI->rcItem.left, lpDI->rcItem.top, hIcon,
		16, 16, 0, NULL, DI_NORMAL);

	return TRUE;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
BOOL CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
		{
		case WM_INITDIALOG:
			if ( !iHaveSystray )
				{
				/* --- show minimized icon --- */
				ShowWindow( hDlg, SW_MINIMIZE );
				break;
				};

			/* else */
			Internal_SendTrayMessage(hDlg, NIM_ADD, IDC_PI3ICON, NULL, NULL);
			Internal_SendTrayMessage(hDlg, NIM_MODIFY, IDC_PI3ICON,
				LoadImage(__hInstance, MAKEINTRESOURCE( IDI_PI3WEB ),
						IMAGE_ICON, 16, 16, 0),
				"Pi3Web HTTP Server Status" );
			break;

		case WM_DRAWITEM:
			if ( iHaveSystray )
				{
				return IconDrawItem( (LPDRAWITEMSTRUCT)lParam );
				};
			break;

		case WM_DESTROY:
			if ( iHaveSystray )
				{
				Internal_SendTrayMessage(hDlg, NIM_DELETE, IDC_PI3ICON,
					NULL, NULL);
				};
			PostQuitMessage( 0 );	
			break;

		case WM_COMMAND:
			switch (GET_WM_COMMAND_ID(wParam, lParam))
				{
				case IDCANCEL:
					DestroyWindow( hDlg );
					break; 	

				case IDABORT:
					if ( !iHaveSystray )
						{
						ShowWindow(hDlg, SW_MINIMIZE);
						}
					else
						{
						ShowWindow(hDlg, SW_HIDE);
						};
					break;

				}
			break;

		case MYWM_NOTIFYICON:
			switch (lParam)
				{
				/*
				** Make dialog come to the front
				*/
				case WM_LBUTTONDOWN:
					ShowWindow(hDlg, SW_SHOW);
					SetForegroundWindow(hDlg);
					break;

				default:
					break;
				}
			break;

		default:
				return FALSE;
		};

	return TRUE;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
	Windowing loop with modeless dialog and tray icon.
\*____________________________________________________________________________*/
int WindowsLoop()
{
	MSG tMsg;
	OSVERSIONINFO tOS;

	/* ---
	Check support for systray
	--- */
	tOS.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
	if ( GetVersionEx( &tOS )==0 )
		{
		return -1;
		};
	if ( tOS.dwMajorVersion>=4 )
		{
		/* ---
		Windows 95 or NT4.0
		--- */
		iHaveSystray = 1;
		}
	else
		{
		iHaveSystray = 0;
		};

	/* ---
	Create modeless dialog box
	--- */
	if ( !CreateDialog( __hInstance,
		MAKEINTRESOURCE(IDD_PI3WEB), NULL, DlgProc) )
		{
		return -1;
		};

	/* ---
	Wait for end of dialog
	--- */
	while( GetMessage( &tMsg, NULL, 0, 0 ) )
		{
		TranslateMessage( &tMsg );
		DispatchMessage( &tMsg );
		};

	return 0;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
DWORD WINAPI fnWindowingThread( void *pDummy )
{
	WindowsLoop();

	(__fnOnWindowingThreadTermination)( __pWindowingThreadTerminationData );

	return 0;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
int StartWindowingThread( HINSTANCE hInstance, 
	void (* fnOnTermination )( void *), void *pTerminationData )
{ 
	DWORD dwThreadId;
	HANDLE hThread;

	__hInstance = hInstance;
	__fnOnWindowingThreadTermination=fnOnTermination;
	__pWindowingThreadTerminationData=pTerminationData;

	/*
	** Create the windowing thread
	*/
	hThread=CreateThread(
		NULL,				//	security attributes
    	0,					//	initial thread stack size, in bytes 
		fnWindowingThread,	//	pointer to thread function 
		0,					//	argument for new thread 
		0,					//	creation flags 
		&dwThreadId			//	pointer to returned thread identifier 
		);	
	if ( hThread==NULL )
		{
		return 0;
		}
	else
		{
		/* --- success, but we don't need the thread handle --- */
		CloseHandle( hThread );
		return 1;
		};
}

#if 0
/* 
** This function is mainly used for testing
*/

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
	Windows entry point
\*____________________________________________________________________________*/
int WINAPI WinMain(
		HINSTANCE hInstance,
		HINSTANCE hPrevInstance,
		LPSTR lpCmdLine,
		int nCmdShow)
{
	return WindowsLoop( hInstance );
}

#endif

⌨️ 快捷键说明

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