|
This code:
IntPtr hWnd = (System.IntPtr)uint.Parse(args[1]);
Graphics g = Graphics.FromHwnd(hWnd);
Control previewWindow = Control.FromHandle(hWnd);
Rectangle rect = previewWindow.ClientRectangle;
SolidBrush brush = new SolidBrush(Color.Orange);
g.FillRectangle(brush, rect);
Gives me a Null reference error, leading me back to the belief that I am unable to parse the hWnd in a meaningful manner.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
leading me back to the belief that I am unable to parse the hWnd in a meaningful manner
If this statement was true, my code wouldn't be running...
Take a look at the API definition I posted to the other part of this thread.
Regards
|
|
|
|
|
It's obviously working for you, but are you doing it in the context of the screensaver preview ? If you are, then I have no idea why I cannot get it to work for me. If I have a valid HWND in my variable, why can't I use the code I posted to get it into a control ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Yes, I am drawing in the context of the preview from the screen saver tab of the desktop properties.
I am not using a control, you don't need it in the preview mode.
|
|
|
|
|
Well, in that case, you're obviously a better man than I am. Could you please zip the project and mail it to me so I can have a look at it and figure out what I am missing ?
Thanks.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
You have mail...
Just a quick app made from pieces I gutted from mine, and enough to show the steps involved to draw in the property sheets preview.
I would suggest separating your drawing code from your form and calling it from both the preview mode and your full display mode.
Regards
|
|
|
|
|
Christian Graus wrote:
why can't I use the code I posted to get it into a control ?
The Control was just used to get away from making a direct call into unmanaged land. I forgot to say that in my original post though
James
Simplicity Rules!
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[DllImport("user32.dll")]
private static extern int GetClientRect(IntPtr hWnd, ref RECT rect);
|
|
|
|
|
In the course of recent enlightenment I have a better solution that will reuse your form as is…
In the preview mode (/p) do this:
if (IntPtr.Zero != hWnd)
{
Application.Run(new MainForm(hWnd));
}
In your form class do this:
private IntPtr parentWindow;
public MainForm(IntPtr parent)
{
parentWindow = parent;
if (IntPtr.Zero != parent)
this.TopLevel = false;
.
.
.
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Parent = parentWindow;
return cp;
}
}
Works like a champ!
|
|
|
|
|
Use the DllImport attribute found in the System.Runtime.InteropServices namespace.
You may also have to use the StructLayout and MarshalAs attributes if you need to pass structures around.
HTH,
James
Simplicity Rules!
|
|
|
|
|
Is C# using the same pseudo generator to generete random numbers like Visuial C?
thanx
|
|
|
|
|
No it doesn't; I can't post the code but you can compare it yourself to verify. The rand function in the CRT doesn't use an array while the .NET version does.
James
Simplicity Rules!
|
|
|
|
|
Hi,
I want to use the ICatInformation Interface in a C# project, but am having a little difficulty.
The header file is comcat.h in the SDK and you can compile the comcat.idl using the MIDL compiler to produce the type libuary msclus.tlb, but i can not import this as a refernece because it is not registered in the registry, so I thought use the msclus.dll but this does not containt the definition or Implementation for ICatInformation.....
So how do i get this interface into C#?
Cheers
Ollie
|
|
|
|
|
Hi all - I've been looking around for a way to disable the "x" (close button) at the top right of every Form. I'd like a way to "gray" (disable) it or, even better, a way to remove it completely. I'd like to keep the minimize/maximize buttons however.
I realize I could use the Closing event to make it so a user can't close a window until certain conditions are met, but that isn't satisfactory.
Any help would be appreciated. Thanks.
- Sabran
|
|
|
|
|
DISCLAIMER: Like most workarounds, This is going outside the .NET Framework "Box", so it may break in the future....
Set the ControlBox property to false and then add this code to your form derived class.
const int WS_SYSMENU = 0x00080000;
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style |= WS_SYSMENU;
return cp;
}
}
|
|
|
|
|
Yet, an alternative method.
const uint MF_BYCOMMAND = 0x00000000;
const uint MF_GRAYED = 0x00000001;
const uint MF_DISABLED = 0x00000002;
const uint SC_CLOSE = 0xF060;
[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool revert);
[DllImport("user32.dll")]
private static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
protected override void OnLoad(
EventArgs e
)
{
base.OnLoad(e);
IntPtr hMenu = GetSystemMenu(Handle, false);
if (IntPtr.Zero != hMenu)
{
EnableMenuItem(
hMenu,
SC_CLOSE,
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED
);
}
}
|
|
|
|
|
And another...
const int CS_NOCLOSE = 0x0200;
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ClassStyle |= CS_NOCLOSE;
return cp;
}
}
|
|
|
|
|
Thanks for all the solutions. I haven't tried them yet, but once I do, I'll let you know how it goes. Would you mind explaining the difference in the solutions you presented to me? Also, is there a place I could learn this? Like, how'd you find out all those hex values? Thanks.
- Sabran
|
|
|
|
|
Sabran wrote:
Like, how'd you find out all those hex values? Thanks.
From the header files
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
Solution #1: I don't like the method as it is using undocumented behavior, or I haven’t seen any documentation on why it should work. Tell you the truth; I was surprised it did work.
Solution #2: Explicitly disables the close menu item in the system menu for the window (by force), pretty standard stuff in the WIN32 world and documented in MSDN. In .NET Terms it is the WIN32 equivalent of "MenuItem.Enabled = false;".
Solution #3: Modifies the class style that is latter used in a WNDCLASSEX structure in the call to RegisterClassEx (internal to the Framework). Again standard stuff in the WIN32 world and also documented in MSDN.
Solution #2 & 3 are by far the most stable. I personally like #3.
Like Nish said, a quick "Find in Files" on the Platform SDK to get the values for the C# definitions.
Actually, I have started using MC++ for most of my C# -> WIN32 glue; it is a major time saver.
Regards
|
|
|
|
|
Thanks so much for the explanation. It helps me a lot.
Can you explain what you mean by "Find in Files" on the Platform SDK? I'm actually downloading the SDK as we speak.
I'm a fairly experienced C++ programmer, but Windows programming is really new to me. You told me that some of your solutions are "standard stuff"... is there a place I can take a look at a listing of all these standards? Then I might not have to post so many questions.
When you say you're using MC++ for most of your C# -> WIN32 glue, do you mean VC++? If not, what is MC++?
Sorry I have so many questions. But I'm a curious guy.
- Sabran
|
|
|
|
|
In the IDE, you have the capability to do a find (search for text) on the file system. What I meant, was to do such a search on the Platform SDK's header files.
MC++, I will quote from MSDN...
Managed Extensions for C++ are a set of language extensions to C++ that help Visual C++ developers write .NET Framework applications. Managed Extensions allow you to intermix traditional unmanaged and managed C++ code within the same application.
Regards
|
|
|
|
|
Hi all. I'm a bit new to threads and I'm having a rather strange problem.
I'll post a snippet of code here just to help explain what I mean.
/* BEGIN CODE */
Thread generateStart = new Thread(new ThreadStart(gen.generateLevel1IP));
generateStart.Start();
pDlg.Show();
while (generateStart.ThreadState == ThreadState.Running)
{
pDlg.labelThread.Text = generateStart.ThreadState.ToString();
pDlg.Update();
}
pDlg.finishUp();
/* END CODE */
pDlg is a System.Windows.Forms.Form derived class, and gen is just a class I've created (that makes use of the pDlg form). Here's the problem - I'm getting VERY inconsistent results.
On some occassions, the pDlg form appears locked - I can't move the window arround. None of the fields are being updated. I have to force the program to quit.
On other occassions, the pDlg.finishUp() function is called, even though the thread is still running! I can tell this because other fields in pDlg are being updated by the thread after the pDlg.finishUp() function has finished execution.
Interestingly, if I stick a MessageBox.Show() call in the middle of the while loop, it *ALWAYS* executes pDlg.finishUp() BEFORE the thread has completed.
Any help would be appreciated. I have no idea what's going on.
- Sabran
|
|
|
|
|
ThreadState is a set of flags, so you need to check for
(generateStart.ThreadState & ThreadState.Running) == TheadState.Running
HTH,
James
Simplicity Rules!
|
|
|
|
|
Oh, all right. Thanks. How then would I check for multiple flags set? Like, if I wanted to check if it were Running and Suspended (not that this is useful, but I'd like to know just for learning's sake.
Would it be:
(generateStart.ThreadState & ThreadState.Running & ThreadState.Suspended) == (ThreadState.Running & ThreadState.Suspended))
Is that right? Or is there an easier way?
- Sabran
|
|
|
|