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

📄 ebstatic.c

📁 基于minigui开发的一套图形控件系统
💻 C
字号:
// $Id: ebstatic.c,v 1.3 2005/06/20 01:06:30 tangjb Exp $

//

// ebstatic.c: the embed Static Control module.

//

// Copyright (C) 2003 gao laihong.

//

// Current maitainer: gaolaihong.



/*

**  This library is free software; you can redistribute it and/or

**  modify it under the terms of the GNU Library General Public

**  License as published by the Free Software Foundation; either

**  version 2 of the License, or (at your option) any later version.

**

**  This library 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

**  Library General Public License for more details.

**

**  You should have received a copy of the GNU Library General Public

**  License along with this library; if not, write to the Free

**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,

**  MA 02111-1307, USA

*/

/*

**  Alternatively, the contents of this file may be used under the terms 

**  of the Mozilla Public License (the "MPL License") in which case the

**  provisions of the MPL License are applicable instead of those above.

*/



// Create date: 2004/01/01

//

// Modify records:

//

//  Who             When        Where       For What                Status

//-----------------------------------------------------------------------------

//  GAO Laihong    2004/01/06   tcl    	   	create            create





#include <stdio.h>

#include <stdlib.h>

#include <string.h>



#include <minigui/common.h>

#include <minigui/minigui.h>

#include <minigui/gdi.h>

#include <minigui/window.h>

#include <minigui/control.h>



#include "ebcontrol.h"

#include "ebstatic.h"





static int EBStaticControlProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam);



BOOL RegisterEBStaticControl (void)

{

    WNDCLASS WndClass;



    WndClass.spClassName = CTRL_EBSTATIC;

    WndClass.dwStyle     = WS_NONE;

    WndClass.dwExStyle   = WS_EX_NONE;

    WndClass.hCursor     = GetSystemCursor (IDC_ARROW);

    WndClass.iBkColor    = PIXEL_transparent;

    WndClass.WinProc     = EBStaticControlProc;



    return RegisterWindowClass (&WndClass);;

}



void EBStaticControlCleanup (void)

{

    // do nothing.

    UnregisterWindowClass (CTRL_EBSTATIC);

}



static int EBStaticControlProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam)

{

    RECT        rcClient;

    HDC         hdc;

    HICON       hIcon;

    const char* spCaption;

    UINT        uFormat;

    DWORD       dwStyle;

    PEBSTATICCTRL ebData =(PEBSTATICCTRL)GetWindowAdditionalData2 (hwnd);

    int id = GetDlgCtrlID (hwnd); 



    switch (message) 

	{

        case MSG_CREATE:

        {

        	DWORD data;

        	if ((ebData = (PEBSTATICCTRL) calloc (1, sizeof (EBSTATICCTRL))) == NULL)

                return 1;

        	data = GetWindowAdditionalData (hwnd);

         	ebData->textcolor = PIXEL_black;

        	ebData->bkbmp = 0;

        	ebData->data1 = data;

        	SetWindowAdditionalData2 (hwnd, (DWORD)ebData);

             	return 0;

        }

        break;  

        case MSG_DESTROY:

        	if(ebData)

        	{

        		if(ebData->bkbmp)

        		{

        			UnloadBitmap((PBITMAP)(ebData->bkbmp));	

        			free((void*)(ebData->bkbmp));

        		}

        		

        		free (ebData);

        	}

		

        break;                     

        case ESTM_GETIMAGE:

        	if(ebData)

        		return (int)(ebData->data1);

            	return 0; 

        

        case ESTM_SETIMAGE:

        {

            int pOldValue = 0;

            if(ebData)

            {

            	pOldValue = (int)ebData->data1;

            

            	ebData->data1 = (DWORD)wParam;

            }

            

            SetWindowAdditionalData2 (hwnd, (DWORD)ebData);

            InvalidateRect (hwnd, NULL, TRUE);

            return pOldValue;

        }

        case ESTM_SETTEXTCOLOR:

        {

            int pOldValue = 0;

            if(ebData)

            {

            	pOldValue = (int)ebData->textcolor;           

            	ebData->textcolor = (DWORD)wParam;

            }

            

            SetWindowAdditionalData2 (hwnd, (DWORD)ebData);

            InvalidateRect (hwnd, NULL, FALSE);

            return pOldValue;

        }

        break;

        case ESTM_GETTEXTCOLOR:

        {

        	if(ebData)

        		return (int)ebData->textcolor;

        	return 0;

        }

        break;

        case MSG_NCPAINT:

        case MSG_ERASEBKGND:

        {

        	/*BOOL fGetDC = FALSE;

        	RECT rcTemp,*pClipRect;

        	HDC hdc = (HDC)wParam;

        	pClipRect =  (RECT*)lParam;

        	

        	if (hdc == 0) {

        		hdc = GetClientDC (hwnd);

        		fGetDC = TRUE;

    		}



    		if (pClipRect)

        		ClipRectIntersect (hdc, pClipRect);

        	

        	if((dwStyle &ESS_BKALPHA) && ebData && ebData->bkbmp)

        	{

          		FillBoxWithBitmap(hdc, 0, 0, 0, 0,(PBITMAP)(ebData->bkbmp));

                		

                }

       

       	

             	if (fGetDC)

        		ReleaseDC (hdc);

        	*/		

        	return 0;

        }

        break;

        case MSG_PAINT:

        {

            PLOGFONT pfont = GetWindowFont(hwnd);

			

            hdc = BeginPaint (hwnd);

            if (pfont)

                SelectFont (hdc, pfont);

                

            GetClientRect (hwnd, &rcClient);

            dwStyle = GetWindowStyle (hwnd);



			SetBrushColor (hdc, GetWindowBkColor (hwnd));

            SetBkColor (hdc, GetWindowBkColor (hwnd));

			SetBkMode(hdc,BM_TRANSPARENT);

			

            switch(dwStyle & ESS_BKTYPEMASK)

            {

             	case ESS_ICON:

        	        if (ebData && ebData->data1) 

					{

                    	hIcon = (HICON)(ebData->data1);

                    	DrawIcon (hdc, 0, 0, 0, 0, hIcon);

						SetBkMode(hdc,BM_TRANSPARENT);

                	}

            		break;

				

            	case ESS_BITMAP:

            	{

            		if (ebData && ebData->data1)

            		{

					//	FillWithBitmapAlpha(hwnd,hdc,(PBITMAP)(ebData->data1),dwStyle &ESS_BKALPHA);

						FillWithPicture(hwnd, hdc, NULL, (PBITMAP)(ebData->data1), 

										BMP_TYPE_NORMAL, 0);

						SetBkMode(hdc,BM_TRANSPARENT);

            		}

					break;

                }



            	case ESS_BKBMPFILE:

            	{

            		if(ebData && ebData->data1)

            		{

            		//	FillWithBmpfile(hwnd,hdc,(char *)(ebData->data1),dwStyle &ESS_BKALPHA);

            			FillWithPicture(hwnd, hdc, (char *)(ebData->data1), 

            							NULL, BMP_TYPE_ALPHACHANNEL, dwStyle &ESS_BKALPHA);

						SetBkMode(hdc,BM_TRANSPARENT);

            		}

					break;

            	}

            	

            	case ESS_ENHMETAFILE:

            		break;

					

            	case ESS_BKTRANSPARENT:

            	{

            		SetBrushColor (hdc, PIXEL_transparent);

					SetBkColor (hdc,PIXEL_transparent); 

					SetBkMode(hdc,BM_TRANSPARENT);

					FillBox(hdc, 0, 0, RECTW(rcClient), RECTH(rcClient));   //add by hj 2005-06-03

					break;

            	}

            		

				case ESS_BKUSECOLOR:

				{

					FillBox(hdc, 0, 0, RECTW(rcClient), RECTH(rcClient)); 

					break;

				}

				

				case ESS_ALPHAIMAGE:

				{

					if(ebData && ebData->data1)

            		{

					//	FillWithAlphaBmpfile(hwnd, hdc, (char *)(ebData->data1), dwStyle &ESS_BKALPHA);

						FillWithPicture(hwnd, hdc, (char *)(ebData->data1), NULL, BMP_TYPE_ALPHARED, dwStyle&ESS_BKALPHA);

            		}

				}

				break;

      			default:

      				break;

            }

            

            switch(dwStyle & ESS_RECTMASK)

            {

            	case ESS_GRAYRECT:

            	    SetBrushColor (hdc, PIXEL_lightgray);

                    FillBox(hdc, 0, 0, RECTW(rcClient), RECTH(rcClient)); 

                    break;

            	case ESS_BLACKRECT: 

            	case ESS_WHITERECT:

            		break;

            	default:

            		break;

            }

            

            switch(dwStyle & ESS_FRAMEMASK)

            {

            	case ESS_BLACKFRAME:

            		break;

					

            	case ESS_GRAYFRAME:

            	     DrawFlatControlFrameEx (hdc,

                            0, 0, rcClient.right - 1, rcClient.bottom - 1, 

                            PIXEL_darkgray, 1, PIXEL_invalid);

                     break;

      

            	case ESS_WHITEFRAME:

            		break;

					

            	default:

            		break;

            }

			

            if(ebData)

           		SetTextColor (hdc, ebData->textcolor);

			

            if(dwStyle & ESS_SIMPLE)

            { 	    

                if (dwStyle & WS_DISABLED)

                    SetTextColor (hdc, PIXEL_darkgray);

   

                spCaption = GetWindowCaption (hwnd);

                /*if (spCaption)    //changed by hejian 2004-5-21

                   TextOut (hdc, 0, 0, spCaption);                         */

                if(spCaption)

                {

                	//fprintf(stderr,"GetFontHeight(hdc)=%d,rcClient.bottom-rcClient.top=%d.\n",GetFontHeight(hdc),(rcClient.bottom-rcClient.top));

                	TextOut(hdc,2,(rcClient.bottom-rcClient.top-GetFontHeight(hdc)),spCaption);

                	/*uFormat = DT_VCENTER;

                        if ( (dwStyle & ESS_LEFT) == ESS_LEFT)

                             uFormat |= DT_LEFT | DT_SINGLELINE;

                        else if ( (dwStyle & ESS_CENTER) == ESS_CENTER)

                             uFormat |= DT_CENTER | DT_SINGLELINE;

                        else if ( (dwStyle & ESS_RIGHT) == ESS_RIGHT)

                             uFormat |= DT_RIGHT | DT_SINGLELINE;

                        DrawText (hdc, spCaption, -1, &rcClient, uFormat);*/

                }                         

            }

			else if(dwStyle & ESS_MULTILINE)

            {

            	    spCaption = GetWindowCaption (hwnd);

	            if(spCaption)

	            {

	            	uFormat = DT_WORDBREAK;

	            	DrawText (hdc, spCaption, -1, &rcClient, uFormat);

	            }

            }

            else

            {

	            spCaption = GetWindowCaption (hwnd);

	            if(spCaption)

	            {

//edit by tjb 2004-3-10

//用DT_SINGLELINE 替换 DT_WORDBREAK

//原因:不能实现文字垂直居中



#if 1//edit by tjb 2004-10-29

            		uFormat = DT_SINGLELINE| DT_VCENTER;



		            if (dwStyle & ESS_CENTER)

		                uFormat |= DT_CENTER;

		            else if (dwStyle & ESS_RIGHT)

		                uFormat |= DT_RIGHT;

					

					if (dwStyle & ESS_LEFTNOWORDWRAP)

						uFormat |= DT_EXPANDTABS;

					else if (dwStyle & ESS_NOPREFIX)

						uFormat |= DT_NOPREFIX;

#else            

            	    uFormat = DT_VCENTER;

                    if ( (dwStyle & ESS_LEFT) == ESS_LEFT)

                        uFormat |= DT_LEFT | DT_SINGLELINE;

                    else if ( (dwStyle & ESS_CENTER) == ESS_CENTER)

                        uFormat |= DT_CENTER | DT_SINGLELINE;

                    else if ( (dwStyle & ESS_RIGHT) == ESS_RIGHT)

                        uFormat |= DT_RIGHT | DT_SINGLELINE;

                    else if ( (dwStyle & ESS_LEFTNOWORDWRAP) == ESS_LEFTNOWORDWRAP)

                        uFormat |= DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS;

                    if (dwStyle & ESS_NOPREFIX)

                        uFormat |= DT_NOPREFIX;

#endif



                    DrawText (hdc, spCaption, -1, &rcClient, uFormat);

	            }

            }

            EndPaint (hwnd, hdc);

        }

        break;



        case MSG_LBUTTONDBLCLK:

            if (GetWindowStyle (hwnd) & ESS_NOTIFY)

                NotifyParent (hwnd, id, ESTN_DBLCLK);

            break;



        case MSG_LBUTTONDOWN:

            if (GetWindowStyle (hwnd) & ESS_NOTIFY)

                NotifyParent (hwnd, id, ESTN_CLICKED);

            break;



        case MSG_NCLBUTTONDBLCLK:

            break;



        case MSG_NCLBUTTONDOWN:

            break;



        case MSG_FONTCHANGED:

            InvalidateRect (hwnd, NULL, TRUE);

            return 0;

            

        case MSG_SETTEXT:

     	{

//     	    dwStyle = GetWindowStyle (hwnd);

     	    SetWindowCaption (hwnd, (char*)lParam);

//     		RefreshChildInParent(hwnd);//why need this func? by tjb 2004-5-19

          	//InvalidateRect (hwnd, NULL, TRUE);

			wndInvalidateRect (hwnd, NULL, TRUE);

    	    SendMessage (hwnd, MSG_PAINT, 0, 0);

        }

            break;

        case MSG_VSCROLL:

        case MSG_HSCROLL:

        	return 0;

            break;  

        default:

            break;

    }



    return DefaultControlProc (hwnd, message, wParam, lParam);

}

⌨️ 快捷键说明

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