WinRT - learning
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
WinRT - learning
Build a WinRT Metro App to Access the Windows 8 File System
http://www.devproconnections.com/articl ... s-8-142173
WinRT GUI controls
http://msdn.microsoft.com/en-us/library ... 27716.aspx
http://www.devproconnections.com/articl ... s-8-142173
WinRT GUI controls
http://msdn.microsoft.com/en-us/library ... 27716.aspx
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
Programmatically create a control:
Code: Select all
Private Sub Button_Click_2(sender As Object, e As RoutedEventArgs)
Dim btn = New Button
btn.Width = 110
btn.Height = 50
btn.Content = "test"
sender.Parent().Children.Add(btn)
End Sub
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
MsgInfo()
Using VB
Using C++
Available from C:
Using VB
Code: Select all
Imports Windows.UI.Popups
Dim messageDialog = New MessageDialog("click")
Await messageDialog.ShowAsync()
Code: Select all
using namespace Windows::UI::Popups;
MessageDialog ^ dialog = ref new MessageDialog("Hello WinRT");
dialog->ShowAsync();
Code: Select all
extern "C" {
void MsgInfo( Platform::String ^ szMsg )
{
MessageDialog ^ dialog = ref new MessageDialog( szMsg );
dialog->ShowAsync();
}
};
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
Convert a char * to Platform::String
Code: Select all
std::wstring stows( std::string s )
{
std::wstring ws;
ws.assign( s.begin(), s.end() );
return ws;
}
std::string wstos( std::wstring ws )
{
std::string s;
s.assign( ws.begin(), ws.end() );
return s;
}
Platform::String ^ stops( std::string s )
{
return ref new Platform::String( stows( s ).c_str() );
}
std::string pstos( Platform::String ^ ps )
{
return wstos( std::wstring( ps->Data() ) );
}
Platform::String ^ atops( const char * text )
{
return stops( std::string( text ) );
}
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
void MsgInfo( char * szMsg );
Code: Select all
extern "C" {
void hb_vmInit( BOOL );
std::wstring stows( std::string s )
{
std::wstring ws;
ws.assign( s.begin(), s.end() );
return ws;
}
std::string wstos( std::wstring ws )
{
std::string s;
s.assign( ws.begin(), ws.end() );
return s;
}
Platform::String ^ stops( std::string s )
{
return ref new Platform::String( stows( s ).c_str() );
}
std::string pstos( Platform::String ^ ps )
{
return wstos( std::wstring( ps->Data() ) );
}
Platform::String ^ atops( const char * text )
{
return stops( std::string( text ) );
}
void MsgInfo( char * szMsg )
{
MessageDialog ^ dialog = ref new MessageDialog( atops( szMsg ) );
dialog->ShowAsync();
}
void HB_FUN_MAIN( void );
};
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
Platform::String to char *
this->code->Text is a Platform::String
buffer holds the char *
Enhanced version
Code: Select all
size_t i;
char buffer[ 300 ];
wcstombs_s( &i, buffer, (size_t) 300, std::wstring( this->code->Text->Data() ).data(), (size_t) 300 );
buffer holds the char *
Enhanced version
Code: Select all
unsigned long ulLen = platformString->Length() * 2;
char * buffer = ( char * ) malloc( uiLen );
size_t i;
wcstombs_s( &i, buffer, uiLen, std::wstring( platformString->Data() ).data(), uiLen );
... (use the text)
free( ( void * ) buffer );
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
Dynamically building a page:
Page ^ page = ref new Page;
Activating it:
this->Frame->Navigate( page->GetType() );
or:
Frame->Navigate( page::typeid );
Page ^ page = ref new Page;
Activating it:
this->Frame->Navigate( page->GetType() );
or:
Frame->Navigate( page::typeid );
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
Dinamically adding controls:
Code: Select all
Button ^ fivewinrt::BlankPage::AddButton( void )
{
static Button ^ btn = ref new Button;
btn->Width = 110;
btn->Height = 50;
btn->Content = "Button";
this->Grid->Children->Append( btn );
return btn;
}
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
Dinamically adding events handlers:
Code: Select all
void btn_Tapped( Object ^ sender, TappedRoutedEventArgs ^ e )
{
MsgInfo( "btn Click" );
}
Button ^ fivewinrt::BlankPage::AddButton( void )
{
static Button ^ btn = ref new Button;
btn->Width = 110;
btn->Height = 50;
btn->Content = "Button";
this->Grid->Children->Append( btn );
btn->AddHandler( TappedEvent, ref new TappedEventHandler( btn_Tapped ), false );
return btn;
}
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: WinRT - learning
What is ^ in the parameters declaration context? I never saw it in C++. Is it C++?Antonio Linares wrote:Code: Select all
void btn_Tapped( Object ^ sender, TappedRoutedEventArgs ^ e )
EMG
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
Enrico,
Though some C++ purists claim that there is no real need for CX, and all that it offers can be done using standard C++...
http://en.wikipedia.org/wiki/C%2B%2B/CXC++/CX (Component Extensions) is a language extension for C++ compilers from Microsoft that enables C++ programmers to write programs for the new Windows Runtime platform, or WinRT. It brings a set of syntax and library abstractions that interface with the COM-based WinRT programming model in a way that is natural to native C++-programmers.
Though some C++ purists claim that there is no real need for CX, and all that it offers can be done using standard C++...
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
^ is quite similar to * but it means that we are using an object with "reference counting" (it will be destroyed when it is no longer used)
http://www.charlespetzold.com/blog/2012 ... ammer.htmlThe ref new instead returns a handle, which is a reference to the object rather than the pointer itself. These references are counted so that the object can be automatically deleted when there are no longer any references to it.
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: WinRT - learning
Thank you. I think that MS still continue with its bad habit of reinventing the wheel to include some custom extension. Something like C++ smart pointers would be enough.
EMG
EMG
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
Enrico,
Yes, I agree with you. IMO MS should have used C++ only and not implement new languages and/or extensions...
We have been using the Clipper language for years and had no need for changes. Ok, some enhancements are fine, but the core of the language should remain the same unless the language is not robust enough...
Yes, I agree with you. IMO MS should have used C++ only and not implement new languages and/or extensions...
We have been using the Clipper language for years and had no need for changes. Ok, some enhancements are fine, but the core of the language should remain the same unless the language is not robust enough...
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: WinRT - learning
Compiling PRGs from VS2012:
1. Add an existing PRG to the project
2. Right click on it and select properties. Select "Custom Build tool":
3. Right click again on it and configure it this way:
4. Right click again on it and compile it, and add the resulting C file to the project too. Set no to the use of Windows runtime extensions:
Working fine
1. Add an existing PRG to the project
2. Right click on it and select properties. Select "Custom Build tool":
3. Right click again on it and configure it this way:
4. Right click again on it and compile it, and add the resulting C file to the project too. Set no to the use of Windows runtime extensions:
Working fine