Click to See Complete Forum and Search --> : empty HNWD


dave2k
November 20th, 2005, 08:30 AM
how do i check for an empty HNWD i tried == NULL but this doesn't seem to work

golanshahar
November 20th, 2005, 08:37 AM
how do i check for an empty HNWD i tried == NULL but this doesn't seem to work

what do you mean by empty window? :confused:

if you want to check if the HWND is a vaild you can use ::IsWindow(..) (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/iswindow.asp) api.

Cheers

ovidiucucu
November 20th, 2005, 08:38 AM
You mean HWND.
Well, some function returns NULL value in case of failure (ex. CreateWindow) so you can directly check if is NULL. In other cases you must check if that HWND value represents a valid window. In these cases call IsWindow function.

EDIT: Yeah indeed. What do you mean with "empty HWND"?

leojose
November 20th, 2005, 08:50 AM
how do i check for an empty HNWD i tried == NULL but this doesn't seem to work
this must work...if this is what you mean
if (hwnd == NULL)
{
// Error: no window found
}

if you want to check if the HWND is a vaild you can use ::IsWindow(..) (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/iswindow.asp) api.
It's api also says...
A thread should not use IsWindow for a window that it did not create because the window could be destroyed after this function was called. Further, because window handles are recycled the handle could even point to a different window.

so won't it be a little 'dangerous' thing to do?:rolleyes:

golanshahar
November 20th, 2005, 08:58 AM
this must work...if this is what you mean
if (hwnd == NULL)
{
// Error: no window found
}


It's api also says...
A thread should not use IsWindow for a window that it did not create because the window could be destroyed after this function was called. Further, because window handles are recycled the handle could even point to a different window.

so won't it be a little 'dangerous' thing to do?:rolleyes:

well i would not say dangerous i would say NOT 100% safe. after all the computer wont explode on the user :D

same thing can happen with your suggestion, your code is also not safe on the same weight:


if (hwnd == NULL) // window is not null at that point.
{
// Error: no window found
}
else
{
// do something with hwnd
}
context switch here. other process destory the window and set HWND to null or cycle the handle.

// now we back to your code:
else
{
// here no one can assure you, on which hwnd you are working on
}


Cheers

dave2k
November 20th, 2005, 09:02 AM
IsWindow is working, cheers

dave2k
November 20th, 2005, 09:05 AM
what if the HWND is actually a control - will IsWindow still work?

golanshahar
November 20th, 2005, 09:22 AM
what if the HWND is actually a control - will IsWindow still work?

Yes.

Cheers

ovidiucucu
November 20th, 2005, 09:29 AM
what if the HWND is actually a control - will IsWindow still work?
As long as a "control" (e.g. edit, combobox, etc) is a window itself, why not?

dave2k
November 20th, 2005, 09:32 AM
ok cheers