📄 urlcls.cpp
字号:
/*____________________________________________________________________________*\
*
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/EnhPi3/URLCls.cpp,v $
* $Date: 2003/05/13 18:41:59 $
*
Description:
This file is a bit of a mess while I sort out what sort of main window
it should have.
\*____________________________________________________________________________*/
/* $SourceTop:$ */
#include <windows.h>
#include <assert.h>
#include "PIString.h"
#include "PICompat.h"
#include "Common.h"
#include "resrc1.h"
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
#define URL_WNDCLASS "Pi3URL"
//static WNDPROC __fnWndProc = 0;
//static HCURSOR __hCursor;
static ATOM __aClass;
#define CBWNDEXTRA (8)
#define GWL_TEXT (0)
#define GWW_FONT (4)
#define GWW_STATE (6)
#define ST_DISABLED 0 /* not enabled */
#define ST_ENABLED 1 /* enabled */
#define ST_HIGHLIGHTED 2 /* highlighted, cursor is over control */
#define ST_SELECTED 3 /* select, control has been clicked */
/* --- Color RGB Values
White 0x00FFFFFF 16777215
Black 0x00000000 0
Gray 0x00808080 8421504
Red 0x000000FF 255
Yellow 0x0000FFFF 65535
Green 0x0000FF00 65280
Cyan 0x00FFFF00 16776960
Blue 0x00FF0000 16711680
Magenta 0x00FF00FF 16711935
--- */
#define CLR_ENABLED (0x00FF0000) // blue
#define CLR_DISABLED (0x00C48080) // pale blue
#define CLR_HIGHLIGHTED (0x0000FF00) // yellow
//#define CLR_HIGHLIGHTED (0x00FFFF00) // cyan
//#define CLR_HIGHLIGHTED (0x00800080)
//#define CLR_SELECTED (0x000000FF) // red
//#define CLR_SELECTED (0x00FF00FF) // magenta
#define CLR_SELECTED (0x008000C4)
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
void Internal_paint( HWND hWnd )
{
PAINTSTRUCT ps;
::BeginPaint( hWnd, &ps );
::SendMessage( GetParent( hWnd ), WM_CTLCOLORSTATIC,
(WPARAM)ps.hdc, (LPARAM)hWnd );
COLORREF tColor = 0x0;
switch( ::GetWindowWord( hWnd, GWW_STATE ) )
{
case ST_DISABLED: tColor = CLR_DISABLED; break;
case ST_ENABLED: tColor = CLR_ENABLED; break;
case ST_HIGHLIGHTED: tColor = CLR_HIGHLIGHTED; break;
case ST_SELECTED: tColor = CLR_SELECTED; break;
default:
assert( 0 );
};
/*
** Make text blue
*/
::SetTextColor( ps.hdc, tColor );
/*
** Get correct font
*/
HFONT hOldFont = (HFONT)::SelectObject(
ps.hdc, (HGDIOBJ)::GetWindowWord( hWnd, GWW_FONT ) );
const char *pText = *((PIString *)::GetWindowLong( hWnd, GWL_TEXT ));
// ::ExtFloodFill( ps.hdc, 0, 0, tColor, FLOODFILLBORDER );
// ::ExtFloodFill( ps.hdc, 0, 0, COLOR_BTNFACE, FLOODFILLBORDER );
::TextOut( ps.hdc, 0, 0, pText, strlen( pText ) );
::SelectObject( ps.hdc, hOldFont );
::EndPaint( hWnd, &ps );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
const char *pText;
LRESULT lResult = 0;
RECT tRect;
LOGFONT tFont;
LONG lTmp;
switch (uMsg)
{
case WM_GETDLGCODE:
lResult = DLGC_BUTTON;
break;
case WM_PAINT:
Internal_paint( hWnd );
break;
case WM_ENABLE:
::SetWindowWord( hWnd, GWW_STATE,
((BOOL)wParam) ? ST_ENABLED : ST_DISABLED );
::InvalidateRect( hWnd, NULL, FALSE );
break;
case WM_LBUTTONDOWN:
::SetWindowWord( hWnd, GWW_STATE, ST_SELECTED );
::SetCapture( hWnd );
::InvalidateRect( hWnd, NULL, FALSE );
break;
case WM_MOUSEMOVE:
::GetClientRect( hWnd, &tRect );
/*
** Pointer must be over window
*/
if ( ( LOWORD(lParam) < tRect.left ) ||
( LOWORD(lParam) > tRect.right ) ||
( HIWORD(lParam) < tRect.top ) ||
( HIWORD(lParam) > tRect.bottom ) )
{
/* --- outside window --- */
switch( ::GetWindowWord( hWnd, GWW_STATE ) )
{
case ST_DISABLED:
case ST_ENABLED:
break;
case ST_HIGHLIGHTED: /* not selected */
case ST_SELECTED: /* selected, unselect */
::SetWindowWord( hWnd, GWW_STATE, ST_ENABLED );
::InvalidateRect( hWnd, NULL, FALSE );
::ReleaseCapture();
break;
default:;
};
}
else
{
/* --- inside window --- */
switch( ::GetWindowWord( hWnd, GWW_STATE ) )
{
case ST_DISABLED:
case ST_HIGHLIGHTED:
case ST_SELECTED:
break;
case ST_ENABLED:
::SetWindowWord( hWnd, GWW_STATE, ST_HIGHLIGHTED );
::InvalidateRect( hWnd, NULL, FALSE );
::SetCapture( hWnd );
break;
default:;
};
};
break;
case WM_LBUTTONUP:
lTmp = ::GetWindowWord( hWnd, GWW_STATE );
::SetWindowWord( hWnd, GWW_STATE, ST_ENABLED );
::InvalidateRect( hWnd, NULL, FALSE );
if ( lTmp!=ST_SELECTED ) { break; };
::ReleaseCapture();
{
UINT uiCode = ::GetDlgCtrlID( hWnd );
if ( !::SendMessage( GetParent( hWnd ), WM_COMMAND,
MAKEWPARAM( uiCode , BN_CLICKED ), (LPARAM)hWnd ) )
{
CTRL_openURL( NULL,
*((PIString *)::GetWindowLong( hWnd, GWL_TEXT ) ));
};
};
break;
case WM_SETTEXT:
*((PIString *)::GetWindowLong( hWnd, GWL_TEXT )) =
(const char *)lParam;
::InvalidateRect( hWnd, NULL, FALSE );
break;
case WM_SETFONT:
/* --- get font object ---*/
if ( !::GetObject( (HFONT)wParam, sizeof( LOGFONT ), &tFont ) )
{ break; };
/* --- delete old font ---*/
if ( ::GetWindowWord( hWnd, GWW_FONT ) )
{ ::DeleteObject( (HGDIOBJ)::GetWindowWord( hWnd, GWW_FONT ) ); };
/* --- add underline --- */
// tFont.lfItalic = TRUE;
tFont.lfUnderline = TRUE;
/* --- create and set new font ---*/
::SetWindowWord( hWnd, GWW_FONT, (WORD)::CreateFontIndirect( &tFont ) );
/* --- repaint ---*/
if ( lParam )
{ ::InvalidateRect( hWnd, NULL, FALSE ); };
break;
case WM_GETFONT:
lResult = ::GetWindowWord( hWnd, GWW_FONT );
break;
case WM_GETTEXT:
pText = *((PIString *)::GetWindowLong( hWnd, GWL_TEXT ));
strncpy( (char *)lParam, pText, wParam );
break;
case WM_CREATE:
::SetWindowLong( hWnd, GWL_TEXT, (LONG)PI_NEW(
PIString( ((LPCREATESTRUCT)lParam)->lpszName )
) );
::SetWindowWord( hWnd, GWW_STATE, ST_ENABLED );
::SetWindowWord( hWnd, GWW_FONT, 0 );
break;
case WM_DESTROY:
if ( ::GetWindowWord( hWnd, GWW_FONT ) )
{ ::DeleteObject( (HGDIOBJ)::GetWindowWord( hWnd, GWW_FONT ) ); };
PI_DELETE( (PIString *)::GetWindowLong( hWnd, GWL_TEXT ) );
break;
default:
lResult = ::DefWindowProc( hWnd, uMsg, wParam, lParam );
}
return lResult;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
void AD_registerURLClass( HINSTANCE hInstance )
{
WNDCLASS tCls;
memset( &tCls, 0, sizeof( WNDCLASS ) );
tCls.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW;
tCls.lpfnWndProc = (WNDPROC)WndProc;
tCls.cbClsExtra = 0;
tCls.cbWndExtra = CBWNDEXTRA;
tCls.hInstance = hInstance;
tCls.hIcon = 0;
tCls.hCursor = ::LoadCursor( hInstance, MAKEINTRESOURCE( IDC_CURSOR ) );
// tCls.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
tCls.hbrBackground = 0;
tCls.lpszMenuName = 0;
tCls.lpszClassName = URL_WNDCLASS;
__aClass = ::RegisterClass( &tCls );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
void AD_unregisterURLClass( HINSTANCE hInstance )
{
::UnregisterClass( URL_WNDCLASS, hInstance );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -