|
A couple of Win32 API functions explained in detail CompareStringA GetDlgItemInt GetDlgItemText GetWindowLongA GetWindowTextA MessageboxA RegQueryValueEx CompareStringA Compares two strings. Overview Supported by: Windows NT, Win95, and Win32s DLL file: kernel32.dll The C/C++ function looks like this: int CompareStringA( LCID lcid DWORD dwCmpFlags LPCSTR lpString1 integer cchCount1 LPCSTR lpString2 integer cchCount2 ); Parameters lcid Locale context for the comparison. The strings are assumed to be represented in the default ANSI code page for this locale. dwCmpFlags Flags that indicate the character traits to use or ignore when comparing the two strings. Several flags can be combined , or none can be used. (In the case of this function, there are no illegal combinations of flags.) Compare flags include the following. Value Meaning NORM_IGNORECASE 1 Ignore case. Default is Off NORM_IGNOREKANATYPE 0x00010000 Ignore Japanese hiragana/katakana character differences. Default is Off NORM_IGNORENONSPACE 2 Ignore nonspacing marks (accents, diacritics, and vowel marks). Default is Off NORM_IGNORESYMBOLS 4 Ignore symbols. Default is Off NORM_IGNOREWIDTH 0x00020000 Ignore character width. Default is OfflpString1 and lpString2 The two strings to be compared. cchCount1 and cchCount2 The character counts of the two strings. The count does not include the null-terminator (if any). If either cchCount1 or cchCount2 is -1, the corresponding string is assumed to be null-terminated, and the length is calculated automatically. Return values 0 Failure 1 lpString1 is less than lpString2 2 lpString1 is equal to lpString2 3 lpString1 is greater than lpString2 Example Because function arguments are passed on the stack, you simply push the needed arguments in reverse order, so they come off the stack in the desired order: push cchCount2 push lpString2 push cchCount1 push lpString1 push dwCmpFlags push lcid call CompareStringA GetDlgItemInt Translates the text of a specified control in a dialog box into an integer value. Overview Supported by: Windows NT, Win95, and Win32s DLL file: user32.dll The C/C++ function looks like this: UINT GetDlgItemInt( HWND hDlg, // handle to dialog box int nIDDlgItem, // control identifier BOOL *lpTranslated, // points to variable to receive success/failure indicator BOOL bSigned // specifies whether value is signed or unsigned ); Parameters hDlg Handle to the dialog box that contains the control of interest. nIDDlgItem Dialog item identifier that specifies the control whose text is to be translated. *lpTranslated Points to a Boolean variable that receives a function success/failure value. TRUE indicates success, FALSE indicates failure. This parameter is optional: it can be NULL. In that case, the function returns no information about success or failure. bSigned Specifies whether the function should examine the text for a minus sign at the beginning and return a signed integer value if it finds one. TRUE specifies that this should be done, FALSE that it should not. Return values If the function succeeds, the variable pointed to by lpTranslated is set to TRUE, and the return value is the translated value of the control text. If the function fails, the variable pointed to by lpTranslated is set to FALSE, and the return value is zero. Note that, since zero is a possible translated value, a return value of zero does not by itself indicate failure. If lpTranslated is NULL, the function returns no information about success or failure. If the bSigned parameter is TRUE, specifying that the value to be retrieved is a signed integer value, cast the return value to an int type Example Because function arguments are passed on the stack, you simply push the needed arguments in reverse order, so they come off the stack in the desired order: push bSigned push *lpTranslated push nIDDlgItem push hDlg call GetDlgItemInt GetDlgItemText Retrieves the title or text associated with a control in a dialog box. Overview Supported by: Windows NT, Win95, and Win32s DLL file: user32.dll The C/C++ function looks like this: UINT GetDlgItemText( HWND hDlg, // handle of dialog box int nIDDlgItem, // identifier of control LPTSTR lpString, // address of buffer for text int nMaxCount // maximum size of string ); Parameters hDlg Identifies the dialog box that contains the control. nIDDlgItem Specifies the identifier of the control whose title or text is to be retrieved. lpString Points to the buffer to receive the title or text. nMaxCount Specifies the maximum length, in characters, of the string to be copied to the buffer pointed to by lpString. If the length of the string exceeds the limit, the string is truncated. Return values If the function succeeds, the return value specifies the number of characters copied to the buffer, not including the terminating null character. If the function fails, the return value is zero. This function cannot retrieve the text of an edit control in another application. Example Because function arguments are passed on the stack, you simply push the needed arguments in reverse order, so they come off the stack in the desired order: push nMaxCount push lpString push nIDDlgItem push hDlg call GetDlgItemText GetWindowLongA Rretrieves information about the specified window. The function also retrieves the 32-bit (long) value at the specified offset into the extra window memory of a window. Overview Supported by: Windows NT, Win95, and Win32s DLL file: user32.dll The C/C++ function looks like this: LONG GetWindowLongA( HWND hWnd, // handle of window (32-bit) int nIndex // offset of value to retrieve (32-bit) ); Parameters hWnd Identifies the window and, indirectly, the class to which the window belongs. nIndex Specifies the zero-based offset to the value to be retrieved. Valid values are in the range zero through the number of bytes of extra window memory, minus four; for example, if you specified 12 or more bytes of extra memory, a value of 8 would be an index to the third 32-bit integer. To retrieve any other value, specify one of the following values: GWL_EXSTYLE -20 Retrieves the extended window styles GWL_STYLE -16 Retrieves the window styles GWL_WNDPROC -4 Retrieves the address of the window procedure, or a handle representing the address of the window procedure. You must use the CallWindowProc function to call the window procedure GWL_HINSTANCE -6 Retrieves the handle of the application instance GWL_HWNDPARENT -8 Retrieves the handle of the parent window, if any GWL_ID -12 Retrieves the identifier of the window GWL_USERDATA -21 Retrieves the 32-bit value associated with the window. Each window has a corresponding 32-bit value intended for use by the application that created the window The following values are also available when the hWnd parameter identifies a dialog box: Value Action DWL_DLGPROC 4 Retrieves the address of the dialog box procedure, or a handle representing the address of the dialog box procedure. You must use the CallWindowProc function to call the dialog box procedure DWL_MSGRESULT 0 Retrieves the return value of a message processed in the dialog box procedure DWL_USER 8 Retrieves extra information private to the application, such as handles or pointers Return values If the function succeeds, the return value is the requested 32-bit value. If the function fails, the return value is zero Example Because function arguments are passed on the stack, you simply push the needed arguments in reverse order, so they come off the stack in the desired order: push nIndex push hWnd call GetWindowLongA GetWindowTextA A function that retrieves information about the specified window. The function also retrieves a long (32-bit) value at the specified offset into the extra window memory of a window. Overview Supported by: Windows NT, Win95, and Win32s DLL file: user32.dll The C/C++ function looks like this: int GetWindowText( HWND hWnd, // handle of window or control with text LPTSTR lpString, // address of buffer for text int nMaxCount // maximum number of characters to copy ); Parameters hWnd Identifies the window or control containing the text. lpString Points to the buffer that will receive the text. nMaxCount Specifies the maximum number of characters to copy to the buffer, including the NULL character. If the text exceeds this limit, it is truncated Return values If the function succeeds, the return value is the length, in characters, of the copied string, not including the terminating null character. If the window has no title bar or text, if the title bar is empty, or if the window or control handle is invalid, the return value is zero. To get extended error information, call GetLastError. This function cannot retrieve the text of an edit control in another application. Example Because function arguments are passed on the stack, you simply push the needed arguments in reverse order, so they come off the stack in the desired order: push nMaxCount push lpString push hWnd call GetWindowTextA MessageboxA A function that displays a message box containing a message, a title, plus any combination of predefined icons and push buttons. Overview Supported by: Windows NT, Win95, and Win32s DLL file: user32.dll The C/C++ function looks like this: int MessageBoxA( HWND hWnd, // handle of owner window (32-bit ptr) LPCTSTR lpText, // address of null-terminated text in message box (32-bit ptr) LPCTSTR lpCaption, // address of null-terminated title of message box (32-bit ptr) UINT uType // style of message box (32-bit) ); Parameters hWnd Identifies the owner window of the message box to be created. If this parameter is NULL (0 hex), the message box has no owner window. lpText Points to a null-terminated (0 hex) string containing the message to be displayed. lpCaption Points to a null-terminated (0 hex) string used for the dialog box title. If this parameter is NULL, the default title Error is used. uType This parameter controls the buttons, defaul button, and icons by adding several values. Buttons MB_OK 0 MB_OKCANCEL 1 MB_ABORTRETRYIGNORE 2 MB_YESNOCANCEL 3 MB_YESNO 4 MB_RETRYCANCEL 5Icons MB_ICONEXCLAMATION 30 MB_ICONWARNING 30 MB_ICONINFORMATION 40 MB_ICONASTERISK 40 MB_ICONQUESTION 20 MB_ICONSTOP 10 MB_ICONERROR 10 MB_ICONHAND 10Default buton MB_DEFBUTTON1 0 The first button is the default button (default) MB_DEFBUTTON2 100 The second button is the default button MB_DEFBUTTON3 200 The third button is the default button MB_DEFBUTTON4 300 The fourth button is the default button Return values IDOK 1 OK button was selected IDCANCEL 2 Cancel button was selected IDABORT 3 Abort button was selected IDRETRY 4 Retry button was selected IDIGNORE 5 Ignore button was selected IDYES 6 Yes button was selected IDNO 7 No button was selected Example Because function arguments are passed on the stack, you simply push the needed arguments in reverse order, so they come off the stack in the desired order: push uType push offset lpCaption push offset lpText push hWnd call MessageBoxA RegQueryValueEx A function that retrieves the type and data for a specified value name associated with an open registry key. Overview Supported by: Windows NT, Win95, and Win32s DLL file: advapi32.lib The C/C++ function looks like this: LONG RegQueryValueEx( HKEY hKey, // handle of key to query LPTSTR lpValueName, // address of name of value to query LPDWORD lpReserved, // reserved LPDWORD lpType, // address of buffer for value type LPBYTE lpData, // address of data buffer LPDWORD lpcbData // address of data buffer size ); Parameters hKey Identifies a currently open key or any of the following predefined reserved handle values: lpValueName Points to a null-terminated string containing the name of the value to be queried. lpReserved Reserved; must be NULL. lpType Return values If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code defined in WINERROR.H. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error. Example push lpcbData push lpData push lpType push lpReserved push lpValueName push hKey call RegQueryValueEx | |||
Related topicsMSDN Online Library Developer documentation from Microsoft Go directly to Win32 Functions in Alphabetical Order | |||