The explanation of Getprop and SetProp in Baidu Encyclopedia is as follows:
Getprop function Function: This function retrieves a data handle from the list of properties for a given window. The given string identifies the handle to retrieve. The string and handle must have been added to the property sheet the first time the SetProp function was called.
Function prototype: HANDLE getprop (HWND hwnd,lpctstr lpstring);
Parameters:
HWnd: Point to the window to search for the property sheet.
Lpstring: A pointer to a null-terminated string, or an atom that contains an identity string. If the argument is an atom, it must be created using the Globaladdatom function. The atom is a 16-bit data value that must be placed in the low rate of the lpstring parameter, and the high word must be O.
Return value: If the property sheet contains the given string, the return value is the related data handle. Otherwise, the return value is null.
SetProp function Function: This function adds a new item to the property sheet of the specified window, or modifies an existing item. If the specified string is not in the property sheet, the new item is added, the string and handle are included in the new item, or the full-front handle of the string is replaced with the specified handle.
Function prototype: BOOL setprop (HWND hwnd,lpctstr lpstring,handle hdata);
Parameters:
HWnd: A handle to the window in which the property sheet is to receive a new item.
Lpstring: A pointer to a null-terminated string, or an atom that contains an identity string. If the argument is an atom, it must have been previously created using the Globaladdatom function. The atom is a 16-bit data value that must be placed in the low word of the lpstring parameter, and the high word must be O.
Hdata: A handle to the data to be copied to the property sheet. The data handle can identify any value that is useful to the application.
Return value: If the data handle and string are added to the attribute table, the return value is nonzero. If the function fails, it returns to zero. To get more error information, call the GetLastError function.
Note: Before the window is cleared (and before the WM_DESTROY message is processed), the application must add it to the property sheet's item cleanup. Applications must use the Removeprop function to clear these items.
You can use the Getprop and SetProp functions to find windows for programs that have already been started.
Use SetProp to add a string to the window's property sheet. You can add the following statement at the end of the OnInitDialog function of the dialog box.
:: SetProp (This->m_hwnd, "string", (HANDLE) 1);
Use Getprop to find the string in the window's property sheet.
:: Getprop (hwnd, "string")
BOOL cautorunapp::ensureoneinstance ()
{
M_hmutex = CreateMutex (NULL, FALSE, _t ("AutoRun"));
if (M_hmutex)
{
if (GetLastError () = = 183/*error_already_exists*/)
{
CloseHandle (M_hmutex);
HWND hwndprevious =:: GetWindow (:: GetDesktopWindow (), gw_child);
while (:: IsWindow (hwndprevious))
{
if (:: Getprop (Hwndprevious, Exeprop))
{
if (:: Isiconic (hwndprevious))
{
:: ShowWindow (Hwndprevious, Sw_restore);
:: SetForegroundWindow (hwndprevious);
}
Else
{
:: SetForegroundWindow (:: Getlastactivepopup (hwndprevious));
}
return FALSE;
}
Hwndprevious =:: GetWindow (Hwndprevious, Gw_hwndnext);
}
return FALSE;
}
}
return TRUE;
}