|
Jinwah wrote:
How can I align controls on the form. I want a panel to be aligned left on the form, but the Align menu options never become enabled.
Aligning aligns two or more controls to each other, not to the form. Thus if you select two or more controls, you'll get your align buttons. What you really want is Docking... check out the Dock property for your control.
Paul
|
|
|
|
|
Hi,
I'm thinking of capturing some regions of my screen
into a Bitmap object. Does anyone have any ideas?
Thanks
Li-kai Liu
|
|
|
|
|
Hi
Eric Gunnerson has a library available on GotDotNet.com[^]. The zip is called Win32window.zip, was a bit tricky to find. You can email me if you cant find it. Unfortunately its a bit long too paste
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
try this...
public Bitmap CaptureWindow(string windowTitle)<br />
{<br />
RECT rect = new RECT();<br />
IntPtr windowDC;<br />
IntPtr dc1;<br />
IntPtr hWnd;<br />
<br />
if (windowTitle == null)<br />
{<br />
hWnd = FindWindow(null, "DISPLAY");<br />
windowDC = GetWindowDC(hWnd);<br />
rect.right = Screen.PrimaryScreen.Bounds.Width;<br />
rect.bottom = Screen.PrimaryScreen.Bounds.Height;<br />
}<br />
else<br />
{<br />
hWnd = FindWindow(null, windowTitle);<br />
windowDC = GetWindowDC(hWnd);<br />
int returnCode = GetWindowRgnBox(hWnd, ref rect);<br />
}<br />
<br />
Graphics g1 = Graphics.FromHdc(windowDC);<br />
Bitmap MyImage = new Bitmap(rect.right, rect.bottom, g1);<br />
Graphics g2 = Graphics.FromImage(MyImage);<br />
<br />
dc1 = g1.GetHdc();<br />
IntPtr dc2 = g2.GetHdc();<br />
<br />
BitBlt(dc2, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc1, 0, 0, 13369376);<br />
<br />
g1.ReleaseHdc(dc1);<br />
g2.ReleaseHdc(dc2);<br />
<br />
ReleaseDC(hWnd, windowDC);<br />
<br />
return MyImage;<br />
}<br />
<br />
[DllImportAttribute("gdi32.dll")]<br />
private static extern bool BitBlt(<br />
IntPtr hdcDest,
int nXDest,
int nYDest,
int nWidth,
int nHeight,
IntPtr hdcSrc,
int nXSrc,
int nYSrc,
System.Int32 dwRop
);<br />
<br />
[DllImportAttribute("gdi32.dll")]<br />
private static extern IntPtr CreateDC(<br />
string lpszDriver,
string lpszDevice,
string lpszOutput,
IntPtr lpInitData
);<br />
<br />
[DllImportAttribute("User32.dll")]<br />
private static extern IntPtr FindWindow(<br />
string lpClassName,
string lpWindowName
);<br />
<br />
[DllImportAttribute("User32.dll")]<br />
private static extern IntPtr GetWindowDC(<br />
IntPtr hWnd
);<br />
<br />
[DllImportAttribute("User32.dll")]<br />
private static extern IntPtr ReleaseDC(<br />
IntPtr hWnd,
IntPtr hdc
);<br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
struct RECT<br />
{<br />
public Int32 left; <br />
public Int32 top; <br />
public Int32 right; <br />
public Int32 bottom; <br />
}<br />
<br />
[System.Runtime.InteropServices.DllImportAttribute("User32.dll")]<br />
private static extern int GetWindowRgnBox(<br />
IntPtr hWnd,
ref RECT rect
);
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Philip Fitzsimons wrote:
[StructLayout(LayoutKind.Sequential)]
struct RECT
{
public Int32 left;
public Int32 top;
public Int32 right;
public Int32 bottom;
}
OK, tell me, why dont you use the Rectangle struct defined in the .NET framework?
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
1. 'cause it did not occur to me.
2. 'cause I just translated the API directly, I was not trying to be clever
good point.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
No, I was just wondering. In my experience Rectangle and the other Drawing structs have been fine for marshalling. I have seen people this alot though...even MS people
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
are you saying we can re-write this
[System.Runtime.InteropServices.DllImportAttribute("User32.dll")]
private static extern int GetWindowRgnBox(
IntPtr hWnd, // handle to window
ref RECT rect // rectangle
);
to
[System.Runtime.InteropServices.DllImportAttribute("User32.dll")]
private static extern int GetWindowRgnBox(
IntPtr hWnd, // handle to window
ref Rectangle rect // rectangle
);
But wouldn't it be relatively confusing because the last two field actually mean different things (width, height in Rectangle, but right, bottom in RECT)...
|
|
|
|
|
Li-kai Liu (Angus) wrote:
are you saying we can re-write this
No! I was wrong. Thanx for pointing it out. For some strange bizarre reason, my brain recorded wrong info Or maybe I'm thinking of something completely different. I have tried to find it, but it was one of those snippets I wrote for someone, but never saved it. In fact, I found 16 blank WindowsApplictions in my code directory.
CHeers
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
Thanks your guys
I'm playing around with philips's code now. looks pretty nice.
When I tried to spot out the location of Win32windows.zip on
gotdotnet.com, I got lost... not well organized as codeproject
So, leppie, would you mind sending it to my mailbox at
ykliu@email-home.com?
Thanks again
Li-kai Liu
|
|
|
|
|
BTW, is that possible to include the cursor in the captured image??
|
|
|
|
|
I don't believe so, its handled by windows.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
I respect your ideas on this issue. Neither sounds very savory though.
I'd like to do what tools such as WebWasher and other popup and ad killers do. They filter the content before it arrives at the browser.
The two solutions you mentioned sound easier, but I'd rather it was elegant and right. I believe that WebWasher and similar tools modify (sic) IE's proxy setting and all communication is routed through the application.
I may go with something along these lines. It would eliminate some of the headaches that I would experience using Mozilla or the document.load() method.
Thanks again for your response. You've helped me greatly.
- John
|
|
|
|
|
BonTon wrote:
The two solutions you mentioned sound easier, but I'd rather it was elegant and right. I believe that WebWasher and similar tools modify (sic) IE's proxy setting and all communication is routed through the application.
Yes, I haven't talked about the solution where you have a local proxy server that forwards requests and gets pages back from the server.T That's easy code, merely multi-threaded socket. What is the problem here ? Usually it slowers down IE so abruptedly so that you end up uninstallin g it.
It's fun to code (I have done one a couple years ago), but there are side effects in the end.
Besides that, you need to change the IE proxy settings to make sure your proxy gets called, which is likely to raise trouble : I've got a lot of bad feedback about it from users.
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
Hey all,
I'm working on a mid-sized project and trying to do some class modeling. I was wondering if there is a good test that I can use when deciding if I should base a class on an actual interface data type as opposed to just having the class outright. For example, having:
public interface ICustomer{
...
}
public class Customer: ICustomer{
....
}
Is it a good idea to have interfaces (the datatype) for each class we model?
Thanks much
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
C# interfaces are not as great as COM interfaces. COM interfaces were supposed to act like a contract, and by the way do separate the interface from the actual implementation.
Using C# this is no longer true, as there is no more "header" files.
The only thing good about C# interfaces is that your class can derive from more than one interface, whereas your class cannot derive from more than one class (same Java limitation).
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
As C# is currently not having a const keyword for return values, I certainly would make an interface for structures that I want to pass as readonly.
Another thing to consider is whether the implementing structure needs to subclass something other than ICustomer, e.g; CPenquin: public ICustomer and CHuman: public ICustomer...
I also find code more readable when you pass interfaces with a limited number of members.
And last: using interfaces makes your code very flexible.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
You define an interface when you have two or more classes implementing common behavoir.
For example "Customer" and "Supplier" might both implement a IContact interface with methods for setting their address, name etc.
You only want to define an interface when there is more than one class that implements that interface, or if there might be in the future.
|
|
|
|
|
I have to agree with Stephane.
I always try look for places where interfaces will be beneficial, but rarely find such places. One example of the top of my head is for "late-binding". Other than that I find them only really useful in Collections. I'm still pretty new to C# (6 months) so maybe they will start making more sense later.
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
It's only useful when saying "I have two or more very different objects that do the same thing in very different ways, but I want a seperate piece of code to perform that common action regardless of the way te different objects act during that action."
And if that makes no sense, read the other post I just put in this thread
It's not infinitely useful but then neither was COM Interfacing but it was forced on you. This is just a simplification on the grounds that some people might still want this kind of functionality.
In other words, don't look for a place to use it, just remember it's there if you ever stumble upon something complicated like this
Paul
|
|
|
|
|
The usefulness of interfaces is best described (IMO) in terms of ArrayList.Sort().
An ArrayList can hold an array of pretty much any kind of object. So how does it sort them? What is the easiest way to define a function that could be sorting strings, objects, numbers, and so on?
You can't use ToString() because 10.ToString() == "10", 5.ToString() == "5". Thus 10.ToString() < 5.ToString().
So ArrayList.Sort calls IComparible.CompareTo(object obj) on each object to sort them. Thus if you want to do an ArrayList.Sort then all the objects in the ArrayList must implement the IComparable interface or it will not be able to cast it.
eg.
private class SortableObject : IComparable
{
public int CompareTo(object Item)
{
}
} This way I can exactly define how I want one SortableObject to compare to another. ArrayList.Sort doesn't give a damn how I compare them, just that I define a method in the exact format public int CompareTo(object Item) . It is a contract between my object and ArrayList.Sort saying I'll do the comparison, you do the sort.
Paul
|
|
|
|
|
You're right . Interface names such like ICompare, IClonable and stuff like that are in fact useful when searching the MSDN doc for classes with particular features, and as such act as search filters.
In the end, you get faster to what you are looking for. I vote on that a 5.
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
|
Hi,
I have some questions about thread programming in C#:
1. Is there any number limitation for threads
2. When multiple threads are initiated (started), each returning an object array, is there any mechanism I can utilise to check all the threads been finished? What if any of them throws an exception?
Thanks!!
|
|
|
|
|
I am trying to set tags for individual Combobox items. In looking through the Combobox doc, I cannot find the equivalent of SetItemData/GetItemData. The tag property is set at the Combobox level, and not at the item level. Can someone point me to an example, or how to set the tags for invidual combobox items. I would like to store database record ids as tags in the combobox.
Gaulles
Gaulles
Gaulles Technologies, Inc.
http://www.gaulles.com
|
|
|
|
|