|
Hi,
I have a little method which registeres an extension (edit: like .ext) into the Windows registry. Does anyone have an idea how I can tell Windows to open a file with the respective extension only in a new program instance, if currently none is running? If the program is already running, a new tab in my program should be created (I have a event void opentab(object sender, EventArgs e) to open a new tab). But how can I tell windows not to open a new instance but to call the running program and let it run the event?
I think one can somehow do it with a subnode "ddeexec" in the subnode "open", but I'm not sure and it didn't work for me.
Best wishes
robin
void DefineAssociations(string extension, string IconFile)
{
string keyName = extension;
RegistryKey key = Registry.ClassesRoot.OpenSubKey(keyName);
if (key != null)
{
string apppath = "";
apppath = Application.ExecutablePath.ToLower() + " \"%1\"";
key.SetValue("", "MyProg");
RegistryKey iconkey;
iconkey = key.CreateSubKey("DefaultIcon");
iconkey.SetValue("", Environment.CurrentDirectory + "\\resources\\" + IconFile);
key = key.CreateSubKey("shell");
key = key.CreateSubKey("open");
key = key.CreateSubKey("command");
key.SetValue("", apppath);
}
}
|
|
|
|
|
I don't think it's possible. Anyway, long story short - that's not the way to do it.
It's your job to find out if another instance is running, and if so, to notify it. It's not an easy task though. There's quite a bit of code required to do this. Namely, first find out if another instance of your app is running, and if so, you need to notify it and send it the new file to open.
More or less, something like this:
[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT {
public IntPtr dwData;
public int cbData;
[MarshalAs(UnmanagedType.LPStr)] public string lpData;
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
public const int WM_COPYDATA = 0x004A;
...
var running_already = Process.GetProcessesByName("Yourapp").ToDictionary(x => x.Id, x => x);
running_already.Remove(Process.GetCurrentProcess().Id);
if (running_already.Count > 0) {
if (args.Length == 0)
return;
string open = args[0];
var cds = new win32.COPYDATASTRUCT {
dwData = new IntPtr(0),
cbData = open.Length * 2 + 1,
lpData = open
};
var handle = running_already.First().Value.MainWindowHandle;
win32.SendMessage(handle, win32.WM_COPYDATA, IntPtr.Zero, ref cds);
return;
}
protected override void WndProc(ref Message m) {
if (m.Msg == win32.WM_COPYDATA) {
var st = (win32.COPYDATASTRUCT) Marshal.PtrToStructure(m.LParam, typeof (win32.COPYDATASTRUCT));
string open = st.lpData;
util.postpone(() => on_file_drop(open), 100);
}
base.WndProc(ref m);
}
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
Wow, it works up to the point at which I just need to call the file open event. Great! thanks a lot;)
robin
|
|
|
|
|
Glad it works I copied the code from my app - it took me a while to do it right
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
It's impossible; here's the code to do the impossible -
+5
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
That step is to be cared of by your program opening the file, not by the registry. The concept is called "single instance application".
|
|
|
|
|
I want to develop Windows App for NGO similar to below URL https://play.google.com/store/apps/details?id=com.savethelife.csr
This is for Non profitable Organisation, so cost should be lower side.Please suggest free database websites those can provide free data services? Thank
|
|
|
|
|
Maybe you should develop the app first before concerning yourself with "hosting".
|
|
|
|
|
That's an Android app. Are you sure this is a C# issue?
|
|
|
|
|
COder876 wrote: I want to develop Windows App for NGO Sounds like a good idea. Please come back here with specific technical questions related to your progress in programming your application using C#.
And, be sure and visit other CP forums, like the Database forum, to ask questions about the other issues with the application.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
My code is failing on the following line.
this.buCursor.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buCursor.BackgroundImage")));
Because appears that
resources.GetObject("buCursor.BackgroundImage")
Is returning NULL or some value that is causing the application to throw a
"'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: MissingManifestResourceException"
Putting a watch on buCursor I see that the BackgroundImage element value says "Could not evaluate expression"
A bit more background is the code runs no problem on a Windows CE5.0 application with C# code developed in VS 2005.
I created a new SDK for a new target we are going to use, for Windows Embedded Compact 13 using VS2013 and application builder. This runs basic test C# applications, developed in C#, I have built for it.
I created new device application C# project in VS 2013, based on the SDK I made, and added the source code and resources from the VS2005 project.
After building the VS2013 code and debugging it, it throws this exception.
I used "Run Custom Tool" on resources.resx.
I also ensured .resx files and other resources were "Embedded Resources"
Any help would be greatly appreciated.
Thank you.
|
|
|
|
|
|
It could also be that you need to copy the files themselves (images) from the source solution, and put them in the exact same folder (the resource manager holds a reference to the file added to the .resx).
I never finish anyth
|
|
|
|
|
hi
i have DataSet that contain Image.
i need to save this Image to File.
i try this:
SQL = ItemCode,PIC from ROW;
dsView = new DataSet();
adp = new SqlCeDataAdapter(SQL, Conn);
adp.Fill(dsView, "ROW");
adp.Dispose();
foreach (DataRow R in dsROW.Tables[0].Rows)
{
ItemCode = R["ItemCode"].ToString().Trim() ;
TEMP = R["PIC"].ToString().Trim();
Image image = R["PIC"] as Image;
if(image != null)
{
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] imagedata = ms.ToArray();
}
but image Always is null
and in TEMP i see System.Byte[]
need some help, thanks
|
|
|
|
|
|
thank for the help !
i try this and i got: InvalidCastException
i work on C# Windows-Mobile
thanks
|
|
|
|
|
That means the field is not a blob (thus, it can't be converted to a byte array). Please check the data type of your "pic"
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
How to get data(json) to listview by MVVM?
Inside View:
<Grid>
<ListView x:Name="lsvItems" VerticalAlignment="Top" HorizontalAlignment="Stretch">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal"></ItemsWrapGrid>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<Grid>
<Ellipse Stroke="Black" Width="180" Height="180" StrokeThickness="0.9" Margin="0,5">
<Ellipse.Fill>
<ImageBrush ImageSource="/Asets/nologo.jpg"></ImageBrush>
</Ellipse.Fill>
</Ellipse>
<Ellipse Stroke="Black" Width="180" Height="180" StrokeThickness="0.9" Margin="0,5">
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding thumbail}"></ImageBrush>
</Ellipse.Fill>
</Ellipse>
</Grid>
<StackPanel Margin="0,5">
<TextBlock Text="{Binding title}" Foreground="White" FontWeight="SemiBold" OpticalMarginAlignment="TrimSideBearings" TextTrimming="CharacterEllipsis" FontSize="15" Margin="2" ></TextBlock>
<TextBlock Text="{Binding user.full_name}" Foreground="White" FontSize="12" Margin="2"></TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
Inside Model:(tracksModel.cs)
...........
public class Track
{
public string urn { get; set; }
public string uri { get; set; }
public string permalink { get; set; }
public string permalink_url { get; set; }
public string title { get; set; }
public string description { get; set; }
public string track_type { get; set; }
public string genre { get; set; }
public string tag_list { get; set; }
................
}
public class RootObject
{
public List<Track> tracks { get; set; }
public string tag { get; set; }
public string next_href { get; set; }
}
Inside ViewModel:
StaticMethod:
public class StaticMethod
{
public static async Task<string> GetJsonStringTask(string link)
{
HttpClient client = new HttpClient();
HttpResponseMessage message = await client.GetAsync(link+ "&client_id=9ac2b...");
string result = await message.Content.ReadAsStringAsync();
return result;
}
}
TrackViewModel:
public ObservableCollection<TracksModel> TrackCollection = new ObservableCollection<TracksModel>();
public async Task GetTrackAsyncTask(string link)
{
var result = await StaticMethod.GetJsonStringTask(link);
if(result!=null)
{
**var getItem = JsonConvert.DeserializeObject<TracksSoundCloud.RootObject>(result);
if(Do not get a error)
{ give data to listview}
else
return a error and show up on listview or show messagebox.
}**
}
Please help me to fix it? I'm new on MVVM.
var getItem = JsonConvert.DeserializeObject<TracksSoundCloud.RootObject>(result);
if(Do not get a error)
{ give data to listview}
else
return a error and show up on listview or show messagebox.
}
|
|
|
|
|
What exactly is the problem?
|
|
|
|
|
I did not get data.
binding trackcollection but no have data.
|
|
|
|
|
If it not mvvm then
lsvitem.itemsource=getitem.track;
but this is mvvm so I don't know .
|
|
|
|
|
I can't seem to find any way to get a GUI in Cosmos OS. I have went on Youtube, Stacks, and more. I did not find any methods that work. If anyone can please help me that would be awesome! Thanks in advanced!
|
|
|
|
|
What does this have to do with C#?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Believe it or not, Cosmos has something to do with C#; but, yes, this question here is way-off this forum's scope.
"Cosmos is an operating system "construction kit", built from the ground up around the IL2CPU compiler in C# and our home-brewed language called X#." [^]
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|