How do I 'correctly' set a default icon? - c#

I'm setting the HKEY_CLASSES_ROOT\.ext\DefaultIcon to the path of my application and it works...for the most part.
// create the HKEY_CLASSES_ROOT\extension
RegistryKey k = Registry.ClassesRoot.CreateSubKey(".spr");
k.SetValue("", "SpaceRead"); // set the default to the program name
RegistryKey di = k.CreateSubKey("DefaultIcon");
di.SetValue("", Application.ExecutablePath);
di.Close();
k.Close();
My problem is that my icon is showing up 'inside a white page' instead of only showing my icon (and losing the page)
here's an example. The first icon is mine, the second one is what I want.
My .ico file has all the standard resolutions in it, but I don't think that's the problem since even small icon views show the 'page' background.
Is there some custom icon rendering going on that I don't know about?
BTW, this is a Windows 7 x64 machine.

Related

Get list of installed Aero themes

I want to get a list of information (with filename and real theme name) of the installed AERO themes in a Windows 7 OS.
Also I need to change the current theme to one of the installed themes, but without using process.start(ThemeFile) because the personalization panel opens when I try that...
I know here is the installed theme files to get the filenames: "C:\Windows\Resources\Themes"
But I'm asking if exist a better way than listing the file content of that dir 'cause I need the real names too, and I want to know how to change the current theme to other without opening the personalization panel.
An example of this... I have only two Aero themes on my OS.
The filenames are:
Aero.theme
Concave_seven.theme
But the theme names wich appears in the personalization panel are:
Windows 7
Concave 7
I want to retreive the filenames and real names to store it in a listbox to change the current theme for the desired theme.
Update,
What I've tried...
' Load theme names
For Each Theme As System.IO.FileInfo In New System.IO.DirectoryInfo(Environment.GetEnvironmentVariable("windir") & "\Resources\Themes").GetFiles("*theme")
ComboBox1.Items.Add(Theme.ToString.Substring(0, Theme.ToString.Length - 6))
Next
' Change theme
' Process.start(ThemeFilename)
' rundll32.exe Shell32.dll,Control_RunDLL desk.cpl desk,#Themes /Action:OpenTheme /File:"C:\Windows\Resources\Themes\aero.theme"
Well like anybody knew how to change the current theme without opening the theme selector with rundll32 etc... then here we go my personal trick (which is not on google and anywhere, it's pure luck).
First step: disable DWMCOMPOSITION for example disabling the "Themes" service.
Second step: add a regkey to specify the desired new theme, specify the msstyles file, not the .theme file.
I do this with a personal func but you can get the idea:
Reg_Set_Value("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ThemeManager", "DllName", "C:\windows\resources\themes\aero\aero.msstyles", Microsoft.Win32.RegistryValueKind.String)
Third step: Re-enable the DWM composition ("Themes" service).
Voilá!
UPDATE:
Also I noticed need to change this value to 0 before enabling the theme to ensure all the color schemes are updated:
Reg_Set_Value("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ThemeManager", "LoadedBefore", "0", Microsoft.Win32.RegistryValueKind.String)

Setting Icon for wpf application (VS 08)

Before going much further i'll mention I have tried solutions in following:
How do I set the icon for my application in visual studio 2008?
Set application icon from resources in VS 05
I am trying to set an icon for my application.
AFAIK, I need potentially 3 images?
1 image is the actual image in explorer when clicking on the .exe (thumbnail for the exe)
1 image (tiny) in the top left corner (16 x 16? Not entirely sure)
1 image in the start menu dock, to the left of the app (maybe 32x32? again not sure)
So thats fine.
Now I have selected an Icon. How do I use it in one of above situations?
I have tried adding it in resources, nothing seems to happen. Following that first SO solution,
"First go to Resource View (from menu: View --> Other Window --> Resource View). Then in Resource View navigate through resources, if any. If there is already a resource of Icon type, added by Visual Studio, then open and edit it. Otherwise right-click and select Add Resource, and then add a new icon."
The resource view is empty, and I cannot right click in this view.
If I right click on the solution > properties > resources > I can add the icon image, but it doesn't show in either of the locations listed above. (or anywhere that I can see)
1) How do I set the application icon for a WPF Application?
Assuming you use VS Express and C#.
The icon is set in the project properties page. To open it right click on the project name in the solution explorer. in the page that opens, there is an Application tab, in this tab you can set the icon.
#742's answer works pretty well, but as outlined in the comments when running from the VS debugger the generic icon is still shown.
If you want to have your icon even when you're pressing F5, you can add in the Main Window:
<Window x:Class="myClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Icon="./Resources/Icon/myIcon.png">
where you indicate the path to your icon (the icon can be *.png, *.ico.)
(Note you will still need to set the Application Icon or it'll still be the default in Explorer).
Note: (replace file.ico with your actual icon filename)
Add the icon to the project with build action of "Resource".
In the Project Properties, set the Application Icon to file.ico
In the main Window XAML set: Icon=".\file.ico" on the Window
After getting a XamlParseException with message: 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' with the given solutions, setting the icon programmatically worked for me. This is how I did it:
Put the icon in a folder <icon_path> in the project directory
Mimic the folder path <icon_path> in the solution
Add a new item (your icon) in the solution folder you created
Add the following code in the WPF window's code behind:
Icon = new BitmapImage(new Uri("<icon_path>", UriKind.Relative));
Please inform me if you have any difficulties implementing this solution so I can help.
You can try this also:
private void Page_Loaded_1(object sender, RoutedEventArgs e)
{
Uri iconUri = new Uri(#"C:\Apps\R&D\WPFNavigation\WPFNavigation\Images\airport.ico", UriKind.RelativeOrAbsolute);
(this.Parent as Window).Icon = BitmapFrame.Create(iconUri);
}

Programmatically change the icon of the executable

I am developing an application called WeatherBar. Its main functionality is based on its interaction with the Windows 7 taskbar — it changes the icon depending on the weather conditions in a specific location.
The icons I am using in the application are all stored in a compiled native resource file (.res) — I am using it instead of the embedded resource manifest for icons only. By default, I modify the Icon property of the main form to change the icons accordingly and it works fine, as long as the icon is not pinned to the taskbar. When it gets pinned, the icon in the taskbar automatically switches to the default one for the executable (with index 0 in the resource file).
After doing a little bit of research, I figured that a way to change the icon would be changing the shortcut icon (as all pinned applications are actually shortcuts stored in the user folder). But it didn't work.
I assume that I need to change the icon for the executable, and therefore use UpdateResource, but I am not entirely sure about this. My executable is not digitally signed, so it shouldn't be an issue modifying it.
What would be the way to solve this issue?
If you want to do this programatically, I would start by looking at the Portable Executable file format (Wikipedia entry). The resources section (.rsrc, see section 6.9) should contain the icon. Using this information, you can write a tool to modify the icon.
If you just want to quickly change an icon in an existing file, you might be able to hack it up in the Visual Studio resource editor. I tested this with a file by deleting the old icon and adding a new one. The .exe icon changed in Explorer to the new icon, and the new icon appeared on the Start menu when I dragged it there.
-- Edit --
Yes, I agree that using UpdateResource is a good approach. Here is an example I found of using C++ functions to do so, and a P/Invoke signature for UpdateResource and FindResource.
private void button1_Click(object sender, EventArgs e)
{
String path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
String name = "test";
Shell32.Shell shl = new Shell32.ShellClass();
// Optional code to create the shortcut
System.IO.StreamWriter sw = new System.IO.StreamWriter(path + #"\" + name + ".lnk", false);
sw.Close();
// End optional code
Shell32.Folder dir = shl.NameSpace(path);
Shell32.FolderItem itm = dir.Items().Item(name + ".lnk");
Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink;
// Optional code to create the shortcut
lnk.Path = Environment.GetFolderPath(Environment.SpecialFolder.System)
+ #"\notepad.exe";
lnk.Description = "nobugz was here";
lnk.Arguments = #"c:\sample.txt";
lnk.WorkingDirectory = #"c:\";
// End optional code
lnk.SetIconLocation(Environment.GetFolderPath(Environment.SpecialFolder.System)
+ "cmd.exe", 1);
lnk.Save(null);
}
This was taken from http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/9e23a82c-8bed-4b96-8b9a-4c2b6136a622/
It may help.
I decided to implement a workaround - the icon will change in the thumbnail for the window (it is possible in Windows 7). If the icon is unpinned, the user can see the icon changing. In case it is pinned, the thumbnail will change according to the current weather conditions.
Seems to me like the structure of pinned icons (being a shortcut, in fact) doesn't allow dynamic icon change. If I am wrong, I am open for comments and ideas on this.

Hide the taskbar using C#

I am running Windows XP 64 bit. I want to hide the taskbar when I run my application.
I tried codes by searching the web. In all those, it hides the task bar. But the problem is, when i open a notepad and maximize it, it is not actually into full screen. Because the space where task bar was there is still blocked with empty space. I want it fit really into full screen mode.
If you like to replace the windows shell (taskbar) you'll have to change a registry key.
Changing the default shell (all users):
open regedit (start menu > run, and type in regedit)
go to: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon.
Change Shell from explorer.exe to your program path and name e.g. c:\myKioskApp\Kiosk.exe
Changing the default shell (only current user):
open regedit (start menu > run, and type in regedit).
go to: HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon.
add a new string value (Edit > New > String Value) called shell. and set the value to the path of the new shell e.g. c:\myKioskApp\Kiosk.exe
log out and log back in.
I've done this by making the application borderless, maximized, and setting it to be Topmost. Here's a perfect example from CodeProject.
As one of the commenters has said, replacing disabling Explorer and running your application might be the best way, security-wise.
You Can Hide your task bar by setting Following Properties of your C# Form.
WindowState : Maximized
FormBorderStyle : FixedDialog
on window 7 (or maybe higher) using FormWindowState.Maximized is wrong because the maximum size will be subtracted by Taskbar height but you can do this
this.WindowState = FormWindowState.Normal; // or default
this.FormBorderStyle = FormBorderStyle.None;
this.TopMost = true;
// do it here
this.Location = new Point(0,0);
var fullscreenSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
this.Size = fullscreenSize;

Five Questions regarding the use of C# / VisualStudio 2005

I've some questions .. and I really need your help.
I have an application.
First I display a splash screen, a form, and this splash would call another form.
Problem: When the splash form is displayed, if I then open another application on the top of the splash, and then minimize this newly opened application window, the splash screen becomes white. How do I avoid this? I want my splash to be displayed clearly and not affected by any application.
I'm using a DropDownList but I realized that there is 2 types of it . I found "Dropdown" which makes the text inside the DDL editable, and "DropDownList" which doesn't.
Problem: when I tried to use DropDownList control it doesn't allow me to add a default text while DropDown does so I want a DropDownList control which prevent modifying on the text and allow a default text .. what property should I use?
Can I add "?" which denotes to Help button to the FormBorder (with the minimization, maximization, and close buttons )
Can I change the colour of the Formborder from its default colour (blue) ?
One of my application functionality is to copy files from server to phone into a certain folder in memory card.
Problem : can I determine the free size of the MMC to notify the user if it's full while copying.
3) You have to set the "HelpButton" property of the form to true. However the "?" button is only visible if you deactivate the maximize and minimize buttons by setting "MinimizeBox" and "MaximizeBox" to false.
Here are a few...
1) you need to launch the window in another thread so that your app can do what it needs to do to start. When the startup finishes, signal to the splash screen that it can close itself.
2)
dropDownList.SelectedIndex = 0;
4) I would not recommend doing so. It is based on the system color scheme, which the user sets. I would not like an app to decide for itself which scheme to use.
5) if the MMC shows up as a mapped drive you could use one of these techniques
Once again there is no answer to this guys question.
Yes, do as the other guy said and launch the splash screen in its own thread.
There is only one type of ComboBox in .Net, However there is a property called DropDownStyle which sets its functionality.
Yes, I am clueless on how this one works and never needed it.
Yes you betcha, Its called non-client painting. you can find more info on it here http://www.codeplex.com/CustomerBorderForm/Wiki/View.aspx?title=Painting%20NonClient%20Area&referringTitle=Home
I Need more details on this.

Categories

Resources