Results 1 to 26 of 26

Thread: Hide Window clock

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Hide Window clock

    Dear all,
    How can I place my clock program to overlap the windows clock control?.

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Hide Window clock

    This may give you some idea.

    Edit 1:
    Or
    [NotTested]
    You can get the clock's hWnd by FindWindow/FindWindowEx APIs.
    Using that hWnd, you can get the clock window's size by GetWindowRect API.
    Then, you can place your form on top of it, or even set your form as a child form of the clock by using SetParent API.
    (you may also need SetWindowPos API to make your form topmost.
    You can get all those API declarations from http://www.allapi.net/
    [/NotTested]

    Edit 2: May be there is another better way to accomplish this by using shell DeskBand objects. I've never tried this. But from the screeshots looks like, this app uses DeskBand.
    Last edited by iPrank; Jun 25th, 2006 at 07:49 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  3. #3

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Hide Window clock

    I am using this code to find the window handle of system clock.But the handle (bwnd)returns zero only. I don't know why.Pls help
    VB Code:
    1. Const WS_CHILD = &H40000000
    2. Const WM_LBUTTONDOWN = &H201
    3. Const WM_LBUTTONUP = &H202
    4. Const SW_HIDE = 0
    5. Const SW_NORMAL = 1
    6. Private Type RECT
    7.     Left As Long
    8.     Top As Long
    9.     Right As Long
    10.     Bottom As Long
    11. End Type
    12. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    13. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    14. Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    15. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    16. Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
    17. Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
    18. Dim tWnd As Long, bWnd As Long, ncWnd As Long
    19. Private Sub Form_Load()
    20.     'KPD-Team 1998
    21.     'URL: [url]http://www.allapi.net/[/url]
    22.     'E-Mail: [email]KPDTeam@Allapi.net[/email]
    23.     Dim R As RECT
    24.     'Get the taskbar's window handle
    25.     'TrayClockWClass
    26.     tWnd = FindWindow("Shell_TrayWnd", vbNullString)
    27.     'tWnd = FindWindow("TrayClockWClass", vbNullString)
    28.     'Get the start-button's window handle
    29.     bWnd = FindWindowEx(tWnd, ByVal 0&, "TrayClockWClass", vbNullString)
    30.    
    31.     'Get the start button's position
    32.     GetWindowRect bWnd, R
    33.     'Create a new button
    34.    End Sub

  4. #4
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Hide Window clock

    try this ..

    VB Code:
    1. tWnd = FindWindow("Shell_TrayWnd", vbNullString)
    2.     bWnd = FindWindowEx(tWnd, ByVal 0&, "TrayNotifyWnd", vbNullString)
    3.     ncWnd = FindWindowEx(bWnd, ByVal 0&, "TrayClockWClass", vbNullString)
    4.     Debug.Print tWnd & "-" & bWnd & "-" & ncWnd

  5. #5

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Hide Window clock

    Thanks Rory,
    It is working now.

  6. #6
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Hide Window clock

    Cool .. whats your code after GetWindowRect for positioning the form?
    Just curious .. thanks.

  7. #7

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Hide Window clock

    I am facing problem setting the program always on top. I am using the follwing code to set the form top most always.
    VB Code:
    1. SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE

    I have placed my form over the windows clock control. While Displaying If click the taskbar the form goes invible.

  8. #8
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444

    Re: Hide Window clock

    I use just 2 constants instead of 4 and never had a problem. Try using just nosize, nomove constants

  9. #9

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Hide Window clock

    I use the following,Even the problem is there
    VB Code:
    1. SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE

  10. #10
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Custom Tray Clock

    Sorry for not replying earlier. I was busy.

    I prefer hooking. That way, you'll be able to listen to any other messages ( like context menu, time change, taskbar moving etc).

    But if you don't like hooking, try the following code.
    Looks like Set/GetWindowPlacement is easier than GetwindowRect.
    VB Code:
    1. Option Explicit
    2. ' [b][color=red]Custom Tray Clock[/color][/b]
    3. ' Set the form's border style to None.
    4. ' Add a timer
    5. '
    6. ' To unload the form, click it.
    7. '
    8. Private Type POINTAPI
    9.   x As Long
    10.   y As Long
    11. End Type
    12. '
    13. Private Type RECT
    14.   Left As Long
    15.   Top As Long
    16.   Right As Long
    17.   Bottom As Long
    18. End Type
    19. '
    20. Private Type WINDOWPLACEMENT
    21.   Length As Long
    22.   flags As Long
    23.   showCmd As Long
    24.   ptMinPosition As POINTAPI
    25.   ptMaxPosition As POINTAPI
    26.   rcNormalPosition As RECT
    27. End Type
    28. '
    29. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    30. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    31. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    32. Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
    33. Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
    34. '
    35. Dim hShellTrayWnd As Long ' Taskbar hWnd
    36. Dim TrayNotifyWnd As Long ' SystemTray  hWnd
    37. Public TrayClockWClass As Long ' TrayClock  hWnd
    38. Dim ReBarWindow32 As Long ' Contains the "Quick Launch" and "Running Applications" toolbars
    39.  
    40. '
    41. Dim lParentOld As Long
    42. Dim wpTrayOld As WINDOWPLACEMENT
    43. Dim wpClockOld As WINDOWPLACEMENT
    44. Dim wpRebarOld As WINDOWPLACEMENT
    45.  
    46. '==========================================================================
    47. ' [b]lWidth is the value we want to add (in pixels)[/b]
    48. Private Sub HijackTrayClock(lWidthIncrese As Long)
    49.   '
    50.   Dim wpTray As WINDOWPLACEMENT
    51.   Dim wpClock As WINDOWPLACEMENT
    52.   Dim wpRebar As WINDOWPLACEMENT
    53.   '
    54.   ' Find the SystemTray and Clock windows ==>
    55.   hShellTrayWnd = FindWindow("Shell_TrayWnd", vbNullString)
    56.   TrayNotifyWnd = FindWindowEx(hShellTrayWnd, ByVal 0&, "TrayNotifyWnd", vbNullString)
    57.   TrayClockWClass = FindWindowEx(TrayNotifyWnd, ByVal 0&, "TrayClockWClass", vbNullString)
    58.   ReBarWindow32& = FindWindowEx(hShellTrayWnd, 0&, "ReBarWindow32", vbNullString)
    59.   '
    60.   ' Save current position of SystemTray and Clock
    61.   ' We'll restore them when exiting  ==>
    62.   GetWindowPlacement TrayClockWClass, wpClockOld
    63.   GetWindowPlacement TrayNotifyWnd, wpTrayOld
    64.   GetWindowPlacement ReBarWindow32, wpRebarOld
    65.   '
    66.   ' Resize the SystemTray ==>
    67.   GetWindowPlacement TrayNotifyWnd, wpTray
    68.   wpTray.rcNormalPosition.Left = wpTray.rcNormalPosition.Left - lWidthIncrese
    69.   SetWindowPlacement TrayNotifyWnd, wpTray
    70.   '
    71.   ' Resize the Clock ==>
    72.   ' GetWindowPlacement TrayNotifyWnd, wpTray
    73.   GetWindowPlacement TrayClockWClass, wpClock
    74.   wpClock.rcNormalPosition.Right = wpClock.rcNormalPosition.Right + lWidthIncrese
    75.   SetWindowPlacement TrayClockWClass, wpClock
    76.   '
    77.   ' Resize QuickLaunch and RunningApplications toolbars ==>
    78.   GetWindowPlacement ReBarWindow32, wpRebar
    79.   wpRebar.rcNormalPosition.Right = wpRebar.rcNormalPosition.Right - lWidthIncrese
    80.   SetWindowPlacement ReBarWindow32, wpRebar
    81.   '
    82.   ' Place our form as a child of Clock==>
    83.   lParentOld = SetParent(Me.hwnd, TrayNotifyWnd)
    84.   SetWindowPlacement Me.hwnd, wpClock
    85. End Sub
    86.  
    87. '==========================================================================
    88. Private Sub Form_Load()
    89.   HijackTrayClock 100
    90.   Me.BackColor = &HC0C0FF
    91.   Me.AutoRedraw = True
    92.   Timer1.Interval = 1000
    93.   Me.Print Time
    94. End Sub
    95.  
    96. '==========================================================================
    97. Private Sub Timer1_Timer()
    98.   Me.Cls
    99.   Me.Print Time
    100. End Sub
    101.  
    102. '==========================================================================
    103. Private Sub Form_Click()
    104.   Unload Me
    105. End Sub
    106.  
    107. '==========================================================================
    108. Private Sub Form_Unload(Cancel As Integer)
    109.   ' Restore all ==>
    110.   SetParent Me.hwnd, lParentOld
    111.   SetWindowPlacement TrayNotifyWnd, wpTrayOld
    112.   SetWindowPlacement TrayClockWClass, wpClockOld
    113.   SetWindowPlacement ReBarWindow32, wpRebarOld
    114. End Sub
    Last edited by iPrank; Jun 28th, 2006 at 04:48 AM. Reason: Added resizing code
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  11. #11
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Hide Window clock

    VB Code:
    1. Option Explicit
    2.  
    3. Const WS_CHILD = &H40000000
    4. Const WM_LBUTTONDOWN = &H201
    5. Const WM_LBUTTONUP = &H202
    6. Const SW_HIDE = 0
    7. Const SW_NORMAL = 1
    8. Private Type RECT
    9.     Left As Long
    10.     Top As Long
    11.     Right As Long
    12.     Bottom As Long
    13. End Type
    14.  
    15. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    16. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    17. Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    18. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    19. Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
    20. Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
    21. Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Integer) As Integer
    22. Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Integer) As Integer
    23. Private Declare Sub SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
    24.  
    25. Const HWND_TOPMOST = -1
    26. Const HWND_NOTOPMOST = -2
    27. Const SWP_NOSIZE = &H1
    28. Const SWP_NOMOVE = &H2
    29. Const SWP_NOACTIVATE = &H10
    30. Const SWP_SHOWWINDOW = &H40
    31.  
    32. Dim tWnd As Long, bWnd As Long, ncWnd As Long
    33.  
    34. '// SET TO TOP
    35. Public Sub SetWindowToTop(ByVal plnghWnd As Long)
    36.     SetWindowPos plnghWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    37. End Sub
    38.  
    39. Private Sub Form_Load()
    40.     Dim R As RECT
    41.     Dim lngX As Integer
    42.     Dim lngY As Integer
    43.     Dim lngW As Integer
    44.     Dim lngH As Integer
    45.     'Get the clocks window handle
    46.     tWnd = FindWindow("Shell_TrayWnd", vbNullString)
    47.     bWnd = FindWindowEx(tWnd, ByVal 0&, "TrayNotifyWnd", vbNullString)
    48.     ncWnd = FindWindowEx(bWnd, ByVal 0&, "TrayClockWClass", vbNullString)
    49.     'Get the clocks position
    50.     GetWindowRect ncWnd, R
    51.     lngX = R.Left * 15
    52.     lngY = R.Top * 15
    53.     lngW = (R.Right - R.Left) * 15
    54.     lngH = (R.Bottom - R.Top) * 15
    55.     Form1.Move lngX, lngY, lngW, lngH
    56.     SetWindowToTop Form1.hwnd
    57.     'Label1.Caption = Time
    58. End Sub

  12. #12
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Hide Window clock

    how do you get the background color of the System Tray though ..?

  13. #13
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Hide Window clock

    In classic theme, it is vbButtonFace.

    I don't know XP theme APIs. In XP theme, I tried hDCToPicture to get the clock's DC. But it gets the text too.
    I can't find any way to delete the text, except changing every pixel.

    I hope there is an API in XP theme library to do this.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  14. #14

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Hide Window clock

    Dear IFrank,
    What is meant by hooking.Pls explain

  15. #15
    Addicted Member silentthread's Avatar
    Join Date
    Jun 2006
    Location
    Miami, Florida
    Posts
    143

    Re: Hide Window clock

    Quote Originally Posted by danasegarane
    Dear IFrank,
    What is meant by hooking.Pls explain
    Hooking is simply serving as a middle man between messages sent to windows.

    Example....

    You click on the return key, this message is posted to a window.


    Example 2 (with hooking)

    You click on the return key, your program checks out the message, the message is posted to a window.
    Watch media as you download it! Excellent tool!
    FREE CUBA!
    MyBlog
    If you feel my post has helped, please rate it.

  16. #16

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Hide Window clock

    And also I want the width of the form to be little more bigger?/

  17. #17
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Hide Window clock

    if you use the code i posted then ..

    lngX = R.Left * 15
    lngY = R.Top * 15
    lngW = (R.Right - R.Left) * 15 <--- This is the Width ..add to it like + 100 etc..
    lngH = (R.Bottom - R.Top) * 15 <--- This is the Height ..
    Form1.Move lngX, lngY, lngW, lngH

    PS. you'll also have to adjust the X (left) Eg. .. -100

  18. #18

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Hide Window clock

    Dear Rory?,
    The problem i face in your code is that when i click taskbar bar, the form goes invisible??

  19. #19
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Hide Window clock

    add a timer ..

    Private Sub Timer1_Timer()
    SetWindowToTop Form1.hwnd
    Label1.Caption = Time
    End Sub

  20. #20
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Hide Window clock

    Quote Originally Posted by danasegarane
    And also I want the width of the form to be little more bigger?/
    I've edited the code to accomplish this.

    But, as the tray/clock will get resized when you resize the taskbar or due to WinXP's inactive tray icon hiding feature, you'll need to constantly poll the SystemTray and Clock's size fom a timer.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  21. #21
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Hide Window clock

    i still want to know how he's getting the color the same ..

  22. #22
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Hide Window clock

    Quote Originally Posted by rory
    i still want to know how he's getting the color the same ..
    I already posted about classic theme.

    I found that, In XP theme Windows simply uses a bitmap.

    Download Resource Hacker.
    Go to C:\WINDOWS\Resources\Themes\Luna folder.
    Open the luna.msstyles file in ResHacker.
    See the *_TASKBAND* bitmaps.
    Windows uses them in themed mode.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  23. #23
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Hide Window clock

    Another code update.
    Added code to resize QuickLaunch and RunningApplications toolbars.

    Taskbar buttons now resizes properly (without being cut off).
    Last edited by iPrank; Jun 28th, 2006 at 04:35 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  24. #24

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Hide Window clock

    Dear IFrank,
    Thanks for the code.But I am finding some difficulties.I want the resized clock to be Present. But Now the clock goes to original Position after some time.

  25. #25
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Hide Window clock

    I don't think you can do sizing correctly without hooking (and/or other methods to get SysTray's condition).

    The size and position of systray (and clock) changes when,
    the taskbar resizes
    or an trayicon gets added or removed,
    or user clicks the arrow button (XP) of system tray..etc.

    We have to monitor all those cases.

    As I mentioned in post#20, the best you can do without hooking is,
    add another timer with very small interval to constantly get systray's position.

    In the following code, I've added another timer (Timer2). Now, everytime the timer fires, it checks the window placement. If the window is resized, it restores back to original position.

    Drag and resize the taskbar - it will work fine.
    But click on the arrow button of systray or add/remove an icon fron systray, you'll see the problem. I have never tried to get systray icon info. (My clock app doesn't resize. ) see if this code helps you.


    Code 2: track sizechangeusing timer.
    VB Code:
    1. Option Explicit
    2. ' [b][color=red]Custom Tray Clock 2[/color][/b]
    3. ' Set the form's border style to None.
    4. ' Add 2 timers
    5. '
    6. Private Type POINTAPI
    7.   x As Long
    8.   y As Long
    9. End Type
    10. '
    11. Private Type RECT
    12.   Left As Long
    13.   Top As Long
    14.   Right As Long
    15.   Bottom As Long
    16. End Type
    17. '
    18. Private Type WINDOWPLACEMENT
    19.   Length As Long
    20.   flags As Long
    21.   showCmd As Long
    22.   ptMinPosition As POINTAPI
    23.   ptMaxPosition As POINTAPI
    24.   rcNormalPosition As RECT
    25. End Type
    26. '
    27. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    28. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    29. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    30. Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
    31. Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
    32. '
    33. Dim hShellTrayWnd As Long ' Taskbar hWnd
    34. Dim TrayNotifyWnd As Long ' SystemTray  hWnd
    35. Public TrayClockWClass As Long ' TrayClock  hWnd
    36. Dim ReBarWindow32 As Long ' Contains the "Quick Launch" and "Running Applications" toolbars
    37.  
    38. '
    39. Dim lParentOld As Long
    40. Dim wpTrayOld As WINDOWPLACEMENT
    41. Dim wpClockOld As WINDOWPLACEMENT
    42. Dim wpRebarOld As WINDOWPLACEMENT
    43. '
    44. Dim wpTray As WINDOWPLACEMENT
    45.   Dim wpClock As WINDOWPLACEMENT
    46.   Dim wpRebar As WINDOWPLACEMENT
    47.  
    48. ' [b]lWidth is the value we want to add (in pixels)[/b]
    49. Private Sub HijackTrayClock(lWidthIncrese As Long)
    50.   GetHwnd
    51.   SaveOriginalPlacement
    52.   Call ResizeClock(lWidthIncrese)
    53.   ' Place our form as a child of Clock==>
    54.   lParentOld = SetParent(Me.hwnd, TrayNotifyWnd)
    55.   SetWindowPlacement Me.hwnd, wpClock
    56. End Sub
    57.  
    58. Private Sub Form_Load()
    59.   HijackTrayClock 100
    60.   Me.BackColor = &HC0C0FF
    61.   Me.AutoRedraw = True
    62.   Timer1.Interval = 1000
    63.   Timer2.Interval = 5
    64.   Me.Print Time
    65. End Sub
    66.  
    67. Private Sub Timer1_Timer()
    68.   Me.Cls
    69.   Me.Print Time
    70. End Sub
    71.  
    72. Private Sub Form_Click()
    73.   Unload Me
    74. End Sub
    75.  
    76. Private Sub Form_Unload(Cancel As Integer)
    77.   ' Restore all ==>
    78.   SetParent Me.hwnd, lParentOld
    79.   SetWindowPlacement TrayNotifyWnd, wpTrayOld
    80.   SetWindowPlacement TrayClockWClass, wpClockOld
    81.   SetWindowPlacement ReBarWindow32, wpRebarOld
    82. End Sub
    83.  
    84. Private Sub CopyUDT(wpSource As WINDOWPLACEMENT, wpDest As WINDOWPLACEMENT)
    85.   wpSource.flags = wpDest.flags
    86.   wpSource.Length = wpDest.Length
    87.   '
    88.   wpSource.ptMaxPosition.x = wpDest.ptMaxPosition.x
    89.   wpSource.ptMaxPosition.y = wpDest.ptMaxPosition.y
    90.   '
    91.   wpSource.ptMinPosition.x = wpDest.ptMinPosition.x
    92.   wpSource.ptMinPosition.y = wpDest.ptMinPosition.y
    93.   '
    94.   wpSource.rcNormalPosition.Top = wpDest.rcNormalPosition.Top
    95.   wpSource.rcNormalPosition.Bottom = wpDest.rcNormalPosition.Bottom
    96.   wpSource.rcNormalPosition.Left = wpDest.rcNormalPosition.Left
    97.   wpSource.rcNormalPosition.Right = wpDest.rcNormalPosition.Right
    98.   '
    99.   wpSource.showCmd = wpDest.showCmd
    100. End Sub
    101.  
    102. Private Function IsEqualUDT(wp1 As WINDOWPLACEMENT, wp2 As WINDOWPLACEMENT) As Boolean
    103.  
    104.   IsEqualUDT = (wp1.flags = wp2.flags) And _
    105.      (wp1.Length = wp2.Length) And _
    106.      (wp1.ptMaxPosition.x = wp2.ptMaxPosition.x) And _
    107.      (wp1.ptMaxPosition.y = wp2.ptMaxPosition.y) And _
    108.      (wp1.ptMinPosition.x = wp2.ptMinPosition.x) And _
    109.      (wp1.ptMinPosition.y = wp2.ptMinPosition.y) And _
    110.      (wp1.rcNormalPosition.Top = wp2.rcNormalPosition.Top) And _
    111.      (wp1.rcNormalPosition.Bottom = wp2.rcNormalPosition.Bottom) And _
    112.      (wp1.rcNormalPosition.Left = wp2.rcNormalPosition.Left) And _
    113.      (wp1.rcNormalPosition.Right = wp2.rcNormalPosition.Right) And _
    114.      (wp1.showCmd = wp2.showCmd)
    115. End Function
    116.  
    117. Private Sub GetHwnd()
    118.   ' Find the SystemTray and Clock windows ==>
    119.   hShellTrayWnd = FindWindow("Shell_TrayWnd", vbNullString)
    120.   TrayNotifyWnd = FindWindowEx(hShellTrayWnd, ByVal 0&, "TrayNotifyWnd", vbNullString)
    121.   TrayClockWClass = FindWindowEx(TrayNotifyWnd, ByVal 0&, "TrayClockWClass", vbNullString)
    122.   ReBarWindow32& = FindWindowEx(hShellTrayWnd, 0&, "ReBarWindow32", vbNullString)
    123. End Sub
    124.  
    125. Private Sub ResizeClock(lWidthIncrese As Long)
    126.   ' Resize the SystemTray ==>
    127.   GetWindowPlacement TrayNotifyWnd, wpTray
    128.   wpTray.rcNormalPosition.Left = wpTray.rcNormalPosition.Left - lWidthIncrese
    129.   SetWindowPlacement TrayNotifyWnd, wpTray
    130.   ' Resize the Clock ==>
    131.   ' GetWindowPlacement TrayNotifyWnd, wpTray
    132.   GetWindowPlacement TrayClockWClass, wpClock
    133.   wpClock.rcNormalPosition.Right = wpClock.rcNormalPosition.Right + lWidthIncrese
    134.   SetWindowPlacement TrayClockWClass, wpClock
    135.   ' Resize QuickLaunch and RunningApplications toolbars ==>
    136.   GetWindowPlacement ReBarWindow32, wpRebar
    137.   wpRebar.rcNormalPosition.Right = wpRebar.rcNormalPosition.Right - lWidthIncrese
    138.   SetWindowPlacement ReBarWindow32, wpRebar
    139. End Sub
    140.  
    141. Private Sub SaveOriginalPlacement()
    142.   ' Save current position of SystemTray and Clock
    143.   ' We'll restore them when exiting  ==>
    144.   GetWindowPlacement TrayClockWClass, wpClockOld
    145.   GetWindowPlacement TrayNotifyWnd, wpTrayOld
    146.   GetWindowPlacement ReBarWindow32, wpRebarOld
    147. End Sub
    148.  
    149. Private Sub Timer2_Timer()
    150.   Dim wp1 As WINDOWPLACEMENT
    151.   Dim wp2 As WINDOWPLACEMENT
    152.   GetWindowPlacement TrayNotifyWnd, wp1
    153.   wpTray.rcNormalPosition.Bottom = wp1.rcNormalPosition.Bottom
    154.   wpClock.rcNormalPosition.Bottom = wp1.rcNormalPosition.Bottom
    155.  
    156.   If Not IsEqualUDT(wp1, wpTray) Then
    157.     SetWindowPlacement TrayNotifyWnd, wpTray
    158.     SetWindowPlacement TrayClockWClass, wpClock
    159.   End If
    160.  
    161.   SetWindowPlacement Me.hwnd, wpClock
    162. End Sub
    Last edited by iPrank; Jun 28th, 2006 at 09:20 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  26. #26

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Hide Window clock

    Dear IFrank,
    I am not abled to implement.The clock flicker.

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