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

📄 defproc.c

📁 深圳市微逻辑电子有限公司 巨果&#8226 Kingmos&reg 系统核心
💻 C
📖 第 1 页 / 共 5 页
字号:
		    //得到系统框大小
			GetCaptionSysBoxRect( &rt, dwMainStyle );
			//居中
			//rt.top += ( (rt.bottom - rt.top) - yIconHeight ) >> 1;// align to middle
			//rt.left += ( (rt.right - rt.left) - xIconWidth ) >> 1;// align to middle
			rt.top += ( (rt.bottom - rt.top) - bitmap.bmHeight ) >> 1;// align to middle
			rt.left += ( (rt.right - rt.left) - bitmap.bmWidth ) >> 1;// align to middle
			//画图标
            DrawIcon( hdc, rt.left, rt.top, hIcon );
        }

        //dwExStyle = lpws->dwExStyle;//GetWindowLong( hWnd, GWL_EXSTYLE );

		// 画标题栏上的文本
		{
			TCHAR szText[128];
			int len;
			len = GetWindowText( hWnd, szText, sizeof(szText)-sizeof(TCHAR) );
			// now , draw caption text if possible
			if( len )//lpws->lpWinText )
			{	//因为已经清除了背景,所以这里画文本用透明模式
				DWORD oldMode = SetBkMode( hdc, TRANSPARENT );	
				
				rt = rtCaption;
				//得到文本矩形
				GetCaptionTextBoxRect( &rt, dwMainStyle, dwExStyle );
				//画之
				DrawText( hdc, szText, len, &rt,  DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS ); 
				SetBkMode( hdc, oldMode );
			}
		}

        // now draw option icon if possible
		// 画标题栏上的功能框
        if( dwExStyle & (WS_EX_CLOSEBOX | WS_EX_OKBOX | WS_EX_HELPBOX) )
        {            
			int xBtWidth;
			HANDLE hbmpSave, hbmp;
			HANDLE hMemDC = CreateCompatibleDC( hdc );
			int x, y;

            rt = rtCaption;
            //得到关闭框矩形
			GetCaptionCloseBoxRect( &rt, dwExStyle );
			xBtWidth = rt.right - rt.left;
			//居中
			//rt.top += ( (rt.bottom - rt.top) - yIconHeight ) >> 1;// align to middle
			//rt.left += ( (rt.right - rt.left) - xIconWidth ) >> 1;// align to middle
			hbmp = GetStockObject(SYS_STOCK_CAPTION_CLOSE);
			GetObject( hbmp, sizeof(bitmap), &bitmap );

			if( dwExStyle & WS_EX_CLOSEBOX )
            {	//画关闭框
				if( fActive )
				{
					hbmp = GetStockObject(SYS_STOCK_CAPTION_CLOSE);//hbmpClose;//用活动的位图
				}
				else
				{
					hbmp = GetStockObject(SYS_STOCK_CAPTION_CLOSE_GRAY);//hbmpGrayClose;//用非活动的位图
				}
				//GetObject( hbmp, sizeof(bitmap), &bitmap );
				y = rt.top + ( ( (rt.bottom - rt.top) - bitmap.bmHeight ) >> 1 );
				x = rt.left + ( ( (rt.right - rt.left) - bitmap.bmWidth ) >> 1 );// align to middle

	            hbmpSave = SelectObject( hMemDC, hbmp );
				//画之
				//BitBlt( hdc, rt.left, rt.top, xIconWidth, yIconHeight, hMemDC, 0, 0, SRCCOPY );
				BitBlt( hdc, x, y, bitmap.bmWidth, bitmap.bmHeight, hMemDC, 0, 0, SRCCOPY );

	            SelectObject( hMemDC, hbmpSave );

				rt.left -= xBtWidth;//为后面的绘制准备矩形
                rt.right -= xBtWidth;//为后面的绘制准备矩形
            }
            if( dwExStyle & WS_EX_OKBOX )
            {	//画关闭框
				if( fActive )
				{
					hbmp = GetStockObject(SYS_STOCK_CAPTION_OK);//hbmpOk;//用活动的位图
				}
				else
				{
					hbmp = GetStockObject(SYS_STOCK_CAPTION_OK_GRAY);//hbmpGrayOk;//用非活动的位图
				}
				//GetObject( hbmp, sizeof(bitmap), &bitmap );
				y = rt.top + ( ( (rt.bottom - rt.top) - bitmap.bmHeight ) >> 1 );
				x = rt.left + ( ( (rt.right - rt.left) - bitmap.bmWidth ) >> 1 );// align to middle

	            hbmpSave = SelectObject( hMemDC, hbmp );
	            //画之
				//BitBlt( hdc, rt.left, rt.top, xIconWidth, yIconHeight, hMemDC, 0, 0, SRCCOPY );
				BitBlt( hdc, x, y, bitmap.bmWidth, bitmap.bmHeight, hMemDC, 0, 0, SRCCOPY );
                SelectObject( hMemDC, hbmpSave );
				rt.left -= xBtWidth;//为后面的绘制准备矩形
                rt.right -= xBtWidth;//为后面的绘制准备矩形
            }
            if( dwExStyle & WS_EX_HELPBOX )
            {	//画帮助框
				if( fActive )
				{
					hbmp = GetStockObject(SYS_STOCK_CAPTION_HELP);//hbmpHelp;
				}
				else
				{
					hbmp = GetStockObject(SYS_STOCK_CAPTION_HELP_GRAY);//hbmpGrayHelp;
				}
				//GetObject( hbmp, sizeof(bitmap), &bitmap );
				y = rt.top + ( ( (rt.bottom - rt.top) - bitmap.bmHeight ) >> 1 );
				x = rt.left + ( ( (rt.right - rt.left) - bitmap.bmWidth ) >> 1 );// align to middle

	            hbmpSave = SelectObject( hMemDC, hbmp );
				//BitBlt( hdc, rt.left, rt.top, xIconWidth, yIconHeight, hMemDC, 0, 0, SRCCOPY );
				BitBlt( hdc, x, y, bitmap.bmWidth, bitmap.bmHeight, hMemDC, 0, 0, SRCCOPY );

                SelectObject( hMemDC, hbmpSave );
            }
			DeleteDC( hMemDC );
        }
    }
}

// **************************************************
// 声明:static void DrawFrame( HWND hWnd, 
//							  HDC hdc, 
//							  DWORD dwMainStyle,
//							  DWORD dwExStyle,
//							  BOOL bEraseBk )
// 参数:
//	IN hWnd - 窗口句柄
//	IN hdc - DC句柄
//	IN dwMainStyle - 窗口风格
//	IN dwExStyle - 窗口扩展风格
//	IN bEraseBk - 是否清除背景
// 返回值:
//	无
// 功能描述:
//	画窗口边框
// 引用: 
// ************************************************

static void DrawFrame( HWND hWnd,
					   HDC hdc, 
					   DWORD dwMainStyle, 
					   DWORD dwExStyle, 
					   BOOL bEraseBk )
{
    RECT rect;
    HBRUSH hBrush;
    int s, i;

    GetWindowRect( hWnd, &rect );
    OffsetRect( &rect, -rect.left, -rect.top );

	if( bEraseBk )
	{	//清除背景
	    FillRect( hdc, &rect, (HBRUSH)(COLOR_WINDOW+1) );
	}

    hBrush = SelectObject( hdc, GetStockObject( NULL_BRUSH ) );
    // draw frame
    if( dwMainStyle & WS_THICKFRAME )
    {	//画粗边框
        s = GetSystemMetrics( SM_CXFRAME );
        DrawEdge( hdc, &rect, EDGE_BUMP, BF_RECT );
		InflateRect( &rect, -s, -s );
    }
    else if( (dwMainStyle & WS_DLGFRAME) == WS_DLGFRAME )
    {	//画对话框风格的边框
        s = GetSystemMetrics( SM_CXDLGFRAME );
        Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
        InflateRect( &rect, -1, -1 );
        for( i = 1; i < s; i++ )  
		{
            DrawEdge( hdc, &rect, BDR_RAISEDOUTER, BF_RECT );
			InflateRect( &rect, -1, -1 );
		}
    }
    else if( dwMainStyle & WS_BORDER )
    {	//画单边框
		s = 1;
        Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
		InflateRect( &rect, -s, -s );
    }
	if( dwExStyle & WS_EX_CLIENTEDGE )
	{	//画客户边框
        if( (dwMainStyle & WS_CAPTION) == WS_CAPTION ||
		    (dwExStyle & WS_EX_TITLE) )
			rect.top += GetSystemMetrics( SM_CYCAPTION );
		DrawEdge( hdc, &rect, BDR_SUNKENOUTER, BF_RECT );
	}

    SelectObject( hdc, hBrush );
}

// **************************************************
// 声明:static LRESULT DoNcActivate( HWND hWnd, BOOL fActive )
// 参数:
//	IN hWnd - 窗口句柄
//	IN fActive - 是否窗口是活动的
// 返回值:
//	TRUE
// 功能描述:
//	处理WM_NCACTIVATE消息
// 引用: 
// ************************************************

static LRESULT DoNcActivate( HWND hWnd, BOOL fActive )
{
    HDC hdc;
    
    hdc = GetWindowDC( hWnd );    
    ShowCaption( hWnd, hdc, (DWORD)GetWindowLong( hWnd, GWL_MAINSTYLE ), fActive );
    ReleaseDC( hWnd, hdc );
    return TRUE;
}

// **************************************************
// 声明:static int DoSysCommand( HWND hWnd, WPARAM wParam, LPARAM lParam )
// 参数:
//	IN hWnd - 窗口句柄
//	IN wParam - 第一个参数
//	IN lParam - 第二个参数
// 返回值:
//	0
// 功能描述:
//	处理WM_SYSCOMMAND消息
// 引用: 
// ************************************************

static int DoSysCommand( HWND hWnd, WPARAM wParam, LPARAM lParam )
{
    if( wParam == SC_MOVE )
        return DoFrameMove( hWnd, LOWORD( lParam ), HIWORD( lParam )  );
    else if( wParam == SC_HSCROLL || wParam == SC_VSCROLL )
        return DoScrollMove( hWnd, wParam, LOWORD( lParam ), HIWORD( lParam ) );
    else if( wParam == SC_CLOSE )
        PostMessage( hWnd, WM_CLOSE, 0, 0 );
    else if( wParam == SC_OK )
        PostMessage( hWnd, WM_OK, 0, 0 );
    else if( wParam == SC_CONTEXTHELP )
        PostMessage( hWnd, WM_HELP, 0, 0 );
    return 0;
}

// **************************************************
// 声明:static LRESULT DoNcPaint( HWND hWnd, 
// 								WPARAM wParam,
// 								LPARAM lParam, 
// 								BOOL bEraseBk )
// 参数:
//	IN hWnd - 窗口句柄
//	IN wParam - 第一个参数
//	IN lParam - 第二个参数
//	IN bEraseBk - 是否清除背景
// 返回值:
//	1
// 功能描述:
//	处理 WM_NCPAINT消息
// 引用: 
// ************************************************

static LRESULT DoNcPaint( HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL bEraseBk )
{
    HDC hdc;
    DWORD dwMainStyle;
	DWORD dwExStyle;

    if( wParam == 1 )
        hdc = GetDCEx(hWnd, 0, DCX_WINDOW|DCX_CLIPSIBLINGS);
    else	// wParam是一个裁剪区域,需要与dc的区域进行AND运算
        hdc = GetDCEx(hWnd, (HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN|DCX_CLIPSIBLINGS);
    
    dwMainStyle = GetWindowLong( hWnd, GWL_MAINSTYLE );
	dwExStyle = GetWindowLong( hWnd, GWL_SUBSTYLE );
    // 画边框 draw frame
    DrawFrame( hWnd, hdc, dwMainStyle, dwExStyle, bEraseBk );
    // 画标题栏 draw text or icon or syscommand button
    if( (dwMainStyle & WS_CAPTION) == WS_CAPTION ||
		(dwExStyle & WS_EX_TITLE) )
        ShowCaption( hWnd, hdc, dwMainStyle, GetActiveWindow() == hWnd );
    // 画滚动条 draw scrollbar
    if( (dwMainStyle & (WS_HSCROLL | WS_VSCROLL) ) )
        DrawScrollBar( hWnd, hdc, dwMainStyle );
    ReleaseDC( hWnd, hdc );
    return 1;
}

// **************************************************
// 声明:LRESULT CALLBACK WinDef_NCPaint( HWND hWnd, 
// 									   WPARAM wParam,
// 									   LPARAM lParam,
// 									   BOOL bEraseBk )
// 参数:
//	IN hWnd - 窗口句柄
//	IN wParam - 第一个参数
//	IN lParam - 第二个参数
//	IN bEraseBk - 是否清除背景
// 返回值:
// 功能描述:
//	对非客户区进行绘制 
// 引用: 
// ************************************************

// call by win.c
LRESULT CALLBACK WinDef_NCPaint( HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL bEraseBk )
{
	return DoNcPaint( hWnd, wParam, lParam, bEraseBk );
}

// **************************************************
// 声明:static LRESULT DoNcCalcSize( HWND hWnd, WPARAM wParam, LPARAM lParam )
// 参数:
//	IN hWnd - 窗口句柄
//	IN wParam - 第一个参数
//	IN/OUT lParam - 第二个参数(为RECT结构指针,传入当前窗口大小,返回客户区大小)
// 返回值:
//	0
// 功能描述:
//	处理 WM_NCCALCSIZE 消息- 计算客户区的大小
// 引用: 
// ************************************************

static LRESULT DoNcCalcSize( HWND hWnd, WPARAM wParam, LPARAM lParam )
{
    LPRECT lprect;
    DWORD dwMainStyle;	
    DWORD dwExStyle;

    if( wParam == 0 )
    {
        lprect = (LPRECT)lParam;
        // 得到风格
        dwMainStyle = GetWindowLong( hWnd, GWL_STYLE );
        dwExStyle = GetWindowLong( hWnd, GWL_EXSTYLE );
        
        if( (dwMainStyle & WS_CAPTION) == WS_CAPTION ||
			(dwExStyle & WS_EX_TITLE ) )
        {
            lprect->top += GetSystemMetrics( SM_CYCAPTION );
        }
        if( (dwMainStyle & WS_THICKFRAME) == WS_THICKFRAME )
        {
            lprect->left += GetSystemMetrics( SM_CXFRAME );
            lprect->top += GetSystemMetrics( SM_CYFRAME );
            lprect->right -= GetSystemMetrics( SM_CXFRAME );
            lprect->bottom -= GetSystemMetrics( SM_CYFRAME );
        }
        else if( (dwMainStyle & WS_DLGFRAME) == WS_DLGFRAME )
        {
            lprect->left += GetSystemMetrics( SM_CXDLGFRAME );
            lprect->top += GetSystemMetrics( SM_CYDLGFRAME );
            lprect->right -= GetSystemMetrics( SM_CXDLGFRAME );
            lprect->bottom -= GetSystemMetrics( SM_CYDLGFRAME );
        }
        else if( (dwMainStyle & WS_BORDER) == WS_BORDER )
        {
            lprect->left += GetSystemMetrics( SM_CXBORDER );
            lprect->top += GetSystemMetrics( SM_CYBORDER );
            lprect->right -= GetSystemMetrics( SM_CXBORDER );
            lprect->bottom -= GetSystemMetrics( SM_CYBORDER );
        }
        if( dwMainStyle & WS_HSCROLL )
            lprect->bottom -= GetSystemMetrics( SM_CYHSCROLL );
        if( dwMainStyle & WS_VSCROLL )
            lprect->right -= GetSystemMetrics( SM_CXVSCROLL );  
		if( dwExStyle & WS_EX_CLIENTEDGE )
		{
			lprect->left++;
			lprect->top++;
			lprect->right--;
			lprect->bottom--;
		}
    }
    return 0;
}

// **************************************************
// 声明:static LRESULT DoActivate( HWND hWnd, BOOL fActivate, BOOL fMinimize )
// 参数:
// 	IN hWnd - 窗口句柄
// 	IN fActivate - 是否活动
// 	IN fMinimize - 是否最小化(不支持)
// 返回值:
// 	0
// 功能描述:
//	处理 WM_ACTIVATE 消息
// 引用: 
// ************************************************

static LRESULT DoActivate( HWND hWnd, BOOL fActivate, BOOL fMinimize )
{
    DWORD dwStyle;
    if( fActivate && fMinimize == FALSE )
    {
        SetFocus( hWnd );
        dwStyle = GetWindowLong( hWnd, GWL_STYLE );
        ASSERT( !(dwStyle & WS_CHILD) );
        if( !(dwStyle & WS_CHILD) )
        {   // popup and overlappend window
            //SetShellBarMenu( hWnd );
        }
    }
    return 0;
}

// **************************************************

⌨️ 快捷键说明

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