![]() |
|
#1
|
|||
|
|||
|
"minimize to tray" function - clean programming
I'm currently trying to add a "minimize to tray" function to one of my programs. But I'm usure how the code should work correctly, since currently I'm using a some invalid code (but for some reason it works).
The program uses a DialogBox as main window and works like the pseudo code below (number of function parameters here is NOT correct - it's just pseudo code): Code:
if (cmd = WM_SYSCOMMAND)
{
if (wParam = SC_MINIMIZE)
{
// Variant 1
ShowWindow(SW_HIDE)
return FALSE
// Variant 2
ShowWindow(SW_HIDE)
return TRUE
// Variant 3
SendMessage(SC_MINIMIZE)
ShowWindow(SW_HIDE)
return FALSE
// Variant 4
DefWindowProc()
ShowWindow(SW_HIDE)
return FALSE
}
}
The DialogBox vanishes without the default minimizing animation and will not disappear from the taskbar. Variant 2: The DialogBox vanishes and is removed from the taskbar, but the minimizing animation is not shown. When restoring the DialogBox from the tray icon by calling ShowWindow(SW_SHOW) and SendMessage(SC_RESTORE), it is visible at once and not restored with the default restore animation. It's no "minimize to tray", but just a "hide to tray" function. Variant 3: As you might have guessed, it's an infinite loop. Variant 4: The DialogBox is minimized to the taskbar and will be hidden after that. It's exactly what I want. Unhiding and restoring works also like I want it. The problem is that I'm using "DefWindowProc". It is only a valid call in window procedures, not in dialog box procedures. "DefDlgProc" is also invalid, since it will produce an infinite loop. How do I code the "minimize to tray" function correctly, so that I'm using "clean" code and not some hack which works for some reason? One other thing I would like to know it the following: When disassembling some programs which have the "minimize to tray" function, I saw that many of then compare not "wParam", but "wParam & 0x0000FFF0" to SC_MINIMIZE. According to MSDN, wParam can be only one of the SC_* parameters and not some bitmask. Why would somebody use this code if it's not neccessary? p.s. 1: I know why Variant 1-3 fails the way I coded it above, so please don't explain me that. But in my oppinion Variant 4 should fail too. p.s. 2: The programs I disassembled for "minimize to tray" all use Variant 2 ("hide to tray"). For some reason I wasn't able to find the "minimize to tray" code in the programs which really minimize before hiding. Last edited by MarkusO; 10-11-2006 at 16:48. |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Wlscgen: Are "Vendor Id" and "Developer Id" different ? | Numega Softice | General Discussion | 6 | 02-12-2007 18:12 |
| how to enable the function of "alt+f4" | deadfish | General Discussion | 0 | 11-10-2003 21:19 |