Close a window(if you know part of the title)
This code closes a window, if you know part of it's title. It uses some AOL API's, hehe(sendmessagebystring). I used it for closing Netscape windows because the "Window Class Name" always changed. Not sure if this code has any use though...
AI
ملخص الذكاء الاصطناعي: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
كود المصدر
Function FindWindowByTitle(Title As String) Dim a, b, Caption a = getwindow(Form1.hWnd, GW_OWNER) Caption = GetCaption(a) If InStr(1, LCase(Caption), LCase(Title)) <> 0 Then FindWindowByTitle = b Exit Function End If b = a Do While b <> 0: DoEvents b = getwindow(b, GW_HWNDNEXT) Caption = GetCaption(b) If InStr(1, LCase(Caption), LCase(Title)) <> 0 Then FindWindowByTitle = b Exit Do Exit Function End If Loop End Function Function GetCaption(hWnd) dim hwndLength%, hwndTitle$, a% hwndLength% = GetWindowTextLength(hWnd) hwndTitle$ = String$(hwndLength%, 0) a% = GetWindowText(hWnd, hwndTitle$, (hwndLength% + 1)) GetCaption = hwndTitle$ End Function Sub KillWin(Title As String) Dim a, hWnd hWnd = FindWindowByTitle(Title) a = sendmessagebystring(hWnd, WM_CLOSE, 0, 0) End Sub Use KillWin to close the window.
التعليقات الأصلية (3)
مسترجع من Wayback Machine