get invalid handle when called GetWindowLong.
-
i'm trying to get information about a panel in my application , so i called GetWindowLong passing this.handle in the custom panel class, but i get the error 6 saying invalid handle, this.handle returns "2081229920" value. any idea, thanx in advance.
-
i'm trying to get information about a panel in my application , so i called GetWindowLong passing this.handle in the custom panel class, but i get the error 6 saying invalid handle, this.handle returns "2081229920" value. any idea, thanx in advance.
Every mature Winforms Control has a Handle property, that is what you should use as a HWND when P/Invoking API functions; and the Handle typically only exists when the Control has been fully created, which I think is when the holding Form is Loaded or Shown. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Every mature Winforms Control has a Handle property, that is what you should use as a HWND when P/Invoking API functions; and the Handle typically only exists when the Control has been fully created, which I think is when the holding Form is Loaded or Shown. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
thanx, ok actually i made that call in the onpaint method, but when i debug this.handle returned a value. so even though the handle is there it is not enough , is it the reason , means the control is not completely drawn. thanx
-
thanx, ok actually i made that call in the onpaint method, but when i debug this.handle returned a value. so even though the handle is there it is not enough , is it the reason , means the control is not completely drawn. thanx
if you want more help, you'll have to provide a better description of the situation and the problem, and probably show some code. I also am puzzled why you would need handles in an OnPaint handler, I've never seen that. I do know it is wise to keep paint handlers short, simple and swift. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
thanx, ok actually i made that call in the onpaint method, but when i debug this.handle returned a value. so even though the handle is there it is not enough , is it the reason , means the control is not completely drawn. thanx
You got A value, not a VALID value. Having a value other than zero does not means it's valid. You can check this with the
IsHandleCreated
property of your control.A guide to posting questions on CodeProject[^]
Dave Kreskowiak