Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can determine when a window handle is valid?

Tags:

winapi

delphi

I am writing a DLL which make some operations on a particular window, but sometimes the handle passed is not valid. Does there exist any function to validate that the handle passed is valid (belongs to a window)?

like image 820
Salvador Avatar asked Jun 06 '11 15:06

Salvador


People also ask

How can I check if my Windows handle is valid?

First method: You can try to duplicate the handle you want to check on validity. Basically, invalid handles can not be duplicated. Second method: The DuplicateHandle function does search the Win32 handle descriptor table from beginning for an empty record to reuse it and so assign into it a duplicated handle.

Are window handles unique?

Yes. There are only a finite number of values a handle can be represented by, so Windows has to reuse them eventually.

What is a handle to a window?

Hi Fardeen, a Window Handle is a unique identifier that holds the address of all the windows. This is basically a pointer to a window, which returns the string value. This window handle function helps in getting the handles of all the windows. It is guaranteed that each browser will have a unique window handle.

What type is handle in Windows?

HANDLEs are defined as void pointers (void*). They are used as unique identifiers to each Windows object in our program such as a button, a window an icon, etc. Specifically their definition follows: typedef PVOID HANDLE; and typedef void *PVOID; In other words HANDLE = void*.


1 Answers

Try using the IsWindow function, which is declared in the Windows unit.

function IsWindow(hWnd: HWND): BOOL; stdcall;
like image 165
RRUZ Avatar answered Oct 02 '22 17:10

RRUZ