|
In this case I doubt that you'll succeed with any of these approaches.
You see, the DataGrid is responsible for drawing the column headers according to their current texts, but I don't think the developers took multiline headings into consideration.
That's why you get blanks where your not-printable characters ('\n', '\r') are.
In order to achive multiline headings you'd have to perform drawing of the DataGrid column headers by yourself (perhaps you're able to do this using P/Invoke, I'm not sure).
Anyway: My suggestion would be _not_ to use multiline headings. Headings are used to give the user a short information what the contents of a column are. You're not supposed to write lengthy texts there.
mav
|
|
|
|
|
I am trying to develop the following functionality. The user selects a button. In the on-click event I then want to bring up a new web page (small one) that contains a dropdowm list box. This list box would be bound to a data base. When the user selects an item the page disappears. I then work with the data that was selected.
How do I do this?
Thanks in advance
|
|
|
|
|
Try the ASP.NET[^] forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi.
Any of you have an working exampel of the function mmioInstallIOProcA??
|
|
|
|
|
Never mind..... made it work.
But thanks anyway.
|
|
|
|
|
I want to track the mouse position by drawing a line or cross at the location of the pointer.
What I can't figure out is how to erase the previous location from the display.
In other languages I would have done used a XOR pen but I can't find the same thing in C#.
I want the behavior to be something similar to the tracking line when panels are resized.
Thanks,
Eric
|
|
|
|
|
Hi, Im having trouble creating an rtp header at the moment as I need to convert a short into a 2 bytes for the sequence number!
I have tried going to an string them byte but this then produces 5 bytes not 2! and also using the Convert class but this only converts to a single byte!
How do I go about this?
Many thanks, Mat
|
|
|
|
|
Try BitConverter.GetBytes
|
|
|
|
|
Hi!
I am wondering about the c# code-technique "using".
As I understand, when the program leaves the using-block, the resourse defined whith the statement is disposed. In that case the two cases below should be identical:
//*** Case 1: (without myConnection.Close()) ***//
using(SqlConnection myConnection = new SqlConnection(sConnectionString))
{
SqlCommand myCommand = new SqlCommand("GetUsers", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
//Fetch data
}
//*** Case 2: (with myConnection.Close()) ***//
using(SqlConnection myConnection = new SqlConnection(sConnectionString))
{
SqlCommand myCommand = new SqlCommand("GetUsers", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
//Fetch data
myConnection.Close();
}
Can anyone confirm that there is no defferences between the who. Case 1 just seems a bit dangerous to me
Thanx!
/Paul
|
|
|
|
|
I think you are asking two questions:
1.
using (SqlConnection myConnection = new SqlConnection(sConnectionString))
{
}
is equal to
SqlConnection myConnection;
try {
myConnection = new SqlConnection(sConnectionString);
} finally {
if (myConnection != null)
myConnection.Dispose();
}
This works good and you can trust in it
2. The other question is if a Dispose call on a SqlConnection is going to close it and yes it does.
|
|
|
|
|
Hi
I want to write a program that use notifyicon but i don't want to use a form container . i create a console aplication and use a notifyicon !
everything was well but my icon does not responce events ?
my goal is to prevent showing a form and reduce memory usage .
how can reach this ?
Thanks Amir Jalaly
|
|
|
|
|
|
Hello,
I have a C# WMEncoder application which is using a C++ transform plugin(DirectShow), I would like to send additional information to the filter and recieve information from the filter.From the filter I can use the SendMessage() function, but how can I send information to the filter?
I tried to create another c++ com, where I give it the IUnknown of the filter(thru a property of the com I created) and use the QueryInterface() method(in a method called SetEvent() I created in the com) inorder to use the IMyInterface of the filter but I get an error trying to use it in C#:
"Object reference not set to an instance of an object"
|
|
|
|
|
While your explanation could use a little bit of elaboration, do make sure that you're accessing an instance of the COM object and not creating another one. This can be tricky in .NET. In your native application you could add an instance of your DMO to the RunningObjectTable (ROT; fairly easy in native code) and then get it out in your managed application using Marshal.GetActiveObject(string progId) (so make sure to register your COM object class with a ProgID).
Note that you can also send information to the filter using SendMessage , but you must P/Invoke it. The generic signature follows:
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int msg,
IntPtr wParam,
IntPtr lParam); Depending on the message parameters and return code, you can redefine this a little differently. If you must pass a pointer to a struct, for example, you can do the following (since a pointer to a struct is the size of an IntPtr ):
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int msg,
IntPtr wParam,
ref MyStruct lParam); What QueryInterface method are you using? Marshal.QueryInterface ? Please post some example code.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
About the sendmessage() explenation, I can use that function in my filter but I want the function to respond to data I send from the C# application to the filter, I dont know how to recieve that information in my C++ filter so I tried to write another native com which will be the mediator, where I send that com the pointer to the IUnknown of the filter that I retrieve in my encoder application using GetTransformPlugin function of the IWMEncTransform object, when I try using that I get the error:
"Object reference not set to an instance of an object".
I also tried a different way inorder to avoid using another com:
Trans is my IWMEncTransform object, and I use
IntPtr s1 = Marshal.GetIUnknownForObject(Trans.GetTransformPlugin());
To retrieve it's IUnknown interface.
Now I'd like to pass that IUnknown as an argument to Queryinterface function:
IntPtr ptr;
Marshal.QueryInterface(s1, ref guid, out ptr);
The question is what's my guid?
I tried to obtain my filter guid from its implementation code (C++), where it says:
// {bc4ed075-019c-4ba1-b69c-4ddd80e562a8}
DEFINE_GUID(IID_IMycamfilterapp,
0xbc4ed075, 0x19c, 0x4ba1, 0xb6, 0x9c, 0x4d, 0xdd, 0x80, 0xe5, 0x62, 0xa8);
Therefore I wrote:
System.Guid guid = new Guid(0xbc4ed075, 0x19c, 0x4ba1, 0xb6, 0x9c, 0x4d, 0xdd, 0x80, 0xe5, 0x62, 0xa8);
Marshal.QueryInterface(s1, ref guid, out ptr);
The code has no warnings/errors, but 'ptr' gets the value '0', which is obviously wrong.
Do you have any suggestion to get it work?
Do you think I should use a different approach in order to obtain my transform filter interface?
All I'm looking for is a simple way to send some information to my filter while it's running.
|
|
|
|
|
Hello everyone
I have written a little app to manage certificates.
Now getting the PRIVATE key from the certificate is, quick, simple and straight forward... but I just get a constant result for the Public Key...
here is an example (I have vut out most of the PVK, but you get the drift )
<result>
Public Key
<rsakeyvalue><modulus><exponent>AA==
Private Key
<rsakeyvalue><modulus>23aDb/XXXXXXXXXXXXXXXXXX+......=
Here is the code I have to get the Public key
<br />
using System;<br />
using CAPICOM;<br />
using System.Security.Cryptography;<br />
using System.Security.Cryptography.X509Certificates;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Forms;<br />
using System.Text;<br />
<br />
namespace CertificateManager<br />
{<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct PUBKEYBLOBHEADERS <br />
{<br />
public byte bType;
public byte bVersion;
public short reserved;
public uint aiKeyAlg;
public uint magic;
public uint bitlen;
public uint pubexp;
}<br />
<br />
public class PublicKey<br />
{ <br />
const uint CERT_SYSTEM_STORE_CURRENT_USER = 0x00010000;<br />
const uint CERT_STORE_READONLY_FLAG = 0x00008000;<br />
const uint CERT_STORE_OPEN_EXISTING_FLAG = 0x00004000;<br />
const uint CERT_FIND_SUBJECT_STR = 0x00080007;<br />
const uint X509_ASN_ENCODING = 0x00000001;<br />
const uint PKCS_7_ASN_ENCODING = 0x00010000;<br />
const uint RSA_CSP_PUBLICKEYBLOB = 19;<br />
const int AT_KEYEXCHANGE = 1;
const int AT_SIGNATURE = 2;<br />
static uint ENCODING_TYPE = PKCS_7_ASN_ENCODING | X509_ASN_ENCODING ;<br />
<br />
[DllImport("crypt32.dll")]<br />
public static extern bool CryptDecodeObject(<br />
uint CertEncodingType,<br />
uint lpszStructType,<br />
byte[] pbEncoded,<br />
uint cbEncoded,<br />
uint flags,<br />
[In, Out] byte[] pvStructInfo,<br />
ref uint cbStructInfo);<br />
<br />
<br />
private byte[] _modulus;<br />
private byte[] _exponent;<br />
<br />
public byte[] Modulus<br />
{<br />
get{return _modulus;}<br />
set{_modulus = value;}<br />
}<br />
<br />
public byte[] Exponent<br />
{<br />
get{return _exponent;}<br />
set{_exponent = value;}<br />
}<br />
<br />
public PublicKey(X509Certificate cert)<br />
{<br />
byte[] publickeyblob = null;<br />
byte[] encodedpubkey = cert.GetPublicKey();
<br />
uint blobbytes=0;<br />
<br />
if(CryptDecodeObject(ENCODING_TYPE, RSA_CSP_PUBLICKEYBLOB, encodedpubkey, (uint)encodedpubkey.Length, 0, null, ref blobbytes))<br />
{<br />
publickeyblob = new byte[blobbytes]; <br />
MessageBox.Show(Encoding.ASCII.GetString(publickeyblob));<br />
}<br />
<br />
<br />
PUBKEYBLOBHEADERS pkheaders = new PUBKEYBLOBHEADERS() ;<br />
int headerslength = Marshal.SizeOf(pkheaders);<br />
IntPtr buffer = Marshal.AllocHGlobal( headerslength);<br />
Marshal.Copy( publickeyblob, 0, buffer, headerslength );<br />
pkheaders = (PUBKEYBLOBHEADERS) Marshal.PtrToStructure( buffer, typeof(PUBKEYBLOBHEADERS) );<br />
Marshal.FreeHGlobal( buffer );<br />
<br />
<br />
<br />
byte[] exponent = BitConverter.GetBytes(pkheaders.pubexp);
Array.Reverse(exponent);
this.Exponent = exponent;<br />
<br />
<br />
int modulusbytes = (int)pkheaders.bitlen/8 ;<br />
byte[] modulus = new byte[modulusbytes];<br />
try<br />
{<br />
Array.Copy(publickeyblob, headerslength, modulus, 0, modulusbytes);<br />
Array.Reverse(modulus);
this.Modulus = modulus;<br />
<br />
}<br />
catch(Exception)<br />
{<br />
}<br />
}<br />
}<br />
}<br />
<br />
Can anyone tell me why I am getting such an odd result for the public key?
Hope someone can shed some light on this, as it's been driving me nuts!
Thanks in advance!
|
|
|
|
|
Hi,
I have a need to update an MSDOS app that runs on a server. I would like to be able to stop the app, update and start it again and then send a NETSEND message to users during this process to notify of an update.
How can I stop (Kill) an app from within a second DOS app?
How can I send a NETSEND message from within a DOS app?
How can I start (execute) a DOS app?
Thanks for all the help.
Stephen
|
|
|
|
|
FYI, if you're running an application Windows NT it's not DOS but DOS emulation.
There are many ways of starting and stopping applications, but very few ways of doing it remotely. You can use WMI (see the System.Management namespace documentation[^] for the classes and examples) to stop and start applications remotely. Updating the application - if you mean copying new files to it - is easily achieved through setting up a share with an ACL that allows your domain user to copy to it and simplying using File.Copy :
File.Copy("srcfile.txt", "\\myserver\myshare\destfile.txt"); The file classes in the .NET BCL work with UNC paths like you see above.
Normally on a local machine you can use the Process class to both start and stop executables:
Process[] procs = Process.GetProcessesByName("dosapp.exe");
if (procs != null && procs.Length > 0)
{
Process proc = procs[0];
proc.Kill();
}
Process.Start("c:\path\dosapp.exe", "-server"); This approach wouldn't work remotely, however, which is where WMI comes in. You could use this approach, however, if you implemented a server - perhaps hosted by a Windows Service or just some persistent application on the server - but that may be more work than what's necessary especially if WMI can do it (assuming that the target computer has WMI installed and the service running).
For a nifty add-in for VS.NET 2003 (and a version is available for 2002), download the Management (WMI) Extensions for Visual Studio .NET 2003 Server Explorer[^]. This allows you to browse and create typed classes for WMI classes - and handle WMI events - from within VS.NET. With this, you'd simply expand the Server Explorer, expand your machine, then the "Management Classes" node, find "Processes", and drag it to your form or control. This creates a class that allows you to enumerate instances on your or another machine, and to create new processes on your or another machine.
To manual way requires a little extra coding:
using System;
using System.IO;
using System.Management;
class Computer
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Usage();
Environment.Exit(1);
}
string machine = null;
string cmdLine = null;
foreach (string arg in args)
if (arg.ToLower().StartsWith("-m"))
machine = arg.Substring(3);
else
cmdLine = arg;
if (cmdLine == null)
{
Console.Error.WriteLine("Error: missing command line.");
Usage();
Environment.Exit(1);
}
try
{
Computer comp = new Computer(machine);
foreach (string proc in comp.GetProcessNames())
Console.WriteLine(proc);
comp.CreateProcess(cmdLine, null);
}
catch (Exception ex)
{
Console.Error.WriteLine("Error: " + ex.Message);
Environment.Exit(1);
}
}
static void Usage()
{
Console.Error.WriteLine("Usage: {0} [-m remoteMachine] \"executable[ " +
"<command line arguments>]\"", Path.GetFileName(
Environment.GetCommandLineArgs()[0]));
}
string computer;
public string ComputerName
{
get { return computer; }
}
public Computer() : this(null)
{
}
public Computer(string name)
{
computer = name;
}
public string[] GetProcessNames()
{
Initialize();
ObjectQuery query = new SelectQuery("Win32_Process", null,
new string[] {"Name"});
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
scope, query);
ManagementObjectCollection processes = searcher.Get();
string[] procs = new string[processes.Count];
int i = 0;
foreach (ManagementObject proc in processes)
procs[i++] = proc["Name"] as string;
return procs;
}
public void CreateProcess(string commandLine, string workingDirectory)
{
if (commandLine == null)
throw new ArgumentNullException("commandLine");
Initialize();
ManagementPath path = new ManagementPath("Win32_Process");
ObjectGetOptions options = new ObjectGetOptions(null,
TimeSpan.FromSeconds(30d), true);
ManagementClass procClass = new ManagementClass(scope, path, options);
ManagementBaseObject inParams = procClass.GetMethodParameters("Create");
inParams["CommandLine"] = commandLine;
if (workingDirectory != null)
inParams["CurrentDirectory"] = workingDirectory;
ManagementBaseObject outParams = procClass.InvokeMethod("Create",
inParams, null);
int retVal = (int)outParams["ReturnValue"];
switch (retVal)
{
case 2:
throw new Exception("Access denied");
case 3:
throw new Exception("Insufficient privilege");
case 9:
throw new Exception("Path not found");
case 21:
throw new Exception("Invalid parameter");
default:
throw new Exception("Unknown failure");
}
}
ManagementScope scope;
bool initialized;
void Initialize()
{
if (!initialized)
{
string scope = computer == null ? string.Empty :
@"\\" + computer + @"\";
scope += @"root\cimv2";
this.scope = new ManagementScope(scope);
initialized = true;
}
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Can C# support a MS Access Database??
David J Harmon
|
|
|
|
|
Yes.
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
Yes. Use ADO.NET's OleDb* classes with a connection string for your Access database, which you can check here[^].
If you don't know how to use ADO.NET, there are several articles here in CodeProject about it. Just search this site or try here[^].
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Thanks Luis for the info, I wanted to use Access database. I guess if I had to I could us SQL.
Thanks again
David J Harmon
|
|
|
|
|
Cappuccino_David wrote:
I guess if I had to I could us SQL.
You can have the same code use either SQL Server/MSDE or Access if you use the OleDb* classes. You only need to change the connection string.
If you use the Sql* classes you'll get better performance, but will be limited to SQL Server.
Good luck!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I am having an interesting situation. I have some a run-time control that is parented to a child run-time control on the main form. When I minimize the form, and then maximize it again, the child control is not entirely displayed. The display for all of the controls, parents and children is fine at the beginning when the application is initially run. However, when the form is minimized and then maximized again, all that is displayed is the part of the child control that is visible inside the parent control. What could be the possible reason? What is going on that is causing only part of the children to be displayed? Is it related to repainting the control.
Does the clipping rectangle have anything to do with why all of the child controls are not displayed when the form is re-maximized? Is there any form of onMaximize(), that could control the event for maximizing the form?
Also, regarding the .NET approach to double-buffering using this.SetStyles(ControlStyle.DoubleBuffer, true), and the other two required commands, would including them more than once increase the buffering capacity? Is there perhaps some way of getting a quadruple buffer to help reduce the flicker of run-time controls?
As an example, for flicker, open up Visual Studio and open up a project. Then press Ctrl-Alt-Delete and open up the Task Manager. Drag the Task Manager around the screen. It leaves a trail of window ghosts. How would I prevent these ghost imprints from being left on one control by either other forms or by other controls, unless there is a capacity to increase the buffering?
|
|
|
|
|
Read the documentation for the ControlStyles.DoubleBuffer enumeration member. You must also specify ControlStyles.AllPaintingInWmPaint and ControlStyles.UserPaint for it to be effective, and that will only be effective if you are painting controls yourself.
Most of the Windows Forms controls encapsulates the native Windows Common Controls - the very controls you see most other applications using including Windows itself - so they are already drawn about as efficiently as possible. Double-buffering your canvas often won't change their drawing behavior at all. If you're noticing flickering, chances are that your computer isn't exactly up to par. No offense.
It could also be that you're responding to an event like the Paint event in your application and performing rather long operations. The Paint event handler (or overriding OnPaint for extended controls, which is a faster and better approach) happens in the main thread depending on the circumstances, so any operations you do block the main thread.
Regarding your resize problem: how are you positioning the controls? Just laying controls out on the container and even setting a mix of Dock and Anchor properties shouldn't cause this, and I've never seen it in all my experience.
And what do you mean when you say "parented to each other". Are these child controls with child/container controls? Or are you saying that each control is sited to another, meaning that they are laid out adjacent to each other. If that's the case, parenting is a different thing. Child controls are parented to container controls. Siting is laying out adjacent or "sibling" controls in a particular manner where their position is relative to one another. If that's the case, how are you implementing it?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|