Results 1 to 2 of 2

Thread: more on those annoying popups

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    15
    Hi folks,
    This code was lovingly ganked from this very board, thanks to all who have posted it.
    I'm attempting to use this snippet as a popup-window killer, for now I'm testing with notepad, calc, and eudora.
    Two small queries:
    First,
    I'm having trouble passing the string to "sApp" from my ini file. The string comes through fine as "puk" and it displays in "label1". Assigning it with "sApp = puk" doesn't work and I don't know exactly why (probably something quite simple). I'm hoping someone can help with this.
    Second,
    For the moment I'm using a timer so I can see what each cycle is doing but in the end it'll likely have a for/next or a do/loop as I haven't messed with do/loops much yet. I'm wondering which method, a for/next or do/loop, a pro would use and why?
    Any help is appreciated.
    TIA,

    Xinny

    MODULE------

    Public Const WM_CLOSE = &H10
    Public Const MAX_PATH = 260

    Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    ByVal lParam As Long) As Long
    Declare Function EnumWindows Lib "user32" _
    (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
    (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

    Private sAppTitle As String
    Public glHwnd As Long

    Public Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As Long
    Dim lResult As Long
    Dim sWndName As String

    fEnumWindowsCallBack = 1
    sWndName = Space$(MAX_PATH)

    lResult = GetWindowText(hwnd, sWndName, MAX_PATH)
    sWndName = Left$(sWndName, lResult)
    'Search Title for our string
    If (InStr(1, sWndName, sAppTitle, vbTextCompare) > 0) Then
    Debug.Print sWndName
    glHwnd = hwnd
    fEnumWindowsCallBack = 0
    End If
    End Function

    Public Function SearchWindows(sApp As String, hwnd As Long) As Long
    sAppTitle = sApp
    glHwnd = 0
    Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)
    SearchWindows = glHwnd
    End Function

    CODE------form with a couple of labels and a timer.

    Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal _
    lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

    Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal _
    lpFileName As String) As Long

    Dim Pukn As Integer
    Dim sApp As String
    Dim pukt As Integer
    Dim puk As String * 128
    Private Sub Timer1_Timer()
    Pukn = Pukn + 1
    pukt = GetPrivateProfileInt("PUKD", "Total", 3, "kia.ini")
    If Pukn = (pukt + 1) Then Pukn = 0
    lntc = GetPrivateProfileString("PUKD", Pukn, "blahblah", puk, Len(puk), "kia.ini")
    Label1 = puk 'labels are temporary
    Label2 = Pukn

    sApp = "note" '<----- needs to pass the name from the ini "puk"
    'sApp = puk 'dunno why this fails

    glHwnd = SearchWindows(sApp, Me.hwnd)
    If glHwnd > 0 Then
    PostMessage glHwnd, WM_CLOSE, 0&, 0&
    End If
    End Sub

    'timer interval is set to 2000
    'c:\windows\kia.ini consists of:
    '[PUKD]
    'total=3
    '1=notepad
    '2=eudora
    '3=calc


  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    15

    figured it out myself.. yay :)

    If anyone is trying to do the same I found a way to make this work (with notepad and calc and such anyway)

    had to use this:
    sApp = Left$(puk, intc)

    instead of

    sApp = puk

    It took a while but I've only been learning VB 2 months or so now.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width