funpanel.c

来自「minigui PDA系统 可实现手机功能」· C语言 代码 · 共 288 行

C
288
字号
#include "funpanel.h"

static BITMAP bkgnd;

static char *xmBmpName[]=
{
"myplayer.png","bomb.png","kuaihenzhun.png",
"tuixiangzi.png", "eluosi.png", "return.png"
};

static char *xmTitle[]=
{
"播放器","扫雷","快很准",
"推箱子","俄罗斯","返  回"
};

static XMBUTTON xmButton [BTM_NUM];

static int myLoadBitmap (BITMAP* bm, const char* filename)
{
    char full_path [MAX_PATH + 1];
    
#ifndef _PASS
#define _PASS

    strcpy (full_path, "./image/funpanel/");
    strcat (full_path, filename);
    
#endif
    return LoadBitmap (HDC_SCREEN, bm, full_path);
}

static int WhichBox(int x,int y)
{
  int i;
  for (i=0;i<BTM_NUM;i++)
  {
    if ((x>xmButton[i].x)&&(x<xmButton[i].x+xmButton[i].w)
        &&(y>xmButton[i].y)&&(y<xmButton[i].y+xmButton[i].h))
      return i;
  }
  return -1;
}
static int changeMode(HWND hWnd,int x,int y,int mode)
{
  int btm=WhichBox(x,y);
  int i;
  RECT rect;
  static int lastbtm=-1;
  static int lastmode=BTM_FLAT;
  if ((btm==lastbtm)&&(mode==lastmode))
    return btm;
  for (i=0;i<BTM_NUM;i++)
  {
    if(xmButton[i].mode==BTM_FLAT) continue;
    xmButton[i].mode=BTM_FLAT;
    rect.left=xmButton[i].x;
    rect.right=xmButton[i].x+xmButton[i].w;
    rect.top=xmButton[i].y;
    rect.bottom=xmButton[i].y+xmButton[i].h;
    InvalidateRect(hWnd,&rect,FALSE);
  }
  if (btm!=-1)
  {
    xmButton[btm].mode=mode;
    rect.left=xmButton[btm].x;
    rect.right=xmButton[btm].x+xmButton[btm].w;
    rect.top=xmButton[btm].y;
    rect.bottom=xmButton[btm].y+xmButton[btm].h;
    InvalidateRect(hWnd,&rect,FALSE);

  }
  if(btm!=lastbtm)    
  	InvalidateRect(hWnd,&rect,FALSE); 

  lastbtm = btm;  
  lastmode = mode;

  return btm;
  
}

static int LogOut(HWND hWnd)
{
	int i;
    for(i=0;i<BTM_NUM;i++)
        UnloadBitmap(&(xmButton[i].bitmap));
    DestroyMainWindow (hWnd);
    PostQuitMessage (hWnd);
    return 0;
}

static int FunPanelWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    static int lastdown=-1;
    
    switch (message)
    {
      case MSG_CREATE:
      {
      }
      break;
    
      case MSG_LBUTTONDOWN:
      {
        lastdown = changeMode(hWnd,LOWORD(lParam),HIWORD(lParam),BTM_DOWN );
       // InvalidateRect(hWnd,NULL,FALSE);
      }
      break;                                                                  
      
      case MSG_LBUTTONUP:
      {
        int up = changeMode(hWnd,LOWORD(lParam),HIWORD(lParam),BTM_FLAT );
       // InvalidateRect(hWnd,NULL,FALSE);
        
        if(up==-1) 
			break;
        
        if(up==lastdown)
        {
			switch(up)
			{
				case  IDM_MPLAYER:
					mplayer(hWnd);
					break ;
       
				case  IDM_BOMB :
					levelbomb(hWnd);
					break ;
        
				case  IDM_KUAIHENZHUN:
					sameGame(hWnd);
					break ;
        
				case  IDM_TUIXIANGZI:
					pushArk(hWnd);
					break ;
        
				case  IDM_ELUOSI:
					russia(hWnd);
					break ;
        
				case  IDM_RETURN:
					LogOut(hWnd);
					break ;
			}
        }
      }
      break;    
                                                                    
      case MSG_MOUSEMOVE:
      {
        changeMode(hWnd,LOWORD(lParam),HIWORD(lParam),BTM_UP );
      //  InvalidateRect (hWnd,NULL,FALSE);
      }
      break;
      
      case MSG_PAINT:
      {
        HDC hdc;
        RECT rc;
        int i;
       
        hdc = BeginPaint (hWnd);

        GetWindowRect(hWnd,&rc);
		
	 
	
		FillBoxWithBitmap (hdc,0, 0, 320, 216, &bkgnd); 

        for(i=0;i<BTM_NUM;i++)
        {
			
			if(xmButton[i].mode == BTM_UP)
				Draw3DUpThickFrame (hdc, xmButton[i].x,  xmButton[i].y ,
					xmButton[i].x+xmButton[i].w,xmButton[i].y+xmButton[i].h,
					PIXEL_black);
			else  
				if(xmButton[i].mode == BTM_DOWN)
					Draw3DDownThickFrame (hdc, xmButton[i].x,  xmButton[i].y ,
						xmButton[i].x+xmButton[i].w,xmButton[i].y+xmButton[i].h,
						PIXEL_black);
						
			FillBoxWithBitmap (hdc, xmButton[i].x+xmButton[i].bmpx,
                                xmButton[i].y+xmButton[i].bmpy,
                                0, 0, &xmButton[i].bitmap);

			SetBkMode(hdc, BM_TRANSPARENT); //这两个函数如果不放在这的话背景图片显示有问题
 	 		SetTextColor(hdc, PIXEL_red);
			
			TextOut(hdc,xmButton[i].x+xmButton[i].titlex,xmButton[i].y+xmButton[i].titley,
					xmButton[i].title);
        }
        EndPaint (hWnd,hdc);
        
      }
		return 0;
	
	  case MSG_DESTROY:
        	DestroyAllControls(hWnd);
            return 0;	
		
      case MSG_CLOSE:
      {
        int i;
        for(i=0;i<BTM_NUM;i++)
         	UnloadBitmap(&(xmButton[i].bitmap));
        UnloadBitmap(&bkgnd);
        DestroyMainWindow (hWnd);
        PostQuitMessage (hWnd);
        return 0;
      }
    }

    return DefaultMainWinProc (hWnd, message, wParam, lParam);
}

static void initBTMs(void)
{
    int i,j;

    for(i=0;i<BTM_NUM;i++)
    {
      //高亮显示框和图标的位置设置
      xmButton[i].x=20+(i%3)*105;
      xmButton[i].y=5+((int)(i/3))*100;
      xmButton[i].h=75; //设置高亮框的高度
      xmButton[i].w=67; //设置高亮框的宽度
      xmButton[i].bmpx=3; //图片在高亮框中的相对定点x,y坐标
      xmButton[i].bmpy=0;
      strcpy(xmButton[i].title,xmTitle[i]);
	
	//title的位置设置
      j=strlen(xmButton[i].title);
      xmButton[i].titlex=(9-j)*3;
      xmButton[i].titley=57;
      myLoadBitmap (&(xmButton[i].bitmap),xmBmpName [i]);
    }
}

static void InitFunPanelInfo (PMAINWINCREATE pCreateInfo, HWND hWnd)
{
    pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_VISIBLE ;
    pCreateInfo->dwExStyle =  WS_EX_IMECOMPOSE;;
    pCreateInfo->spCaption = "娱乐面板";
    pCreateInfo->hMenu = 0;
    pCreateInfo->hCursor = GetSystemCursor(0);
    pCreateInfo->hIcon = 0;
    pCreateInfo->MainWindowProc = FunPanelWinProc;
    pCreateInfo->lx = 0;
    pCreateInfo->ty = 0;
    pCreateInfo->rx = 320;
    pCreateInfo->by = 216;
    pCreateInfo->iBkColor = PIXEL_lightwhite;
    pCreateInfo->dwAddData = (DWORD)0;
    pCreateInfo->hHosting = hWnd;
}


int FunPanel(HWND hWnd)
{
    MSG Msg;
    MAINWINCREATE CreateInfo;
    HWND hMainWnd;
	
    initBTMs();
	
    InitFunPanelInfo (&CreateInfo, hWnd);
    
    if (LoadBitmap (HDC_SCREEN, &bkgnd, "image/background/bkgnd20.jpg"))//HDC_SCREEN:屏幕设备,加载图片必须在CreateMainWindow(&CreateInfo)之前
		return -1;
    
    hMainWnd = CreateMainWindow (&CreateInfo);
	
    if (hMainWnd == HWND_INVALID)
        return -1;

    while( GetMessage(&Msg, hMainWnd) )
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

   MainWindowThreadCleanup(hMainWnd);
   return 0;
}

⌨️ 快捷键说明

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