📄 defproc.c
字号:
/******************************************************
Copyright(c) 版权所有,1998-2003微逻辑。保留所有权利。
******************************************************/
/*****************************************************
文件说明:默认的窗口消息处理
版本号:2.0.0
开发时期:2000
作者:李林
修改记录:
2005-01-08, 去掉了 WM_STYLECHANGED 的无效整个窗口的功能, gwme 将发 WM_NCPAINT 消息
2003-06-13: 增加 WS_EX_CLIENTEDGE
******************************************************/
#include <eframe.h>
#include <ealloc.h>
#include <eassert.h>
#include <esymbols.h>
#include <gwmeobj.h>
#include "..\include\scrollbar.h"
#include <keybdsrv.h>
#include <ekeybrd.h>
//#include <eapisrv.h>
//#include <eobjcall.h>
//#include <epwin.h>
//#include <winsrv.h>
//#include <gdisrv.h>
//#include <gdc.h>
#ifdef EML_DOS
#include <conio.h>
#include <stdio.h>
#include <emouse.h>
#endif
static LRESULT CopyText( HWND, LPSTR, int );
static LRESULT SetText( HWND hWnd, LPCSTR lpcstr );
static BOOL TrackWindowRect( HWND hWnd, POINT ptOld, HWND hwndClipTo, LPRECT lprc );
static LRESULT DoNcPaint( HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL bEraseBk );
BOOL _GetFrameSize( SIZE FAR* lpSize, DWORD dwMainStyle );
static LRESULT GetTextLength( HWND hWnd );
#define IN_RANGE( v, minv, maxv ) ( (v) >= (minv) && (v) < (maxv) )
// **************************************************
// 声明:
// 参数:
// 无
// 返回值:
// 假如成功,返回TRUE;否则,返回FALSE
// 功能描述:
//
// 引用:
//
// ************************************************
static LPSTR NewStr( LPCSTR lpstr )
{
LPSTR p;
if( lpstr == 0 )
return 0;
p = (LPSTR)malloc( strlen(lpstr) + 1 );
if( p )
strcpy( p, lpstr );
return p;
}
// **************************************************
// 声明:
// 参数:
// 无
// 返回值:
// 假如成功,返回TRUE;否则,返回FALSE
// 功能描述:
//
// 引用:
//
// ************************************************
static void FreeStr( LPSTR lpstr )
{
if( lpstr )
free( lpstr );
}
// **************************************************
// 声明:
// 参数:
// 无
// 返回值:
// 假如成功,返回TRUE;否则,返回FALSE
// 功能描述:
//
// 引用:
//
// ************************************************
BOOL _GetFrameSize( SIZE FAR* lpSize, DWORD dwMainStyle )
{
lpSize->cx = lpSize->cy = 0;
if( (dwMainStyle & WS_THICKFRAME) == WS_THICKFRAME )
{
lpSize->cx = GetSystemMetrics( SM_CXFRAME );
lpSize->cy = GetSystemMetrics( SM_CYFRAME );
}
else if( (dwMainStyle & WS_DLGFRAME) == WS_DLGFRAME )
{
lpSize->cx = GetSystemMetrics( SM_CXDLGFRAME );
lpSize->cy = GetSystemMetrics( SM_CYDLGFRAME );
}
else if( (dwMainStyle & WS_BORDER) == WS_BORDER )
{
lpSize->cx = GetSystemMetrics( SM_CXBORDER );
lpSize->cy = GetSystemMetrics( SM_CYBORDER );
}
else
return FALSE;
return TRUE;
}
// **************************************************
// 声明:
// 参数:
// 无
// 返回值:
// 假入成功,返回TRUE;否则,返回FALSE
// 功能描述:
//
// 引用:
//
// ************************************************
static BOOL TrackWindowRect( HWND hWnd, POINT ptOld,
HWND hwndClipTo, LPRECT lprc )
{
RECT rcNew = *lprc;
HBRUSH hOldBrush;
int rop2;
int xoff, yoff;
BOOL bEraseTrack;
HWND hwndTrack;
HDC hdcTrack;
RECT rcTrack;
MSG msg;
bEraseTrack = TRUE;
if ( GetCapture() != NULL)
return FALSE;
if( hwndClipTo )
UpdateWindow( hwndClipTo );
UpdateWindow( hWnd );
hwndTrack = hWnd;
SetCapture(hwndTrack);
hdcTrack = GetDC(hwndClipTo);
hOldBrush = SelectObject( hdcTrack, GetStockObject(NULL_BRUSH) );
rop2 = SetROP2( hdcTrack, R2_NOT );
Rectangle( hdcTrack, rcNew.left, rcNew.top, rcNew.right, rcNew.bottom );
rcTrack = rcNew;
bEraseTrack= FALSE;
while( 1 )
{
//if( _posEvent.Peek( &msg, PM_REMOVE ) )
//if( PeekMessage( &msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE ) )
//if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
//if( GetMessage( &msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST) == 0 )
if( GetMessage( &msg, NULL, NULL, NULL ) == 0 )
//if( GetMessage( &msg, NULL, 0, 0) == 0 )
{
ASSERT( 0 );
break;
}
if( GetCapture() != hWnd )
{
break;
}
switch (msg.message)
{
case WM_LBUTTONUP:
case WM_MOUSEMOVE:
// erase rectangle
Rectangle( hdcTrack, rcTrack.left, rcTrack.top, rcTrack.right, rcTrack.bottom );
bEraseTrack = TRUE;
xoff = msg.pt.x - ptOld.x;
yoff = msg.pt.y - ptOld.y;
rcNew = *lprc;
OffsetRect( &rcNew, xoff, yoff );
if( msg.message == WM_LBUTTONUP )
goto ExitLoop;
Rectangle( hdcTrack, rcNew.left, rcNew.top, rcNew.right, rcNew.bottom );
bEraseTrack = FALSE;
rcTrack = rcNew;
break;
default:
DispatchMessage(&msg);
break;
}
}
}
ExitLoop:
if( bEraseTrack == FALSE )
{
Rectangle( hdcTrack, rcTrack.left, rcTrack.top, rcTrack.right, rcTrack.bottom );
bEraseTrack = TRUE;
}
hwndTrack = 0;
SelectObject( hdcTrack, hOldBrush );
ReleaseDC( hwndClipTo, hdcTrack );
hdcTrack = 0;
ReleaseCapture();
if( EqualRect(lprc, &rcNew) )
return FALSE;
else
{
*lprc = rcNew;
return TRUE;
}
}
// **************************************************
// 声明:
// 参数:
// 无
// 返回值:
// 假如成功,返回TRUE;否则,返回FALSE
// 功能描述:
//
// 引用:
//
// ************************************************
static LRESULT GetTextLength( HWND hWnd )
{
//_LPWINDATA lpws = _GetHWNDPtr( hWnd );
LPCSTR lpWinText = (LPCSTR)GetWindowLong( hWnd, GWL_TEXT_PTR );
if( lpWinText )
return strlen( lpWinText );
return 0;
}
// **************************************************
// 声明:
// 参数:
// 无
// 返回值:
// 假如成功,返回TRUE;否则,返回FALSE
// 功能描述:
//
// 引用:
//
// ************************************************
static LRESULT SetText( HWND hWnd, LPCSTR lpcstr )
{
//_LPWINDATA lpws = _GetHWNDPtr( hWnd );
LPSTR p = NewStr( lpcstr );
if( p )
{
DWORD dwMainStyle, dwExStyle;
LPSTR lpWinText = (LPSTR)SetWindowLong( hWnd, GWL_TEXT_PTR, (LONG)p );
if( lpWinText )
free( lpWinText );
//lpws->lpWinText = p;
dwMainStyle = GetWindowLong( hWnd, GWL_STYLE );
dwExStyle = GetWindowLong( hWnd, GWL_EXSTYLE );
if( (dwMainStyle & WS_CAPTION) == WS_CAPTION ||
(dwExStyle & WS_EX_TITLE) )
{
/*
RECT rect = lpws->rectClient;
HRGN hrgn;
rect.bottom = rect.top;
rect.top = rect.bottom - GetSystemMetrics( SM_CYCAPTION );
// 2003-09-16, 删除代码, WM_NCPAINT's hrgn client坐标
//OffsetRect( &rect, lpws->rectWindow.left, lpws->rectWindow.top );
hrgn = CreateRgnRect( rect.left, rect.top, rect.right, rect.bottom );
SendMessage( hWnd, WM_NCPAINT, (WPARAM)hrgn, 0 );
DeleteObject( hrgn );
*/
DoNcPaint( hWnd, 1, 0, FALSE );
}
}
return (BOOL)(!(p==0));
}
// **************************************************
// 声明:
// 参数:
// 无
// 返回值:
// 假如成功,返回TRUE;否则,返回FALSE
// 功能描述:
//
// 引用:
//
// ************************************************
static LRESULT CopyText( HWND hWnd, LPSTR lpstr, int nMax )
{
LPCSTR lpWinText = (LPCSTR)GetWindowLong( hWnd, GWL_TEXT_PTR );
//_LPWINDATA lpws = _GetHWNDPtr( hWnd );
int i = 0;
ASSERT( lpstr && nMax > 0 );
if( lpWinText && nMax > 0 )
{
LPCTSTR lpcWinStr = lpWinText;
nMax--;
while( *lpcWinStr && i < nMax )
{
*lpstr++ = *lpcWinStr++; i++;
}
*lpstr = 0;
}
return i;
}
// **************************************************
// 声明:
// 参数:
// 无
// 返回值:
// 假如成功,返回TRUE;否则,返回FALSE
// 功能描述:
//
// 引用:
//
// ************************************************
BOOL WINAPI Wnd_DrawCaption( HWND hWnd, HDC hdc, LPCRECT lprc, UINT uFlags )
{
HBRUSH hBrush;
HICON hIcon;
int xicon = 0;
int oldMode;
//_LPWINDATA lpws = _GetHWNDPtr( hWnd );
RECT rect;
rect = *lprc;
//ASSERT( lpws );
//if( lpws )
{
if( uFlags & DC_ICON )
{
//hIcon = lpws->hSmallIcon;//(HICON)WinClass_GetLong( hWnd, GCL_HICON );
hIcon = (HICON)GetClassLong( hWnd, GCL_HICON );
if( hIcon == NULL )
{
if( uFlags & DC_ACTIVE )
hIcon = GetStockObject(SYS_STOCK_LOGO);//hicoSysMenu;
else
hIcon = GetStockObject(SYS_STOCK_LOGO_GRAY);//hicoGraySysMenu;
}
if( hIcon )
{
DrawIcon( hdc, lprc->left, lprc->top, hIcon );
// 2004-07-08, modify
//xicon = GetSystemMetrics( SM_CXICON );
xicon = GetSystemMetrics( SM_CXSIZE );
//
}
}
if( uFlags & DC_ACTIVE )
{
SetTextColor( hdc, GetSysColor(COLOR_CAPTIONTEXT) );
hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
}
else
{
SetTextColor( hdc, GetSysColor(COLOR_INACTIVECAPTIONTEXT) );
hBrush = GetSysColorBrush(COLOR_INACTIVECAPTION);
}
rect.left += xicon;
FillRect( hdc, &rect, hBrush );
if( (uFlags & DC_TEXT) )
{
LPCTSTR lpWinText = (LPCTSTR)GetWindowLong( hWnd, GWL_TEXT_PTR );//lpws->lpWinText
if( lpWinText )
{
oldMode = SetBkMode( hdc, TRANSPARENT );
DrawText( hdc, lpWinText, strlen( lpWinText ), &rect, DT_SINGLELINE | DT_END_ELLIPSIS );
SetBkMode( hdc, oldMode );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -