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

[原创]利用LabWindows/CVI制作不规则界面的演示

[原创]利用LabWindows/CVI制作不规则界面的演示

各位观客,大家好!
  这是一个利用LabWindows/CVI制作的不规则界面的播放器的例子,这个例子演示了如何获得不规则界面图形,图形的拖拽,以及个性化菜单的制作过程,其中的媒体播放功能并不是很全面,因为我已经用Windows API函数重新封装了一个全新的MP3、MID、WMA、WAV解码器,并制作成了动态链接库,所以在这里不做过多演示。
  本程序只是为了说明LabWindows/CVI的强大功能。但细心的同志很快会发现,其实在LabWindows/CVI中隐藏着数以百计的BUG,而且,有些是致命的硬伤!如果在编写程序时不去触碰它的伤处其实也是一门技巧。
  这个程序使用了邦丰公司的播放器的皮肤来创建,用来展现真正复杂界面编程的过程。其中也包含了本人程序制作过程中的一些感想,请大家分享!
  如果有观客对此感兴趣,我们可以进一步讨论!
 
  程序内容:
  1.图片的应用(重点)
  2.拖拽效果
  3.鼠标按下与抬起事件
  4.mciSendString函数的初步使用
  5.动画效果
 
  程序的界面如下:
 
 
部分代码:
#include "mci.h"
#include "animate.h"
#include "toolbox.h"
#include <cvirte.h>  
#include <userint.h>
#include "不规则面板.h"
static int menubarhandle;
static int listhandle;
static int handle;
static int panellisthandle;
static int panelHandle;
static Rect mainrect;
static Rect listrect;
struct sing {
 int min;
 int max;
 int hour;
 int minute;
 int second;
 int position;
 char timelen[20];
}singer, showtime;
static int flag = 0;
static char path[MAX_PATHNAME_LEN];
void regin (int panel, int control, HWND hwnd);
void mainposition (void);
int top (void);
void listposition (void);
void popupmenu (int panel, int control, int *left, int *top);
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, "不规则面板.uir", PANEL)) < 0)
  return -1;
 
   
 panellisthandle = LoadPanel (0, "不规则面板.uir", PANEL_LIST);
 
 menubarhandle = LoadMenuBar (panelHandle, "不规则面板.uir", MENUBAR);
 
 
 AnimateCtrl_ConvertFromPictRing (panelHandle, PANEL_ANIMATION); 
 
 GetPanelAttribute (panelHandle, ATTR_SYSTEM_WINDOW_HANDLE, &handle);
 GetPanelAttribute (panellisthandle, ATTR_SYSTEM_WINDOW_HANDLE, &listhandle);     
 
 regin(panelHandle, PANEL_PICTURE, (HWND)handle);
 regin(panellisthandle, PANEL_LIST_PICTURE_LIST, (HWND)listhandle);
 
 
 SetCtrlAttribute (panelHandle, PANEL_TEXTMSG, ATTR_TEXT_BGCOLOR, VAL_TRANSPARENT);
 
 
// hin = GetWindowLong((HWND)handle, GWL_HINSTANCE); 
 
// h = GetDC((HWND)handle);
 
// hcur = LoadCursor((HINSTANCE)&hin, IDC_HELP);
 
// hcur = LoadCursorFromFile("Normal.cur");
 
// hcur = SetCursor(hcur);
 
// WindowProc((HWND)handle,
// ShowCursor(FALSE);
 
 AnimateCtrl_SetAttribute (panelHandle, PANEL_ANIMATION, ATTR_ANIMATE_FRAME_INTERVAL, 0.7);
 AnimateCtrl_SetAttribute (panelHandle, PANEL_ANIMATION, ATTR_ANIMATE_ENABLED, 0);
 
 
 SetMouseCursor (VAL_POINTING_FINGER_CURSOR);
 EnableExtendedMouseEvents (panelHandle, PANEL_PICTURE_MINIMUM, 0.2);
 EnableExtendedMouseEvents (panelHandle, PANEL_PICTURE_SHUTDOWN, 0.2);
 EnableExtendedMouseEvents (panellisthandle, PANEL_LIST_PICTURE_HIDE, 0.2);
 
 SetCtrlToolTipAttribute (panelHandle, PANEL_PICTURE_MINIMUM, CTRL_TOOLTIP_ATTR_TEXT, "最小化");
 SetCtrlToolTipAttribute (panelHandle, PANEL_PICTURE_SHUTDOWN, CTRL_TOOLTIP_ATTR_TEXT, "关闭");
 SetCtrlToolTipAttribute (panelHandle, PANEL_PICTURE_SLIDE, CTRL_TOOLTIP_ATTR_TEXT, "播放进度");
 
 DisplayPanel (panelHandle);
 RunUserInterface ();
 DiscardPanel (panelHandle);
 return 0;
}
int CVICALLBACK panelCB (int panel, int event, void *callbackData,
  int eventData1, int eventData2)
{
 int modifier;
 int character;
 int vk;
 switch (event)
 {
  case EVENT_KEYPRESS:
   vk = GetKeyPressEventVirtualKey (eventData2);
   modifier = GetKeyPressEventModifiers (eventData2);
   character = tolower(GetKeyPressEventCharacter (eventData2));
   
   
   if (vk == VAL_ESC_VKEY)
   {
    QuitUserInterface (0);
   }
   
   if ((modifier == VAL_UNDERLINE_MODIFIER)  && (character == 'f'))
   {
    openfile(panelHandle, PANEL_PICTURE_FILE, EVENT_LEFT_CLICK, 0, 0, 0);    
   }
   
   
   break;
  case EVENT_LEFT_CLICK:
   ReleaseCapture();
   SendMessage((HWND)handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
   
   if (flag == 1)
   {
    SetCtrlAttribute (panelHandle, PANEL_TIMER, ATTR_ENABLED, 1);
   }
   else
   {
    SetCtrlAttribute (panelHandle, PANEL_TIMER, ATTR_ENABLED, 0);      
   }
   
   break;
  case EVENT_RIGHT_CLICK:
   
   mainposition();
   
   SetPanelAttribute (panellisthandle, ATTR_LEFT, mainrect.left);
   SetPanelAttribute (panellisthandle, ATTR_TOP, top());
   
   DisplayPanel (panellisthandle);
   
   flag = 1;
   
   break;
  case EVENT_LOST_FOCUS:
   SetCtrlAttribute (panelHandle, PANEL_TIMER, ATTR_ENABLED, 0);
   break;
 }
 return 0;
}
int CVICALLBACK timer (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
 {
  case EVENT_TIMER_TICK:
   mainposition();
   
   SetPanelAttribute (panellisthandle, ATTR_LEFT, mainrect.left);
   SetPanelAttribute (panellisthandle, ATTR_TOP, top()); 
   break;
 }
 return 0;
}
int CVICALLBACK minimum (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 static int i = 0;
 switch (event)
 {
  case EVENT_LEFT_CLICK:
   DisplayImageFile (panelHandle, PANEL_PICTURE_MINIMUM, "minimum1.bmp");
   i = 1;
   break;
  case EVENT_LEFT_MOUSE_UP:
   if (i == 1)
   {
    SetPanelAttribute (panelHandle, ATTR_WINDOW_ZOOM, VAL_MINIMIZE);
    SetPanelAttribute (panellisthandle, ATTR_WINDOW_ZOOM, VAL_MINIMIZE);
    DisplayImageFile (panelHandle, PANEL_PICTURE_MINIMUM, "minimum.bmp");
    i = 0;
   }
   break;
 }
 return 0;
}
int CVICALLBACK shutdown (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 static int i = 0;
 switch (event)
 {
  case EVENT_LEFT_CLICK:
   DisplayImageFile (panelHandle, PANEL_PICTURE_SHUTDOWN, "shutdown1.bmp");
   i = 1;
   break;
  case EVENT_LEFT_MOUSE_UP:
   if (i == 1)
   {
    QuitUserInterface (0);   
   }
   break;
 }
 return 0;
}
转自:小信的博客
网址:http://blog.sina.com.cn/u/1265070197
如果需要源程序,请在博客上留言!
wo xiang yao
返回列表