wxImage Icon for output file 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

wxImage Icon for output file

Post by RobertHK »

Hello everyone, Please, I need help. I have a program that produces an output file. I have an association of the program set up in Inno Setup and the association works. When you double-click the file icon, the program starts, but the program icons do not work - it will list the error. I know it's because I have icons in the program and the output file does not find a way to them. Into OnNewFile(wx..), OnOpenFile(wx.., OnSaveFile(wx..), I tried to give the following code:

Code: Select all

wxStandardPaths::Get().GetResourcesDir() + "/icons";

The icons in the program are in the MyFrame constructor, using the following statement:

Code: Select all

wxImage::AddHandler(new wxPNGHandler);
    wxImage newDB(wxT("icons/document-new-5.png"), wxBITMAP_TYPE_PNG);
...
I have the png icons in the folder: D: \ Program Files (x86) \ MyProgram \ icons.
The problem is that when I install the program I do not know where the user installs it and also where it stores the output file. Does anyone have any idea?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxImage Icon for output file

Post by PB »

You already have an answer: provide the wxImage ctor full path to the image, e.g.

Code: Select all

wxImage newDB(wxStandardPaths::Get().GetResourcesDir() + "\\icons\\document-new-5.png", wxBITMAP_TYPE_PNG);
If your program is supposed to work on OSes other than Windows, you might want to consider using wxFileName::GetPathSeparator() instead of hardcoding slashes in the string literal.

OTOH, if your program is MSW only, you may consider including the bitmaps in the resource file as is customary there and you will also save yourself troubles like these.
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: wxImage Icon for output file

Post by RobertHK »

Thanks a lot for the answer. I tried it and it does not work. MyProgram.exe itself reports errors to me :(
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: wxImage Icon for output file

Post by RobertHK »

I have WIN 10 Pro x64
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxImage Icon for output file

Post by doublemax »

That fact that you're talking about file associations confuses me a little bit. Maybe the problem is not what others thought it is.

Can you explain in more detail what you're trying to do and what doesn't work?
MyProgram.exe itself reports errors to me
What error?
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: wxImage Icon for output file

Post by RobertHK »

Hi doublemax. I want with my program (budget.exe) to create an output file (for example budget_01.fbmr). And I want to run the main program - budget.exe by double-clicking the file icon 'budget_01.fbmr'. I do this with 2 functions: 'void BaseApp :: OnInitCmdLine (wxCmdLineParser & parser)' and 'bool BaseApp :: OnCmdLineParsed (wxCmdLineParser & parser)'. Then, in InnoSetup, i write to the Windows Registry (Root: HKCR; Subkey: ....) + the output file association. But after double-clicking on the 'budget_01.fbmr' icon, the program started but could not find the icons (absolute path). It has already been solved as follows:

Code: Select all

wxImage::AddHandler(new wxPNGHandler);
wxString icons = wxStandardPaths::Get().GetResourcesDir() + wxT("/icons/");
wxImage newDB(icons + wxT("document-new-5.png"), wxBITMAP_TYPE_PNG);
...
Post Reply