|
When I came across the problem of clearing the IE history from a .net app, I searched for days before finding this solution.
It's not pretty, but it gets the job done. Yes, every line is required. Just call the ClearHistory method to do it.
Add these imports:
using System.Runtime.InteropServices;
using Microsoft.Win32; Then,
[StructLayout(LayoutKind.Sequential)]
private struct UUID
{
public int Data1;
public short Data2;
public short Data3;
public byte[] Data4;
}
[StructLayout(LayoutKind.Sequential)]
private struct STATURL
{
public int cbSize;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsUrl;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsTitle;
public System.Runtime.InteropServices.ComTypes.FILETIME ftLastVisited;
public System.Runtime.InteropServices.ComTypes.FILETIME ftLastUpdated;
public System.Runtime.InteropServices.ComTypes.FILETIME ftExpires;
public uint dwFlags;
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("3C374A42-BAE4-11CF-BF7D-00AA006946EE")]
private interface IEnumSTATURL
{
void Next(int celt, ref STATURL rgelt, out int pceltFetched);
void Skip(int celt);
void Reset();
void Clone(out IEnumSTATURL ppenum);
void SetFilter([MarshalAs(UnmanagedType.LPWStr)] string poszFilter, uint dwFlags);
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("3C374A41-BAE4-11CF-BF7D-00AA006946EE")]
private interface IUrlHistoryStg
{
void AddUrl(string pocsUrl, string pocsTitle, uint dwFlags);
void DeleteUrl(string pocsUrl, int dwFlags);
void QueryUrl([MarshalAs(UnmanagedType.LPWStr)] string pocsUrl, uint dwFlags, ref string lpSTATURL);
void BindToObject([In] string pocsUrl, [In] UUID riid, IntPtr ppvOut);
object EnumUrls { [return: MarshalAs(UnmanagedType.IUnknown)] get;}
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("AFA0DC11-C313-11D0-831A-00C04FD5AE38")]
private interface IUrlHistoryStg2 : IUrlHistoryStg
{
new void AddUrl(string pocsUrl, string pocsTitle, uint dwFlags);
new void DeleteUrl(string pocsUrl, int dwFlags);
void QueryUrl([MarshalAs(UnmanagedType.LPWStr)] string pocsUrl, uint dwFlags, ref STATURL lpSTATURL);
new void BindToObject([In] string pocsUrl, [In] UUID riid, IntPtr ppvOut);
new object EnumUrls { [return: MarshalAs(UnmanagedType.IUnknown)] get;}
void AddUrlAndNotify(string pocsUrl, string pocsTitle, int dwFlags, int fWriteHistory, object poctNotify, object punkISFolder);
void ClearHistory();
}
[ComImport]
[Guid("3C374A40-BAE4-11CF-BF7D-00AA006946EE")]
private class UrlHistoryClass { }
public static void ClearHistory()
{
UrlHistoryClass c = new UrlHistoryClass();
((IUrlHistoryStg2)c).ClearHistory();
}
Sorry for the long post.
Hope this helps,
DigitalKing
|
|
|
|
|
Also useful is clearing the RecentDocs list:
using System.Runtime.InteropServices;
...
[DllImport("shell32.dll")]
static extern void SHAddToRecentDocs(ShellAddToRecentDocsFlags flag, IntPtr pidl);
[Flags]
private enum ShellAddToRecentDocsFlags : uint
{
Pidl = 0x001,
Path = 0x002,
}
public static void ClearRecentDocs()
{
SHAddToRecentDocs(ShellAddToRecentDocsFlags.Pidl, IntPtr.Zero);
}
|
|
|
|
|
thanks for the advice, but it seems a bit more advanced than what i can handle right now. maybe this scenario will be a little more simple and get me going in the right direction. say i want to delete a folder or file in any directory i chose, how would i go about that. i read something about a fileinfo.delete method, will this work. also, can you point me to any good texts about file,folder,directory handling in csharp. thanks again
|
|
|
|
|
I am developing an UI application for pocket pc. Two panels are overlayed, and each panel has two buttons anchored in. I want to use tab function to navigate among those buttons. As I use tab order, it shows buttons in one panel in the orde of 0.0, 0.1, buttons in another panel in the order 1.0, 1.1. How to use the parameters 0.0, 0.1 and 1.0, 1.0? Thanks.
|
|
|
|
|
How does one detect the current control the mouse cursor is over when one does a mouse button down and move? It appears that the control when the move started repeatedly fires its mouse move event but other controls are ignored. Do i have to do some kind of hit test? What is typically done in C#?
|
|
|
|
|
Greetings,
I'm in .NET 2.0
I'm working on an app where the Main Form contains a webBrowser Control. I do not want to show the Main Form until the document has completed loading in the web browser control or until 60 seconds has passed...in which case, I will then load an offline version.
The webBrowser control has a DocumentCompleted event. So that I know if it has finished loading. The problem is, I need to Load the url for the webBrowser control on a separate thread, and then loop for 60 seconds on the GUI Thread, or Until Ive been notified that the document has loaded. I have tried something like this....but I think the problem is that the webBrowser Control belongs to the GUI Thread.
public frmMain()
{
ThreadStart ts = new ThreadStart(DoWork);
Thread thread = new Thread(ts);
thread.Start();
for (int i = 0;i<60;i++)
{ if (m_documentLoaded)
{
i = 60;
}
else
{
System.Threading.Thread.Sleep(1000);
}
}
}
public void DoWork()
{
System.Uri url = new System.Uri("http://myDomain.com/default.aspx/");
webBrowser1.Url = url;
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
m_documentLoaded = true;
}
I know what I want to Do...just not sure exactly how to carry it out...
Thanks for any input
|
|
|
|
|
Create a timer on your form with interval set to 60 seconds. Load the browser page on the UI thread, start the timer. When the timer tick event has been raised, check if m_documentLoaded is true, and if not, load the offline version.
|
|
|
|
|
Excellent.... once again...I was overthinking.
Thanks
|
|
|
|
|
Hi, I am using recursion to search for a folder in searchPath and if a subfolder or the searchfolder is the same as saveFolder(the
folder to copy the files to), it skips searching file in the saveFolder. Other than that, it keeps searching the file recursively and calls the
method this.SearchFile(..)
This obiviously fails to build because I didn't assign anyting to 'string folderName' and breaks the logic.
Can anyone please correct this method?
saveFolder path is at saveTextbox.Text
public void GetsubFolders(ref string searchPath, string fileName)
{
string[] folder = Directory.GetDirectories(searchPath);
string folderName;
int index = 0;
if (folder.Length !=0)
{
if (String.Compare(folder[index].ToString(), saveTextbox.Text.ToString()) == 0)
{
index++;
if (folder.Length == index)
{
return;
}
else
{
for (; index < folder.Length; index++)
{
folderName = Convert.ToString(folder[index]);
GetsubFolders(ref folderName, fileName);
}
}
}
else
{
for (; index < folder.Length; index++)
{
folderName = Convert.ToString(folder[index]);
GetsubFolders(ref folderName, fileName);
}
}
}
this.SearchFile(folderName, fileName);
}
|
|
|
|
|
How can I send a struct/class from client to server by using tcp/ip in c# ?
|
|
|
|
|
Hi TJVictor
Have a look at .Net remoting. I think that's the technology you're looking for.
For example:
http://www.codeproject.com/csharp/DotNetRemotingBasicTutor.asp[^]
Kind regards - Jakob
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!
10 kinds of people in the world:
- Those who understand binary
- Those who don't
|
|
|
|
|
I have read a lot of books on C#, but what I am ultimately looking for I have yet to find. 1st I would like a book on explaining good practice of creating classes and explains inheritence. Next, I would like a desk reference, with good explanations and examples ( unlike MS Documentation ) for C#.
Thanx in advance
Jude
|
|
|
|
|
I am dynamically connecting to an unmanaged C++ COM interface using GetTypeFromProgID, but I must get a secondary IDispatch interface by calling the "GetBasicCallInfoIDisp" function of that interface. Using this secondary interface, I am trying to get a simple property.
The JavaScript is very rudimentary:
var winoperdoc = new ActiveXObject("WinOper.Document");<br />
var winoper = winoperdoc.GetBasicCallInfoIDisp();<br />
window.alert(winoper.SeizureID);<br />
The C# version I have looks like this:
Type objWinOper = Type.GetTypeFromProgID("WinOper.Document");<br />
<br />
object objWinOperLateBound = objWinOper.InvokeMember("GetBasicCallInfoIDisp",<br />
BindingFlags.CreateInstance,<br />
null, <br />
objWinOper, <br />
new object[]{});<br />
<br />
int SeizureID = (int) objWinOper.InvokeMember("SeizureID",<br />
BindingFlags.Default | BindingFlags.GetProperty, <br />
null, <br />
objWinOperLateBound,<br />
new object[]{});<br />
This compiles, but I get an "Unknown Name" when I try to get the value from a member property.
Any help is appreciated.
Cheers,
Daaron
|
|
|
|
|
- how I can add more image in pictureBox ?
- how I can move image in pictureBox with mouse ?
|
|
|
|
|
You cannot add more than one image to a picture box. You can, however, add multiple picture boxes to another control such as a panel.
The picture box control doesn't contain any functionality for moving pictures within it. You can do this yourself by watching for when the user drags the mouse, then move the picture box itself.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
hi
codeproject is best .
i want to embedd one or more exe files in my app as resource and use it programmatically ..
how to do that ?
|
|
|
|
|
|
|
Boo! Do your own homework. The only way to become a good developer is by solving problems on your own. Do you know what companies do with people who don't do their own work...they promote them! But that's beside the point...
Josh
|
|
|
|
|
Josh Smith wrote: Do you know what companies do with people who don't do their own work...they promote them!
Oh god he is telling the truth...Take my 5
|
|
|
|
|
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2
|
|
|
|
|
Is it possible to open Shared Memory in a C# Windows application? specifically, Shared Memory created in a C++ app using the CreateFile, CreateFileMapping API.
(& if it is possible, can I get a hint where to start looking for the "instructions"?)
|
|
|
|
|
|
I used the flwing code to focus a control. But i got nothing. why?
private void button1_Click(object sender, EventArgs e)
{
if (lst1.Items.Count > 0)
{
lst2.Items.Add(lst1.SelectedItem);
lst1.Items.Remove(lst1.SelectedItem);
}
if (lst1.CanFocus)
{
lst1.Focus();
}
}
rgds,
stephen myint
|
|
|
|
|
There is an design paradox here: To have this event, you need to click the buttom which forces the focus onto the button. If it was anywhere else, you wouldn't be able to click the button.
You don't want things stealing focus while doing various operations (like clicking, drag-and-drop, etc) anyway. You should consider another UI design instead of trying to have focus jump around on the form while performing user input.
|
|
|
|
|