Results 1 to 12 of 12

Thread: Flashing

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    73

    Flashing

    hey, how can i make my program flash when the text inside a text box changes, like chat programs when you have a message?

    cheers

    EDIT: and also how do i disable the X in the top right hand corner?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Flashing

    Quote Originally Posted by JoshUK
    hey, how can i make my program flash when the text inside a text box changes, like chat programs when you have a message?
    VB Code:
    1. Private Declare Function GetActiveWindow Lib "user32.dll" () As Long
    2. Private Declare Function FlashWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wActive As Long) As Long
    3. Private Declare Sub Sleep Lib "kernel32" (ByVal dMilliseconds As Long)
    4.  
    5. Private Sub Text1_Change()
    6. Dim i As Integer
    7. Dim handle As Long ' Handle for the active window
    8. Dim rval As Long
    9. handle = GetActiveWindow()  'Get the handle of active window
    10. For i = 1 To 10  ' Flash five times
    11.     rval = FlashWindow(handle, 1)  'Flash the window
    12.     Sleep 500  ' Delay the execution for 1/2 minute
    13. Next
    14. rval = FlashWindow(handle, 0) ' Bring the window to normal position
    Quote Originally Posted by JoshUK
    EDIT: and also how do i disable the X in the top right hand corner?
    VB Code:
    1. Private Const SC_CLOSE As Long = &HF060&
    2. Private Const MIIM_STATE As Long = &H1&
    3. Private Const MIIM_ID As Long = &H2&
    4. Private Const MFS_GRAYED As Long = &H3&
    5. Private Const WM_NCACTIVATE As Long = &H86
    6.  
    7. Private Type MENUITEMINFO
    8.     cbSize As Long
    9.     fMask As Long
    10.     fType As Long
    11.     fState As Long
    12.     wID As Long
    13.     hSubMenu As Long
    14.     hbmpChecked As Long
    15.     hbmpUnchecked As Long
    16.     dwItemData As Long
    17.     dwTypeData As String
    18.     cch As Long
    19. End Type
    20.  
    21. Private Declare Function GetSystemMenu Lib "user32" ( _
    22.     ByVal hWnd As Long, ByVal bRevert As Long) As Long
    23.  
    24. Private Declare Function GetMenuItemInfo Lib "user32" Alias _
    25.     "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
    26.     ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long
    27.  
    28. Private Declare Function SetMenuItemInfo Lib "user32" Alias _
    29.     "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
    30.     ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
    31.  
    32. Private Declare Function SendMessage Lib "user32" Alias _
    33.     "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
    34.     ByVal wParam As Long, lParam As Any) As Long
    35.  
    36. Private Declare Function IsWindow Lib "user32" _
    37.     (ByVal hWnd As Long) As Long
    38.  
    39. ' Enables / Disables the close button on the titlebar and in the system menu
    40. ' of the form window passed.
    41. ' Return Values:
    42. '
    43. '    0  Close button state changed succesfully / nothing to do.
    44. '   -1  Invalid Window Handle (hWnd argument) Passed to the function
    45. '   -2  Failed to switch command ID of Close menu item in system menu
    46. '   -3  Failed to switch enabled state of Close menu item in system menu
    47.  
    48. Public Function EnableCloseButton(ByVal hWnd As Long, Enable As Boolean)
    49. As Integer
    50.     Const xSC_CLOSE As Long = -10
    51.     ' Check that the window handle passed is valid    
    52.     EnableCloseButton = -1
    53.     If IsWindow(hWnd) = 0 Then Exit Function    
    54.     ' Retrieve a handle to the window's system menu    
    55.     Dim hMenu As Long
    56.     hMenu = GetSystemMenu(hWnd, 0)    
    57.     ' Retrieve the menu item information for the close menu item/button    
    58.     Dim MII As MENUITEMINFO
    59.     MII.cbSize = Len(MII)
    60.     MII.dwTypeData = String(80, 0)
    61.     MII.cch = Len(MII.dwTypeData)
    62.     MII.fMask = MIIM_STATE
    63.    
    64.     If Enable Then
    65.         MII.wID = xSC_CLOSE
    66.     Else
    67.         MII.wID = SC_CLOSE
    68.     End If
    69.    
    70.     EnableCloseButton = -0
    71.     If GetMenuItemInfo(hMenu, MII.wID, False, MII) = 0 Then Exit Function    
    72.     ' Switch the ID of the menu item so that VB can not undo the action itself    
    73.     Dim lngMenuID As Long
    74.     lngMenuID = MII.wID
    75.    
    76.     If Enable Then
    77.         MII.wID = SC_CLOSE
    78.     Else
    79.         MII.wID = xSC_CLOSE
    80.     End If
    81.    
    82.     MII.fMask = MIIM_ID
    83.     EnableCloseButton = -2
    84.     If SetMenuItemInfo(hMenu, lngMenuID, False, MII) = 0 Then Exit Function    
    85.     ' Set the enabled / disabled state of the menu item    
    86.     If Enable Then
    87.         MII.fState = (MII.fState Or MFS_GRAYED)
    88.         MII.fState = MII.fState - MFS_GRAYED
    89.     Else
    90.         MII.fState = (MII.fState Or MFS_GRAYED)
    91.     End If
    92.    
    93.     MII.fMask = MIIM_STATE
    94.     EnableCloseButton = -3
    95.     If SetMenuItemInfo(hMenu, MII.wID, False, MII) = 0 Then Exit Function    
    96.     SendMessage hWnd, WM_NCACTIVATE, True, 0    
    97.     EnableCloseButton = 0    
    98. End Function
    99.  
    100. 'Usage
    101. Private Sub Form_Load()
    102.         'enabled
    103.         EnableCloseButton Me.hWnd, True      
    104.  End Sub
    105.  
    106. Private Sub Command1_Click()
    107.       'disabled
    108.        EnableCloseButton Me.hWnd, False
    109. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    73

    Re: Flashing

    neither of them seemed to work, do they work in VB5?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    73

    Re: Flashing

    Bump

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Flashing

    I guess not. Just make it visible and not every 50 milliseconds. It should flash.

    Change the border stype to 0. No border.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    73

    Re: Flashing

    i mean say on MSN when you receive a message when the message window is minimized or behind another program the bar on the task bar flashes, how would i gio about doing that?

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Flashing

    Quote Originally Posted by JoshUK
    neither of them seemed to work, do they work in VB5?
    According to AllAPI.Net, this API calls should work in VB4(32 bit), VB5 and VB6 (although I've no way of testing them in anything but VB6)

    What happens when you run that code?

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Flashing

    the flash window worked for me, but when i put it in the form load event i flashed the calling window, maybe he wants it to change color, like yahoo's and keeps flashing till it gets focus

    disable the X in the top right hand corner
    you can set me.controlbox to false to hide the X and the other controls, or you can put code in the form unload event to make it do something else, Cancel = True, will stop the unload process
    pete

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    73

    Re: Flashing

    Quote Originally Posted by westconn1
    the flash window worked for me, but when i put it in the form load event i flashed the calling window, maybe he wants it to change color, like yahoo's and keeps flashing till it gets focus
    thats exactly what i need!, do you have to code for it?

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Flashing

    nope, probably have to send message to titlebar,
    someone else may be able to tell you how it is done now they know what you want

    pete

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Flashing

    have a look here, there is 3 example to flashing the window

    vbnet

    rgds pete

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    73

    Re: Flashing

    http://vbnet.mvps.org/index.html?code/forms/index.html
    this one does exactly what i want it to do, but i can't seem to impliment it into my program, on txtmain_change

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