|
发表于 2013-8-2 21:10:19
|
显示全部楼层
本帖最后由 565123 于 2013-8-4 13:50 编辑
BOOL WINAPI FlashWindow(
_In_ HWND hWnd,
_In_ BOOL bInvert
);
BOOL WINAPI FlashWindow(
_In_ HWND hWnd,
_In_ BOOL bInvert
);
Parameters
hWnd [in]
A handle to the window to be flashed. The window can be either open or minimized.
bInvert [in]
If this parameter is TRUE, the window is flashed from one state to the other. If it is FALSE, the window is returned to its original state (either active or inactive).
When an application is minimized and this parameter is TRUE, the taskbar window button flashes active/inactive. If it is FALSE, the taskbar window button flashes inactive, meaning that it does not change colors. It flashes, as if it were being redrawn, but it does not provide the visual invert clue to the user.
Return value
The return value specifies the window's state before the call to the FlashWindow function. If the window caption was drawn as active before the call, the return value is nonzero. Otherwise, the return value is zero.
Remarks
Flashing a window means changing the appearance of its caption bar as if the window were changing from inactive to active status, or vice versa. (An inactive caption bar changes to an active caption bar; an active caption bar changes to an inactive caption bar.)
Typically, a window is flashed to inform the user that the window requires attention but that it does not currently have the keyboard focus.
The FlashWindow function flashes the window only once; for repeated flashing, the application should create a system timer.
第一个参数是窗口的句柄,第二个参数必须为真,如果要闪烁多次,要使用timer#define UNICODE
#include <Windows.h>
#include <tchar.h>
#include <Shlwapi.h>
#define TIMER_ID 10
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
union A
{
WNDCLASSEX * wndClass;
HWND hWnd;
MSG *msg;
};
static HWND hWnd;
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdline, int nCmdShow)
{
A a;
a.wndClass = new WNDCLASSEX;
a.wndClass->cbSize = sizeof(WNDCLASSEX);
a.wndClass->cbWndExtra = 0;
a.wndClass->cbClsExtra = 0;
a.wndClass->hbrBackground = (HBRUSH) COLOR_BACKGROUND + 1;
a.wndClass->hCursor = LoadCursor(nullptr, IDC_ARROW);
a.wndClass->hIcon = LoadIcon(nullptr, IDI_APPLICATION);
a.wndClass->hIconSm = a.wndClass->hIcon;
a.wndClass->hInstance = hInstance;
a.wndClass->lpfnWndProc = WndProc;
a.wndClass->lpszClassName = L"Test";
a.wndClass->lpszMenuName = nullptr;
a.wndClass->style = CS_HREDRAW | CS_VREDRAW;
RegisterClassEx(a.wndClass);
delete a.wndClass;
a.hWnd = CreateWindow(L"Test", L"Class", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, 0);
hWnd = a.hWnd;
ShowWindow(a.hWnd, SW_SHOWNORMAL);
a.msg = new MSG;
while (GetMessage(a.msg, nullptr, 0, 0))
{
TranslateMessage(a.msg);
DispatchMessage(a.msg);
}
delete a.msg;
a.msg = 0;
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static int count;
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CREATE:
if (StrCmp(((CREATESTRUCT*) lParam)->lpszClass, L"Test") == 0)
CreateWindow(L"button", L"闪烁", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 50, 50, 100, 20, hWnd, 0, GetModuleHandle(nullptr), 0);
break;
case WM_COMMAND:
SetTimer(hWnd, TIMER_ID, 2000, nullptr);
break;
case WM_TIMER:
if (wParam == TIMER_ID && count < 5)
{
FlashWindow(hWnd, true);
count++;
}
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
break;
}
return 0;
}
点击按钮让窗口闪烁五次
|
评分
-
参与人数 1 | 荣誉 +10 |
鱼币 +10 |
贡献 +5 |
收起
理由
|
怡静
| + 10 |
+ 10 |
+ 5 |
感谢楼主无私奉献! |
查看全部评分
|