|
I need more info to form an opinion on this.
Is 1400 hex or decimal ?
is it exactly my code that reports "handle=00000000" and "last error=00001400" ??
Please provide exact code and output.
What is your OS (winXP ? any service pack ?) and .NET version (1.1, 2.0 ? any
service pack?)
Furthermore, I have some ideas.
Idea 1:
I am not sure, maybe it is necessary to prefix my code by the following:
SetLastError(0);
together with the declaration:
[DllImport("kernel32.dll", CallingConvention=CallingConvention.StdCall)]
private static extern int SetLastError(int err);
Rationale: a lot of system calls change the "last error" value only when something
goes wrong, but don't clear it beforehand. This is what SetLastError(0) is about.
(So it may have been set by CreateWindow or any call executed earlier).
Idea 2:
there might be a problem with the className/windowName arguments (ASCII/Unicode
confusion). If so, this could be fixed by specifying CharSet=CharSet.ASCII or Unicode
inside the DllImport line of CreateWindowEx declaration, and/or by changing
the EntryPoint to either CreateWindowExA or CreateWindowExW.
Luc Pattyn
|
|
|
|
|
Here is more info:
-1400 is decimal, it gives 00000578 when I put i.ToString("X8").
-my OS i WinXP and .NET is 2.0
Here is complete code:
<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
SetLastError(0);<br />
int handle = CreateWindowEx(<br />
0,
"PrintTray_Notify_WndClass",
"",
0x80000000,
0, 0, 10, 10,
IntPtr.Zero,
IntPtr.Zero,
IntPtr.Zero,
IntPtr.Zero);
<br />
MessageBox.Show("Handle: "+ handle.ToString("X8"));<br />
if (handle == 0)<br />
{<br />
int i = GetLastError();<br />
<br />
if (i == 183)<br />
MessageBox.Show("ERROR_ALREADY_EXISTS");<br />
else<br />
MessageBox.Show("error code:"+ i.ToString("X8"));<br />
<br />
}<br />
}<br />
<br />
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall)]<br />
private static extern int GetLastError();<br />
<br />
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall)]<br />
private static extern int SetLastError(int err);<br />
<br />
[DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "CreateWindowEx", CallingConvention = CallingConvention.StdCall)]<br />
public static extern int CreateWindowEx(uint style2, string className,<br />
string windowName, uint style, int x, int y, int w, int h, IntPtr parent,<br />
IntPtr menu, IntPtr instance, IntPtr lpParam);<br />
}<br />
And it always gets to: MessageBox.Show("error code:"+ i.ToString("X8")); giving 00000573.
I tried your two ideas and nothing happens. Can you give me any more help?
Thanks!
|
|
|
|
|
One or more of the arguments to CreateWindowEx seems to be wrong.
If we assume Windows did report an accurate error code (ERROR_INVALID_WINDOW_HANDLE),
then the problem must be with one of the handles
(i.e. parent/menu/instance/lpParam) but then MSDN says:
- parent: "This parameter is optional for pop-up windows"
- menu: more complex text, but then there also exists ERROR_INVALID_MENU_HANDLE
which is not what you are getting
- instance: "Windows NT/2000/XP: This value is ignored"
but your reference article did supply hInstance here (I replaced it by null because
of MSDN's "is ignored")
- lpParam: is explained as a pointer, not really a handler.
So maybe MSDN is wrong and it just needs an hInstance.
Getting hInstance is somewhat tricky; my best guess is:
IntPtr hInstance=Marshal.GetHINSTANCE(GetType().Module);
which only works inside an instance (= non-static) method.
Once again good luck !
BTW, you are not running on a 64-bit OS by any chance ?
Luc Pattyn
|
|
|
|
|
Funny thing about this is that when using NativeWindow (.NET wrapper class over CreateWindowEx), I get same error...
<br />
NativeWindow nw = new NativeWindow();<br />
CreateParams cp = new CreateParams();<br />
cp.ExStyle = 0;<br />
cp.ClassName = "PrintTray_Notify_WndClass";<br />
cp.Caption = "";<br />
<br />
nw.CreateHandle(cp);<br />
I wish I'm using 64-bit OS... I'm getting desperate this way - can't create one window for two days .
|
|
|
|
|
Hi Mikker,
I wasnt aware of NativeWindow and CreateParams classes.
These make my code unnecessary (but it seems to confirm it was correct...)
So there must be a deeper problem somewhere. Did you Google it ?
Or try Microsoft Connect ?
BTW, dit you try the same on .NET 1.1 ?
Luc Pattyn
|
|
|
|
|
Dear Luc.
I found your answer on problem at slow printing when custom shell is used. I tried to use PrintTray_notify_WndClass class to create window, but I get error 1407=cannot find wnd class. What is wrong?
Tnx,
Matjaž
|
|
|
|
|
Like the title says.
I have no idea what to do, i'll keep on looking but...
-- modified at 10:50 Tuesday 2nd January, 2007
This always happens when i post a message in places... anyways, FileStream inherits Stream, and Stream i can inherit so.. yeah. Just means i need one extra line of code (NOOO >_<)
|
|
|
|
|
FileStream is not sealed, meaning you can inherit from it if you want.
class Class1 : FileStream
{
public Class1()
: base("c:\\foo.txt", FileMode.Open)
{
}
}
|
|
|
|
|
I am designing my print form but im having a small problem, some strings that I am wanting to print are longer than the print bounds and I would like to know if there is a way to make the string print within the bounds and wrap to the next line when it hits those bounds?
|
|
|
|
|
Hi,
the application that shows stuff on the screen is also responsible for formatting it
while printing. It could use the same PaintEvent handler for doing so.
Amongst others this means the application itself must do any word wrapping that is required.
Printing may vary from simple to complex depending on functionality:
- if the screen also shows pages (as in MS Word when viewing "Print layout", then
nothing much has to change for printing (except some border settings, and scaling
that is)
- if the screen only shows continuous data (as in Word's "Normal view", or in
a simple text editor) then new code is required to figure out page boundaries etc.
- furthermore there are issues around printer selection, page settings (per document?
per page?), duplex printing, etc.
So my advice is to separate all these concerns as much as possible.
For one this implies providing a "page mode" or "print layout" view capability to your
app (at least during the development phase, but then why not keep it?),
in order to separate the different problem domains.
Good luck !
Luc Pattyn
|
|
|
|
|
Hi,
I am trying to find a way to customize the color of the check mark that appears in the CheckedListBox. I want to alter the color of the check mark of certains items (not all) in the list based on some criteria.
Is there is any way of doing it?
Thanks in advance
|
|
|
|
|
How can i hide the row indicator column. Its the first column that as the user moves up and down the grid a black triangle shows in the first column to show the user the current row. I want to hide this column?
|
|
|
|
|
DataGridView1.RowHeadersVisible = false;
thanks
|
|
|
|
|
how to print a page in a protrate design.
thanks
|
|
|
|
|
printDoc.PrinterSettings.DefaultPageSettings.Landscape=false (or =true);
did it for me.
Luc Pattyn
|
|
|
|
|
I am trying to take text data from a listview in my program and print it in a report. Im new to printing anything in any language. I have followed this article[^] only to get part of what i need. the error that i have is the part where it actually prints the elements, it wont, it just does the header and footer. but what i would like to know is does anyone know of a good tutorial i can follow to print text from a listview?
|
|
|
|
|
Try using the PrintDocument class
SkyWalker
|
|
|
|
|
Hi, happy new year for all.
I wanted to make a full-screen windows application, but after changing the
height and width properties of form, the start menu still visible over the
form, is there any way to make a full-screen application? and also cover the
start menu.
please excuse my bad English >> (I'm new at learning English)
|
|
|
|
|
Set the FormBorderStyle property to None and the WindowState property to Maximized
SkyWalker
|
|
|
|
|
thanks, it worked.
but suppose i want the application with border, covering the whole screen, it migth look like the old setup wizards, is that possible.
|
|
|
|
|
Of course! Set the following:
FormBorderStyle to Fixed3d
WindowState to Maximized
ControlBox to False
MaximizeBox to False
MinimizeBox to False
ShowIcon to False
Text to an empty string
SkyWalker
|
|
|
|
|
|
is there any way to handle the unhandled exceptions generated to display user define messages instead of breaking the execution.
|
|
|
|
|
kalaveer wrote: handle the unhandled exceptions
Obviously not. The way to handle exceptions, is to handle them. You can handle all exceptions at a top level, but you can't then resume execution at the lower level where there were not handled.
I think you need to define your question better, but if you're hoping for a way to get the framework to ignore exceptions at the point they occur, without writing a try/catch, the answer is no. This is one reason that exceptions work better than error codes. They cannot be ignored.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
hi
i tried to display message box in C# library but i din't find the message.show instead of that mbox saying code snippet for message.show is there so how to use mbox in the library file to display messageboxes
thanks in advance.
|
|
|
|