首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

[原创]利用LabWindows/CVI实现浮动屏幕功能

QUOTE:
以下是引用wangjianxin2001在2006-12-29 22:15:00的发言:

各位看官,大家也许都知道,像瑞星杀毒和金山毒霸之类的软件之中,通常都会一个可爱的小东西从界面上蹦出来,并且还会在任务栏中显示一个小图标,看起来是不是很有意思?!感觉今天的心情不错,我也试着做了一个,本人的美术功底不足,所以可能看起来不太好看,请原谅!哈哈!

  这其中,主要是基于我对一个DLL的扩展,大家看一下就知道了!
界面为:
图片点击可在新窗口打开查看
代码为:

#include "windows.h"
#include "toolbox.h"
#include <cvirte.h>
#include <userint.h>
#include "bitmappanel.h"
#include "transpanel.h"

static int index;
static int iconhandle;
static int menubarhandle;

static int handle;
static int panelHandle;
static RECT windowrect;
static RECT clientrect;
static RECT shape;
static HRGN hrgn;
static int flag = 0;

void settings (void);
void trayicon (void);
int CVICALLBACK iconCB (int iconHandle, int event, int eventData);

int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
if (InitCVIRTE (hInstance, 0, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "bitmappanel.uir", PANEL)) < 0)
return -1;

menubarhandle = LoadMenuBar (panelHandle, "bitmappanel.uir", MENUBAR);

SetSystemAttribute (ATTR_TASKBAR_BUTTON_VISIBLE, 0);

TransPanelEx (panelHandle, 0, 1);
SetCtrlAttribute (panelHandle, PANEL_PICTURERING, ATTR_PICT_BGCOLOR, VAL_TRANSPARENT);
GetPanelAttribute (panelHandle, ATTR_SYSTEM_WINDOW_HANDLE, &handle);

settings ();

trayicon ();

DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);

DeleteObject (hrgn);

RemoveSysTrayIcon (iconhandle);
DetachTrayIconMenu (iconhandle);

return 0;
}

int CVICALLBACK timer (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
static int i = 0;
static int j = 11;
switch (event)
{
case EVENT_TIMER_TICK:
settings ();
if (flag == 0)
{
SetCtrlVal (panelHandle, PANEL_PICTURERING, i);
i ++;
if (i >= 8)
{
i = 0;
}
}
else
{
SetCtrlVal (panelHandle, PANEL_PICTURERING, i);
i ++;
if (i >= 34)
{
i = 11;
}
}
break;
}
return 0;
}

int CVICALLBACK marquee (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
static int i = 1;
switch (event)
{
case EVENT_TIMER_TICK:
switch (i)
{
case 1:
SetTrayIconAttr (iconhandle, ATTR_TRAY_ICOFILE, "icon1.ico");
break;
case 2:
SetTrayIconAttr (iconhandle, ATTR_TRAY_ICOFILE, "icon2.ico");
break;
case 3:
SetTrayIconAttr (iconhandle, ATTR_TRAY_ICOFILE, "icon3.ico");
break;
}
i ++;
if (i >= 4)
{
i = 1;
}

break;
}
return 0;
}

int CVICALLBACK panelCB (int panel, int event, void *callbackData,
int eventData1, int eventData2)
{
switch (event)
{
case EVENT_KEYPRESS:

break;
case EVENT_LEFT_CLICK:
ReleaseCapture ();
SendMessage ((HWND)handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);


break;
case EVENT_RIGHT_CLICK:
RunPopupMenu (menubarhandle, MENUBAR_FILE, panelHandle, eventData1, eventData2, 0, 0, 0, 0);

break;
case EVENT_CLOSE:
QuitUserInterface (0);
break;
case EVENT_PANEL_SIZE:

break;
}
return 0;
}

void CVICALLBACK followmouse (int menuBar, int menuItem, void *callbackData,
int panel)
{
flag = !flag;
}

void CVICALLBACK soundeffect (int menuBar, int menuItem, void *callbackData,
int panel)
{
PlayWave ("Autorun.wav");
}

void CVICALLBACK animate (int menuBar, int menuItem, void *callbackData,
int panel)
{
int checked;

GetMenuBarAttribute (menubarhandle, MENUBAR_FILE_ANIMATE, ATTR_CHECKED, &checked);
if (checked)
{
SetCtrlAttribute (panelHandle, PANEL_TIMER, ATTR_ENABLED, 0);
}
else
{
SetCtrlAttribute (panelHandle, PANEL_TIMER, ATTR_ENABLED, 1);
}
SetMenuBarAttribute (menubarhandle, MENUBAR_FILE_ANIMATE, ATTR_CHECKED, !checked);
}

void CVICALLBACK about (int menuBar, int menuItem, void *callbackData,
int panel)
{
AboutMe (panelHandle);
}

void CVICALLBACK hideicon (int menuBar, int menuItem, void *callbackData,
int panel)
{
HidePanel (panelHandle);
}

void settings (void)
{
int ctrlwidth;
int ctrlheight;

GetCtrlAttribute (panelHandle, PANEL_PICTURERING, ATTR_HEIGHT, &ctrlheight);
GetCtrlAttribute (panelHandle, PANEL_PICTURERING, ATTR_WIDTH, &ctrlwidth);
SetPanelAttribute (panelHandle, ATTR_HEIGHT, ctrlheight + 24);
SetPanelAttribute (panelHandle, ATTR_WIDTH, ctrlwidth);

GetWindowRect ((HWND)handle, &windowrect);
GetClientRect ((HWND)handle, &clientrect);
shape.left = 4;
shape.top = clientrect.top + 26;
shape.right = clientrect.right - 6;
shape.bottom = clientrect.bottom - 6;

hrgn = CreateRectRgn (shape.left, shape.top, shape.right, shape.bottom);
SetWindowRgn ((HWND)handle, hrgn, 1);
}

void trayicon (void)
{
InstallSysTrayIcon ("icon1.ico", "舞蹈小人", iconCB, &iconhandle);
AttachTrayIconMenu (iconhandle);

InsertTrayIconMenuItem (iconhandle, "退出", &index);
InsertTrayIconMenuItem (iconhandle, NULL, &index);
InsertTrayIconMenuItem (iconhandle, "关于", &index);
InsertTrayIconMenuItem (iconhandle, NULL, &index);
InsertTrayIconMenuItem (iconhandle, "动画效果", &index);
InsertTrayIconMenuItem (iconhandle, "音效", &index);
InsertTrayIconMenuItem (iconhandle, "下一图像", &index);
InsertTrayIconMenuItem (iconhandle, "显示图像", &index);

SetTrayIconMenuItemAttr (iconhandle, 5, ATTR_CHECKED, 1);
SetTrayIconMenuItemAttr (iconhandle, 8, ATTR_DIMMED, 1);
}

int CVICALLBACK iconCB (int iconHandle, int event, int eventData)
{
int visible;
int top;
int left;
int panel;
int down;
int y;
int x;
static int i = 0;
switch (event)
{
case EVENT_LEFT_CLICK:
GetGlobalMouseState (&panel, &x, &y, &left, &down, NULL);
GetPanelAttribute (panelHandle, ATTR_LEFT, &left);
GetPanelAttribute (panelHandle, ATTR_TOP, &top);
RunPopupMenu (menubarhandle, MENUBAR_FILE, panelHandle, y-top, x-left, 0, 0, 0, 0);
break;
case EVENT_RIGHT_CLICK:
GetPanelAttribute (panelHandle, ATTR_VISIBLE, &visible);
if (!visible)
{
SetTrayIconMenuItemAttr (iconhandle, 8, ATTR_DIMMED, 0);
}
break;
case EVENT_MENU_ITEM:
switch (eventData)
{
case 1:
QuitUserInterface (0);
break;
case 3:
AboutMe (panelHandle);
break;
case 5:
GetTrayIconMenuItemAttr (iconhandle, 5, ATTR_CHECKED, &i);
SetTrayIconMenuItemAttr (iconhandle, 5, ATTR_CHECKED, !i);
animate (menubarhandle, MENUBAR_FILE_ANIMATE, 0, panelHandle);
break;
case 6:
soundeffect (menubarhandle, MENUBAR_FILE_SOUNDEFFECT, 0, panelHandle);
break;
case 7:
followmouse (menubarhandle, MENUBAR_FILE_FOLLOWMOUSE, 0, panelHandle);
break;
case 8:
DisplayPanel (panelHandle);
SetTrayIconMenuItemAttr (iconhandle, 8, ATTR_DIMMED, 1);
break;
}

break;
}

return 0;
}

下载信息
图片点击可在新窗口打开查看[点击浏览该文件:] | 图片点击可在新窗口打开查看[快车下载]

转自:小信的博客
网址:http://blog.sina.com.cn/u/1265070197

建议到www.cpubbs.com看看,那的资料不少,人气也挺旺的

欢迎访问我的博客
http://blog.sina.com.cn/mylabview
labview开发工具及翔实资料(正版破解)

返回列表