|
In general, no, there is no other way.
Depending on what you're trying to do, you may be able to use Process.MainWindowTitle[^]. This will tell you the title of the main window of each process, and you can iterate through those looking for the one you want without P/Invoke. But (as far as I'm aware at least) there is no way to get a window by name that looks at all open windows without using FindWindowByName.
|
|
|
|
|
This tips[^] might help you.
|
|
|
|
|
Hello ::- ). I've recently upgraded to Windows 7 and, naturally, some of my apps have run into a black, merciless wall of changed behaviors.
One of the things which stopped working are my applications to bring stuff out of SysTray. Some applications don't have good methods to bring them out of SysTray via hotkey. Total Commander for example sometimes fails and you have to press Enter. So I made an application which worked fine on XP. But now, instead of bringing it back from SysTray and popping it in my face, it just blinks it on the Taskbar.
Before you say "ForegroundLockTimeout", know that I already set this to 0 across the registry.
What I'm trying to do is to make Total Commander come out from SysTray via a hotkey. The hotkey actually launches my C# application. In my C# application I do this:
int hwndTC = Win32API.FindWindow("TTOTAL_CMD", null);
Win32API.ShowWindow((IntPtr)hwndTC, Win32API.ShowWindowCommand.Show);
Win32API.ShowWindow((IntPtr)hwndTC, Win32API.ShowWindowCommand.ShowMaximized);
Win32API.ShowWindow((IntPtr)hwndTC, Win32API.ShowWindowCommand.Maximize);
Win32API.SetForegroundWindow(hwndTC);
But the result is that instead of TC showing itself in my face, I see it blinking on the TaskBar.
One very strange thing is that when Visual Studio is running (and thus, the .vshost.exe is running), everything works fine. As soon as I shut down VS, the blinking stuff happens again.
|
|
|
|
|
|
When two event handlers are registered for one event, they are executed in the order they were registered (yes, I know, I must not rely on that).
Now I want the event handler which was registered second to be executed first (reliably of course). How can that be achieved - or can it be achieved at all?
|
|
|
|
|
You can use the event's delegate array if you have control over the event source.
e.g. Helpfully in the standard order!
public EventHandler MyEvent;
private void OnMyEvent(EventArgs args) {
EventHandler temp = MyEvent;
if (temp != null) {
Delegate[] handlers = temp.GetInvocationList();
for(Int32 i = 0; i < handlers.Length; ++i) {
((EventHandler)handlers[i])(this, args);
}
}
}
Alan.
|
|
|
|
|
While this will work well at the moment, GetInvocationList is defined as returning things in the same order as they will be executed, and I'm not sure that order is defined anywhere.
|
|
|
|
|
Yes I see what you mean and it made me wonder if an explicit backing list combined with implementation of the event's add and remove accessors would help.
It wouldn't as the multicast nature of delegates means that the list would actually be a list of delegate chains and the only way to iterate through the chains would still be via GetInvocationList.
Alan.
|
|
|
|
|
Thanks for the idea. The more complicated thing is that I must inject that somehow into a foreign control.
I manipulated the CollectionEditor for TabPageCollection , because I want to log the changes. The collection editor has a CollectionForm , and on that form there's the removeButton .
A click on the removeButton first removes the item from the list, then my handler gets executed where I want to know which item was removed (well, found a workaround: add another handler to the MouseDown event).
That is, I'd like to get
removeButton.Click += new EventHandler(removeButton_Click);
executed before the standard handler gets executed.
I tried now
EventInfo ei = removeButton.GetType().GetEvent("Click");
MethodInfo mir = ei.GetRaiseMethod(true);
MethodInfo[] mis = ei.GetOtherMethods(true);
MethodInfo mic = removeButton.GetType().GetMethod("OnClick", BindingFlags.Instance| BindingFlags.NonPublic| BindingFlags.Public| BindingFlags.FlattenHierarchy);
but EventInfo does not want to show me the GetInvocationList() method, the RaiseMethod is null, and GetOtherMethods returns an empty array.
I can get the OnClick method, but do not know how to manipulate that.
Can you provide further ideas?
|
|
|
|
|
I don't know much about reflection beyond discovering and instantiating types in dynamically loaded assemblies but I did find this http://www.bobpowell.net/eventsubscribers.htm[^] which may be of relevant. I assume that you intend to compare the 'before removal' and 'after removal lists' to get the name of the removed delegate.
Alan.
|
|
|
|
|
Thanks a lot for this valuable hint - you got my 5.
After re-rodering the event handlers with a
removeButton.Click -= subscribers[0] as System.EventHandler;
removeButton.Click += new EventHandler(removeButton_Click);
removeButton.Click += subscribers[0] as System.EventHandler;
I was struck by Microsoft re-enabling the addButton in their event handler - which now runs last. A BeginInvoke from my handler to the function for disabling the button again was then required...
Working with the CollectionEditor really means a lot of hackz.
|
|
|
|
|
You can use the custom event accessors[^] to put them in a list or something, combined with the other answer (manually invoking the handlers) that should give you a well-defined order.
|
|
|
|
|
hi
is it possible to debug my C# program (for Windows-Mobile)
Through LAN ?
i have cradle with IP and terminal that on him (with my C# windows-mobile program) , i need to debug my program from my PC
i work with Visual-Studio 2008
thanks in advance
|
|
|
|
|
AFAIK, the crasdle has to be connected to your dev machine. I don't think debugging over IP is possible.
|
|
|
|
|
Hi all, I'd like to create a C# program that:
1) It will allow me to navigate through the internet.
2) When browsing, I will must have the opportunity to begin a recording session. This recorded session will be written onto a file on HD.
When I say "record a web-session" I intend to record every step I follow during my web browsing.
A program that best-fits these requirements is iMacro.
I cannot use it so I have to develop something similiar.
I create my form with my browser within (simply using the WebBrowser tool), but what I'm trying to understand is HOW can I keep trace of any actions I do in my web-browsing.
Anyone can help me please?
Any advice will be appreciated,
Thank you in advance,
Pietro
|
|
|
|
|
The main thing to record is the URLs you follow. If the method is "POST", you should also record the data you sent to the server.
|
|
|
|
|
Yes, I'd like to record URLs I visited, but also to record all actions I do in these URLs, so if I write on a Form and press a Button I'd like to capture these information to replicate them later.
When I write my code where can I attach on it to grab such informations?
Is possible to have some c# code examples or links to better understand the way I have to follow?
Thank you very much,
Pietro
|
|
|
|
|
Good one,
So for every action on the page, you want to capture and store some where for further checking?
|
|
|
|
|
Yes, any advice?
I don't know how can I do it.
Pietro
|
|
|
|
|
I think you will need to write a browser plugin to capture things that are going on within a page. If you want to use the WebBrowser then it would have to be an IE plugin, if those even get loaded when you run the OCX version.
|
|
|
|
|
Why do you think plugin are better? Does their capabilities best fit my application? Now I'reading some documents on plugins. What features have I to study regarding my target?
Thank you for all,
Pietro
|
|
|
|
|
As far as I know the browser (including the WebBrowser control) doesn't expose the API you need to capture most things that the user does, so to get that you'd have to use something inside the browser, i.e. a plugin.
|
|
|
|
|
Can you show me some web link or other sources I can use to begin my work?
Thank you,
Pietro
|
|
|
|
|
Sorry, I've never done any plugin work with IE. I'd just be Googling and you can do that just as efficiently.
|
|
|
|
|
Hello again, CP! I am now trying to create a custom Form by painting a new title bar. I have never done this before but I did remember seeing it a lot when I was heavy into C++ and MFC. So I knew to look for WM_NCPAINT. The resources I found were telling me to override WndProc for the form and catch WM_NCPAINT, and then do my custom drawing from there. So this is what I did:
protected override void WndProc(ref Message m)
{
IntPtr hdc = GetWindowDC(m.HWnd);
Graphics g = null;
if ((int)hdc != 0)
g = Graphics.FromHdc(hdc);
if (m.Msg == WM_NCPAINT || m.Msg == WM_NCACTIVATE || m.Msg == WM_SETTEXT)
{
if ((int)hdc != 0)
{
OnNcPaint(g);
ReleaseDC(m.HWnd, hdc);
m.Result = (IntPtr)1;
}
}
else
base.WndProc(ref m);
}
In OnNcPaint(Graphics) I make a simple call to graphics.FillRectangle, which fills the entire rectangle with a solid color (in this case, Color.Blue). However, when I resize the form I am seeing a large amount of flickering across the entire form. The background is not custom painted. I have ResizeRedraw set in the form's "SetStyle()" method. When I remove ResizeRedraw it does not paint properly at all.
How can I eliminate the flicker here? This is kind of irritating. Haha.
BTW, I have "base.WndProc(ref m);" in the "else" statement because otherwise, if I call it alongside WM_NCPAINT, it will just paint Windows' non-client area (Win7, Aero Theme). Thanks in advance.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|