WinRT - learning

WinRT - learning

Postby Antonio Linares » Sat Sep 29, 2012 4:41 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Antonio Linares » Sat Sep 29, 2012 5:22 am

Programmatically create a control:

Code: Select all  Expand view  RUN
   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


Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Antonio Linares » Sat Sep 29, 2012 8:54 pm

MsgInfo()

Using VB
Code: Select all  Expand view  RUN
Imports Windows.UI.Popups

        Dim messageDialog = New MessageDialog("click")
        Await messageDialog.ShowAsync()
 


Using C++
Code: Select all  Expand view  RUN
  using namespace Windows::UI::Popups;

MessageDialog ^ dialog = ref new MessageDialog("Hello WinRT");
       
   dialog->ShowAsync();  
 


Available from C:
Code: Select all  Expand view  RUN
extern "C" {
void MsgInfo( Platform::String ^ szMsg  )
{
    MessageDialog ^ dialog = ref new MessageDialog( szMsg );
       
    dialog->ShowAsync();  
}
};
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Antonio Linares » Sun Sep 30, 2012 10:25 am

Convert a char * to Platform::String

Code: Select all  Expand view  RUN
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 ) );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Antonio Linares » Sun Sep 30, 2012 10:30 am

void MsgInfo( char * szMsg );

Code: Select all  Expand view  RUN
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 );

};
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Antonio Linares » Sun Sep 30, 2012 6:39 pm

Platform::String to char *

Code: Select all  Expand view  RUN
    size_t i;
    char buffer[ 300 ];

    wcstombs_s( &i, buffer, (size_t) 300, std::wstring( this->code->Text->Data() ).data(), (size_t) 300 );
 


this->code->Text is a Platform::String
buffer holds the char *

Enhanced version
Code: Select all  Expand view  RUN

    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 );
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Antonio Linares » Wed Oct 03, 2012 10:41 am

Dynamically building a page:

Page ^ page = ref new Page;

Activating it:

this->Frame->Navigate( page->GetType() );

or:

Frame->Navigate( page::typeid );
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Antonio Linares » Tue Oct 09, 2012 4:01 pm

Dinamically adding controls:

Code: Select all  Expand view  RUN
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;
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Antonio Linares » Tue Oct 09, 2012 4:20 pm

Dinamically adding events handlers:

Code: Select all  Expand view  RUN
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;
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Enrico Maria Giordano » Tue Oct 09, 2012 6:05 pm

Antonio Linares wrote:
Code: Select all  Expand view  RUN
void btn_Tapped( Object ^ sender, TappedRoutedEventArgs ^ e )


What is ^ in the parameters declaration context? I never saw it in C++. Is it C++?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: WinRT - learning

Postby Antonio Linares » Wed Oct 10, 2012 10:02 am

Enrico,

C++/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.


http://en.wikipedia.org/wiki/C%2B%2B/CX

Though some C++ purists claim that there is no real need for CX, and all that it offers can be done using standard C++...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Antonio Linares » Wed Oct 10, 2012 10:06 am

^ 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)

The 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.


http://www.charlespetzold.com/blog/2012/05/Programming-Windows-6th-Edition-for-the-CPlusPlus-Programmer.html
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Enrico Maria Giordano » Wed Oct 10, 2012 10:24 am

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
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: WinRT - learning

Postby Antonio Linares » Wed Oct 10, 2012 10:46 am

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...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: WinRT - learning

Postby Antonio Linares » Wed Oct 10, 2012 9:53 pm

Compiling PRGs from VS2012:

1. Add an existing PRG to the project

Image

2. Right click on it and select properties. Select "Custom Build tool":

Image

3. Right click again on it and configure it this way:

Image

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:

Image

Working fine :-)
Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to Utilities / Utilidades

Who is online

Users browsing this forum: No registered users and 4 guests