控制面板添加新项目

在Windows mobile系统中,用户可以通过设置来访问控制面板的应用程序软件开发人员也可以通过Windows mobile提供的API函数来访问控制面板的一些信息,例如可以向其中增加一个控制面板的应用。


  Windows mobile中的控制面板应用程序和我之前的文章《控制面板程序编程方法》中的一样,实现为一个Dll中,但必须以cpl为后缀,它导出一个回调函数:

              LONG CPlApplet(HWND hwndCPl, UINT msg, LPARAM lParam1, LPARAM lParam2);


  在用户点击设置时,ctlpnl.exe进程会通过调用CPlApplet来发送一些消息,一个cpl可以支持多个控制面板的小程序(applets):
  hwndCPl:控制面板窗口句柄,即是小程序的父窗口。
  Msg:控制面板程序(ctlpnl.exe)向我们的应用程序发送的消息,这些消息决定了应用程序初始化、启动、停止、退出,主要包括:
  CPL_INIT、CPL_GETCOUNT、CPL_NEWINQUIRE、CPL_IDNAME、CPL_DBLCLK、CPL_STOP、CPL_EXIT。
  CPL_INIT:初始化消息,即ctlpnl.exe通知控制面板应用程序做一些全局的初始化工作,如内存分配。
  CPL_GETCOUNT:获取控制面板应用程序支持的小程序个数。
  CPL_NEWINQUIRE:查询控制面板应用程序的小程序的信息。这些信息包含在NEWCPLINFO结构中。
  CPL_IDNAME:获得控制面板应用程序的名称,通过设置下面的注册表键值可以改变应用位于控制面板属性页的位置。

  [HKEY_LOCAL_MACHINE\ControlPanel\<ID name>].
  "Group" = dword:1

  Group value     Settings tab where CPL exists 

  0                         Personal 
  1 (default value)   System 
  2                           Connections

  CPL_DBLCLK:此消息表明用户点击了控制面板应用,可以在此启动一个进程,进而完成相应的工作。
  CPL_STOP、CPL_EXIT:分别是停止和退出消息。

  下面给出一个简单的实例:

  首先建立一个Smart Device的Win32 Smart Device Project DLL工程

  加入下面的代码

// TestCPL.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include <cpl.h>
#define NUM_APPLETS        1

HINSTANCE g_hInstance  = NULL;

typedef struct tagApplets
{
  int icon;      // icon resource identifier
  int namestring;   // name-string resource identifier
  int descstring;   // description-string resource identifier
} APPLETS;

const APPLETS SystemApplets[] =
{
  APPLET_ICON, APPLET_NAME, APPLET_DESC
  // add more struct members here if supporting more than on applet
};

BOOL APIENTRY DllMain( HANDLE hModule,
          DWORD ul_reason_for_call,
          LPVOID lpReserved
          )
{
  if (DLL_PROCESS_ATTACH == ul_reason_for_call)
    g_hInstance = (HINSTANCE)hModule; 

  return TRUE;
}

BOOL InitApplet(HWND hwndParent)
{
  return TRUE;
}

void TermApplet()
{
  return;
}


// This is the entry point called by ctlpnl.exe
// 

LONG CALLBACK CPlApplet (HWND hwndCPL, UINT uMsg, LONG lParam1, LONG lParam2)
{
  int      iApplet;
  LPNEWCPLINFO lpNewCPlInfo;
  static int  iInitCount = 0; 

  switch (uMsg)
  {
    // First message sent. It is sent only once to
    // allow the dll to initialize it's applet(s)
  case CPL_INIT:
    if (!iInitCount)
    {
      if (!InitApplet(hwndCPL))
       return FALSE;
    }

    iInitCount++;
    return TRUE;

    // Second message sent. Return the count of applets supported
    // by this dll
  case CPL_GETCOUNT:
    return (LONG)NUM_APPLETS;

    // Third message sent. Sent once for each applet supported by this dll.
    // The lParam1 contains the number that indicates which applet this is
    // for, from 0 to 1 less than the count of applets.
    // lParam2 is a NEWCPLINFO that should be filled with information about
    // this applet before returning
  case CPL_NEWINQUIRE:
    lpNewCPlInfo       = (LPNEWCPLINFO)lParam2;
    iApplet           = (int)lParam1;
    lpNewCPlInfo->dwSize   = (DWORD)sizeof(NEWCPLINFO);
    lpNewCPlInfo->dwFlags    = 0;
    lpNewCPlInfo->dwHelpContext = 0;
    lpNewCPlInfo->lData     = SystemApplets[iApplet].icon;
    lpNewCPlInfo->hIcon     = LoadIcon(g_hInstance,(LPCTSTR)MAKEINTRESOURCE(SystemApplets[iApplet].icon));
    lpNewCPlInfo->szHelpFile[0] = '';
    LoadString(g_hInstance,SystemApplets[iApplet].namestring,lpNewCPlInfo->szName,32);
    LoadString(g_hInstance,SystemApplets[iApplet].descstring,lpNewCPlInfo->szInfo,64);
    break;

  case CPL_IDNAME:
    lParam1 = 100;
    _tcscpy((LPTSTR)lParam2, _T("Device Information"));
    break;

    // This is sent whenever the user clicks an icon in Settings for one of
    // the applets supported by this dll. lParam1 contains the number indicating
    // which applet. Return 0 if applet successfully launched, non-zero otherwise
  case CPL_DBLCLK:
    iApplet = (UINT)lParam1;
    //LoadDialog(g_hInstance, hwndCPL);
    CreateProcess(_T("DeviceInfo.exe"),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);

    break;
    // Sent once per applet, before CPL_EXIT
  case CPL_STOP:
    break;
    // Sent once before the dll is unloaded
  case CPL_EXIT:
    iInitCount--;
    if (!iInitCount)
      TermApplet();
    break;
  default:
    break;
  }
  return 0;
}

  资源文件
// TestCPL.rc
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/
#undef APSTUDIO_READONLY_SYMBOLS


// Chinese (P.R.C.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
  LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED

/
//
// TEXTINCLUDE
//
  1 TEXTINCLUDE
  BEGIN
      "resource.h"
  END

  2 TEXTINCLUDE
  BEGIN
      "#include ""afxres.h""rn"
      ""
  END

  3 TEXTINCLUDE
  BEGIN
      "rn"
      ""
  END

#endif  // APSTUDIO_INVOKED
/

//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.

  APPLET_ICON       ICON          "Device.ico"

/
//
// String Table
//
  STRINGTABLE
  BEGIN
      APPLET_NAME       "Device Information"
      APPLET_DESC       "Device Information"
  END

#endif  // Chinese (P.R.C.) resources
/


#ifndef APSTUDIO_INVOKED
/
//
// Generated from the TEXTINCLUDE 3 resource.
//
/
#endif  // not APSTUDIO_INVOKED

//TestCPL.def

  LIBRARY  "TestCPL"
  EXPORTS      DllMain
                        CPlApplet

  


       另外,添加注册表键值,如下:

  [HKEY_LOCAL_MACHINE\ControlPanel\Device Information].
  "Group" = dword:1

posted on 2009-07-22 20:55  yongshi123 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/yongshi123/articles/1528853.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Agilent 33220A是一款功能强大的任意波形发生器,可以用于各种测试和测量应用。下面是一个基于CVI的Agilent 33220A程序控制面板的设计步骤: 1. 首先,在CVI中创建一个项目,然后添加一个控制面板。 2. 在控制面板添加必要的控件,如按钮、文本框和滑动条等。 3. 在程序中添加Agilent 33220A的控制命令,如设置波形类型、频率、幅度等。 4. 将控件与相应的控制命令进行关联,以便在控制面板上进行操作时可以控制Agilent 33220A的参数。 5. 运行程序,测试控制面板是否能够正确地控制Agilent 33220A。 以下是一个简单的基于CVI的Agilent 33220A程序控制面板的代码示例: ``` #include <cvirte.h> #include <userint.h> #include <visa.h> static ViSession defaultRM, vi; // 定义Visa会话 int main (int argc, char *argv[]) { int panelHandle; ViChar instrDescriptor[VI_FIND_BUFLEN]; ViFindList findList; ViUInt32 numInstrs; ViStatus status; if (InitCVIRTE (0, argv, 0) == 0) return -1; /* 初始化Visa */ status = viOpenDefaultRM(&defaultRM); if (status < VI_SUCCESS) { MessagePopup("Error", "无法打开Visa资源管理器!"); return -1; } /* 查找Agilent 33220A */ status = viFindRsrc(defaultRM, "USB?*INSTR", &findList, &numInstrs, instrDescriptor); if (status < VI_SUCCESS) { MessagePopup("Error", "无法找到Agilent 33220A!"); viClose(defaultRM); return -1; } /* 打开Agilent 33220A */ status = viOpen(defaultRM, instrDescriptor, VI_NULL, VI_NULL, &vi); if (status < VI_SUCCESS) { MessagePopup("Error", "无法打开Agilent 33220A!"); viClose(defaultRM); return -1; } /* 创建控制面板 */ status = LoadPanel (0, "Agilent33220A.uir", PANEL); if (status < 0) { MessagePopup("Error", "无法创建控制面板!"); viClose(vi); viClose(defaultRM); return -1; } panelHandle = status; /* 将控件与相应的控制命令进行关联 */ SetCtrlVal(panelHandle, PANEL_WAVEFORM_TYPE, 1); SetCtrlVal(panelHandle, PANEL_FREQUENCY, 1000); SetCtrlVal(panelHandle, PANEL_AMPLITUDE, 1); SetCtrlAttribute(panelHandle, PANEL_SEND_WAVEFORM, ATTR_CALLBACK_FUNCTION_POINTER, SendWaveformCallback); SetCtrlAttribute(panelHandle, PANEL_SEND_WAVEFORM, ATTR_CTRL_VAL, (unsigned long)vi); /* 显示控制面板 */ DisplayPanel (panelHandle); RunUserInterface (); /* 关闭Agilent 33220A */ viClose(vi); viClose(defaultRM); return 0; } /* 回调函数:发送波形 */ int CVICALLBACK SendWaveformCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViSession vi = (ViSession)callbackData; ViStatus status; ViReal64 frequency, amplitude; ViInt32 waveformType; /* 获取控件值 */ GetCtrlVal(panel, PANEL_WAVEFORM_TYPE, &waveformType); GetCtrlVal(panel, PANEL_FREQUENCY, &frequency); GetCtrlVal(panel, PANEL_AMPLITUDE, &amplitude); /* 设置Agilent 33220A的参数 */ status = viPrintf(vi, "FUNC:SHAPE %d\n", waveformType); status = viPrintf(vi, "FREQ %lf\n", frequency); status = viPrintf(vi, "VOLT %lf\n", amplitude); status = viPrintf(vi, "OUTP:STAT ON\n"); if (status < VI_SUCCESS) { MessagePopup("Error", "无法发送波形!"); return -1; } return 0; } ``` 在上面的代码中,我们首先使用`viOpenDefaultRM()`函数打开Visa资源管理器,然后使用`viFindRsrc()`函数查找Agilent 33220A,最后使用`viOpen()`函数打开Agilent 33220A。然后,我们创建一个控制面板,并使用`SetCtrlAttribute()`函数将控件与相应的控制命令进行关联。在`SendWaveformCallback()`回调函数中,我们获取控件值并使用`viPrintf()`函数设置Agilent 33220A的参数,最后发送波形。在主函数的末尾,我们关闭Agilent 33220A并退出程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值