Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1427353
  • 博文数量: 430
  • 博客积分: 9995
  • 博客等级: 中将
  • 技术积分: 4388
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-24 18:04
文章存档

2013年(1)

2008年(2)

2007年(14)

2006年(413)

分类:

2006-06-13 17:27:32

小超 @ 2004-11-04 01:06

controlpanel.h

#ifndef H_CONTROLPANEL
#define H_CONTROLPANEL

#include

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

#define MINIGUI_CONFIG "/etc/MiniGUI.cfg"

#define IDM_EXIT 400
#define IDM_ABOUT_THIS 401
#define IDM_ABOUT 402

#define TITLE_MAX 10
#define INFO_MAX 200
#define BTM_NUM 13
#define BTM_UP 1
#define BTM_FLAT 0
#define BTM_DOWN -1
typedef struct
{
 int x,y,w,h;
 BITMAP bitmap;
 int bmpx,bmpy;
 char title[TITLE_MAX];
 int titlex,titley;
 char info[INFO_MAX];
 int mode;//0:flat,1:up,-1:down
}XMBUTTON;

typedef struct
{
 int x,y,w,h;
 BITMAP *bitmap;
 int bmpx,bmpy;
 BITMAP myBitmap;
 char *info;
 char myInfo[INFO_MAX];
 int infox,infoy,infow,infoh;
} FDKBUTTON;
void AboutLaodan (HWND hParent);


#define IDM_SYSTEM    0
#define IDM_DISPLAY   1
#define IDM_MOUSE     2
#define IDM_APP       3
#define IDM_IME       4
#define IDM_PASSWD    5
#define IDM_BROWSER   6
#define IDM_FONTS     7
#define IDM_PROGRAMERS  8
#define IDM_ICON      9
#define IDM_IE        10
#define IDM_SOUND     11
#define IDM_KEYBOARD  12

void* ControlPanel(void* data);
int myLoadBitmap (BITMAP* bm, const char* filename);

#ifdef __cplusplus
}
#endif  /* __cplusplus */

#endif

panels.h

#ifndef H_PANELS
#define H_PANELS

#include

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

void OpenPanel(HWND parent,int id);


#ifdef __cplusplus
}
#endif  /* __cplusplus */

#endif


main.c



#include
#include
#include

#include
#include
#include
#include
#include
#include
#include

#include "controlpanel.h"

int MiniGUIMain (int args, const char* arg[])
{
#if defined(_LITE_VERSION) && !(_STAND_ALONE)
   int i;
   const char* layer = NULL;
   RECT max_rect = {0, 0, 0, 0};

   for (i = 1; i < args; i++) {
       if (strcmp (arg, "-layer") == 0) {
           layer = arg[i + 1];
           break;
       }
   }

   GetLayerInfo (layer, &max_rect, NULL, NULL, NULL);

   if (JoinLayer (layer, arg[0],
               max_rect.left, max_rect.top,
               max_rect.left + 600,
               max_rect.top + 500) == INV_LAYER_HANDLE) {
       printf ("JoinLayer: invalid layer handle.\n");
       exit (1);
   }

   ControlPanel (NULL);

#else
#ifdef _IME_GB2312
   GBIMEWindow (HWND_DESKTOP);
#endif
   ControlPanel(NULL);
#endif
   return 0;
}

#ifndef _LITE_VERSION
#include
#endif



controlpanel.c

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#include
#include
#include
#include
#include
#include
#include

#include "controlpanel.h"
#include "panels.h"

int myLoadBitmap (BITMAP* bm, const char* filename)
{
   char full_path [MAX_PATH + 1];
#if 0
   static char res_dir [MAX_PATH + 1] = {'{post.content}'};

   if (res_dir [0] == '{post.content}') {
       if (GetValueFromEtcFile (ETCFILEPATH, "appinfo", "apprespath",
           res_dir, MAX_PATH) < 0)
           strcpy (res_dir, "res/");
   }

   strcpy (full_path, res_dir);
   if (full_path [strlen (full_path) - 1] != '/')
       strcat (full_path, "/");
   strcat (full_path, "controlpanel/");
   strcat (full_path, filename);
#else
   strcpy (full_path, "./res/");
   strcat (full_path, filename);
#endif

   return LoadBitmap (HDC_SCREEN, bm, full_path);
}

void AboutLaodan (HWND hParent)
{
   MessageBox (hParent,
         "老聃 (laodan), 本名李耳, 道家创始人"
           "著有道德二篇, 清净无为以治万物.\n\n"
           "本系统设计目的是试图寻找 MiniGUI "
           "系统的应用前景, 并在制作中寻找方便的开发方法与工具.\n\n"
           "作者喜爱先秦哲学, 诸子百家之言, 每下工夫制作一新系统, "
           "必以一子为名. "
           "故作者在 MiniGUI 上的工作均以老聃 (Laodan) 为代名.",
           "老聃",
         MB_OK | MB_ICONINFORMATION);
}

void AboutControlPanel (HWND hParent)
{
   MessageBox (hParent,
     "其实熟悉 MINIGUI 的朋友都可以通过直接修改参数文件来设置MINIGUI。\n\n"
     "出于完善图形界面系统的功能的原因, 我制作了这个面板,并加入了一些我认为"
     "在未来会添加进来的功能, 顺便排除系统BUG.\n\n"
     "            --冯大可 minx@thtfchain.com\n"
     "                   (or frankcd@263.net)",
     "控制面板",
     MB_OK | MB_ICONINFORMATION);
}

static HMENU createpmenuabout (void)
{
   HMENU hmnu;
   MENUITEMINFO mii;
   memset (&mii, 0, sizeof(MENUITEMINFO));
   mii.type        = MFT_STRING;
   mii.id          = 0;
   mii.typedata    = (DWORD)"帮助";
   hmnu = CreatePopupMenu (&mii);

   memset (&mii, 0, sizeof(MENUITEMINFO));
   mii.type        = MFT_STRING ;
   mii.state       = 0;
   mii.id          = IDM_ABOUT_THIS;
   mii.typedata    = (DWORD)"关于控制面板...";
   InsertMenuItem(hmnu, 0, TRUE, &mii);

   memset (&mii, 0, sizeof(MENUITEMINFO));
   mii.type        = MFT_STRING ;
   mii.state       = 0;
   mii.id          = IDM_ABOUT;
   mii.typedata    = (DWORD)"关于老聃...";
   InsertMenuItem(hmnu, 1, TRUE, &mii);

   return hmnu;
}

static HMENU createpmenufile (void)
{
   HMENU hmnu;
   MENUITEMINFO mii;
   memset (&mii, 0, sizeof(MENUITEMINFO));
   mii.type        = MFT_STRING;
   mii.id          = 0;
   mii.typedata    = (DWORD)"文件";
   hmnu = CreatePopupMenu (&mii);

   memset (&mii, 0, sizeof(MENUITEMINFO));
   mii.type        = MFT_STRING;
   mii.state       = 0;
   mii.id          = IDM_EXIT;
   mii.typedata    = (DWORD)"退出";
   InsertMenuItem(hmnu, 0, TRUE, &mii);

   return hmnu;
}

static HMENU createmenu (void)
{
   HMENU hmnu;
   MENUITEMINFO mii;

   hmnu = CreateMenu();

   memset (&mii, 0, sizeof(MENUITEMINFO));
   mii.type        = MFT_STRING;
   mii.id          = 100;
   mii.typedata    = (DWORD)"文件";
   mii.hsubmenu    = createpmenufile ();
   InsertMenuItem(hmnu, 0, TRUE, &mii);

   mii.type        = MFT_STRING;
   mii.id          = 140;
   mii.typedata    = (DWORD)"帮助";
   mii.hsubmenu    = createpmenuabout ();
   InsertMenuItem(hmnu, 1, TRUE, &mii);

   return hmnu;
}

static char *xmBmpName[]=
{
"system.bmp","display.bmp","mouse.bmp",
"app.bmp", "ime.bmp", "passwd.bmp",  "browser.bmp",
"fonts.bmp", "programers.bmp",
"adddel.bmp","ie.bmp","sound.bmp", "keyboard.bmp"
};
static char fdkBmpName[]="controlpanel.bmp";

static char *xmTitle[]=
{
"系统","显示","鼠标",
"应用程序","输入法","口令","浏览",
"字体","程序员","图标","浏览器",
"声音","键盘"
};

static char *xmInfo[]=
{
"系统:设定采用何种显示引擎",
"显示:设定显示属性",
"鼠标:设定鼠标参数和指针",
"应用程序:设定应用程序路径",
"输入法:设定输入法属性",
"口令:(尚未实现)",
"浏览:查看MINIGUI的文件位置",
"字体:修改字体设定(实现中)",
"程序员:MINIGUI的贡献者们,也包括你哦。",
"图标:显示MINIGUI图标",
"浏览器:设置WEB浏览器属性(尚未实现)",
"声音:设置系统声音(尚未实现)",
"键盘:设置键盘属性(尚未实现)",
};
static char fdkInfo[]="控制面板:对MINIGUI进行配置的图形工具";

static XMBUTTON xmButton [BTM_NUM];
static FDKBUTTON fdkButton ;

int WhichBox(int x,int y)
{
 int i;
 for (i=0;i  {
   if ((x>xmButton.x)&&(x        &&(y>xmButton.y)&&(y      return i;
 }
 return -1;
}
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  {
   if(xmButton.mode==BTM_FLAT) continue;
   xmButton.mode=BTM_FLAT;
   rect.left=xmButton.x;
   rect.right=xmButton.x+xmButton.w;
   rect.top=xmButton.y;
   rect.bottom=xmButton.y+xmButton.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);
   fdkButton.info=xmButton[btm].info;
   fdkButton.bitmap = & xmButton[btm].bitmap;
 }
 else
 {
   fdkButton.info = fdkButton.myInfo;
   fdkButton.bitmap = &fdkButton.myBitmap;
 }
 rect.left = fdkButton.x;
 rect.right= fdkButton.x+fdkButton.w;
 rect.top= fdkButton.y;
 rect.bottom= fdkButton.y+fdkButton.h;
 if(btm!=lastbtm)
   InvalidateRect(hWnd,&rect,FALSE);
 lastbtm = btm;
 lastmode = mode;
 return btm;
}

int ControlPanelWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
   static int lastdown=-1;
   switch (message)
   {
     case MSG_CREATE:
     {
     }
     break;
     case MSG_COMMAND:
     {
       int id   = LOWORD(wParam);
//        int code = HIWORD(wParam);
       switch (id)
       {
         case IDM_EXIT:
           if(MessageBox(hWnd,"确实要退出吗?","控制面板",MB_YESNO|MB_ICONQUESTION)==IDYES)
           {
               int i;
               for(i=0;i                  UnloadBitmap(&(xmButton.bitmap));
               UnloadBitmap(&fdkButton.myBitmap);
               DestroyMainWindow (hWnd);
               PostQuitMessage (hWnd);
               return 0;
           }

         break;
         case IDM_ABOUT_THIS:
           AboutControlPanel(hWnd);
         break;
         case IDM_ABOUT:
           AboutLaodan(hWnd);
         break;
       }
     }
     break;
     case MSG_LBUTTONDOWN:
     {
       lastdown = changeMode(hWnd,LOWORD(lParam),HIWORD(lParam),BTM_DOWN );
//        InvalidateRect(hWnd,NULL,FALSE);
     }
     break;                                                                  //
     case MSG_LBUTTONUP:
     {
//        char temp[100];
       int up = changeMode(hWnd,LOWORD(lParam),HIWORD(lParam),BTM_FLAT );
//        InvalidateRect(hWnd,NULL,FALSE);
       if(up==-1) break;
       if(up==lastdown)
       {
//          sprintf(temp,"you have choosed:%d\n",up);
//          MessageBox(hWnd,temp,"hei",MB_OK);
           OpenPanel(hWnd,up);
       }
     }
     break;                                                                  //
     case MSG_MOUSEMOVE:
     {
       changeMode(hWnd,LOWORD(lParam),HIWORD(lParam),BTM_UP );
//        InvalidateRect (hWnd,NULL,FALSE);
     }
     break;
     case MSG_PAINT:
     {
       HDC hdc;
       RECT rc,rect;
       int i;
       hdc = BeginPaint (hWnd);

       GetWindowRect(hWnd,&rc);

       Draw3DDownFrame (hdc, 3,  3 ,
                 (rc.right - rc.left - 5)/3,
                 rc.bottom - rc.top - 46,// - GetMainWinMetrics( MWM_CAPTIONY ),
                 PIXEL_lightwhite);
       Draw3DDownFrame (hdc, (rc.right - rc.left - 5)/3 +4,  3,
                 rc.right - rc.left - 7,
                 rc.bottom - rc.top - 46,// - GetMainWinMetrics( MWM_CAPTIONY ),
                 PIXEL_lightwhite);

       Draw3DUpFrame (hdc,fdkButton.x,fdkButton.y,
                     fdkButton.x+fdkButton.w,fdkButton.y+fdkButton.h,
                     PIXEL_lightwhite);
       FillBoxWithBitmap (hdc, fdkButton.x+fdkButton.bmpx,
                               fdkButton.y+fdkButton.bmpy,
                               0, 0, fdkButton.bitmap);

       rect.left = fdkButton.x+fdkButton.infox;
       rect.right = fdkButton.x+fdkButton.infox+fdkButton.infow;
       rect.top = fdkButton.y+fdkButton.infoy;
       rect.bottom = fdkButton.y+fdkButton.infoy+fdkButton.infoh;
       DrawText(hdc,fdkButton.info,-1,&rect, DT_NOCLIP | DT_WORDBREAK|DT_LEFT|DT_VCENTER);

       for(i=0;i        {
         if(xmButton.mode == BTM_UP)
           Draw3DUpFrame (hdc, xmButton.x,  xmButton.y ,
                   xmButton.x+xmButton.w,xmButton.y+xmButton.h,
                 PIXEL_lightwhite);
         else  if(xmButton.mode == BTM_DOWN)
           Draw3DDownFrame (hdc, xmButton.x,  xmButton.y ,
                   xmButton.x+xmButton.w,xmButton.y+xmButton.h,
                 PIXEL_lightwhite);
         FillBoxWithBitmap (hdc, xmButton.x+xmButton.bmpx,
                               xmButton.y+xmButton.bmpy,
                               0, 0, &xmButton.bitmap);
         TextOut(hdc,xmButton.x+xmButton.titlex,xmButton.y+xmButton.titley,
                 xmButton.title);
       }
       EndPaint (hWnd,hdc);
     }
     return 0;

     case MSG_CLOSE:
     {
       int i;
       for(i=0;i          UnloadBitmap(&(xmButton.bitmap));
       UnloadBitmap(&fdkButton.myBitmap);
       DestroyMainWindow (hWnd);
       PostQuitMessage (hWnd);
       return 0;
     }
   }

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

static void InitControlPanelInfo (PMAINWINCREATE pCreateInfo)
{
   pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER |
                        WS_VISIBLE ;
   pCreateInfo->dwExStyle =  WS_EX_IMECOMPOSE;;
   pCreateInfo->spCaption = "控制面板";
   pCreateInfo->hMenu = createmenu();
   pCreateInfo->hCursor = GetSystemCursor(0);
   pCreateInfo->hIcon = 0;
   pCreateInfo->MainWindowProc = ControlPanelWinProc;
   pCreateInfo->lx = 50;
   pCreateInfo->ty = 50;
   pCreateInfo->rx = 530;
   pCreateInfo->by = 410;
   pCreateInfo->iBkColor = COLOR_lightgray;
   pCreateInfo->dwAddData = (DWORD)0;
   pCreateInfo->hHosting = HWND_DESKTOP;
}

void initBTMs(void)
{
   int i,j;

   for(i=0;i    {
     xmButton.x=170 + (i%5)*55;
     xmButton.y=20 + ((int)(i/5))*80;
     xmButton.h=60;
     xmButton.w=50;
     xmButton.bmpx=5;
     xmButton.bmpy=2;
     strcpy(xmButton.title,xmTitle);
     strcpy(xmButton.info,xmInfo);
     j=strlen(xmButton.title);
     xmButton.titlex=(8-j)*3;
     xmButton.titley=42;
     myLoadBitmap (&(xmButton.bitmap),xmBmpName );
   }
   fdkButton.x=30;
   fdkButton.y=50;
   fdkButton.h=200;
   fdkButton.w=100;
   fdkButton.bmpx=30;
   fdkButton.bmpy=20;
   strcpy(fdkButton.myInfo,fdkInfo);
   myLoadBitmap(&(fdkButton.myBitmap),fdkBmpName);
   fdkButton.info = fdkButton.myInfo;
   fdkButton.bitmap = &(fdkButton.myBitmap);
   fdkButton.infox = 10;
   fdkButton.infoy = 80;
   fdkButton.infoh = 100;
   fdkButton.infow = 80;
}
void* ControlPanel(void* data)
{
   MSG Msg;
   MAINWINCREATE CreateInfo;
   HWND hMainWnd;
   initBTMs();
   InitControlPanelInfo (&CreateInfo);
   hMainWnd = CreateMainWindow (&CreateInfo);

   if (hMainWnd == HWND_INVALID)
       return NULL;

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

   MainWindowThreadCleanup(hMainWnd);
   return NULL;
}


panel.c
阅读(1208) | 评论(0) | 转发(0) |
0

上一篇:输入法窗口

下一篇:button.c

给主人留下些什么吧!~~