bool APIENTRY MainDlgProc(HWND hDlg,//对话框句柄
UINT message,//消息类型
WPARAM wParam,//消息附带信息
LPARAM lParam)//消息附带信息
{
POINT MousePoint;
char str[256];
HWND hWnd;//存放窗口句柄
switch(message)//消息处理
{
case WM_INITDIALOG://对话框初始化消息
{
//使窗口常居顶层
SetWindowPos(hDlg,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
SetTimer(hDlg,1,100,NULL);
m_hWnd=hDlg;
return(true);
}
case WM_CLOSE:
{
EndDialog(hDlg,true);
return(true);
}
case WM_TIMER:
{
GetCursorPos(&MousePoint);//取鼠标位置
hWnd=WindowFromPoint(MousePoint);//获取鼠标指针所在位置窗口句柄
SendMessage(hWnd,WM_GETTEXT,255,(long)str);
SetDlgItemText(hDlg,IDC_CAPTION,str);
//获取窗口类名
GetClassName(hWnd,str,255);
SetDlgItemText(hDlg,IDC_CLASSNAME,str);
//获取窗口类值
ltoa(GetClassLong(hWnd,GCW_ATOM),str,10);
SetDlgItemText(hDlg,IDC_CLASSATOM,str);
//获取窗口风格
ltoa(GetWindowLong(hWnd,GWL_EXSTYLE),str,2);
SetDlgItemText(hDlg,IDC_EXTSTYLE,str);
//获取窗口ID
ltoa(GetWindowLong(hWnd,GWL_ID),str,10);
SetDlgItemText(hDlg,IDC_ID,str);
return(true);
}
case WM_DESTROY:
{
KillTimer(hDlg,1);
//TaskBarDeleteIcon(GetSafeHwnd(),100,m_hIcon,_T("hi!"));
return(true);
}
case WM_COMMAND://命令按钮消息
{
if(LOWORD(wParam)==IDC_QUIT)
EndDialog(hDlg,TRUE);
return(true);
}
}
return(false);
}
int WINAPI WinMain(HINSTANCE hInst,
HINSTANCE hInstPrev,
LPSTR szCmdline,
int nCmdShow)
{
DialogBox(hInst,//应用程序实力句柄
MAKEINTRESOURCE(IDD_MAINDLG),//对话框资源标识
NULL,//对话框所属父窗口句柄
(DLGPROC)MainDlgProc);//对话框过程函数指针
return(0);
}