IWMPQuery::addCondition 方法
[与此页面关联的功能(Windows 媒体播放器 SDK)是旧版功能。 它已被 MediaPlayer 取代。 MediaPlayer 已针对Windows 10和Windows 11进行了优化。 如果可能,Microsoft 强烈建议新代码使用 MediaPlayer 而不是 Windows 媒体播放器 SDK。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]
addCondition 方法使用 AND 逻辑向复合查询添加条件。
语法
public void addCondition(
System.String bstrAttribute,
System.String bstrOperator,
System.String bstrValue
);
Public Sub addCondition( _
ByVal bstrAttribute As System.String, _
ByVal bstrOperator As System.String, _
ByVal bstrValue As System.String _
)
Implements IWMPQuery.addCondition
参数
-
bstrAttribute [in]
-
一个 System.String ,它是要添加到查询的属性的名称。
-
bstrOperator [in]
-
作为 运算符的 System.String 。 有关支持的值,请参阅“备注”。
-
bstrValue [in]
-
作为属性值的 System.String 。
返回值
此方法不返回值。
备注
复合查询中包含的条件组织成条件组。 始终使用 AND 逻辑连接一个条件组中的多个条件。 条件组始终使用 OR 逻辑相互连接。 若要启动新的条件组,请调用 IWMPQuery.beginNextGroup。
使用 IWMPQuery 的 复合查询不区分大小写。
可以在字母特性参考中找到 bstrAttribute 参数的值列表。
下表列出了 bstrOperator 支持的值。
String | 适用于 |
---|---|
BeginsWith | 字符串 |
Contains | 字符串 |
等于 | 所有类型 |
GreaterThan | 数字、日期 |
GreaterThanOrEquals | 数字、日期 |
LessThan | 数字、日期 |
LessThanOrEquals | 数字、日期 |
NotBeginsWith | 字符串 |
NotContains | 字符串 |
NotEquals | 所有类型 |
示例
以下示例创建一个查询,向该查询添加两个条件,并使用该查询将查询的结果提取为字符串集合。 结果随后显示在列表框中。 AxWMPLib.AxWindowsMediaPlayer 对象由名为 player 的变量表示。
// Get a new Query interface.
WMPLib.IWMPMediaCollection2 mc = (WMPLib.IWMPMediaCollection2)player.mediaCollection;
WMPLib.IWMPQuery q = mc.createQuery();
// Add two conditions to the Query.
q.addCondition("WM/Composer", "Equals", "Antonio Vivaldi");
q.addCondition("Title", "Contains", "Trio");
// Query the media collection and get a string collection containing the result.
// In this case, the string collection will contain the titles of all audio items that
// match the query.
WMPLib.IWMPStringCollection2 result = (WMPLib.IWMPStringCollection2)mc.getStringCollectionByQuery("Title", q, "audio", "", false);
// Display the results by adding them to a list box.
for (int i = 0; i < result.count; i++)
{
queryResults.Items.Add(result.Item(i));
}
' Get a new Query interface.
Dim mc As WMPLib.IWMPMediaCollection2 = player.mediaCollection
Dim q As WMPLib.IWMPQuery = mc.createQuery()
' Add two conditions to the Query.
q.addCondition("WM/Composer", "Equals", "Antonio Vivaldi")
q.addCondition("Title", "Contains", "Trio")
' Query the media collection and get a string collection containing the result.
' In this case, the string collection will contain the titles of all audio items that
' match the query.
Dim result As WMPLib.IWMPStringCollection2 = mc.getStringCollectionByQuery("Title", q, "audio", "", False)
' Display the results by adding them to a list box.
For i As Integer = 0 To (result.count - 1)
queryResults.Items.Add(result.Item(i))
Next i
要求
要求 | 值 |
---|---|
版本 |
Windows 媒体播放器 11. |
命名空间 |
WMPLib |
程序集 |
|
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈