|
Friends I need your help because I want to print any document in a printer 3700dn whit mirror out,I need this in c#.Help me please because I´ve found this problem in many pages and the result have been null,I wait that anyone bring me any help
Thanks
S.
bigmega
|
|
|
|
|
In C++ you could use negative co-ordinates to flip an image when you BitBlt. You could import this from the dlls if C#/GDI+ does not do the same.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi, I am having problem using Win32 SendMessage function to send a string from one process to another in a C# Windows Form app. I am using .Net 1.1 SP1 on a Windows XP Pro box.
What I am trying to do is to restrict user from running multiple instances of a windows form app. When they do "MyWindowsFormApp.exe userArgument", I want to pass "userArgument" to current running instance of the app.
Here is the code
/***dll import part***/
[DllImport("User32.dll", EntryPoint="SendMessage")]
public static extern int SendMessage( int hwnd, int uMsg, int wParam, [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)] string lParam);
/***code that sends message***/
//this returns currently running process of my application.
Process process = GetCurrentInstance();
//get first argument
string s = GetArgument();
//send argument Win32.WM_USER = 0x0400;
SendMessage(process.MainWindowHandle.ToInt32(),Win32.WM_USER, 0, s);
/***code in main form of MyWindowsFormApp that receives message***/
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case Win32.WM_USER:
IntPtr intPtr = m.LParam;
string str = Marshal.PtrToStringAuto(intPtr);
string str2 = (string)m.GetLParam( typeof(string) );
break;
}
}
Sending message part seems working(not exception thrown) and the WndProc method in the windows form IS receiving the message.
Problems are:
intPtr.ToInt32() always returns 1242424. Marshal.PtrToStringAuto(intPtr) always returns a empty string.
and (string)m.GetLParam( typeof(string) ) throws a MissingMethodExcpetion ("No parameterless constructor defined for this object.")
What am I doing wrong? Any suggestion will be greatly appreciated!
LS
|
|
|
|
|
Liu Shuai wrote:
What am I doing wrong? Any suggestion will be greatly appreciated!
Sorry, I don't know, but a few things you could try:
1. Try to first change the code to SendMessage in-process to check if the problem is between processes.
2. Try to SendMessage a WM_SETTEXT to some control (e.g., a textbox) to check if the problem is happening when sending the string or receiving it.
Yes, even I am blogging now!
|
|
|
|
|
Thanks for the response Daniel. I did those two testes.
1. SendMessage in-process is giving me the same (invalid) result
2. WM_SETTEXT works...
but isn't WM_SETTEXT sending string too?
|
|
|
|
|
Liu Shuai wrote:
1. SendMessage in-process is giving me the same (invalid) result
2. WM_SETTEXT works...
I asked you to do those tests to isolate if the problem was on the code that was sending the message or receiving the message. Now, we can see that the problem clearly seems to be in the part receiving the message.
Re-reading your post I notice that you're using a WM_USER message to send the string. This is not a good practice, and even the .NET framework can be using the same message, and that's why you are getting a bogus result. Another thing to try is calling RegisterWindowMessage with the same string - I use a GUID to assure that it's unique - on both ends (sender and receiver) and see if this time it works.
Yes, even I am blogging now!
|
|
|
|
|
Yes, I realized too using WM_USER isn't appropriate...tried RegisterWindowMessage and got some result. But at least I think it's consistent as I WAS able to receive message and corrent integer type lparam by using WM_USER.
Any thought?
|
|
|
|
|
When sending messages between processes, Windows has to marshal the message's parameters - if the parameter is a pointer, it needs to copy the target of that pointer into the receiver's address space and set the pointer value appropriately. It therefore has to know what the parameters mean - is this (WPARAM or LPARAM) a pointer to a structure, a string, or just a number? If it's a structure, what's the structure's layout - does it have any embedded pointers that also need to be marshalled?
Windows has built-in logic for doing this for the standard Windows messages it knows about, but if you use your own message numbers, it simply passes the values of WPARAM and LPARAM without translating them.
Windows features a little-known message WM_COPYDATA (0x004A). This message can be used to copy an arbitrary data buffer between processes.
Since both ends are written in C#, I'd recommend using .NET Remoting to communicate between the processes.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thanks Mike.
Doesn't "[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)] string lParam"
tell .Net how to marshall strings?
Also I tried to call SendMessage() in-process and I am getting the same exception.
Does that make sense? Thank you.
|
|
|
|
|
I'm working on a Graph grid that is it's own region on the form. I want the OnMouseMove event to display the x and y coords. in text boxes, if the mouse goes inside this grid area.
I was getting pretty far by myself until I ran into a problem... I'll just print the code so you'll know what I mean.
if(region.GetBounds().Right >= MousePosition.X && region.GetBounds().Left <= MousePosition.X))
{
txtXcoord.Text = MousePosition.X.ToString();
}
it keeps giving me an exception if I stick a graphics object in the GetBounds(). Please help me, I dunno what to do.
If someone's got a simpler way of doing this, that would be awesome too.
|
|
|
|
|
What is region defined as? A Region struct? In what class is this code contained (the one that declares region )? What's the access on the region field?
What is the exception that is thrown (type)? What does the exception text read?
Please be specific and verbose when asking for help. We don't know your code (and what you posted isn't nearly enough to help diagnose the problem) nor the circumstances under which your code is called.
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]
|
|
|
|
|
Sorry. I am new at this.
Region is defined in the main form, at the top (private Region region;)
with graphics as a class variable. (private Graphics g;)
Graph is a .cs file that holds the region data, and the Override Paint event instances the method and tells it to paint itself.
Here's more code:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Graph gr = new Graph();
}
gr.DrawGraph(toolBarMain.Location.X+5,toolBarMain.Size.Height+5,500,500,g);
}
protected override void OnMouseMove(MouseEventArgs e)
{
Graph gr = new Graph();
region = gr.GetRegion();
if(region.GetBounds(g). >= MousePosition.X && region.GetBounds(g).Left <= MousePosition.X)
{
txtXcoord.Text = MousePosition.X.ToString();
}
base.OnMouseMove (e);
}
I didn't call it in OnPaintArgs, but does that matter?
It paints my grid fine, but I want to display the x/y coordinates of my mouse in two text boxes.
I didn't put the 2nd text box in yet because I wanted to make sure that it was working properly.
is this enough info?
|
|
|
|
|
Hey There,
Why are you instatiating the Graph() object both in OnPaint and again in onmousemove. Shouldn't you be using the same object?
|
|
|
|
|
Never store a Graphics object as a field. You either create a temporary Graphics object with CreateGraphics or - when overring OnPaint or handling the Paint event of a different control - use PaintEventArgs.Graphics . Do not store these ever.
The other reply is asking the right question: why are you re-instantiating Graph ? It's that object you should be referencing in a field.
The other thing you need to do is read about the MousePosition static property. This returns the screen position - not the client (your control) position, i.e. relative to your control's upper-left coordinate (always 0,0). To translate the coordinates, call Control.PointToClient (reads the SDK documentation that was installed by default when you install VS.NET or the .NET Framework SDK; it's also available online at http://msdn.microsoft.com/library[^]) the compare the coordinates.
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]
|
|
|
|
|
Thank you for setting me straight on that. And thank you for your time, patience and help!
You guys are the best!
|
|
|
|
|
No there isnt. .NET Framework has to be installed in the computer for any .NET based app to be able to run.
|
|
|
|
|
The Visual Studio .NET Setup project does not install the .NET Framework, as is documented in the Visual Studio Product Documentation. You can create your own bootstrapper to install it, however. Read HOW TO: Distribute the .NET Framework with a Visual Studio .NET Deployment Project[^]. Specifically, you'll want to read about and download the sample bootstrapper from MSDN at http://msdn.microsoft.com/library/default.asp?url=/downloads/list/netdevframework.asp[^].
The Framework does have to be installed because it is the runtime that JITs and executes the assemblies, as well as defines the methods that you use to write your app (the BCL). That's no different than a Java application requiring the Java Runtime Environment (JRE) or applications built against Microsoft Visual C Runtime v7.1 to require msvcr71.dll. This isn't limited to the Windows platform, either, but to all platforms.
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]
|
|
|
|
|
Right, I see.
Ok thanks for the help
|
|
|
|
|
C# requires the dot net framework to run, dotnetFX.exe is teh installation file for the framework so yes, you do need it. Every single C# application requires this framework to be installed. I used to work as an admin at a school and personally i would have installed it for you if it was neccesary for a class then uninstalled it after. Ask your admin to install it for you, the worst they can do is say no.
Kev
|
|
|
|
|
Moochie5 wrote:
Does dotnetfx always need to be installed on a computer that doesn't have the .NET Framework on it?
Yes
Moochie5 wrote:
s there anyway around that?
No.
Moochie5 wrote:
I find it hard to believe that for every program that one creates one needs to install dotnetfx on the computer for it to run
Why is it so hard to believe? Where do you think all those neat features come from? Did you see the size of a "hello, world" program compared to a C++ one with the libraries statically linked?
BTW, it's not "every program", it's only the first .NET program.
Yes, even I am blogging now!
|
|
|
|
|
I have finished created a setup for my program using the setup wizard in Visual Studio .NET 2003. The setup works fine on my computer and the program works perfect. However, when I go to install the program on other computers it says I need the .NET Framework Redistribution package installed, which I believe is "dotnetfx" when I looked this up on msdn.
The problem is I need to run this program at school and demonstrate it to the class. But I cannot install dotnetfx on the computer it because an administrator must do this, students to not have the right access.
Does dotnetfx always need to be installed on a computer that doesn't have the .NET Framework on it? Is there anyway around that? I find it hard to believe that for every program that one creates one needs to install dotnetfx on the computer for it to run. Is there any way around that?
|
|
|
|
|
Hi,
I looking to storing some datas to a combobox with for each datas a would like to store a Tag value.
Best regrads
youssef
|
|
|
|
|
Create a custom object collection where your objects show all the info u need through properties. Then set the collection as ur combo's datasource and set the displaymember and valuemember to your object's properties (Name and Tag for example).
If u dont want to go through all that, it might be easier to just store all objects + info in the necessary fields of a datatable (that would solve ur custom object collection) and proceed the same way as before.
|
|
|
|
|
For more information and an example of what Skynyrd mentioned, read about the MappingName Property[^] for the DataGridTableStyle class in the .NET Framework SDK.
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]
|
|
|
|
|
You can add any object as an item to a ComboBox , and to display it, the ComboBox calls the object's ToString method.
So, create a MyComboItem class that contians two (or more) properties, Text and Tag , and override ToString to return the contents of the Text property. When you get an item from the ComboBox 's Items collection, don't forget to do the appropiate cast.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|