SetProp (), Getprop (), Removeprop () API interface

Source: Internet
Author: User

It feels like these three interfaces are rarely seen, so I've tidied up the next

1. Function Introduction

Website Source: http://blog.csdn.net/ly131420/article/details/8865845

In the Windows interface design, we have more contact with the window, but these three API interfaces are rarely used, namely: SetProp, Getprop, removeprop three API interface, actually these three API interface is associated with the window handle, this is very important, Because they can set the window to add, delete the new properties, which expands the window's associated data, so that we can link any data to the window, in the design of some interface architecture can be used to these interfaces, directly to the window handle and object association, the processing of the window process into Object event processing, To the object-oriented to become more logical, in the framework of the Delphi framework is the use of this method, so that Delphi in the interface development is very efficient, of course, performance is lower than MFC, but MFC sacrificed more reasonable event processing, more are in the window process of processing events , making the MFC design interface relatively difficult.

2. Introduction to Usage2.1 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) Parameter: hwnd: A handle to a window that receives a new item in its 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 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 (that is, before the Wm_ncdestroy 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.2.2GetProp ()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); parameter: 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. 2.3 Removeprop () function function: This function removes an item from the property sheet of the specified window. The specified string identifies the item to be deleted. Function prototype: HANDLE Removeprop (hwnd hwnd,lpctstr lpstring); parameter: hwnd: A handle to the window to which you want to change the property 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 be created using the Addatom function. The atom is a 16-bit data value that must be placed in the low word of the lpstring parameter, and the high rate must be 0. Return value: The return value identifies the specified string. If the string cannot be found in the specified property sheet, the return value is null. Note: The application must release the data handle associated with the item purged from the property sheet. The application can only purge those attributes it joins, and it cannot purge other applications or attributes that are added by the system itself. The Removeprop function returns the data handle associated with the string so that the application can release the data associated with the handle. 3. Code sample site Source: http://blog.csdn.net/primer_programer/article/details/2050750
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 a 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;}

4. Other Introduction website Source: http://blog.csdn.net/fengbangyue/article/details/5222185http://bigboyzhang.phpfs.com/?p=29
You can also view the "CListCtrl implementation sequencing" feature in my article, which is also useful to SetProp and getprop.

SetProp (), Getprop (), Removeprop () API interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.