how to output filename in win Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

how to output filename in win

Post by RobertHK » Sat Jul 08, 2017 9:41 am

Hello everyone. Finally, my program (* .exe) will output the output file (* .fbmr). I double-click the output file icon but (badly) open the empty program. Example: wxFormBuilder is a (very good) program. Project is an output file (* .fbp). I, as a user, click on the project icon and open the file. All data will be loaded. Not me. An empty output file opens even if you double-click the icon for example a1.fbmr. What returns to a1.fbmr and how do I open it when I double-click the a1.fbmr icon?

User avatar
doublemax
Moderator
Moderator
Posts: 14098
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: how to output filename in win

Post by doublemax » Sat Jul 08, 2017 11:00 am

The full path of the file you clicked on will be passed as parameter to your application. Use argc/argv to get it.

This also happens when the user drags one or more files onto the exe itself (or a link to it), in which case you could receive multiple files.
Use the source, Luke!

RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: how to output filename in win

Post by RobertHK » Sat Jul 08, 2017 11:27 am

Hello, Doublemax. Thank you very much for your answer. Can I ask for some instructions (example)? I'm worried about the different options, and my head is getting around. I'm trying different things, and nothing makes sense to me. I wanted to paste the vector m_filesFromCmdLine into MyApp :: OnInit () and initialize the file to start. The more I think about it, the more frustrating - if I do not know how to do it. #-o :(

User avatar
doublemax
Moderator
Moderator
Posts: 14098
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: how to output filename in win

Post by doublemax » Sat Jul 08, 2017 12:49 pm

Put this code into your OnInit() method and you should see what happens:

Code: Select all

    if( argc > 1 )
    {
      for(int i=1; i<argc; i++)
      {
          wxLogMessage("arg %d = %s", i, argv[i] );
      }
    }
Use the source, Luke!

RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: how to output filename in win

Post by RobertHK » Sat Jul 08, 2017 2:23 pm

Doublemax, hi. Message is: arg 1 = D:\A1.FBMR. This is OK, it's true. :) And how do I load the current A1 file into my program?

User avatar
doublemax
Moderator
Moderator
Posts: 14098
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: how to output filename in win

Post by doublemax » Sat Jul 08, 2017 2:50 pm

You must have a function to load a file somewhere in your program? Just take that filename and load it.
Use the source, Luke!

RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: how to output filename in win

Post by RobertHK » Sat Jul 08, 2017 3:03 pm

When I run the program, apriory it's empty. Then I will run "NewFile or OpenFile ... When I wanted to run OnOpenFile (event) from myApp :: OnInit (), I got an error message that 'event' was not declared in this scope ... #-o

RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: how to output filename in win

Post by RobertHK » Sat Jul 08, 2017 3:06 pm

So I wanted to find a procedure that opens a file from MyApp :: OnInit () but did not find

User avatar
doublemax
Moderator
Moderator
Posts: 14098
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: how to output filename in win

Post by doublemax » Sat Jul 08, 2017 3:58 pm

You have to refactor your code so that you can call the function that loads a file from different places.

E.g. you have a method MyFrame::LoadFile( wxString pathname ) that actually loads the file. And you call this method from OnOpenFile() and from MyApp::OnInit()
Use the source, Luke!

RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: how to output filename in win

Post by RobertHK » Sun Jul 09, 2017 6:28 am

It works, thanks very much. :D

Post Reply