|
softwarejaeger wrote: how can i minimize, maximaze, show, hide or close a Window from a Process?
P-Invoke ? If you have the window handle, you can use SetWindowPlacement[^] function to set minimize, maximized or restored states.
|
|
|
|
|
OK, thanks but...
how do i use this in c#? i get everytime a lot of errors
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
struct WINDOWPLACEMENT
{
internal int Length;
internal int flags;
internal int showCmd;
internal System.Drawing.Point ptMinPosition;
internal System.Drawing.Point ptMaxPosition;
internal System.Drawing.Rectangle rcNormalPosition;
}
[DllImport("user32")]
public static extern int SetWindowPlacement(int hwnd, ref WINDOWPLACEMENT lpwndpl);
public class TestClass
{
}
The Debugger told me, that in the line public static extern int a class,delegate or something else is expected, it underlines me the "int"... what to do? And when i delete the int it told me that "extern" isn't valid for this item...
|
|
|
|
|
|
Hi,
Set WindowState property of your form to
FormWindowState.Maximized or
FormWindowState.Minimized for maximizing and minimizing the Form.
Refer to this [^]
To Show/Hide and Close the form, use use Form.Hide/Close/Show.
E.g. to show the current form, use this.Show()
I hope this would be helpful.
John Adams
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
hi
this is about process not about Forms
I see A Code Snippet in vs.net 2008 about this but Not remember that code
tanx
|
|
|
|
|
Importing user32.dll and using ShowWindow function with window handle is another solution:
Here is a piece code u may use:
[System.Runtime.InteropServices.DllImport("User32.dll")]
static extern long ShowWindow(int windowHandle, int nCmdShow);
private const int SM_SHOWMAXIMIZED = 3;
private const int SM_SHOWMINIMIZED = 2;
Always keep the Murphy Rules in mind!
|
|
|
|
|
|
I have used the caching and logging application block. It worked well.
|
|
|
|
|
Hi all,
I've added multiple tab pages in a form and set some data to each using a list view. Basically I've added data to the list view using a open dialog. Initially I'm added data to the tab page one. If I add another data to the form, if the tab page 0ne contain data, want to added data to the next tab page.
How can I do it.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
I dont think I understand your question.
open dialog and get the data.
after dialog closes create a new tab, add it to the tab collection,
add the controls to the tab and load them with data.
Natza Mitzi
|
|
|
|
|
Ok, I'll explain more. On a button click event I add data to a tabpage as follows.
<br />
private void OpenLocalFile()<br />
{<br />
BackgroundWorker backgroundWorkerOpenFile; <br />
OpenFileDialog fd = new OpenFileDialog();<br />
<br />
fd.Filter = "Word File (*.doc)|*.doc|Text File (*.txt)|*.txt|All supported File|*.doc;*.txt";<br />
fd.FilterIndex = 3;<br />
fd.RestoreDirectory = true;<br />
if (fd.ShowDialog(this) == DialogResult.OK)<br />
{<br />
CloseFile();<br />
backgroundWorkerOpenFile.RunWorkerAsync(fd.FileName);<br />
FileInfo fi = new FileInfo(fd.FileName);<br />
tabPage1.Text = fi.Name;<br />
}<br />
}<br />
On the first button click call this function and added data to the tab page 1. In the next click I want to check on the all tab pages and add data to the first empty content tab page.
Hope it's clear now.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hi guys.
I want to put a checkBox in menuStrip.
Do you know how can I do it ?
Thank you
|
|
|
|
|
Mohammad Dayyan wrote: Do you know how can I do it ?
Yes I do. Thanks for asking.
Well you could always set the CheckOnClick property of a menu item to true.
|
|
|
|
|
Oh.I'm sorry for my question.
Pete O'Hanlon wrote: Well you could always set the CheckOnClick property of a menu item to true.
Thank you Pete .
But it doesn't thing that I want.
I want to put CheckBox Control (or Button control) in a menuStrip.
|
|
|
|
|
This class will do what you want - it may need some expanding to expose the checkboxes properties and events you need. You can add more controls to the flowlayoutpanel for a multicontrol control, or change the checkbox for a button or whatever.
using System;
using System.Drawing;
using System.Windows.Forms;
public class CheckBoxToolStripItem : ToolStripControlHost
{
private FlowLayoutPanel controlPanel;
private CheckBox chk = new CheckBox();
public CheckBoxToolStripItem()
: base(new FlowLayoutPanel())
{
controlPanel = (FlowLayoutPanel)base.Control;
controlPanel.BackColor = Color.Transparent;
chk.AutoSize = true;
controlPanel.Controls.Add(chk);
}
public bool Checked
{
get { return chk.Checked; }
set { chk.Checked = value; }
}
public new string Text
{
get { return chk.Text; }
set { chk.Text = value; }
}
protected override void OnSubscribeControlEvents(System.Windows.Forms.Control control)
{
base.OnSubscribeControlEvents(control);
chk.CheckedChanged += new EventHandler(CheckedChanged);
chk.TextChanged += new EventHandler(TextChanged);
}
protected override void OnUnsubscribeControlEvents(System.Windows.Forms.Control control)
{
base.OnUnsubscribeControlEvents(control);
chk.CheckStateChanged -= new EventHandler(CheckedChanged);
chk.TextChanged -= new EventHandler(TextChanged);
}
private void CheckedChanged(object sender, EventArgs e)
{
}
private new void TextChanged(object sender, EventArgs e)
{
}
} You can then create and add your item like this
CheckBoxToolStripItem chk = new CheckBoxToolStripItem();
chk.Text = "ABC";
chk.Checked = true;
menuStrip1.Items.Add(chk);
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Research ToolStripControlHost.
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
Hi all,
I'm looking for an easy way to send message containing String data from C# application to C++ application, using the SendMessage API call.
Please refer to both sending the message and receiving it (in C++).
Thanks a lot!
Eyal.
|
|
|
|
|
are both applications exe ?
|
|
|
|
|
Yes, both Windows applications. One's GUI is written on .NET 2 C# and the second is C++ application with GUI designed using FLTK.
Thank you.
|
|
|
|
|
On the C# side, something like this maybe:
[DllImport("User32", SetLastError = true)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
...
string ManagedString = "A string!";
IntPtr PtrToUnmanagedString = Marshal.StringToHGlobalAnsi(ManagedString);
SendMessage(hwnd, WM_SOMEMESSAGE, IntPtr.Zero, PtrToUnmanagedString);
Marshal.FreeHGlobal(PtrToUnmanagedString);
On the C++ side, handle messages in the app's message loop as usual
(kind of a big topic for here).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
On the C++ side I have lparam of type int. How should I refer to it in order to get my string?
Thanks!
|
|
|
|
|
For the ANSI string sample I showed, something like this:
const char *pANSIstring = (const char *)lParam;
For Unicode, you could change the StringToHGlobalAnsi to
StringToHGlobalUni on the C# side, and on the C++ side, something like:
const wchar_t *pUnicodestring = (const wchar_t *)lParam;
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
The two options you suggested doesn't work: At both cases I get 'Bad Ptr' at the C++ side (I get junk and not string).
Maybe the reason is that each one of the applications (C# and C++) uses different memory space, so passing pointers from one to another is meaningless.
Or am I missing something?
Thanks a lot,
Eyal.
|
|
|
|
|
eyalbi007 wrote: Maybe the reason is that each one of the applications (C# and C++) uses different memory space
You're absolutely right! I'm an idiot
Sorry about that - I totally spaced on the inter-process
requirement.
Looks like oobimoo showed you a solution.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You must use the WM_COPYDATA msg
in the c# proj declare the following
[StructLayout(LayoutKind.Sequential)]
struct CopyDataStruct
{
public IntPtr dwData;
public int dataSize;
public IntPtr data;
}
enum WinMessage
{
WM_COPYDATA = 0x4A
}
class NativeAPI
{
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, WinMessage msg, IntPtr wParam, IntPtr lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string className, string windowName);
}
and when you press a button for example
private void button1_Click(object sender, EventArgs e)
{
string s = "This is a message from sharp";
IntPtr hCWindow = NativeAPI.FindWindow("RECIEVE_DATA", "Recieve_Data");
byte[] tmpStringData = System.Text.Encoding.Unicode.GetBytes(s);
byte[] stringData = new byte[tmpStringData.Length + 2];
Array.Copy(tmpStringData, stringData, tmpStringData.Length);
stringData[stringData.Length - 2] = stringData[stringData.Length - 1] = 0;
CopyDataStruct cds = new CopyDataStruct();
cds.dwData = IntPtr.Zero;
cds.dataSize = stringData.Length;
GCHandle gch_data = GCHandle.Alloc(stringData, GCHandleType.Pinned);
cds.data = gch_data.AddrOfPinnedObject();
GCHandle gch_cds = GCHandle.Alloc(cds, GCHandleType.Pinned);
NativeAPI.SendMessage(hCWindow, WinMessage.WM_COPYDATA, this.Handle, gch_cds.AddrOfPinnedObject());
gch_data.Free();
gch_cds.Free();
}
and in the windowproc of the native app
case WM_COPYDATA:
{
PCOPYDATASTRUCT pcds = (PCOPYDATASTRUCT)lParam;
MessageBox(0, (LPCTSTR)pcds->lpData, _T("CopyData message"), 0);
}
break;
The windowclass name is "RECIEVE_DATA" and the window name is "Recieve_Data" (for use with the find file in c#, although windowclass name may be null)
The default charset for my configuration is unicode. You must use ASCII encoding to get the bytes of the string in the c# code, otherwise
modified on Monday, August 25, 2008 9:39 AM
|
|
|
|