📄 bgset.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#include <errno.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include "sysset.h"
#include "../mybuttonreg.h"
extern BITMAP main_bkgnd;
#define IDL_DIR 100
#define IDL_FILE 110
#define IDC_PATH 120
//#define FILE_bgset "data/background_text.txt"
static BITMAP bmp_bkgnd;
static BITMAP ok_pushed;
static BITMAP ok_unpushed;
static BITMAP ok_mousemove;
static BITMAP return_pushed;
static BITMAP return_unpushed;
static BITMAP return_mousemove;
static HWND hCtrl1;
static HWND hCtrl2;
char cwd [MAX_PATH + 1];
static DLGTEMPLATE DlgDelFiles =
{
WS_BORDER | WS_CAPTION,
WS_EX_NONE,
0, 0, 320, 240,
"★★☆★★ 4主题背景选择 ★★☆★★",
0, 0,
2, NULL,
0
};
static CTRLDATA CtrlDelFiles[] =
{
{
CTRL_LISTBOX,
WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_NOTIFY,
10, 30, 140, 100,
IDL_DIR,
"",
0
},
{
CTRL_LISTBOX,
//WS_CHILD | WS_VISIBLE | WS_BORDER | LBS_SORT |LBS_AUTOCHECK |LBS_USEICON | LBS_AUTOCHECKBOX | WS_VSCROLL,
WS_CHILD | WS_VISIBLE | WS_BORDER | LBS_SORT |LBS_AUTOCHECK |LBS_USEICON |WS_VSCROLL,
165, 30, 140, 100,
IDL_FILE,
"",
0
},
/*
{
"button",
WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP,
40, 160, 80, 28,
IDOK,
"确定",
0
},
{
"button",
WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
190, 160, 80, 28,
IDCANCEL,
"返回",
0
},
*/
};
static void fill_boxes (HWND hDlg, const char* path)
{
#ifdef __ECOS__
LISTBOXITEMINFO lbii;
lbii.string = "file.1";
lbii.cmFlag = CMFLAG_BLANK;
lbii.hIcon = 0;
SendDlgItemMessage (hDlg, IDL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii);
lbii.string = "file.2";
SendDlgItemMessage (hDlg, IDL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii);
lbii.string = "file.3";
SendDlgItemMessage (hDlg, IDL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii);
#else
struct dirent* dir_ent;
DIR* dir;
struct stat ftype;
char fullpath [PATH_MAX + 1];
SendDlgItemMessage (hDlg, IDL_DIR, LB_RESETCONTENT, 0, (LPARAM)0);
SendDlgItemMessage (hDlg, IDL_FILE, LB_RESETCONTENT, 0, (LPARAM)0);
SetWindowText (GetDlgItem (hDlg, IDC_PATH), path);
if ((dir = opendir (path)) == NULL)
return;
while ( (dir_ent = readdir ( dir )) != NULL ) {
/* Assemble full path name. */
strncpy (fullpath, path, PATH_MAX);
strcat (fullpath, "/");
strcat (fullpath, dir_ent->d_name);
if (stat (fullpath, &ftype) < 0 ) {
continue;
}
if (S_ISDIR (ftype.st_mode))
SendDlgItemMessage (hDlg, IDL_DIR, LB_ADDSTRING, 0, (LPARAM)dir_ent->d_name);
else if (S_ISREG (ftype.st_mode)) {
LISTBOXITEMINFO lbii;
lbii.string = dir_ent->d_name;
lbii.cmFlag = CMFLAG_BLANK;
lbii.hIcon = 0;
SendDlgItemMessage (hDlg, IDL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii);
}
}
closedir (dir);
#endif
}
static void dir_notif_proc (HWND hwnd, int id, int nc, DWORD add_data)
{
if (nc == LBN_CLICKED || nc == LBN_ENTER) {
int cur_sel = SendMessage (hwnd, LB_GETCURSEL, 0, 0L);
if (cur_sel >= 0) {
// char cwd [MAX_PATH + 1];
char dir [MAX_NAME + 1];
GetWindowText (GetDlgItem (GetParent (hwnd), IDC_PATH), cwd, MAX_PATH);
SendMessage (hwnd, LB_GETTEXT, cur_sel, (LPARAM)dir);
if (strcmp (dir, ".") == 0)
return;
strcat (cwd, "/");
strcat (cwd, dir);
fill_boxes (GetParent (hwnd), cwd);
}
}
}
void file_notif_proc (HWND hwnd, int id, int nc, DWORD add_data)
{
}
/*static void prompt (HWND hDlg)
{
int i=0;
HWND hDlg_bgset;
char files [1024] = "背景图片更换成功!\n";
char cBufmain[40]="image/";
for (i = 0; i < SendDlgItemMessage (hDlg, IDL_FILE, LB_GETCOUNT, 0, 0L); i++)
{
char file [MAX_NAME + 1];
// int status = SendDlgItemMessage (hDlg, IDL_FILE, LB_GETCHECKMARK, i, 0);
//int status = SendDlgItemMessage (hDlg, IDL_FILE, LB_GETITEMDATA, i, 0);
if (CMFLAG_CHECKED)
{
SendDlgItemMessage (hDlg, IDL_FILE, LB_GETTEXT, i, (LPARAM)file);
strcat (files, file);
strcat (files, "\n");
strcat (cBufmain, file);
LoadBitmap (HDC_SCREEN, &main_bkgnd, cBufmain);
}
}
MessageBox (hDlg, files, "确认更换", MB_OK | MB_ICONINFORMATION);
}*/
static void prompt (HWND hDlg)
{
int index=0;
HWND hDlg_bgset;
char files [1024] = "要更换的背景图片为:\n";
char cBufmain[1024];
char file [MAX_NAME + 1];
index = SendMessage ( GetDlgItem ( hDlg,IDL_FILE ), LB_GETCURSEL, 0, 0 );
if ( index >= 0 )
{
SendDlgItemMessage (hDlg, IDL_FILE, LB_GETTEXT, index, (LPARAM)file);
strcat (files, file);
strcat (files, "\n");
strcat ( cwd, "/" );
strcpy (cBufmain, cwd);
strcat (cBufmain, file);
UnloadBitmap ( &main_bkgnd );
index = LoadBitmap (HDC_SCREEN, &main_bkgnd, cBufmain);
if ( index < 0 )
{
MessageBox (hDlg, "更换背景失败", "错误", MB_OK | MB_ICONINFORMATION);
LoadBitmap (HDC_SCREEN, &main_bkgnd, "image/bkgnd.jpg");
return;
}
else
MessageBox (hDlg, "更换背景成功", "成功", MB_OK | MB_ICONINFORMATION);
}
}
static void notify_proc (HWND hwnd, int id, int nc, DWORD add_data)
{
//printf("hwnd=%d\n", hwnd);
if ( hwnd == hCtrl1 && nc == MYBUTTON_PUSHED)
{
//SetWindowAdditionalData(hwnd, (DWORD)&ok_pushed);
}
if(hwnd == hCtrl2 && nc == MYBUTTON_PUSHED)
{
//SetWindowAdditionalData(hwnd, (DWORD)&return_pushed);
}
if ( hwnd == hCtrl1 && nc == BN_CLICKED&&id==IDOK)
{
//SetWindowAdditionalData(hwnd, (DWORD)&ok_unpushed);
prompt (GetParent(hwnd));
// add your business code
}
if(hwnd == hCtrl2 && nc == BN_CLICKED&&id==IDCANCEL)
{
// SetWindowAdditionalData(hwnd, (DWORD)&return_unpushed);
SendNotifyMessage(GetParent(hwnd),MSG_CLOSE,0,0);
}
if( hwnd == hCtrl1 && nc == MYBUTTON_MOUSEMOVE)
{
// SetWindowAdditionalData(hwnd, (DWORD)&ok_mousemove);
}
if(hwnd == hCtrl2 && nc == MYBUTTON_MOUSEMOVE)
{
// SetWindowAdditionalData(hwnd, (DWORD)&return_mousemove);
}
InvalidateRect (hwnd, NULL, TRUE);
}
static int DelFilesBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
char cwd[MAX_PATH+1];
switch (message) {
case MSG_INITDIALOG:
{
//LoadBitmap (HDC_SCREEN, &ok_pushed, "image/button/413.jpg");
// LoadBitmap (HDC_SCREEN, &ok_unpushed, "image/button/411.jpg");
// LoadBitmap (HDC_SCREEN, &ok_mousemove, "image/button/412.jpg");
//LoadBitmap (HDC_SCREEN, &return_pushed, "image/button/423.jpg");
// LoadBitmap (HDC_SCREEN, &return_unpushed, "image/button/421.jpg");
// LoadBitmap (HDC_SCREEN, &return_mousemove, "image/button/422.jpg");
CreateWindowEx(CTRL_STATIC,
"路径:",WS_VISIBLE | SS_SIMPLE, WS_EX_TRANSPARENT, IDC_PATH, 10, 140, 290, 15, hDlg, 0);
// hCtrl1 = CreateWindowEx(CTRL_MYBUTTON,
// "确定",WS_VISIBLE , WS_EX_TRANSPARENT,IDOK, 40, 160, 80, 28, hDlg, (DWORD)&ok_unpushed);
hCtrl1 =CreateWindow ("button",
"确定",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
IDOK, 40, 160, 80, 28, hDlg, 0);
// hCtrl2 = CreateWindowEx(CTRL_MYBUTTON,
// "返回",WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,IDCANCEL, 190, 160, 80, 28,hDlg, (DWORD)&return_unpushed);
hCtrl2 =CreateWindow ("button",
"返回",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
IDCANCEL, 190, 160, 80, 28,hDlg, 0);
SetNotificationCallback (hCtrl1, notify_proc);
SetNotificationCallback (hCtrl2, notify_proc);
SetNotificationCallback (GetDlgItem (hDlg, IDL_DIR), dir_notif_proc);
SetNotificationCallback (GetDlgItem (hDlg, IDL_FILE), file_notif_proc);
fill_boxes (hDlg, getcwd (cwd, MAX_PATH));
return 1;
}
case MSG_MOUSEMOVE:
// SetWindowAdditionalData(hCtrl1, (DWORD)&ok_unpushed);
//SetWindowAdditionalData(hCtrl2, (DWORD)&return_unpushed);
InvalidateRect (hCtrl1, NULL, TRUE);
InvalidateRect (hCtrl2, NULL, TRUE);
break;
case MSG_PAINT:
//printf ("BeginPaint.\n");
hdc = BeginPaint (hDlg);
SetBkMode(hdc, BM_TRANSPARENT);
SetTextColor(hdc, PIXEL_red);//设置字体颜色
TextOut (hdc, 10, 10, "目录列表");
TextOut (hdc, 165, 10, "文件列表");
// SetTextColor(GetClientDC(GetDlgItem(hDlg,IDC_PATH)), PIXEL_red);
EndPaint (hDlg, hdc);
//printf ("EndPaint.\n");
return 0;
case MSG_ERASEBKGND:
{
HDC hdc = (HDC)wParam;
const RECT* clip = (const RECT*) lParam;
BOOL fGetDC = FALSE;
RECT rcTemp;
if (hdc == 0) {
hdc = GetClientDC (hDlg);
fGetDC = TRUE;
}
if (clip) {
rcTemp = *clip;
ScreenToClient (hDlg, &rcTemp.left, &rcTemp.top);
ScreenToClient (hDlg, &rcTemp.right, &rcTemp.bottom);
IncludeClipRect (hdc, &rcTemp);
}
FillBoxWithBitmap (hdc, 0, 0, 320, 206, &bmp_bkgnd);
if (fGetDC)
ReleaseDC (hdc);
return 0;
}
/*
case MSG_COMMAND:
switch (wParam)
{
case IDOK: //此处有一BUG---如果没选中文件也弹出更换成功消息框
prompt (hDlg);
break;
case IDCANCEL:
EndDialog (hDlg, wParam);
break;
}
break;
*/
case MSG_CLOSE:
{
/* UnloadBitmap (&bmp_bkgnd);
UnloadBitmap (&return_pushed);
UnloadBitmap (&return_unpushed);
UnloadBitmap (&return_mousemove);
UnloadBitmap (&ok_pushed);
UnloadBitmap (&ok_unpushed);
UnloadBitmap (&ok_mousemove);
*/
EndDialog (hDlg, IDCANCEL);
}
return 0;
}
return DefaultDialogProc (hDlg, message, wParam, lParam);
}
int backgroundset(HWND SYShcwd)
{
RegisterMyButtonControl ();
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/background/bkgnd29.jpg"))
return 1;
DlgDelFiles.controls = CtrlDelFiles;
DialogBoxIndirectParam (&DlgDelFiles, HWND_DESKTOP, DelFilesBoxProc, 0L);
UnregisterMyButtonControl ();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -