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

2013年(1)

2008年(2)

2007年(14)

2006年(413)

分类:

2006-06-13 17:29:31

小超 @ 2004-10-31 01:28

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] = {'{row.content}'};

   if (res_dir [0] == '{row.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.x+xmButton.w)
       &&(y>xmButton.y)&&(y.y+xmButton.h))
     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

#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"

/************************ system panel dialog  *************************/
#define IDC_ENGNATIVERADIO0    100
#define IDC_ENGLIBGGIDRADIO1   101
#define IDC_ENGSVGALIBRADIO2   102

DLGTEMPLATE DlgSystemPanelInfo =
{
   WS_BORDER|WS_CAPTION, WS_EX_NONE,
   120, 120, 240, 200, "系统属性", 0, 0, 6, NULL
};

CTRLDATA CtrlSystemPanelInfo [] =
{
   { "static", WS_VISIBLE | SS_GROUPBOX | SS_LEFT,
       10, 10, 220, 140, IDC_STATIC, "图形引擎", 0 },
   {  "button", WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE | WS_GROUP| WS_TABSTOP,
       20, 40, 120, 22, IDC_ENGNATIVERADIO0, "自带引擎", 0 },
   {  "button", WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE ,
       20, 65, 120, 22, IDC_ENGLIBGGIDRADIO1, "LibGGI引擎", 0 },
   {  "button", WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE ,
       20, 90, 120, 22, IDC_ENGSVGALIBRADIO2, "SVGALib引擎", 0 },
   { "button", WS_VISIBLE | BS_PUSHLIKE | BS_CENTER ,
       100, 154, 60, 22, IDOK, "确定", 0 },
   { "button", WS_VISIBLE | BS_PUSHLIKE | BS_CENTER ,
       170, 154, 60, 22, IDCANCEL, "取消", 0 },

};

static int
DialogSystemPanelProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
   char tempStr[21];
   switch(message)
   {
       case MSG_INITDIALOG:
       {
         if(GetValueFromEtcFile(MINIGUI_CONFIG,
                 "system","engine",tempStr,20)!=ETC_OK)
         {
           tempStr[0]=0;
         };
         tempStr[20]=0;
         if(strcmp(tempStr,"native")==0)
           CheckDlgButton(hDlg,IDC_ENGNATIVERADIO0,TRUE);
         else if(strcmp(tempStr,"LibGGI")==0)
           CheckDlgButton(hDlg,IDC_ENGLIBGGIDRADIO1,TRUE);
         else if(strcmp(tempStr,"SVGALib")==0)
           CheckDlgButton(hDlg,IDC_ENGSVGALIBRADIO2,TRUE);

       }
       break;
   case MSG_COMMAND:
       if (wParam == IDOK)
       {
         if(IsDlgButtonChecked(hDlg,IDC_ENGNATIVERADIO0))
           strcpy (tempStr,"native");
         else if(IsDlgButtonChecked(hDlg,IDC_ENGLIBGGIDRADIO1))
           strcpy (tempStr,"LibGGI");
         else if(IsDlgButtonChecked(hDlg,IDC_ENGSVGALIBRADIO2))
           strcpy (tempStr,"SVGALib");
         else
         {
           MessageBox(hDlg,"必须选择一个引擎","控制面板",MB_OK| MB_ICONSTOP);
           return 0;
         }
         if(SetValueToEtcFile(MINIGUI_CONFIG,
                 "system","engine",tempStr)!=ETC_OK)
         {
           MessageBox(hDlg,"设置文件写入失败","控制面板",MB_OK| MB_ICONSTOP);
           return 0;
         }
         SetValueToEtcFile(MINIGUI_CONFIG,"system","availableEngine1","native");
         SetValueToEtcFile(MINIGUI_CONFIG,"system","availableEngine2","LibGGI");
         SetValueToEtcFile(MINIGUI_CONFIG,"system","availableEngine3","SVGALib");
         EndDialog(hDlg,IDOK);
       }
       break;
   }
   return DefaultDialogProc(hDlg, message, wParam, lParam);
}


int SystemPanelDialog(HWND hWnd)
{
   DlgSystemPanelInfo.controls = CtrlSystemPanelInfo;
   return DialogBoxIndirectParam(&DlgSystemPanelInfo, hWnd,
                   DialogSystemPanelProc, 0);

}

/************************ display panel dialog  *************************/
#define IDC_BACKGROUNDPLACEMBUTTON    100
#define IDC_BACKGROUNDBITMAPEDIT      101
#define IDC_DISPLAYRESOLUTIONMBUTTON  102
#define IDC_DISPLAYCOLORSMBUTTON      103
#define IDC_FILECHOISE                104
#define IDC_CHBMPPATHBTM              105
#define IDC_BMPPATHEDIT               106

DLGTEMPLATE DlgDisplayPanelInfo =
{
   WS_BORDER|WS_CAPTION, WS_EX_NONE,
   120, 40, 440, 400, "显示属性", 0, 0, 16, NULL
};

CTRLDATA CtrlDisplayPanelInfo [] =
{
   {  "static", WS_VISIBLE | SS_GROUPBOX | SS_LEFT,
       10, 10, 420, 270, IDC_STATIC, "背景", 0 },
   {  "static", WS_VISIBLE | SS_LEFT,
       20, 32, 80, 20, IDC_STATIC, "图片文件名", 0 },
   {  "listbox", WS_VISIBLE | WS_TABSTOP | LBS_NOTIFY | WS_VSCROLL | WS_BORDER,
       20, 55, 185, 150, IDC_FILECHOISE, NULL, 0 },
   {  "static", WS_VISIBLE | SS_LEFT,
       20, 225, 60, 20, IDC_STATIC, "图片路径", 0 },
   {  "button", WS_VISIBLE | BS_PUSHLIKE | BS_CENTER ,
       77, 220, 120, 22, IDC_CHBMPPATHBTM, "选择图片路径", 0 },
   {  "sledit", WS_VISIBLE | WS_TABSTOP | LBS_NOTIFY | WS_BORDER,
       20, 250, 380, 22, IDC_BMPPATHEDIT, "", 0 },

   {  "static", WS_VISIBLE | SS_LEFT,
       240, 32, 80, 20, IDC_STATIC, "预览", 0 },
   {  "static", WS_VISIBLE | SS_LEFT,
       220, 225, 60, 20, IDC_STATIC, "背景位置", 0 },
   {  "menubutton", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
       280, 220, 120, 22, IDC_BACKGROUNDPLACEMBUTTON, "选择背景位置", 0 },

   {  "static", WS_VISIBLE | SS_GROUPBOX | SS_LEFT,
       10, 280, 420, 70, IDC_STATIC, "显示分辩率(功能未实现)", 0 },
   {  "static", WS_VISIBLE | SS_LEFT,
       20, 310, 60, 20, IDC_STATIC, "分辩率", 0 },
   {  "menubutton", WS_CHILD | WS_VISIBLE | WS_TABSTOP ,
       77, 305, 120, 22, IDC_DISPLAYRESOLUTIONMBUTTON, "选择分辩率", 0 },
   {  "static", WS_VISIBLE | SS_LEFT,
       220, 310, 80, 20, IDC_STATIC, "颜色数目", 0 },
   {  "menubutton", WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE ,
       280, 305, 120, 22, IDC_DISPLAYCOLORSMBUTTON, "选择颜色数目", 0 },

   {  "button", WS_VISIBLE | BS_PUSHLIKE | BS_CENTER ,
       300, 354, 60, 22, IDOK, "确定", 0 },
   {  "button", WS_VISIBLE | BS_PUSHLIKE | BS_CENTER ,
       370, 354, 60, 22, IDCANCEL, "取消", 0 },

};

void ListBMPFiles(HWND hDlg,char* path)
{
   struct      dirent* pDirEnt;
   DIR*        dir;
   struct      stat ftype;
   char        fullpath [PATH_MAX + 1];

   SendDlgItemMessage (hDlg, IDC_FILECHOISE, LB_RESETCONTENT, 0, (LPARAM)0);
   dir = opendir (path);
   while ( (pDirEnt = readdir ( dir )) != NULL )
   {
       strncpy (fullpath, path, PATH_MAX);
       strcat (fullpath, "/");
       strcat (fullpath, pDirEnt->d_name);

       if (lstat (fullpath, &ftype) < 0 )
       {
          Ping();
          continue;
       }
       if (S_ISREG(ftype.st_mode))
       {
          SendDlgItemMessage (hDlg, IDC_FILECHOISE, LB_ADDSTRING,0,(LPARAM)pDirEnt->d_name);
       }
   }
}

static char *Cposition[]=
{
"上左", "上中", "上右",
"左中", "居中", "右中",
"下左", "下中", "下右",
"不设背景"
};

static char *Eposition[]=
{
"upleft", "upcenter", "upright",
"vcenterleft","center","vcenterright",
"downleft", "downcenter", "downright",
"none"
};

int Cp(char* CName)
{
 int i;
 for (i=0;i<10;i++)
   if(strcmp(Cposition,CName)==0)
     return i;
 return -1;
}

int Ep(char* EName)
{
 int i;
 for (i=0;i<10;i++)
   if(strcmp(Eposition,EName)==0)
     return i;
 return -1;
}

static int
DialogDisplayPanelProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
   char tempStr[101];
   static BITMAP screenbitmap;
   static BITMAP bgbitmap;
   static char bmppath[PATH_MAX];
   static char bmpfile[PATH_MAX];
   static int bgposition;
   int i;
   RECT invrc;

   switch(message)
   {
       case MSG_INITDIALOG:
       {
         MENUBUTTONITEM mbi;
         HWND hTmp;
         mbi.data=0;
         mbi.bmp=0;
         //resolution
         hTmp = GetDlgItem(hDlg,IDC_DISPLAYRESOLUTIONMBUTTON);
         mbi.text= "640X480";
         SendMessage (hTmp, MBM_ADDITEM, -1, (LPARAM) &mbi);
         mbi.text= "800X600";
         SendMessage (hTmp, MBM_ADDITEM, -1, (LPARAM) &mbi);
         mbi.text= "1024X768";
         SendMessage (hTmp, MBM_ADDITEM, -1, (LPARAM) &mbi);
         //color
         hTmp = GetDlgItem(hDlg,IDC_DISPLAYCOLORSMBUTTON);
         mbi.text= "16";
         SendMessage (hTmp, MBM_ADDITEM, -1, (LPARAM) &mbi);
         mbi.text= "256";
         SendMessage (hTmp, MBM_ADDITEM, -1, (LPARAM) &mbi);
         mbi.text= "64K";
         SendMessage (hTmp, MBM_ADDITEM, -1, (LPARAM) &mbi);
         //position
         hTmp = GetDlgItem(hDlg,IDC_BACKGROUNDPLACEMBUTTON);
         for(i=0;i<10;i++)
         {
           mbi.text= Cposition;
           SendMessage (hTmp, MBM_ADDITEM, -1, (LPARAM) &mbi);
         }
         if(GetValueFromEtcFile(MINIGUI_CONFIG,
                 "bgpicture","position",tempStr,100)!=ETC_OK)
         {
           tempStr[0]=0;
         }
         else
         {
           tempStr[100]=0;
           bgposition = Ep(tempStr);
           SendMessage (hTmp,MBM_SETCURITEM,bgposition,0);
         }

         myLoadBitmap (&screenbitmap, "screen.bmp");

         hTmp = GetDlgItem(hDlg,IDC_BMPPATHEDIT);
         EnableWindow(hTmp,FALSE);

         if(GetValueFromEtcFile(MINIGUI_CONFIG,
                 "bitmapinfo","bitmappath",bmppath,100)!=ETC_OK)
         {
           bmppath[0]=0;
         };
         bmppath[100]=0;
         SetDlgItemText(hDlg,IDC_BMPPATHEDIT,bmppath);
         ListBMPFiles(hDlg,bmppath);

         if(GetValueFromEtcFile(MINIGUI_CONFIG,
                 "bitmapinfo","bgpicture", tempStr, 100)!=ETC_OK)
         {
           tempStr[0]=0;
         }
         else
         {
           tempStr[100]=0;
           strcpy(bmpfile, bmppath);
           strcat(bmpfile, "/");
           strcat(bmpfile, tempStr);
           LoadBitmap (HDC_SCREEN, &bgbitmap,bmpfile);
           i=SendDlgItemMessage (hDlg, IDC_FILECHOISE,  LB_FINDSTRINGEXACT, 0, (LPARAM)tempStr);
           SendDlgItemMessage (hDlg, IDC_FILECHOISE,  LB_SETCURSEL,  i,0);
         }

       }
       break;
   case MSG_PAINT:
   {
       HDC hdc;
//        hdc = BeginPaint (hDlg);
       hdc = GetClientDC (hDlg);
       FillBoxWithBitmap (hdc, 220,45,0, 0, &screenbitmap);
//        printf("%d,%d,%d\n",bgposition,bgposition%3,bgposition/3);
       if((bgposition<9)&&(bgposition>=0))
         FillBoxWithBitmap (hdc, 220+20+2 + (bgposition%3)*158/3,
                   45+20 + (bgposition/3)*111/3,
                   158/3, 111/3, &bgbitmap);
//        EndPaint(hDlg,hdc);
        ReleaseDC (hdc);
   }
   break;
   case MSG_COMMAND:
   {
       int id   = LOWORD(wParam);
       int code = HIWORD(wParam);
       switch (id)
       {
         case IDC_BACKGROUNDPLACEMBUTTON:
         {
           if(code != MBN_CHANGED) return 0;
           bgposition =  SendDlgItemMessage(hDlg,IDC_BACKGROUNDPLACEMBUTTON, MBM_GETCURITEM ,0,0);
           invrc.left = 220;
           invrc.top = 45;
           invrc.right = invrc.left + screenbitmap.bmWidth;
           invrc.bottom = invrc.top + screenbitmap.bmHeight;
           InvalidateRect(hDlg,&invrc,FALSE);

           break;
         }
         case IDC_CHBMPPATHBTM:
         {
           MessageBox(hDlg,"功能未考虑好是否该实现","控制面板",MB_OK);
           break;
         }
         case IDC_FILECHOISE:
         {
           if(code != LBN_SELCHANGE) return 0;
           i = SendDlgItemMessage(hDlg, IDC_FILECHOISE, LB_GETCURSEL, 0, 0);
           if (i == -1) return 0;
           SendDlgItemMessage(hDlg, IDC_FILECHOISE, LB_GETTEXT,
                               i, (LPARAM)tempStr);
           strcpy(bmpfile,bmppath);
           strcat(bmpfile,"/");
           strcat(bmpfile,tempStr);
           LoadBitmap(HDC_SCREEN,&bgbitmap,bmpfile);
           invrc.left = 220;
           invrc.top = 45;
           invrc.right = invrc.left + screenbitmap.bmWidth;
           invrc.bottom = invrc.top + screenbitmap.bmHeight;
           InvalidateRect(hDlg,&invrc,FALSE);
           break;
         }
         case IDOK:
         {
           int i;
           char temp[30];
           if(SetValueToEtcFile(MINIGUI_CONFIG,
                 "bgpicture","position",Eposition[bgposition])!=ETC_OK)
           {
             MessageBox(hDlg,"设置文件写入失败","控制面板",MB_OK| MB_ICONSTOP);
             return 0;
           }
           for(i=0;i<10;i++)
           {
             sprintf(temp,"availPosition%d",i+1);
             SetValueToEtcFile(MINIGUI_CONFIG,
                 "bgpicture",temp,Eposition);
           }
           i = SendDlgItemMessage(hDlg, IDC_FILECHOISE, LB_GETCURSEL, 0, 0);
//            if (i == -1) return;
           SendDlgItemMessage(hDlg, IDC_FILECHOISE, LB_GETTEXT,
                               i, (LPARAM)tempStr);
           if(SetValueToEtcFile(MINIGUI_CONFIG,
                 "bitmapinfo","bgpicture",tempStr)!=ETC_OK)
           {
             MessageBox(hDlg,"设置文件写入失败","控制面板",MB_OK| MB_ICONSTOP);
             return 0;
           }
           EndDialog(hDlg,IDOK);
           break;
         }
       }
     }
   }
   return DefaultDialogProc(hDlg, message, wParam, lParam);
}


int DisplayPanelDialog(HWND hWnd)
{
   DlgDisplayPanelInfo.controls = CtrlDisplayPanelInfo;
   return DialogBoxIndirectParam(&DlgDisplayPanelInfo, hWnd,
                   DialogDisplayPanelProc, 0);

}

/************************ mouse panel dialog  *************************/
#define IDC_CURLIST                   100
#define IDC_CHCURPATHBTM              101
#define IDC_CURPATHEDIT               102
#define IDC_MOUSEDEVEDIT              103
#define IDC_MOUSETYPEMBUTTON          104
#define IDC_MOUSETIMEEDIT             105

DLGTEMPLATE DlgMousePanelInfo =
{
   WS_BORDER|WS_CAPTION, WS_EX_NONE,
   120, 40, 320, 400, "鼠标属性", 0, 0, 16, NULL
};

CTRLDATA CtrlMousePanelInfo [] =
{
   {  "static", WS_VISIBLE | SS_GROUPBOX | SS_LEFT,
       10, 10, 300, 220, IDC_STATIC, "指针(仅供浏览)", 0 },
   {  "static", WS_VISIBLE | SS_LEFT,
       20, 32, 80, 20, IDC_STATIC, "指针列表", 0 },
   {  "listbox", WS_VISIBLE | WS_TABSTOP | LBS_NOTIFY | WS_VSCROLL | WS_BORDER,
       20, 55, 190, 100, IDC_CURLIST, NULL, 0 },
   {  "static", WS_VISIBLE | SS_LEFT,
       20, 175, 60, 20, IDC_STATIC, "指针路径", 0 },
   {  "button", WS_VISIBLE | BS_PUSHLIKE | BS_CENTER ,
       77, 170, 120, 22, IDC_CHCURPATHBTM, "选择指针图片路径", 0 },
   {  "sledit", WS_VISIBLE | WS_TABSTOP | LBS_NOTIFY | WS_BORDER,
       20, 200, 280, 22, IDC_CURPATHEDIT, "", 0 },

   {  "static", WS_VISIBLE | SS_LEFT,
       220, 32, 80, 20, IDC_STATIC, "预览(未实现)", 0 },

   {  "static", WS_VISIBLE | SS_GROUPBOX | SS_LEFT,
       10, 235, 300, 110, IDC_STATIC, "鼠标", 0 },
   {  "static", WS_VISIBLE | SS_LEFT,
       20, 260, 100, 20, IDC_STATIC, "鼠标设备", 0 },
   {  "sledit", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP ,
       130, 255, 120, 22, IDC_MOUSEDEVEDIT, "", 0 },

   {  "static", WS_VISIBLE | SS_LEFT,
       20, 290, 100, 20, IDC_STATIC, "鼠标类型", 0 },
   {  "menubutton", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
       130, 285, 120, 22, IDC_MOUSETYPEMBUTTON, "请选择鼠标类型", 0 },
   {  "static", WS_VISIBLE | SS_LEFT,
       20, 320, 100, 20, IDC_STATIC, "双击间隔时间", 0 },
   {  "sledit", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP ,
       130, 315, 120, 22, IDC_MOUSETIMEEDIT, "", 0 },


   {  "button", WS_VISIBLE | BS_PUSHLIKE | BS_CENTER ,
       180, 354, 60, 22, IDOK, "确定", 0 },
   {  "button", WS_VISIBLE | BS_PUSHLIKE | BS_CENTER ,
       250, 354, 60, 22, IDCANCEL, "取消", 0 },

};

void ListCURFiles(HWND hDlg,char* path)
{
   struct      dirent* pDirEnt;
   DIR*        dir;
   struct      stat ftype;
   char        fullpath [PATH_MAX + 1];

   SendDlgItemMessage (hDlg, IDC_CURLIST, LB_RESETCONTENT, 0, (LPARAM)0);
   dir = opendir (path);
   while ( (pDirEnt = readdir ( dir )) != NULL )
   {
       strncpy (fullpath, path, PATH_MAX);
       strcat (fullpath, "/");
       strcat (fullpath, pDirEnt->d_name);

       if (lstat (fullpath, &ftype) < 0 )
       {
          Ping();
          continue;
       }
       if (S_ISREG(ftype.st_mode))
       {
          SendDlgItemMessage (hDlg,
阅读(1914) | 评论(0) | 转发(0) |
0

上一篇:button.c

下一篇:mycontrol

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