|
I would like to know how to get the handle of the currently active window. I've tried using Findwindow and it works, but i want the whole view of the active window (including the toolbar and menubar) as i would like to create a program to take a screenshot of the active window (something like ALT+PRINTSCREEN but using BitBlt to do the capturing).
|
|
|
|
|
I'm not sure what problems you're having, but the typical way is similar to the following pseudo code:
HWND hWnd = FindWindow(NULL, "MyApp");
RECT rc;
GetClientRect(hWnd, &rc);
HDC hDC = GetDC(hWnd);
HDC hCDC = CreateCompatibleDC(hDC);
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
BitBlt(hCDC, 0, 0, width, height, hDC, 0, 0, SRCCOPY | CAPTUREBLT);
Is this what you're doing (roughly)?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Yeah more or less. Here's the exact code :
hWnd = FindWindow(null, "Form1");
RECT rc = new RECT();
GetWindowRect(hWnd, ref rc);
this.Text = "LEFT" + rc.left + " RIGHT " + rc.right + " TOP " + rc.top;
Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics gr1 = Graphics.FromImage(myImage);
IntPtr dc1 = gr1.GetHdc();
IntPtr dc2 = GetDC(hWnd);
BitBlt(dc1, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, dc2, 0, 0, 13369376);
gr1.ReleaseHdc(dc1);
ReleaseDC(GetDC(hWnd)), dc2);
GC.Collect();
Graphics gr = Graphics.FromHwnd(pictureBox1.Handle);
pictureBox1.Image = myImage;
|
|
|
|
|
Hi,
I´m playing a .wav file through a buffer with CSound. How do I get hold of the actual sound raw data in the buffer in order to do DSP on them? I´ve tried with GetBuffer(), but I can't get it to work.
/Thanks
|
|
|
|
|
hi, how i can achieve functionality of Gantt Chart like in MS Project using C#..is ther any library...or i have to code it separately..? pls tell me soon..-bhavin
|
|
|
|
|
I would hope that you searched the Internet first. A search of "gantt chart C#" on google yielded many results, including one here on CodeProject that mentioned Dundas, one of the sponsers of CodeProject and admittedly a decent library development company.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
thanx for the reply Heath. u r right...i searched on the net first...but i found so many links which has their own library..i mean all are third party controls..while i want to use it in my academic project..so, if any library of C# is available then it would help me..otherwise i will have to create the component..which takes time...
pls tell me if u have any idea for that..and yeah..i want to create network diagram also...so, what should i do? i have to create component or default library facility is there...if yes then please give me the details...thanx again..
-bhavin
|
|
|
|
|
What's wrong with using a library? That's the whole point of libraries - reuse.
Besides, if you include the code in yours and the code is copyrighted (and it most likely is), you run the chance that 1) you get sued, 2) you fail the course and / or are expelled from school (most schools will), and 3) you're going against everything OOD and shared libraries stand for.
If you're assignment is to create a Gantt chart, then what you want to do is cheating and I won't be party to that. If you only need to use a Gantt chart for your assignment, then just use a library. There are free ones out there and you should simply use the assembly. .NET assemblies (of these nature) don't require any installation, so any copy operations that the TAs require should just grab the assembly in which the Gantt chart is created. My old university's turn-in script let us upload all appropriate files, be they source or libraries (back then, only C/C++ static and dynamic libs).
You should talk to your TA or professor if you have concerns about using a third party control. If you hesitate because they might fail you for cheating, then you definitely shouldn't use it and start looking for information on programming basic grids and lines (which really isn't that hard for a basic Gantt chart).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
What's the difference between destructor and finalize? And is there any way that I can step thru code in destructor or finalize?
Thanks!
norm
|
|
|
|
|
norm wrote:
What's the difference between destructor and finalize?
Whatever code you put into your destructor would get renamed to a method called Finalize in the generated IL. There is a method generated called __dtor which is the actual class destructor and which can be thought to look something like this (imaginary projection only and not to be taken as it is) :-
void __dtor()
{
GC::SuppressFinalize(this);
Finalize();
}
protected virtual void Finalize()
{
}
Regards
Nish
Extending MFC Applications with the .NET Framework [NW] (My book with Tom)
Summer Love and Some more Cricket [NW] (My first novel)
Shog's review of SLASMC [NW]
Come with me if you want to live
|
|
|
|
|
Thanks, but why'd do we need destructor then? I mean, all the code in destructor will be transferred to Finalize() in IL anyway.
Also, when I tried to implement Finalize in my C# class, i got this CS0249 error, the compiler wont let me implement/declare Finalize?? Anyway, here is an extract from MSDN:
*************************************************************
QUOTE MSDN:
Do not override object.Finalize. Instead, provide a destructor.
Use destructor syntax to specify instructions to execute when your object is destroyed.
See Using C# and Managed C++ Destructor Syntax for more information.
The following sample generates CS0249:
// CS0249.cs
class C
{
protected override void Finalize() // CS0249
// try the following line instead
// ~C()
{
}
public static void Main()
{
}
}
norm
|
|
|
|
|
In a Garbage Collected programming environment like the CLR, it's not very smart to put clean-up code in the destructor because you do not have much control over when it gets called. MS recommends that you implement IDisposable and put all your clean up code in the Dispose method. And as for the error you got, the C# compiler wont let you implement Finalize because they rename the class Destructor method to Finalize in the generated IL.
Nish
Extending MFC Applications with the .NET Framework [NW] (My book with Tom)
Summer Love and Some more Cricket [NW] (My first novel)
Shog's review of SLASMC [NW]
Come with me if you want to live
|
|
|
|
|
I want to make sure all threads of the application is aborted before the object goes out of scope. Now, I'm writing a control. I do not want to place the burden to call Dispose in my client's code since it's a UI control that I'm writing. The remaining choice is destructor. I pretty much gave up on Finalize because compiler keep bugging me. The only remaining option is:
~myclass()
{
if(m_Thread.ThreadState!=System.Threading.ThreadState.Stopped)
m_Thread.Abort();
... the rest of it...
}
What can I do in a destructor in .NET - besides releasing memory? I know I can't even Console.Write() in a destructor with .NET (although that won't generate a bug) - same applies for Thread.Abort()??
norm
|
|
|
|
|
If your threads have the IsBackground property set to ture, when all foreground threads are terminated the background threads will automatically be aborted.
norm wrote:
What can I do in a destructor in .NET - besides releasing memory?
Not much, basically you can only use value types. Typically you use a destructor in .NET for freeing unmanaged resources, which are typically held by an IntPtr to represent the handle returned by windows.
James
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
|
I am trying to use a c++ api from C# code. I know how to import DLL's, and also about tlbimp, but what is the mechanism for importing a .lib file.
Thanks
Trevoe
|
|
|
|
|
I guess you need to wrap your lib API into Managed C++ lib (assemblies)? This is what I will do.
Not sure of this. Would like to find out as well.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
I have 2 binary numbers, NO. I have 1 binary number...
01010011
Now, how would I convert that to hex? I.E. (53)
convert this bin number...
11111111
into this... (FF)??
/\ |_ E X E GG
|
|
|
|
|
Convert class may be useful for you. If not, maybe you have to write your own convertor
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Hex numbers are composed of 4 bits, since 1111 = F so you need to split the bitstring into pieces of 4 bits wide. Then you need to find the decimal value of these bits. Next you look if the value is < 10 if not then you will need to assign a letter A-F to the value and append that to your result. Else you can simply convert the number to text and append that to your result. The problem you will probably ecounter is that the string is not big enough to split into pieces that all are 4 bits wide. You can simply solve that with a check if(bitString.Length % 4 != 0) .... this will indicate that the string is not long enough!
ArrayList strings;<br />
string result = "";<br />
int tempValue;<br />
int counter;<br />
<br />
strings = new ArrayList();<br />
<br />
for(int i = 0; i < bitString.Length; i += 4)<br />
{<br />
strings.Add(bitString.Substring(i,4)); <br />
}<br />
<br />
<br />
foreach(string bits in strings)<br />
{<br />
tempValue = 0;<br />
counter = 1;<br />
<br />
for(int j = bits.Length-1; j > 0; j--)<br />
{<br />
if(bits[j] == '1')<br />
{<br />
tempValue += counter;<br />
}<br />
<br />
counter *= 2;<br />
} <br />
<br />
if(tempValue < 10)<br />
{ <br />
result += tempValue.ToString();<br />
}<br />
else<br />
{<br />
switch(tempValue)<br />
{<br />
case 10:<br />
result += "A";<br />
break;<br />
case 11:<br />
result += "B";<br />
break;<br />
}<br />
}
I am sorry for you if there are any mistakes in the code above. This code was written in approx. 30 seconds and not tested. Good luck!!
Greetings....
|
|
|
|
|
When I right-click on a node in my treeview, is it possible to find out which node I clicked? The TreeView.SelectedNode wont work because apparently, you need to left click to select a node.
So, any pointers?
God, I pity me! - Phoncible P. Bone
If I end up Windows ME someone is going to be hurting. - One of the answers to a question for What OS are you
|
|
|
|
|
Hi,
The first thing that you need to do is add an oncontextmenu statement on your treeview control there are 2 ways to do that.
1) Go into Design view and add this statement to the treeview
oncontextmenu="javascript: showMenu(this); return false;"
2) Go into your CS code and add an attribute to use the function below
this.TreeView1.Attributes.Add("oncontextmenu","showMenu(this)");
Now here is some code:
function showMenu(Item)
{
var NodeSelected = document.getElementById(Item.id).getTreeNode(event.treeNodeIndex);
var NodeLevel = new Number(event.treeNodeIndex)
var ParentNode = document.getElementById(Item.id).getTreeNode(event.treeNodeIndex).getParent();
var NodeType = "";
var strTreeNodeIndex = "";
strTreeNodeIndex = new String(NodeSelected.getNodeIndex());
NodeType = new String(NodeSelected.getAttribute("type") );
NodeType = NodeType.toUpperCase();
alert("The Node type is " + NodeType + " The Node text is " + NodeSelected.getAttribute("text") );
}
this should get you started
|
|
|
|
|
Um, that'd work for ASP.NET, but he never mentioned that he was using ASP.NET. And, since this is the C# forum and not the ASP.NET forum, you should take that into consideration.
The answer in Windows Forms uses hit tracking. Handle the TreeView.MouseUp event. In the handler, check to see if the right mouse button was clicked (don't worry about lefties - Windows swaps the left and right mouse messages so developers don't have to worry about it) using Control.MouseButtons == MouseButtons.Right . If that condition is true, get the position of the mouse click from the event arguments and get the node that was clicked using TreeView.GetNodeAt after translating the point accordingly since the X and Y coordinates of the click are relative to the form.
Example:
public class MyForm : Form
{
private TreeNode activeNode;
private void myTreeView_MouseUp(object sender, MouseEventArgs args)
{
if (MouseButtons == MouseButtons.Right)
{
Point p = new Point(args.X, args.Y);
p = this.myTreeView.PointToClient(p);
this.activeNode = myTreeView.GetNodeAt(p);
}
}
}
Then just use the activeNode field for your context menu items' Click handlers or in the context menu's Popup event handler (to enable, disable, or change menu items).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks, this is exactly what I needed!
God, I pity me! - Phoncible P. Bone
If I end up Windows ME someone is going to be hurting. - One of the answers to a question for What OS are you
|
|
|
|
|
Ummm...Thanks for the prompt reply. I probably should've said I was using Windows Form
God, I pity me! - Phoncible P. Bone
If I end up Windows ME someone is going to be hurting. - One of the answers to a question for What OS are you
|
|
|
|