I want to set image to button:
GtkImage* imageForButton = gtk_image_new_from_resource("which path is here?");
GtkWidget* btn = gtk_button_new();
gtk_button_set_image(GTK_BUTTON(btn));
How to make it work with embedded resources?
I have resource.h/resource.rc, gonna try to use MakeIntResource, but I don't see any use of it for GTK.
GTK+ doesn't support Windows resources (at least as far as I can tell). Instead, it uses its own cross-platform resource format, GResource. The easiest way to get embedded resources working is to use this. It isn't compatible with Windows resource editors, and requires generating an extra C source file, but it should work fine so long as you use GLib or GTK+. You should have the GResource compiler as part of your GTK+ install (but I'm not 100% sure). And if you go this route, you'll be able to keep using PNG files. (I don't know how to use PNG files with Windows resources, if that even is possible.)
If you insist on using Windows resources, though, I can think of one possible way to do this, though this isn't the only one: use the Windows API resource functions to load an HBITMAP from your resource, call GetObject() to get the BITMAP structure from the HBITMAP, and then calling gdk_pixbuf_new_from_data() with the appropriate fields from the BITMAP structure as parameters (rowstride == BITMAP.bmWidthBytes). Good luck!
Related
I’m working with an application for both Windows desktop and Windows store, potentially I will add Windows Phone in the future. I’m having most of my logic in a library and create different GUI for the different platforms.
I want to localize my application and want to share string resources between the platforms. But how do I do that?
For Windows desktop the most common approach seems to be using resx files. Here is a short example:
http://compositeextensions.codeplex.com/discussions/52910
For Windows store app resw files are used instead, here is an example of that:
http://msdn.microsoft.com/en-us/library/windows/apps/hh965326.aspx
Both these solutions are platform specific which I don’t like :-(. I really want to have all my string in one file/language and being able to use that in all platforms. Is there any solution for this?
Update 17 Feb 2014: As I understand it resx and resw files are in the same format. What is missing in Windows store app is that no class file is generated for the resw file. If I just could get a file like that my problems would be solved. Then I could put an instance of that class in my view model and access all text via properties.
The class file generated in WPF application almost works. The problem is this line that looks something like this:
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ResxTest.Properties.StringTest", typeof(StringTest).Assembly);
To get this to compile I need to change it to this:
global::System.Resources.ResourceManager temp = new System.Resources.ResourceManager("ResxTest.Properties.StringTest", typeof(StringTest).GetTypeInfo().Assembly);
But the resource ResxTest.Properties.StringTest can’t be loaded in my Windows Store application. For some reason I need to rename my resource to Resource.resw and load it with the name “Resource”. I have tried all kind of names but this is the only one that works. Using name MyApplication.MyResource never works.
I’m not sure if I’m on the right track. I’m almost so desperate that I will make my own solution were I convert an XML-file with all strings I needed to a huge class with properties that I could use to get all string without any resource files. But I think that is ugly and cheating so I hope someone could give me a better idea :-).
Update 24 Feb 2014: I was wrong! Things are working quite nicely with Portable class library. If I use that I could put an instance of auto generated C# class in my view model and access all strings from that object.
But if I use an ordinary library things doesn’t work as properly in Windows Store app (WPF is fine). I have tried to copy all files to a Windows store class library from a working Portable class library. When I try to create an instance of the auto generated file I always get:
An exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll but was not handled in user code
Additional information: Unable to load resources for resource file "MetroLib.StringResources" in package…
Quite annoying since I’m using the express editions of Visual Studio where portable class library isn’t available. So probably I will develop my own solution to generate classes from a resource file (which also gives me some other benefits). But I’m still curious what I’m doing wrong.
I finally solved the problem. I simply developed a simple tool (ResToCode) to convert resource files to pure C# classes. Quite similar to what Visual Studios resgen.exe is doing, but with some extra features. It works really well so I’m quite happy about it :-).
The tool is available for anyone at CodeProject:
http://www.codeproject.com/Articles/744528/ResToCode-Localization-tool-for-Windows-Desktop-St
You can put all your resources in a Portable class library and use these libraries on all platform. You might have to check what version of .NET framework you are using. Portable libraries are not available on all the versions of all the platforms.
http://msdn.microsoft.com/en-us/library/vstudio/hh871422(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/vstudio/gg597391(v=vs.110).aspx#members
Have you looked at the Multilingual App Toolkit? It keeps the translations in an industry standard XLIFF format and can generate resources files for Windows and Windows Phone.
I had the same issue with the MissingManifestResourceException for Portable Class Libraries too. Today I created a new Portable Class Library with another name (without the string 'Resources' in it): and it works like a charm. No idea why this hasn't worked before (perhaps the name of the resource).
Now, I have my simple project on changing the color image into white&black image using CUDA-C.
But I got a problem with importing/loading a bitmap image into program. I don't know how to import it.
So...
CUDA-C have a specific function about importing/loading bitmap image?
If yes, what is it and how to use it?
If no, how do you do with importing/loading bitmap image?
Thank you.
There's really nothing that is CUDA-specific about loading a bitmap image into an application.
If you have a preferred method for loading a bitmap image into an application, you should be able to use it with a CUDA app. You will obviously be loading the image into the host application space first. After that, if you want to transfer it to the device, you can use any of the standard methods for transferring data to the device to accomplish this.
CUDA (i.e. the runtime API) doesn't have any specific functions for importing/loading a bitmap image
-
There are many ways to load an image. If you are already using OpenGL or DirectX, then you will want to use a method associated with one of those APIs, and then use the appropriate interop API within CUDA to manipulate the object.
If you want to import a bitmap image directly into a CUDA program without using a graphics API, take a look at the CUDA samples, as a number of them do this and provide helper functions that you may want to re-use.
For example, the dct8x8 sample provides a file called BmpUtil.cpp which contains a number of useful bitmap import/handling routines, and the dct8x8 app (dct8x8.cu) shows how these may be used directly in a CUDA app.
I built up a module that creates a window with an edit box from windows' EDIT windowclass. It is designed to only work with ansi character set and not using any unicode.
I make use of EM_GETHANDLE to recieve the buffer to the edit control.
Now here is my problem: (quoted from link above)
Note For Comctl32.dll version 6, the buffer always contains an array of WCHARs, regardless of whether an ANSI or Unicode function created the edit control. For more information on DLL versions, see Common Control Versions.
So when my module gets loaded by an application that has comctl32 initialized, my whole code breaks.
My Question: Is there a way to prevent CreateWindowA to use comclt32 or does anyone have an idea to fix this problem?
The application uses COMCTL32.DLL if it is specified in the app's manifest as described e.g. here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb773175%28v=vs.85%29.aspx
If your module is DLL, then you might try use some isolation technique so it does not rely on what version of COMCTL32.DLL the .exe decided to use, but that might bring many other drawbacks.
I recommend to use WM_GETTEXTA or GetWindowTextA() instead, which will copy converted string into your buffer. Designing a module which requires old version of a DLL to work correctly is simply bad idea.
this is my 1st question in the site.
I need a 3DS model loader for opengl applications. Loader should also be able to load .jpg textures. I tried to use OpenSceneGraph for this purpose but this time I have to also use the whole OpenSceneGraph data structure to render the scene. Is it possible to use OpenSceneGraph only for model loading and do the rest with standart opengl code, especially glTranslate, glRotate, etc.
Googling turned up this: lib3ds
Not sure if it can read JPEGs but that should be easy enough with libjpeg or equivalent.
OpenSceneGraph uses "plugins" to load file formats - both models and textures. There are working plugins for 3ds and for jpeg, though at least the jpeg one (I believe) isn't built in the default configuration - when creating the OpenSceneGraph makefiles (or projects on Windows), you need to specify the location of the libjpeg files in order for it to be built (as the plugin is based on that library). Once you have these two plugins, you'll have no problem reading 3ds files and jpeg textures. Another option is to use some other convertor which supports both osg (or ive) - OpenSceneGraph's native format- and 3ds. Blender comes to mind, and it's free...
As for mixing openGL calls with OpenSceneGraph - that can be tricky, but possible. One option is to derive your own class from Drawable, then override its draw implementation method, and place it anywhere you want in the graph, though manually drawing the 3ds files defeats the whole purpose of using a scene-graph...
Simple question.
So MEF doesn't support importing or exporting loose files (such as xml files) etc.
However, it should at least support embedded resources right?
I currently have a silverlight application that loads xaps dynamically. These dynamically loaded xaps each have an xml file attached as an embedded resource accesible via an instance method that looks something like this...
public XDocument MenuStructure
{
get
{
return XDocument.Load("myFile.xml");
}
}
However, this property fails after import with a message saying "Cannot find file 'myFile.xml' in the application xap package."
I'm not sure whether the problem is how I'm accessing the file now that it's BuildAction is set to EmbeddedResource or not.
Any ideas?
Thanks
Ok, according to http://msdn.microsoft.com/en-us/library/ms596994(VS.95).aspx I was supposed to use Application.GetResourceStream. Everything works great now.
You are correct that MEF does not support loading resources from secondary downloaded XAP's. You can however do embedded resources (embedded in the assembly not the XAP) but the way you are accessing it will not pull the file from the embedded resources.
For BuildAction EmbeddedResource you will need to get the stream from the Assembly.GetManifestResourceStream(...)(http://msdn.microsoft.com/en-us/library/xc4235zt.aspx).
For BuildAction Resource you will need to build a proper pack uri (see Resource File Pack URIs - Referenced Assembly in http://msdn.microsoft.com/en-us/library/aa970069(VS.85).aspx) and pass to Application.GetResourceStream (I'm actually not entirely sure if this approach works for dynamically loaded XAPs or not).