📄 openwel.c
字号:
#include <fcntl.h>
#include <termios.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <minigui/mgext.h>
#include "sysset.h"
#include "../mybuttonreg.h"
#define IDC_WEL_INFOR 0x3210
#define IDC_welset0 0x3201
#define IDC_welset1 0x3202
#define IDC_welset2 0x3203
#define IDC_welset3 0x3204
#define IDC_welset4 0x3206
#define IDL_KAIGUAN 0x3205
#define IDC_KAI 0x3207
#define IDC_GUAN 0x3208
#define IDC_welset8 2222
#define FILE_openwel "data/openwel_text.txt"
static BITMAP bmp_bkgnd;
/*static BITMAP save_pushed;
static BITMAP save_unpushed;
static BITMAP save_mousemove;
static BITMAP return_pushed;
static BITMAP return_unpushed;
static BITMAP return_mousemove;
*/
static HWND hCtrl1;
static HWND hCtrl2;
static HWND openwelhcwd;
void READ_fileOPENWEL(void)//--------------------READ------------------
{
FILE *fp = NULL;
//open file
if((fp = fopen(FILE_openwel,"r")) == NULL)
{
//no file or open error
printf ("\nSystem Message :Cant't open the file");
printf ("\nIf you first use this ,The system don't have the file");
printf ("\nSysrem will create the file to save data");
//create a new file
if ((fp = fopen(FILE_openwel,"w")) == NULL)
{
printf ("\nCreate File ERROR");
return ;
}
fclose (fp);
}
//read file to struct
if ( fread(&OW.openwel_text_name,sizeof(OW),1,fp)>0)
{
fclose (fp);
}
//read file error
else
{
printf("\nRead the file Error or no data\n");
fclose (fp);
return ;
}
}
//---------------WRITEFILE---------------
void WRITE_fileOPENWEL(void)
{
FILE *fp = NULL;
//open file
if ( (fp = fopen(FILE_openwel,"w")) == NULL)
{
printf ("\nOpen the file Error(write)");
return ;
}
//write file
if (fwrite(&OW,sizeof(OW),1,fp) <= 0)
printf ("\nwrite the file error");
fclose (fp);
return ;
}
static int BAOCUN(HWND BChcwd)
{
int len;
HWND hWnd_OPENW;
hWnd_OPENW = GetDlgItem (BChcwd, IDC_WEL_INFOR); //---比较——》如果该文本中没字符的话,则提示输入内容
len = GetWindowTextLength(hWnd_OPENW); //---比较——》如果该文本中没字符的话,则提示输入内容
if(len == 0) //---比较——》如果该文本中没字符的话,则提示输入内容
{
MessageBox (BChcwd, "请输入开机问候语", "提示", MB_OK | MB_ICONINFORMATION);//---比较——》如果该文本中没字符的话,则提示输入内容
return 0;
}
GetWindowText(hWnd_OPENW,OW.openwel_text_name, 100);
WRITE_fileOPENWEL();
MessageBox (BChcwd,"保存成功", "提示", MB_OK | MB_ICONINFORMATION);
return 0;
}
/*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)&save_pushed);
}
if(hwnd == hCtrl2 && nc == MYBUTTON_PUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&return_pushed);
}
if ( hwnd == hCtrl1 && nc == MYBUTTON_UNPUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&save_unpushed);
BAOCUN(openwelhcwd);
// add your business code
}
if(hwnd == hCtrl2 && nc == MYBUTTON_UNPUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&return_unpushed);
WRITE_fileOPENWEL();
SendNotifyMessage(openwelhcwd,MSG_CLOSE,0,0);
}
if( hwnd == hCtrl1 && nc == MYBUTTON_MOUSEMOVE)
{
SetWindowAdditionalData(hwnd, (DWORD)&save_mousemove);
}
if(hwnd == hCtrl2 && nc == MYBUTTON_MOUSEMOVE)
{
SetWindowAdditionalData(hwnd, (DWORD)&return_mousemove);
}
InvalidateRect (hwnd, NULL, TRUE);
}
*/
static int openwelProc(HWND openwelhcwd,int message,WPARAM wParam,LPARAM lParam)
{
int i;
static HWND Med;
HDC hdc;
const RECT* clip;
RECT rcTemp;
BOOL fGetDC;
switch(message)
{
case MSG_CREATE:
/*LoadBitmap (HDC_SCREEN, &save_pushed, "image/button/213.jpg");
LoadBitmap (HDC_SCREEN, &save_unpushed, "image/button/311.jpg");
LoadBitmap (HDC_SCREEN, &save_mousemove, "image/button/212.jpg");
LoadBitmap (HDC_SCREEN, &return_pushed, "image/button/223.jpg");
LoadBitmap (HDC_SCREEN, &return_unpushed, "image/button/221.jpg");
LoadBitmap (HDC_SCREEN, &return_mousemove, "image/button/222.jpg");
*/
READ_fileOPENWEL();
CreateWindowEx(CTRL_BUTTON,
"开",WS_VISIBLE | BS_AUTORADIOBUTTON | BS_CHECKED | WS_TABSTOP | WS_GROUP,WS_EX_TRANSPARENT,IDC_KAI,185,90,40,20,openwelhcwd,0);
CreateWindowEx(CTRL_BUTTON,
"关",WS_VISIBLE | BS_AUTORADIOBUTTON,WS_EX_TRANSPARENT,IDC_GUAN,185,120,40,20,openwelhcwd,0);
//hCtrl1 = CreateWindowEx(CTRL_MYBUTTON,
// "保存",WS_VISIBLE , WS_EX_TRANSPARENT,IDC_welset3, 60,150,50,25, openwelhcwd, (DWORD)&save_unpushed);
hCtrl1 =CreateWindow ("button",
"保存",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
IDC_welset3,
60,150,50,25, openwelhcwd, 0);
//hCtrl2 = CreateWindowEx(CTRL_MYBUTTON,
// "返回",WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,IDC_welset0, 210,150,50,25, openwelhcwd, (DWORD)&return_unpushed);
hCtrl2 =CreateWindow ("button",
"返回",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
IDC_welset0,
210,150,50,25,openwelhcwd, 0);
Med = CreateWindow(CTRL_SLEDIT,
"",WS_VISIBLE | ES_BASELINE, IDC_WEL_INFOR ,20,50,140,18, openwelhcwd, 0);
SetFocus(Med);
SetWindowText(GetDlgItem(openwelhcwd, IDC_WEL_INFOR),OW.openwel_text_name);
//SetNotificationCallback (hCtrl1, notify_proc);
// SetNotificationCallback (hCtrl2, notify_proc);
return 0;
case MSG_MOUSEMOVE:
//SetWindowAdditionalData(hCtrl1, (DWORD)&save_unpushed);
//SetWindowAdditionalData(hCtrl2, (DWORD)&return_unpushed);
InvalidateRect (hCtrl1, NULL, TRUE);
InvalidateRect (hCtrl2, NULL, TRUE);
break;
case MSG_PAINT:
//printf ("BeginPaint.\n");
hdc = BeginPaint (openwelhcwd);
SetBkMode(hdc, BM_TRANSPARENT);//把时间设置为透明显示
SetTextColor(hdc, PIXEL_red);//设置字体颜色
TextOut (hdc, 20, 20, "开机问候语:");
TextOut (hdc, 20, 90, "开机问候语开关状态:");
EndPaint (openwelhcwd, hdc);
//printf ("EndPaint.\n");
return 0;
case MSG_ERASEBKGND:
{
hdc = (HDC)wParam;
clip = (const RECT*) lParam;
fGetDC = FALSE;
if (hdc == 0) {
hdc = GetClientDC (openwelhcwd);
fGetDC = TRUE;
}
if (clip) {
rcTemp = *clip;
ScreenToClient (openwelhcwd, &rcTemp.left, &rcTemp.top);
ScreenToClient (openwelhcwd, &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 IDC_welset3:
BAOCUN(openwelhcwd);
break;
case IDC_KAI:
OW.openwel_text_flag=1;
MessageBox (openwelhcwd, "问候语已开起", "提示", MB_OK | MB_ICONINFORMATION);
break;
case IDC_GUAN:
OW.openwel_text_flag=0;
//WRITE_fileOPENWEL();
MessageBox (openwelhcwd, "问候语已关闭", "提示", MB_OK | MB_ICONINFORMATION);
break;
case IDC_welset0: //返回
WRITE_fileOPENWEL();
DestroyMainWindow(openwelhcwd);
PostQuitMessage(openwelhcwd);
return 0;
}
return 0;
case MSG_DESTROY:
DestroyAllControls(openwelhcwd);
return 0;
case MSG_CLOSE:
UnloadBitmap (&bmp_bkgnd);
/*UnloadBitmap (&return_pushed);
UnloadBitmap (&return_unpushed);
UnloadBitmap (&return_mousemove);
UnloadBitmap (&save_pushed);
UnloadBitmap (&save_unpushed);
UnloadBitmap (&save_mousemove);*/
DestroyMainWindow(openwelhcwd);
PostQuitMessage(openwelhcwd);
return 0;
}
return DefaultMainWinProc(openwelhcwd,message,wParam,lParam);
}
int openwel(HWND SYShcwd)
{
MSG Msg;
MAINWINCREATE CreateInfo;
// HWND openwelhcwd;
RegisterMyButtonControl ();
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/background/bkgnd29.jpg"))
return -1;
CreateInfo.dwStyle=WS_VISIBLE | WS_BORDER | WS_CAPTION;
CreateInfo.dwExStyle=WS_EX_IMECOMPOSE;
CreateInfo.spCaption="★☆★☆★ 开 机 问 候 语 ★☆★☆★";
CreateInfo.hMenu=0;
CreateInfo.hCursor=GetSystemCursor(IDC_ARROW);
CreateInfo.hIcon=0;
CreateInfo.MainWindowProc=openwelProc;
CreateInfo.lx=0;
CreateInfo.ty=0;
CreateInfo.rx=320;
CreateInfo.by=216;
CreateInfo.iBkColor=PIXEL_lightwhite;
CreateInfo.dwAddData=0;
CreateInfo.hHosting=SYShcwd;
openwelhcwd=CreateMainWindow(&CreateInfo);
ShowWindow(openwelhcwd,SW_SHOWNORMAL);
while(GetMessage(&Msg,openwelhcwd))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup(openwelhcwd);
UnregisterMyButtonControl ();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -