//###############################################################################################################
//Main.cpp
//Designed by xqh
//Date:2009--12--28
//#include <pwinuser.h>
#include <XamlRuntime.h>
#include <XRDelegate.h>
#include <XRPtr.h>
#include <Ehm.h>
//=================================================================================================================
IXRApplication* pApplication = NulL;
IXRVisualHost* pVisualHost = NulL;
class BtnEventHandler //单独响应按钮 *** 作
{
public:
//button使用示范
HRESulT Btn_OnClick(IXRDependencyObject* source,XRMousebuttonEventArgs* args)
{
#if 1
// MessageBox(NulL,TEXT("Btn_OnClick!"),TEXT("Silverlight for windows Embedded test"),MB_OK);
RETAILMSG(1,(TEXT("++++BtnEventHandler( )----Btn_OnClick!/r/n")));
#else
UINT exitCode=0;
// pApplication->StopProcessing(exitCode);
pVisualHost->EndDialog(0);
#endif
return S_OK;
}
//ComboBox使用示范
HRESulT ComboBox_SelChange(IXRDependencyObject* source,XRSelectionChangedEventArgs* args)
{
//MessageBox(NulL,TEXT("ComboBox_SelChange!"),MB_OK);
RETAILMSG(1,(TEXT("++++BtnEventHandler( )----ComboBox_SelChange!/r/n")));
return S_OK;
}
//ListBox使用示范
HRESulT ListBox_SelChange(IXRDependencyObject* source,TEXT("ListBox_SelChange!"),MB_OK);
RETAILMSG(1,(TEXT("++++BtnEventHandler( )----ListBox_SelChange!/r/n")));
return S_OK;
}
//CheckBox使用示范
HRESulT CheckBox_Check(IXRDependencyObject* source,XRRoutedEventArgs* args)
{
MessageBox(NulL,TEXT("CheckBox_Check!"),MB_OK);
return S_OK;
}
//Radiobutton使用示范
HRESulT RadioBtn_Check(IXRDependencyObject* source,TEXT("RadioBtn_Check!"),MB_OK);
return S_OK;
}
//Progressbar使用示范
/*
HRESulT Prgbar_Change(IXRDependencyObject* source,XRValueChangedEventArgs* args)
{
MessageBox(NulL,TEXT("Prgbar_Change!"),MB_OK);
return S_OK;
}
*/
//TextBox使用示范
HRESulT TextBox_SelChange(IXRDependencyObject* source,TEXT("TextBox_SelChange!"),(TEXT("++++BtnEventHandler( )----TextBox_SelChange!/r/n")));
return S_OK;
}
HRESulT TextBox_TextChange(IXRDependencyObject* source,XRTextChangedEventArgs* args)
{
//MessageBox(NulL,TEXT("TextBox_TextChange!"),(TEXT("++++BtnEventHandler( )----TextBox_TextChange!/r/n")));
return S_OK;
}
//SlIDer使用示范
/*
HRESulT SlIDer_Change(IXRDependencyObject* source,TEXT("SlIDer_Change!"),MB_OK);
return S_OK;
}
*/
//Scrollbar使用示范
/*
HRESulT ScrollbarVr_Change(IXRDependencyObject* source,TEXT("ScrollbarVr_Change!"),MB_OK);
return S_OK;
}
*/
/*
HRESulT ScrollbarHr_Change(IXRDependencyObject* source,TEXT("ScrollbarHr_Change!"),MB_OK);
return S_OK;
}
*/
//PasswordBox使用示范
HRESulT Password_Change(IXRDependencyObject* source,XRRoutedEventArgs* args)
{
//MessageBox(NulL,TEXT("Password_Change!"),(TEXT("++++BtnEventHandler( )----Password_Change!/r/n")));
return S_OK;
}
};
//###################################################################################################################
INT WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdline,
int nCmdshow
)
{
int exitCode = -1;
BOol bRet;
HRESulT hr;
bRet= XamlRuntimeInitialize();
GetXRApplicationInstance(&pApplication);
XRXamlSource SourceXaml;
SourceXaml.Setfile(L"//Storage Card//XAMLPERF//Page_Control.xaml");
//###############################################################
XRWindowCreateParams WindowParameters;
ZeroMemory(&WindowParameters,sizeof(WindowParameters));
WindowParameters.Style = WS_POPUP;
WindowParameters.pTitle = L"Title name";
WindowParameters.left = 0;
WindowParameters.top = 0;
//################################################################
//IXRVisualHost* pVisualHost = NulL;
pApplication->CreateHostFromXaml(&SourceXaml,&WindowParameters,&pVisualHost);
if(!pVisualHost)
RETAILMSG(1,(TEXT("++++the pVisualHost is NulL!/r/n")));
//################################################################
//找到根目录
IXRFrameworkElementPtr root;
if (Failed(hr=pVisualHost->GetRootElement(&root)))
return -1;
//--------------------------------------------------------------
IXRStylusInfoPtr StylusInfo;
pApplication->CreateObject(IID_IXRStylusInfo,&StylusInfo);
bool bStylusstatus;
StylusInfo->GetIsInverted(&bStylusstatus);
if(bStylusstatus)
RETAILMSG(1,(TEXT("++++the bStylusstatus is true!/r/n")));
else
RETAILMSG(1,(TEXT("++++the bStylusstatus is false!/r/n")));
StylusInfo->SetIsInverted(true);
StylusInfo->GetIsInverted(&bStylusstatus);
if(bStylusstatus)
RETAILMSG(1,(TEXT("++++the bStylusstatus is false!/r/n")));
//################################################################
//button使用示范
IXRbuttonBasePtr btn;
if (Failed(hr=root->Findname(TEXT("DVD"),&btn)))
return -1;
BtnEventHandler handlerBtn;
IXRDelegate<XRMousebuttonEventArgs>* clickdelegateBtn;
if (Failed(hr=CreateDelegate(&handlerBtn,&BtnEventHandler::Btn_OnClick,&clickdelegateBtn)))
return -1;
if (Failed(hr=btn->AddClickEventHandler(clickdelegateBtn))) //注册交互事件
return -1;
//##########################################################################################################333
//ComboBox使用示范
IXRComboBoxPtr ComBox;
//IXRComboBoxItem
IXRComboBoxItemPtr ComBoxItem=NulL,ComBoxItemT=NulL;
XRValue XValueComBox,XValueComBoxT;
if (Failed(hr=root->Findname(TEXT("ComBox"),&ComBox)))
return -1;
//XValueComBox.vType=VTYPE_BSTR;
//XValueComBox.bstrStringVal=L"熊清华";
XValueComBox.vType=VTYPE_Readonly_STRING;
XValueComBox.pReadonlyStringVal=L"XQH";
if(ComBoxItem==NulL)
RETAILMSG(1,(TEXT("++++the ComBoxItem is NulL!/r/n")));//2009--12--29 XQH 是一个空指针!!!
pApplication->CreateObject(IID_IXRComboBoxItem,&ComBoxItem);
hr=ComBoxItem->SetContent(&XValueComBox);
DWORD DWError;
DWError=GetLastError( );
int *pIndex=NulL;
IXRItemCollection* ppItems;
ComBox->GetItems(&ppItems);
//ppItems->Add((IXRDependencyObject*)ComBoxItem,pIndex);
ppItems->Insert(0,(IXRDependencyObject*)ComBoxItem);
//------------------------------------------------------------
pApplication->CreateObject(IID_IXRComboBoxItem,&ComBoxItemT);
//XValueComBoxT.SetNull();
XValueComBoxT.vType=VTYPE_Readonly_STRING;
XValueComBoxT.pReadonlyStringVal=L"WXY";
hr=ComBoxItemT->SetContent(&XValueComBoxT);
//ppItems->Add((IXRDependencyObject*)ComBoxItem,pIndex);
ppItems->Insert(1,(IXRDependencyObject*)ComBoxItemT);
//=================================================================
ComBox->SetSelectedindex(0);
//ComBox->SetSelectedItem(ComBoxItem);
BtnEventHandler handlerComboBox;
IXRDelegate<XRSelectionChangedEventArgs>* clickdelegateComBox;
if (Failed(hr=CreateDelegate(&handlerComboBox,&BtnEventHandler::ComboBox_SelChange,&clickdelegateComBox)))
return -1;
//if (Failed(hr=ComBox->AddSelectionChangedHandler(clickdelegateComBox))) //注册交互事件
// return -1;
ComBox->AddSelectionChangedEventHandler(clickdelegateComBox);
//##########################################################################################################333
//ListBox使用示范
IXRListBoxPtr ListBox;
IXRListBoxItemPtr ListBoxItem=NulL,ListBoxItemT=NulL;
XRValue XValueListBox,XValueListBoxT;
if (Failed(hr=root->Findname(TEXT("ListBox"),&ListBox)))
return -1;
XValueListBox.vType=VTYPE_Readonly_STRING;
XValueListBox.pReadonlyStringVal=L"XQH";
if(ListBoxItem==NulL)
RETAILMSG(1,(TEXT("++++the ListBoxItem is NulL!/r/n")));//2009--12--29 XQH 是一个空指针!!!
pApplication->CreateObject(IID_IXRListBoxItem,&ListBoxItem);
hr=ListBoxItem->SetContent(&XValueListBox);
int *pIndexList=NulL;
IXRItemCollection* ppItemsList;
ListBox->GetItems(&ppItemsList);
//ppItemsList->Add((IXRDependencyObject*)ListBoxItem,pIndexList);
ppItemsList->Insert(0,(IXRDependencyObject*)ListBoxItem);
//------------------------------------------------------------
pApplication->CreateObject(IID_IXRListBoxItem,&ListBoxItemT);
//XValueListBoxT.SetNull();
XValueListBoxT.vType=VTYPE_Readonly_STRING;
XValueListBoxT.pReadonlyStringVal=L"WXY";
hr=ListBoxItemT->SetContent(&XValueListBoxT);
//ppItemsList->Add((IXRDependencyObject*)ListBoxItemT,pIndexList);
ppItemsList->Insert(1,(IXRDependencyObject*)ListBoxItemT);
//=================================================================
ListBox->SetSelectedindex(0);
//ListBox->SetSelectedItem(ListBoxItem);
BtnEventHandler handlerListBox;
IXRDelegate<XRSelectionChangedEventArgs>* clickdelegateListBox;
if (Failed(hr=CreateDelegate(&handlerListBox,&BtnEventHandler::ListBox_SelChange,&clickdelegateListBox)))
return -1;
//if (Failed(hr=ListBox->AddSelectionChangedHandler(clickdelegateListBox))) //注册交互事件
// return -1;
ListBox->AddSelectionChangedEventHandler(clickdelegateListBox);
//##########################################################################################################333
//CheckBox使用示范
IXRCheckBoxPtr CheckBox;
if (Failed(hr=root->Findname(TEXT("CheckBox"),&CheckBox)))
return -1;
XRThreeState status;
CheckBox->GetIsChecked(&status);
BtnEventHandler handlerCheckBox;
IXRDelegate<XRRoutedEventArgs>* clickdelegateCheckBox;
if (Failed(hr=CreateDelegate(&handlerCheckBox,&BtnEventHandler::CheckBox_Check,&clickdelegateCheckBox)))
return -1;
if (Failed(hr=CheckBox->AddCheckedEventHandler(clickdelegateCheckBox))) //注册交互事件
return -1;
//##########################################################################################################333
//Radiobutton使用示范
IXRRadiobuttonPtr RadioBtn;
if (Failed(hr=root->Findname(TEXT("RadioBtn1"),&RadioBtn)))
return -1;
XRThreeState statusRadioBtn;
RadioBtn->GetIsChecked(&statusRadioBtn);
BtnEventHandler handlerRadioBtn;
IXRDelegate<XRRoutedEventArgs>* clickdelegateradioBtn;
if (Failed(hr=CreateDelegate(&handlerRadioBtn,&BtnEventHandler::RadioBtn_Check,&clickdelegateradioBtn)))
return -1;
if (Failed(hr=RadioBtn->AddCheckedEventHandler(clickdelegateradioBtn))) //注册交互事件
return -1;
//##########################################################################################################333
//Progressbar进度条使用示范
IXRProgressbarPtr Prgbar;
if (Failed(hr=root->Findname(TEXT("Prgbar"),&Prgbar)))
return -1;
Prgbar->SetMinimum(0);
Prgbar->SetMaximum(100);
Prgbar->SetValue(50);
/*
BtnEventHandler handlerPrgbar;
IXRDelegate<XRValueChangedEventArgs>* clickdelegatePrgbar;
if (Failed(hr=CreateDelegate(&handlerPrgbar,&BtnEventHandler::Prgbar_Check,&clickdelegatePrgbar)))
return -1;
if (Failed(hr=Prgbar->AddMaximumChangedEventHandler(clickdelegatePrgbar))) //注册交互事件
return -1;
*/
//##########################################################################################################333
//TextBox使用示范
IXRTextBoxPtr TextBox;
if (Failed(hr=root->Findname(TEXT("TextBox"),&TextBox)))
return -1;
TextBox->SetText(L"XQH");
BtnEventHandler handlerTextBox;
IXRDelegate<XRTextChangedEventArgs>* clickdelegateTextBox;
if (Failed(hr=CreateDelegate(&handlerTextBox,&BtnEventHandler::TextBox_TextChange,&clickdelegateTextBox)))
return -1;
if (Failed(hr=TextBox->AddTextChangedEventHandler(clickdelegateTextBox))) //注册交互事件
return -1;
//##########################################################################################################333
//SlIDer使用示范
IXRSlIDerPtr SlIDer;
if (Failed(hr=root->Findname(TEXT("SlIDer"),&SlIDer)))
return -1;
SlIDer->SetMinimum(0);
SlIDer->SetMaximum(100);
SlIDer->SetValue(50);
/*
BtnEventHandler handlerSlIDer;
IXRDelegate<XRValueChangedEventArgs>* clickdelegateSlIDer;
if (Failed(hr=CreateDelegate(&handlerSlIDer,&BtnEventHandler::SlIDer_Change,&clickdelegateSlIDer)))
return -1;
if (Failed(hr=SlIDer->AddValueChangedEventHandler(clickdelegateSlIDer))) //注册交互事件
return -1;
*/
//##########################################################################################################333
//Scrollbar使用示范
//垂直Scrollbar
IXRScrollbarPtr ScrollbarVr;
if (Failed(hr=root->Findname(TEXT("Scrollbar_Vr"),&ScrollbarVr)))
return -1;
ScrollbarVr->SetMinimum(0);
ScrollbarVr->SetMaximum(100);
ScrollbarVr->SetValue(50);
/*
BtnEventHandler handlerScrollbarVr;
IXRDelegate<XRValueChangedEventArgs>* clickdelegateScrollbarVr;
if (Failed(hr=CreateDelegate(&handlerScrollbarVr,&BtnEventHandler::ScrollbarVr_Change,&clickdelegateScrollbarVr)))
return -1;
if (Failed(hr=ScrollbarVr->AddValueChangedEventHandler(clickdelegateScrollbarVr))) //注册交互事件
return -1;
*/
//----------------------------------------------------------------
//水平Scrollbar
IXRScrollbarPtr ScrollbarHr;
if (Failed(hr=root->Findname(TEXT("Scrollbar_Hr"),&ScrollbarHr)))
return -1;
ScrollbarHr->SetMinimum(0);
ScrollbarHr->SetMaximum(100);
ScrollbarHr->SetValue(50);
/*
BtnEventHandler handlerScrollbarHr;
IXRDelegate<XRValueChangedEventArgs>* clickdelegateScrollbarHr;
if (Failed(hr=CreateDelegate(&handlerScrollbarHr,&BtnEventHandler::ScrollbarHr_Change,&clickdelegateScrollbarHr)))
return -1;
if (Failed(hr=ScrollbarHr->AddValueChangedEventHandler(clickdelegateScrollbarHr))) //注册交互事件
return -1;
*/
//##########################################################################################################333
//PasswordBox使用示范
IXRPasswordBoxPtr PassBox;
if (Failed(hr=root->Findname(TEXT("PassBox"),&PassBox)))
return -1;
PassBox->SetPassword(L"xqh");
BtnEventHandler handlerPassBox;
IXRDelegate<XRRoutedEventArgs>* clickdelegatePassBox;
if (Failed(hr=CreateDelegate(&handlerPassBox,&BtnEventHandler::Password_Change,&clickdelegatePassBox)))
return -1;
if (Failed(hr=PassBox->AddPasswordChangedEventHandler(clickdelegatePassBox))) //注册交互事件
return -1;
//###############################################################
pVisualHost->StartDialog(NulL);//显示对话框
UINT StartProcessCode = 0;
pApplication->StartProcessing(&StartProcessCode);
//##################################################################
clickdelegateBtn->Release();
clickdelegateComBox->Release( );
clickdelegateListBox->Release( );
clickdelegateCheckBox->Release( );
clickdelegateradioBtn->Release( );
//clickdelegatePrgbar->Release( );
clickdelegateTextBox->Release( );
//-----------------------------------
//clickdelegateSlIDer->Release( );
//clickdelegateScrollbarVr->Release( );
//clickdelegateScrollbarHr->Release( );
//------------------------------------
clickdelegatePassBox->Release( );
return exitCode;
}
//=============================================================================
//对应的Page_Control.xaml内容
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SilverlightApplication1.Page"
WIDth="640" Height="480">
<GrID x:name="LayoutRoot" Background="#FF0000FF"> <ListBox HorizontalAlignment="left" margin="120,166,154" WIDth="160" x:name="ListBox" RendertransformOrigin="0.5,0.25"/> <CheckBox Height="40" HorizontalAlignment="Right" margin="0,39,80,0" VerticalAlignment="top" WIDth="160" Content="CheckBox" x:name="CheckBox"/> <Radiobutton Height="40" HorizontalAlignment="Right" margin="0,81,0" VerticalAlignment="top" WIDth="160" Content="Com1" x:name="RadioBtn1"/> <Progressbar HorizontalAlignment="Right" margin="0,158,40,0" WIDth="280" x:name="Prgbar" VerticalAlignment="top" Height="40" Background="#FF00FF00" Foreground="#FFFF0000"/> <Radiobutton HorizontalAlignment="Right" margin="0,119,0" WIDth="160" Content="Com2" x:name="RadioBtn2" VerticalAlignment="top" Height="40"/> <button Height="32" HorizontalAlignment="left" margin="80,8,0" VerticalAlignment="top" WIDth="160" Content="DVD" x:name="DVD"/> <ComboBox Height="40" HorizontalAlignment="left" margin="80,0" VerticalAlignment="top" WIDth="160" x:name="ComBox"/> <TextBox Height="40" HorizontalAlignment="Right" margin="0,200,200" VerticalAlignment="Bottom" WIDth="120" Text="" textwrapPing="Wrap" x:name="TextBox" RendertransformOrigin="0.1,0.4"/> <SlIDer Height="40" HorizontalAlignment="Right" margin="0,100" VerticalAlignment="Bottom" WIDth="240" x:name="SlIDer"/> <Scrollbar Height="40" HorizontalAlignment="left" margin="80,80" VerticalAlignment="Bottom" WIDth="200" x:name="Scrollbar_Hr" OrIEntation="Horizontal"/> <PasswordBox Height="40" HorizontalAlignment="Right" margin="0,160,40" VerticalAlignment="Bottom" WIDth="160" x:name="PassBox"/> <TextBlock Height="40" HorizontalAlignment="Right" margin="0,200" VerticalAlignment="Bottom" WIDth="120" Text="TextBlock" textwrapPing="Wrap" x:name="TextBlock"/> <Scrollbar HorizontalAlignment="left" margin="40,160" WIDth="40" x:name="Scrollbar_Vr"/> </GrID> </UserControl>
总结以上是内存溢出为你收集整理的WINCE6.0下用SilverLight技术的基本控件使用全部内容,希望文章能够帮你解决WINCE6.0下用SilverLight技术的基本控件使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)