|
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
|
|
|
|
|
(generateStart.ThreadState & (ThreadState.Running | ThreadState.Suspended) == ( ThreadState.Running | ThreadState.Suspended)
If you want to check whether either flag is set either split it up into 2 checks, or just see if the result is greater than zero.
You can do the same with a single check as well (generateStart.ThreadState & ThreadState.Running) > 0 .
I didn't mention that earlier because my head was thinking that you couldn't compare an enum in that way, you of course can compare them that way.
James
Simplicity Rules!
|
|
|
|
|
Ok. This is making a bit more sense to me now. It's just like any other bitwise comparison. What I'm confused about is this:
If the state of the Thread is *just* running, then checking if
generateStart.ThreadState == ThreadState.Running
should yield true, right? It's only the case where there's the possibility of the ThreadState having more than one flag set where I must do a bitwise AND comparison of the two, to ensure that at least one of those flags is the "Running" flag.
Isn't this the way it works? Or am I just losing my mind?
- Sabran
|
|
|
|
|
hi
is it possible to change the cell color of a datagrid depending on the values of the cell. like ....suppose i have the datagrid control binded to a table which has profit and loss values. now if it is profit i want to change the cell color to green and red for loss.
please help
prash
|
|
|
|
|
Create a new DataGridColumnStyle and override the Paint methods in it.
James
Simplicity Rules!
|
|
|
|
|
Am I right in thinking I need to derive a class from IDictionary to write a map class ? Does anyone know of any examples ?
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
|
|
|
|
|
Correct, If Hashtable doesn't work for you. There is also DictionaryBase and DictionaryEntry to help you along.
Glad to see your still with us, How did the display resolution change work on your machine?
Regards
|
|
|
|
|
Yes you can derive from IDictionary to write your own map class. However, if you're looking for a simple map class, then the Hashtable class is probably what you need:
Hashtable table = new Hashtable();
table.Add(1, "Chris Maunder");
table.Add(6422, "Christian Graus");
table.Add(232, "Tom Archer");
foreach (DictionaryEntry entry in table)
{
Console.WriteLine("CodeProject ID {0} = {1}",
entry.Key, entry.Value);
}
Cheers,
Tom Archer
Author, Inside C#
Please note that the opinions expressed in this correspondence do not necessarily reflect the views of the author.
|
|
|
|
|
hi
i have a MdiForm which loads a child form on startup and displays the form to the right side. now when i resize the Mdi Form. i want the child form to maintain its right most position to the mdiform.
whatis happening is as soon as i am resizing the right border of the mdiform.....the child form remain in the current position and hence is not right aligned.
the right property of the form is read only....
how do i come to know how much i need to shift the child form to the right or left of the mdi form...depending on the resize?????
please help?
prash
|
|
|
|