FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index Utilities / Utilidades WinRT - learning
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
WinRT - learning
Posted: Sat Sep 29, 2012 04:41 AM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: Sat Sep 29, 2012 05:22 AM
Programmatically create a control:

Code (fw): Select all Collapse
    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


regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: Sat Sep 29, 2012 08:54 PM
MsgInfo()

Using VB
Code (fw): Select all Collapse
Imports Windows.UI.Popups

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


Using C++
Code (fw): Select all Collapse
   using namespace Windows::UI::Popups;

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


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

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: Sun Sep 30, 2012 10:25 AM
Convert a char * to Platform::String

Code (fw): Select all Collapse
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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: Sun Sep 30, 2012 10:30 AM
void MsgInfo( char * szMsg );

Code (fw): Select all Collapse
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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: Sun Sep 30, 2012 06:39 PM
Platform::String to char *

Code (fw): Select all Collapse
    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 (fw): Select all Collapse
    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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: 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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: Tue Oct 09, 2012 04:01 PM
Dinamically adding controls:

Code (fw): Select all Collapse
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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: Tue Oct 09, 2012 04:20 PM
Dinamically adding events handlers:

Code (fw): Select all Collapse
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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: WinRT - learning
Posted: Tue Oct 09, 2012 06:05 PM
Antonio Linares wrote:
Code (fw): Select all Collapse
void btn_Tapped( Object ^ sender, TappedRoutedEventArgs ^ e )


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

EMG
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: 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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: 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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: WinRT - learning
Posted: 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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: 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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: WinRT - learning
Posted: Wed Oct 10, 2012 09:53 PM
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 :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion