一、Isiconic
功能 函数功能:该函数确定给定窗口是否是最小化(图标化)的窗口。函数原型:BOOL IsIconic(HWND hWnd);
函数isiconic返回值取决于指定窗口是否已经最小化。
BOOL IsIconic(
HWND hWnd // handle of window
);
二、 CenterWindow()的用法
CenterWindow()的用法为:
void CenterWindow( CWnd* pAlternateOwner = NULL );
其中参数pAlternateOwner指向所想居中的窗口的指针。
然后利用函数GetSystemMetrics( int nIndex )得到系统当前设置如屏幕分辨率等。
nIndexs= SM_CXSCREEN 时函数返回屏幕的宽度;返回值单位为像素点。
nIndexs= SM_CYSCREEN 时函数返回屏幕的高度;返回值单位为像素点。
函数BOOL GetWindowPlacement( WINDOWPLACEMENT* lpwndpl ) 是最重要的。他的参数为一个指向结构变量WINDOWPLACEMENT的指针(lpwndpl);其中WINDOWPLACEMENT结构变量数据结构具体为:
typedef struct tagWINDOWPLACEMENT { /* wndpl */
UINT length;
UINT flags;
UINT showCmd;
POINT ptMinPosition;
POINT ptMaxPosition;
RECT rcNormalPosition;
} WINDOWPLACEMENT;
他包含了窗口在屏幕上的定位信息。
其中成员变量的含义为:
length:指结构变量的长度,单位字节。
flags: 标志值,控制窗口最小化或窗口还原的方法,可以取如下值:
WPF_SETMINPOSITION:指定窗口最小化时的x位置和y位置。
WPF_RESTORETOMAXIMIZED:指定窗口以最大化方式还原,尽管可能窗口并不是在最大化时最小化的。不改变窗口的缺省还原方式。
showCmd:指定窗口的当前显示状态。可以取值:
SW_HIDE:隐藏窗口并激活另一窗口。
SW_MINIMIZE:最小化指定窗口并激活系统窗口列表中最顶层窗口。
SW_RESTORE:激活并显示窗口,如果窗口处于最小化或最大化状态,则窗口还原到原始大小和位置。
SW_SHOW:以窗口的当前大小和位置激活并显示窗口。
SW_SHOWMAXIMIZED:以最大化方式激活并显示窗口。
SW_SHOWMINIMIZED:以图标方式激活并显示窗口。
SW_SHOWMINNOACTIVE:以图标方式窗口。 但不改变窗口的活动状态。
SW_SHOWNA:以窗口的当前状态显示窗口。
SW_SHOWNOACTIVATE:以窗口最近一次的大小和位置显示窗口。 但不改变窗口的活 动状态。
SW_SHOWNORMAL:激活并显示窗口。如果窗口被最大化或最小化,则窗口还原到原始大小和位置。
ptMinPosition:指定窗口最小化时的左上角坐标。
ptMaxPosition:指定窗口最大化时的左上角坐标。
rcNormalPosition:指定窗口在还原时的坐标。
通过灵活使用函数GetWindowPlacement()就可以得到窗口的配置信息。
看到这,可能有些读者已经想到了GetWindowPlacement()函数的姐妹函数SetWindowPlacement(),不用多说,其用法如下:
BOOL SetWindowPlacement( WINDOWPLACEMENT* lpwndpl );
显然,通过函数SetWindowPlacement(),再加以简单的计算,我们就可以来设置窗口的位置、大小以及状态等,从而可以自如地控制窗口显示与否以及窗口的大小、位置等
GetWindowPlacement
函数功能:该函数返回指定窗口的显示状态以及被恢复的、最大化的和最小化的窗口位置。
函数原型:BOOL
参数:
hWnd:
lpwndpl:指向WINDOWPLACEMENT结构的指针,该结构存贮显示状态和位置信息。
在调用GetWindowPlacement函数之前,将WINDOWPLACEMENT结构的长度设为sizeof(WIDNOWPLACEMENT)。如果lpwndpl->length设置不正确则函数GetWindowPlacement将失败。
返回值;如果函数成功,返回值为非零;如果函数失败,返回值为零。若想获得更多错误信息,请调用GetlastError函数。
备注:由该函数获得的WINDOWPLACEMENT结构的flag单元总为0。如果hWnd的窗口被最大化,则showCmd元为
三、LockWindowUpdate
LockWindowUpdate做的事情其实很简单。当一个窗口被“锁定”,所有向它及其子窗口的绘制都会失败。取代绘制操作的是,窗口管理器记住了应用程序试图在窗口的哪一部分中进行绘制。当窗口“解锁”后,这些区域被无效化,使得应用程序得到一个WM_PAINT消息,从而重新恢复了屏幕内容与应用程序认为应当在屏幕上显示的内容之间的同步。
LockWindowUpdate(hwndB); // 将窗口B也锁定
LockWindowUpdate(NULL); // ???
void BeginOperationA()
{
LockWindowUpdate(hwndA);
...
}
void EndOperationA()
{
...
LockWindowUpdate(NULL);
}
void BeginOperationB()
{
LockWindowUpdate(hwndB);
...
}
void EndOperationB()
{
...
LockWindowUpdate(NULL);
}
// fLock = TRUE 锁定, FALSE 解锁
BOOL LockWindowUpdate(HWND hwnd, BOOL fLock);
// 方法B – 独立函数
BOOL LockWindowUpdate(HWND hwnd);
BOOL UnlockWindowUpdate(HWND hwnd);
LockWindowUpdate系列2:LockWindowUpdate是打算如何使用的?
正常行为 | 更新被锁定 | |
BeginPaint, GetDC,等等… | 绘制操作绘制到窗口上 | 绘制操作没有在窗口上绘出任何东西,但影响的区域被记录下来以供后面无效化 |
带DCX_LOCKWINDOWUPDATE标志的GetDCEx | (不要使用) | 绘制操作绘制到窗口上 |
- 当你想接管另一个窗口的绘制,对那个窗口调用LockWindowUpdate。
- 保存你将要覆盖绘制的窗口的象素。
- 绘制新的象素(这些象素往往是原始象素的修正,比如在将一个对象拖动到一个窗口上方时,你可能会添加一个表示此对象的图片)。
- 只要你的操作还在进行中,尽管重复。(这么做时,如果你正修改的屏幕区域与之前修改的不同,可能需要“备份”更多的屏幕上的象素。你可以增量的做备份/还原。例如,你不必在绘制新图片前累计需要恢复的象素集,只需要先把保存的所有象素恢复到屏幕,然后计算拖动图片的新位置,保存新位置处的象素,接着就可以在新位置绘制新图片。通过这种方式,你只需要处理一组“备份象素”)
- 当操作完成,恢复原始象素,并调用LockWindowUpdate(NULL)。
LockWindowUpdate系列3:什么样的操作中应当使用LockWindowUpdate?
LockWindowUpdate系列4:什么样的操作中不应当使用LockWindowUpdate?
不使用 | LockWindowUpdate(hwnd) |
代而使用 | SendMessage(hwnd, WM_SETREDRAW, FALSE, 0) or SetWindowRedraw(hwnd, FALSE) |
不使用 | LockWindowUpdate(NULL) |
代而使用 | SendMessage(hwnd, WM_SETREDRAW, TRUE, 0) or SetWindowRedraw(hwnd, TRUE) |
在C:\Windows\System32\credui.dll文件中的接口。
DWORD WINAPI CredUIParseUserName(
_In_ PCTSTR pszUserName,
_Out_ PTSTR pszUser,
_In_ ULONG ulUserMaxChars,
_Out_ PTSTR pszDomain,
_In_ ULONG ulDomainMaxChars
);
Parameters
-
pszUserName [in]
-
Pointer to a null-terminated string that contains the user name to be parsed. The name must be in UPN or down-level format, or a certificate. Typically, pszUserNameis received from the CredUIPromptForCredentials or CredUICmdLinePromptForCredentials.
pszUser [out]
-
Pointer to a null-terminated string that receives the user account name.
ulUserMaxChars [in]
-
Maximum number of characters to write to the pszUser string including the terminating null character.
Note CREDUI_MAX_USERNAME_LENGTH does NOT include the terminating null character.
pszDomain [out]
-
Pointer to a null-terminated string that receives the domain name. If pszUserName specifies a certificate, pszDomain will be NULL.
ulDomainMaxChars [in]
-
Maximum number of characters to write to the pszDomain string including the terminating null character.
Note CREDUI_MAX_DOMAIN_TARGET_LENGTH does NOT include the terminating null character.
Return value
This function returns the following:
- NO_ERROR
The user name is valid.
- ERROR_INVALID_ACCOUNT_NAME
The user name is not valid.
- ERROR_INSUFFICIENT_BUFFER
One of the buffers is too small.
- ERROR_INVALID_PARAMETER
- ulUserMaxChars or ulDomainMaxChars is zero.
- pszUserName, pszUser, or pszDomain is NULL.
Remarks
This function parses the user name information returned by the CredUIPromptForCredentials and CredUICmdLinePromptForCredentials functions so that the resulting credentials can be passed to functions, such as LogonUser, that require the user name and domain as separate strings.
CredUIPromptForCredentials function
The CredUIPromptForCredentials function creates and displays a configurable dialog box that accepts credentials information from a user.
Applications that target Windows Vista or Windows Server 2008 should call CredUIPromptForWindowsCredentials instead of this function, for the following reasons:
- CredUIPromptForWindowsCredentials is consistent with the current Windows user interface.
- CredUIPromptForWindowsCredentials is more extensible(可扩充的 ), allowing integration(一体化的) of additional authentication mechanisms such as biometrics and smart cards.
- CredUIPromptForWindowsCredentials is compliant with the Common Criteria specification.
DWORD WINAPI CredUIPromptForCredentials(
_In_opt_ PCREDUI_INFO pUiInfo,
_In_ PCTSTR pszTargetName,
_In_ PCtxtHandle Reserved,
_In_opt_ DWORD dwAuthError,
_Inout_ PCTSTR pszUserName,
_In_ ULONG ulUserNameMaxChars,
_Inout_ PCTSTR pszPassword,
_In_ ULONG ulPasswordMaxChars,
_Inout_ PBOOL pfSave,
_In_ DWORD dwFlags
);
Parameters
-
pUiInfo [in, optional]
-
A pointer to a CREDUI_INFO structure that contains information for customizing the appearance of the dialog box.
pszTargetName [in]
-
A pointer to a null-terminated string that contains the name of the target for the credentials, typically a server name. For Distributed File System (DFS) connections, this string is of the form ServerName\ShareName. This parameter is used to identify target information when storing and retrieving credentials.
Reserved [in]
-
This parameter is reserved for future use. It must be NULL.
dwAuthError [in, optional]
-
Specifies why the credential dialog box is needed. A caller can pass this Windows error parameter, returned by another authentication call, to allow the dialog box to accommodate certain errors. For example, if the password expired status code is passed, the dialog box could prompt the user to change the password on the account.
pszUserName [in, out]
-
A pointer to a null-terminated string that contains the user name for the credentials. If a nonzero-length string is passed, the UserName option of the dialog box is prefilled with the string. In the case of credentials other than UserName/Password, a marshaled format of the credential can be passed in. This string is created by calling CredMarshalCredential.
This function copies the user-supplied name to this buffer, copying a maximum of ulUserNameMaxChars characters. This format can be converted toUserName/Password format by using CredUIParseUsername. A marshaled format can be passed directly to a security support provider (SSP).
If the CREDUI_FLAGS_DO_NOT_PERSIST flag is not specified, the value returned in this parameter is of a form that should not be inspected, printed, or persisted other than passing it to CredUIParseUsername. The subsequent results of CredUIParseUsername can be passed only to a client-side authentication function such asWNetAddConnection or an SSP function.
If no domain or server is specified as part of this parameter, the value of the pszTargetName parameter is used as the domain to form a DomainName\UserName pair. On output, this parameter receives a string that contains that DomainName\UserName pair.
ulUserNameMaxChars [in]
-
The maximum number of characters that can be copied to pszUserName including the terminating null character.
Note CREDUI_MAX_USERNAME_LENGTH does not include the terminating null character.
pszPassword [in, out]
-
A pointer to a null-terminated string that contains the password for the credentials. If a nonzero-length string is specified for pszPassword, the password option of the dialog box will be prefilled with the string.
This function copies the user-supplied password to this buffer, copying a maximum of ulPasswordMaxChars characters. If the CREDUI_FLAGS_DO_NOT_PERSIST flag is not specified, the value returned in this parameter is of a form that should not be inspected, printed, or persisted other than passing it to a client-side authentication function such as WNetAddConnection or an SSP function.
When you have finished using the password, clear the password from memory by calling the SecureZeroMemory function. For more information about protecting passwords, see Handling Passwords.
ulPasswordMaxChars [in]
-
The maximum number of characters that can be copied to pszPassword including the terminating null character.
Note CREDUI_MAX_PASSWORD_LENGTH does not include the terminating null character.
pfSave [in, out]
-
A pointer to a BOOL that specifies the initial state of the Save check box and receives the state of the Save check box after the user has responded to the dialog box. If this value is not NULL and CredUIPromptForCredentials returns NO_ERROR, then pfSave returns the state of the Save check box when the user chose OK in the dialog box.
If the CREDUI_FLAGS_PERSIST flag is specified, the Save check box is not displayed, but is considered to be selected.
If the CREDUI_FLAGS_DO_NOT_PERSIST flag is specified and CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX is not specified, the Save check box is not displayed, but is considered to be cleared.
An application that needs to use CredUI to prompt the user for credentials, but does not need the credential management services provided by the credential manager, can use pfSave to receive the state of the Save check box after the user closes the dialog box. To do this, the caller must specify CREDUI_FLAGS_DO_NOT_PERSIST and CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX in dwFlags. When CREDUI_FLAGS_DO_NOT_PERSIST and CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX are set, the application is responsible for examining *pfSave after the function returns, and if *pfSave is TRUE, then the application must take the appropriate action to save the user credentials within the resources of the application.
dwFlags [in]
-
A DWORD value that specifies special behavior for this function. This value can be a bitwise-OR combination of zero or more of the following values.
Value Meaning -
CREDUI_FLAGS_ALWAYS_SHOW_UI
0x00080
Specifies that a user interface will be shown even if the credentials can be returned from an existing credential in credential manager. This flag is permitted only if CREDUI_FLAGS_GENERIC_CREDENTIALS is also specified.
-
CREDUI_FLAGS_COMPLETE_USERNAME
0x00800
Populate the combo box with the prompt for a user name.
-
CREDUI_FLAGS_DO_NOT_PERSIST
0x00002
Do not store credentials or display check boxes. You can pass CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX with this flag to display the Save check box only, and the result is returned in the pfSave output parameter.
-
CREDUI_FLAGS_EXCLUDE_CERTIFICATES
0x00008
Populate the combo box with user name/password only. Do not display certificates or smart cards in the combo box.
-
CREDUI_FLAGS_EXPECT_CONFIRMATION
0x20000
Specifies that the caller will call CredUIConfirmCredentials after checking to determine whether the returned credentials are actually valid. This mechanism ensures that credentials that are not valid are not saved to the credential manager. Specify this flag in all cases unless CREDUI_FLAGS_DO_NOT_PERSIST is specified.
-
CREDUI_FLAGS_GENERIC_CREDENTIALS
0x40000
Consider the credentials entered by the user to be generic credentials.
-
CREDUI_FLAGS_INCORRECT_PASSWORD
0x00001
Notify the user of insufficient credentials by displaying the "Logon unsuccessful" balloon tip.
-
CREDUI_FLAGS_KEEP_USERNAME
0x10000
Do not allow the user to change the supplied user name.
-
CREDUI_FLAGS_PASSWORD_ONLY_OK
0x00200
Populate the combo box with the password only. Do not allow a user name to be entered.
-
CREDUI_FLAGS_PERSIST
0x01000
Do not show the Save check box, but the credential is saved as though the box were shown and selected.
-
CREDUI_FLAGS_REQUEST_ADMINISTRATOR
0x00004
Populate the combo box with local administrators only.
Windows XP Home Edition: This flag will filter out the well-known Administrator account.
-
CREDUI_FLAGS_REQUIRE_CERTIFICATE
0x00010
Populate the combo box with certificates and smart cards only. Do not allow a user name to be entered.
-
CREDUI_FLAGS_REQUIRE_SMARTCARD
0x00100
Populate the combo box with certificates or smart cards only. Do not allow a user name to be entered.
-
CREDUI_FLAGS_SERVER_CREDENTIAL
)X04000
This flag is meaningful only in locating a matching credential to prefill the dialog box, should authentication fail. When this flag is specified, wildcard credentials will not be matched. It has no effect when writing a credential. CredUI does not create credentials that contain wildcard characters. Any found were either created explicitly by the user or created programmatically, as happens when a RAS connection is made.
-
CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX
0x00040
If the check box is selected, show the Save check box and return TRUE in the pfSave output parameter, otherwise, return FALSE. Check box uses the value in pfSave by default.
-
CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS
0x80000
The credential is a "runas" credential. The TargetName parameter specifies the name of the command or program being run. It is used for prompting purposes only.
-
CREDUI_FLAGS_VALIDATE_USERNAME
0x00400
Check that the user name is valid.
NET_API_STATUS NetGetJoinInformation(
_In_ LPCWSTR lpServer,
_Out_ LPWSTR *lpNameBuffer,
_Out_ PNETSETUP_JOIN_STATUS BufferType
);
Parameters
-
lpServer [in]
-
Pointer to a constant string that specifies the DNS or NetBIOS name of the computer on which to call the function. If this parameter is NULL, the local computer is used.
lpNameBuffer [out]
-
Pointer to the buffer that receives the NetBIOS name of the domain or workgroup to which the computer is joined. This buffer is allocated by the system and must be freed using the NetApiBufferFree function. For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths.
BufferType [out]
-
Receives the join status of the specified computer. This parameter can have one of the following values.
typedef enum _NETSETUP_JOIN_STATUS {
NetSetupUnknownStatus = 0,
NetSetupUnjoined,
NetSetupWorkgroupName,
NetSetupDomainName
} NETSETUP_JOIN_STATUS, *PNETSETUP_JOIN_STATUS;