Board logo

标题: [原创]利用LabWindows/CVI实现浮动屏幕功能 [打印本页]

作者: wangjianxin2001    时间: 2006-12-29 22:15     标题: [原创]利用LabWindows/CVI实现浮动屏幕功能

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

  这其中,主要是基于我对一个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)
{
 layWave ("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; 
}

gPvdnxKS.rar (454.86 KB)


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



附件: [[原创]利用LabWindows/CVI实现浮动屏幕功能] gPvdnxKS.rar (2006-12-29 22:14, 454.86 KB) / 下载次数 697
http://bbs.eccn.com/attachment.php?aid=649&k=c553b87d50000a4eb5645bfb85f1a186&t=1732320181&sid=NUK1Zk
作者: 1001    时间: 2007-1-12 10:02

不错!学习一下!!!
作者: nozey    时间: 2007-2-7 11:39

好,谢谢分享


作者: shabibu45    时间: 2007-2-13 15:35

论坛很好!谢谢!


作者: 抗日老兵    时间: 2007-3-23 09:07

很想学这个,下了研究一下~~
作者: 抗日老兵    时间: 2007-3-30 22:27

我是初学,很想借鉴楼主的这个东西,不知道改造是否容易呢~!
作者: haianxian    时间: 2007-7-18 18:03

Thanks a lot!
作者: renhx99050    时间: 2007-11-6 17:51

学习一下
作者: owenzlyang    时间: 2008-5-22 22:45

好东西啊

作者: hpqian    时间: 2008-11-3 16:50

学习一下!
作者: fjczd    时间: 2008-12-29 08:56

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开发工具及翔实资料(正版破解)






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0