写个概要吧
1.用blend 3 画个界面(blend 2也行,但不好),可以在pc上运行获得想要的界面后,将生成的.xaml文件copy 到你的工作目录
2.下载XAML2CPP.exe 1.02版本的,执行 XAML2CPP.exe xaml文件名 生成class模板和你的xaml中定义class的头文件,定义class
例:
/*
This file has been generated by XAML2CPP tool version 1.0.2.0.
Modifications to this source code may be overwritten without warning when the XAML2CPP tool is executed.
XAML2CPP (c) 2009 by Valter Minute ([email protected])
This code is provided as is and it's generated automatically. It's up to the developer to check that it works as expected.
*/
#pragma warning(disable : 4996)
#ifndef Page_TEMPLATE_HEADER_FILE_H
#define Page_TEMPLATE_HEADER_FILE_H
#include "windows.h"
#include "pwinuser.h"
#include "xamlruntime.h"
#include "XRCustomControl.h"
#include "xrdelegate.h"
#include "xrptr.h"
#include "XAML2CPPBase.h"
#include "XAML2CPP_res.h"
//#include <atlstr.h>
/*
class generated by XAML2CPP from ./Page.xaml
*/
template <class X,class B=XAML2CPPPage>
class TPage : public B
{
public:
TPage(TCHAR* title=TEXT("Page"),TCHAR* xamlid=IDR_XAML_Page) : B(title,xamlid)
{
}
protected:
// XAML defined objects (declared as smart pointers)
IXRGridPtr LayoutRoot;
IXRCanvasPtr MenuButton[10];
IXRRectanglePtr MenuButtonImage[10];
protected:
// binds objects smart pointers to objects created by the runtime
virtual HRESULT Bindobjects()
{
HRESULT retcode=S_OK;
char buttonName[17];
TCHAR lpszFile[34];
if (Failed(retcode=root->FindName(L"LayoutRoot",&LayoutRoot)))
return retcode;
for(int i=0;i<10;i++)
{
sprintf(buttonName,"Button%d",i);
int nLen = strlen(buttonName) + 1;
int nwLen = MultiBytetoWideChar(CP_ACP, 0, buttonName, nLen, NULL, 0);
MultiBytetoWideChar(CP_ACP, lpszFile, nwLen);
//if (Failed(retcode=root->FindName(L"Button0",&MenuButton[0])))
if (Failed(retcode=root->FindName(lpszFile,&MenuButton[i])))
return retcode;
}
for(int i=0;i<10;i++)
{
sprintf(buttonName,"ButtonPushImage%d", nwLen);
/*if (Failed(retcode=root->FindName(L"ButtonPushImage0",&MenuButtonImage[0]))) */
if (Failed(retcode=root->FindName(lpszFile,&MenuButtonImage[i])))
return retcode;
}
return retcode;
}
// binds event handlers to template class member functions
// should be called after Bindobjects
virtual HRESULT BindEventHandlers()
{
HRESULT retcode;
IXRDelegate<XRMouseButtonEventArgs>* OnClickDelegate[10];
for(int i=0;i<10;i++)
{
retcode=CreateDelegate<X,XRMouseButtonEventArgs>((X*)this,&X::OnClick,&OnClickDelegate[i]);
if (Failed(retcode))
return retcode;
if (Failed(retcode=MenuButton[i]->AddMouseLeftButtonDownEventHandler(OnClickDelegate[i])))
return retcode;
}
IXRDelegate<XRMouseButtonEventArgs>* OffClickDelegate[10];
for(int i=0;i<10;i++)
{
retcode=CreateDelegate<X,&X::OffClick,&OffClickDelegate[i]);
if (Failed(retcode))
return retcode;
if (Failed(retcode=MenuButton[i]->AddMouseLeftButtonUpEventHandler(OffClickDelegate[i])))
return retcode;
}
return retcode;
}
};
// Base class for user control
template <class A,class B>
class PageUserControlRegister : public XRCustomUserControlImpl<A,B>,public TPage<A,XAML2CPPUserControl>
{
protected:
static HINSTANCE hInstance;
public:
static HRESULT GetXamlSource(XRXamlSource* pXamlSource)
{
pXamlSource->SetResource(hInstance,TEXT("XAML"),IDR_XAML_Page);
return S_OK;
}
static HRESULT Register()
{
return XRCustomUserControlImpl<A,B>::Register(__uuidof(B),L"Page",L"clr-namespace:PageNamespace");
}
static HRESULT RegisterUserControl(HINSTANCE hInstance)
{
PageUserControlRegister::hInstance=hInstance;
return PageUserControlRegister<A,B>::Register();
}
virtual HRESULT OnLoaded(__in IXRDependencyObject* pRoot)
{
HRESULT retcode;
IXRApplicationPtr app;
if (Failed(retcode=GetXRApplicationInstance(&app)))
return retcode;
return ((A*)this)->Init(pRoot,hInstance,app);
}
};
#endif //Page_TEMPLATE_HEADER_FILE_H
================================================================
Vtalk_MAIN.cpp
class VTalkPage : public TPage<VTalkPage>
{
private:
IXRBitmapImagePtr img01;
IXRBitmapImagePtr img02;
CMp3WaveIn *mp3_pIn;
CMyWaveIn *m_pIn;
csoundBase *mySound_pIn;
CMp3Decthread *m_test;
public:
VTalkPage()
{
// Todo: Add extra initialization here
mySound_pIn = csoundBase::GetInstance();
}
virtual HRESULT Init(HINSTANCE hinstance,IXRApplication* app)
{
HRESULT retcode;
if (Failed(retcode=TPage<VTalkPage>::Init(hinstance,app)))
return retcode;
if (Failed(retcode=app->CreateObject(IID_IXRBitmapImage,&img01)))
return retcode;
if (Failed(retcode=app->CreateObject(IID_IXRBitmapImage,&img02)))
return retcode;
if (Failed(retcode=img01->SetUriSource(TEXT("//NandFlash//按下白底.png"))))
return retcode;
if (Failed(retcode=img02->SetUriSource(TEXT("//NandFlash//img02.jpg"))))
return retcode;
return S_OK;
}
HRESULT OnClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)
{
HRESULT retcode;
int i;
IXRImageBrushPtr pMyBlueBrush;
IXRCanvasPtr pTmpCanvas;
IXRApplicationPtr app;
if (Failed(retcode=GetXRApplicationInstance(&app)))
return retcode;
if (Failed(retcode=app->CreateObject(IID_IXRImageBrush,&pMyBlueBrush)))
return retcode;
pMyBlueBrush->SetimageSource(img01);
pTmpCanvas = (IXRCanvasPtr)source;
for(i=0;i<10;i++)
{
if(pTmpCanvas==MenuButton[i])
{
MenuButtonImage[i]->SetFill(pMyBlueBrush);
break;
}
}
if(pTmpCanvas==MenuButton[0])//通话-开录音
{
m_pIn = new CMyWaveIn();
if (!m_pIn->StartRec ())
{
}
}
else if(pTmpCanvas==MenuButton[1]) //监视-关录音
{
if (!m_pIn->StopRec())
{
}
delete m_pIn;
}
else if(pTmpCanvas==MenuButton[2])//信息中心-开MP3录音
{
mp3_pIn = new CMp3WaveIn();
if (!mp3_pIn->StartRec ())
{
}
}
else if(pTmpCanvas==MenuButton[3]) //安防-关MP3录音
{
if (!mp3_pIn->StopRec())
{
}
delete mp3_pIn;
}
else if(pTmpCanvas==MenuButton[5]) //浏览器-录音
{
// Todo: Add your control notification handler code here
WAVEFORMAT_SETTING waveFormat;
waveFormat.bits = BITS_16;
waveFormat.channel = CHANNEL_SINGLE;
waveFormat.samples = SAMPLES_32000;//SAMPLES_44100;//
if(mySound_pIn->Record(TEXT("//nandflash//waveTest.wav"),&waveFormat) == FALSE)
{
}
}
else if(pTmpCanvas==MenuButton[6]) //数码相框-关录音
{
// Todo: Add your control notification handler code here
mySound_pIn->StopAll();
delete mySound_pIn;
}
else if(pTmpCanvas==MenuButton[7]) //我的助理
{
m_test = new CMp3Decthread();
m_test->SetURLFile(_T("//nandflash//wave32.mp3"));
}
else if(pTmpCanvas==MenuButton[8])
{
delete m_test;
}
else if(pTmpCanvas==MenuButton[9])
{
vhost->EndDialog(0);
return S_OK;
}
pMyBlueBrush->Release();
//MessageBox(NULL,TEXT("Click!"),TEXT("Silverlight for Embedded test"),MB_OK);
return S_OK;
}
HRESULT OffClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)
{
HRESULT retcode;
IXRImageBrushPtr pMyBlueBrush;
IXRCanvasPtr pTmpCanvas;
IXRApplicationPtr app;
if (Failed(retcode=GetXRApplicationInstance(&app)))
return retcode;
if (Failed(retcode=app->CreateObject(IID_IXRImageBrush,&pMyBlueBrush)))
return retcode;
pMyBlueBrush->SetimageSource(NULL);
pTmpCanvas = (IXRCanvasPtr)source;
for(int i=0;i<10;i++)
{
if(pTmpCanvas==MenuButton[i]){
MenuButtonImage[i]->SetFill(pMyBlueBrush);
break;
}
}
pMyBlueBrush->Release();
return S_OK;
}
HRESULT ExitOnClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)
{
this->vhost->EndDialog(0);
return S_OK;
}
HRESULT PopOnClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)
{
return S_OK;
}
};
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdshow)
{
if (!XamlRuntimeInitialize())
return -1;
HRESULT retcode;
IXRApplicationPtr app;
if (Failed(retcode=GetXRApplicationInstance(&app)))
return -1;
VTalkPage vtalkPage;
if (Failed(vtalkPage.Init(hInstance,app)))
return -1;
UINT exitcode;
if (Failed(vtalkPage.GetVisualHost()->StartDialog(&exitcode)))
return -1;
return 0;
}
绑定事件等等。
以上只是一个测试程序,多有不足,见谅。
4.善用XAML2CPP.exe 生成其他的class;其他就是vc++编程序了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。