API函数之一:根据窗口标题查找窗口_FindWindowA

来源:互联网 发布:关于旅游数据统计网站 编辑:程序博客网 时间:2024/05/01 04:55

Function Long FindWindowA(uLong lpClassName,ref string lpWindowName) Library "user32"
************************************************************************************
功能:根据窗口标题查找窗口
示例:
ulong l_handle
string ls_wname
ls_wname="<窗口标题>"//如,无标题---记事本
l_handle=FindWindowA(0,ls_wname)

*******************************************************example 1
Function Long PostMessage(Long hwnd,Long wMsg,Long wParam,Long lParam) Library "user32" Alias for "PostMessageA"
功能:向创建指定窗口的线索发送一条消息,便不等待线索处理该消息
示例:
ulong l_handle
boolean rtn
l_handle=handle(w_main)
//61472=最小化窗口;  61488=最大化窗口  61728=正常窗口
rtn=PostMessageA(l_handle,274,61472,0)

////////////////////////////////////////////////////////////////////////////////////////////example 2
For applications on Windows, the Handle function does not return a useful value when the previous flag is TRUE. You can use the FindWindowA Windows function to determine whether a Windows application is already running.
Declare FindWindowA as a global external function:

FUNCTION uint FindWindowA (long classname,  &

   string windowname) LIBRARY "user32.dll"

Then add code like the following to your application's open event:

uint  val

val = FindWindowA(0, "MyApp Main Window")

IF val > 0 THEN

   MessageBox("Application already running", &

   "MyApp is already running. You cannot &

      start it again")

   HALT CLOSE

ELSE

   open(w_main)

END IF
Handle = FindWindowA(nul,wtitle)
SetParent(handle,Handle(w_main))
//使Run程序窗口成为PB主程序的子窗口
/////////////////////////////////////////////////////////////////////////////////example 3

Long WM_CLOSE,hwnd,Mval
WM_CLOSE=16
hwnd=FindWindowA(0,cTitle)
if hwnd=0 then
 messagebox("系统提示","没有打开该应用程序!")
else
 Mval=PostMessage(hwnd,WM_CLOSE,0,0)
end if

 
原创粉丝点击