net.c
来自「minigui PDA系统 可实现手机功能」· C语言 代码 · 共 217 行
C
217 行
#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>
//SearchingNet主窗口句柄
static HWND hMainWnd;
//线程停止标志位
static BOOL STOP;
//GPRS初始化完成标志
static BOOL OK=FALSE;
//背景图片句柄
static BITMAP bmp_bkgnd;
static int LoadBmps(void)
{
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/waiting/waiting0.jpg"))
return 1;
return 0;
}
static void UnloadBmps (void)
{
UnloadBitmap (&bmp_bkgnd);
}
static int SearchingNetPro(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
RECT rc;
switch (message)
{
case MSG_ERASEBKGND: //重绘背景
{
//printf("111111111\n");
BOOL fGetDC = 0;
hdc = (HDC)wParam;
if (hdc == 0)
{
hdc = GetClientDC (hWnd);
fGetDC = 1;
}
//用图片填充背景
FillBoxWithBitmap (hdc, 0, 0, 320, 240, &bmp_bkgnd);
//printf("222222222\n");
if (fGetDC)
ReleaseDC (hdc);
return 0;
}
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
/********************************************************************************************
* Function Name: DesktopUpdate()
* Function Discription: Refurbish the SearchingNet window per half second
********************************************************************************************/
static void * DesktopUpdate (void * arg)
{
int i = 1;
STOP = FALSE;
while(STOP == FALSE)
{
//6张图片一次轮换,形成动态效果
UpdateWindow (hMainWnd, 1);
UnloadBitmap (&bmp_bkgnd);
switch(i)
{
case 0:
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/waiting/waiting0.jpg"))
printf("open bmp error!\n");
i++;
break;
case 1:
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/waiting/waiting1.jpg"))
printf("open bmp error!\n");
i++;
break;
case 2:
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/waiting/waiting2.jpg"))
printf("open bmp error!\n");
i++;
break;
case 3:
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/waiting/waiting3.jpg"))
printf("open bmp error!\n");
i++;
break;
case 4:
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/waiting/waiting4.jpg"))
printf("open bmp error!\n");
i++;
break;
case 5:
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/waiting/waiting5.jpg"))
printf("open bmp error!\n");
i++;
break;
case 6:
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/waiting/waiting6.jpg"))
printf("open bmp error!\n");
i++;
break;
case 7:
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/waiting/waiting7.jpg"))
printf("open bmp error!\n");
i++;
break;
case 8:
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/waiting/waiting8.jpg"))
printf("open bmp error!\n");
i++;
break;
case 9:
if (LoadBitmap (HDC_SCREEN, &bmp_bkgnd, "image/waiting/waiting9.jpg"))
printf("open bmp error!\n");
i=0;
break;
}
usleep (300000);
}
PostQuitMessage (hMainWnd);
}
void * GprsInit (void * arg)
{
//初始化串口3
tty_init ();
//初始化gprs模块
gprs_init ();
usleep(5000000);
OK=TRUE;
printf("init OK\n");
}
int SearchingNet (void)
{
MSG Msg;
pthread_t th_desktopupdate, th_init;
MAINWINCREATE CreateInfo;
time_t StartTime,EndTime;
LoadBmps();
//窗口属性设置
CreateInfo.dwStyle = WS_VISIBLE;
CreateInfo.dwExStyle = WS_EX_TOPMOST;
CreateInfo.spCaption = " ";
CreateInfo.hMenu = 0;
CreateInfo.hCursor = GetSystemCursor(IDC_NONE);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = SearchingNetPro;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = 320;
CreateInfo.by = 240;
CreateInfo.iBkColor = COLOR_lightwhite;
CreateInfo.dwAddData = 0;
CreateInfo.hHosting = HWND_DESKTOP;
//创建窗口
hMainWnd = CreateMainWindow (&CreateInfo);
if (hMainWnd == HWND_INVALID)
return -1;
//建立gprs模块初始化线程
pthread_create (&th_init, NULL, GprsInit, NULL);
//建立更新窗口背景线程
pthread_create (&th_desktopupdate, NULL, DesktopUpdate, NULL);
//显示窗口
ShowWindow(hMainWnd, SW_SHOWNORMAL);
while (GetMessage(&Msg, hMainWnd))
{
if(OK == TRUE)
{
//计算程序执行时间,当执行了5秒后,将线程停止位置1,以结束线程
STOP = TRUE;
}
DispatchMessage(&Msg);
}
//结束线程,销毁窗口
pthread_join (th_init, NULL);
pthread_join (th_desktopupdate, NULL);
DestroyMainWindow (hMainWnd);
MainWindowThreadCleanup (hMainWnd);
UnloadBmps ();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?