GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Apr-2005, 13:08
WillyumYum WillyumYum is offline
New Member
 
Join Date: Apr 2005
Posts: 4
WillyumYum is on a distinguished road

Win32 Window Shading behavior (like linux)


I'm writing a program to work with ALL windows applications. It will cause double clicking on the titlebar of an application to shade the window (exactly like window behavior in linux). Shading meaning the main part of the application window 'rolls up' and all that is visiible is the titlebar of the application.

What I'm wondering is what the best way to go about this application might be. I've had one person tell me that the only way to do it with the original windows is by modifying the windows API (which im not really sure how to go about doing), and my own ideas are the following:

Idea 1. Just set the height of the application window to 0 (I realized that this won't work with everything because not all applications will have to listen to setting the window height to 0, so this option is out.

Idea 2. When the titlebar of the application is double clicked, minimize the original window, and create a fake window with 0 height that is in the same location as the application's titlebar, and the icon and titlebar text of the application clicked are the same on this fake window.

Idea 3. I was thinking it MAY be possible to just hide the bottom part of an application, similar to the way windows media player hides the titlebar of its own application window, I Was wondering if this is a possibility?

I'm open to other suggestions, code examples, and anything else anyone has to offer. Thanks for taking the time to read my post.

If my description of what I'm trying to do is too vague please let me know, and I will post screenshots and a more elaborate description.

Thanks again.

will
  #2  
Old 17-Apr-2005, 22:17
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
Idea 1. there are other programs on the market (free ones) that do this window shading, and I believe this is what they do. however, they do not work all the time. so if what you want is absolute reliability, then you are right in discrediting this idea.
Idea 2. If you want absolute reliability, then this would seem to be the best idea. You would want to set some kind of hook to catch double-clicks on the titlebars, and then your hook handler would be something like this:
CPP / C++ / C Code:
//in the hook handler. win_clicked is the HWND of the window whose titlebar has been clicked (i don't know where it would come from. maybe from the wParam or lParam, or a call to WindowFromPoint). hide is a bool that contains whether the window is currently unshaded (true) or already shaded (false).
if (hide)
{
WINDOWINFO wnd_info; //structure to hold info about the window we're working on.
ZeroMemory(&wnd_info, sizeof(WINDOWINFO)); //formality
wnd_info.cbSize = sizeof(WINDOWINFO); //formality
GetWindowInfo(win_clicked, &wnd_info); //fill up our structure
ShowWindow(win_clicked, SW_HIDE); //hide the window in question
//now we will create a window that is as exact a copy as possible as the other window, except for the height being 0.
WNDCLASSEX shadedwincl; //window class
LPSTR clname; //will hold the name of the old window's class
GetClassName(win_clicked, clname, 100); //god help us if the class name is over 100 characters long
GetClassInfoEx(GetWindowLong(win_clicked, GWL_HINSTANCE), clname, &shadedwincl); //fill the window class with an exact copy of the old one
RegisterClass(shadedwincl); //register our copy class
HWND shadedWin = CreateWindowEx( //the HWND of the newly created window will go into shadedWin
wnd_info.dwExStyle, //whatever the old window had as its extended style
clname, //registered above
titletext, //retrieved above
wnd_info.dwStyle, //copied
wnd_info.rcWindow->left, //copied
wnd_info.rcWindow->top,  //copied
wnd_info.rcWindow->right - wnd_info.rcWindow->left, //copied. window's right boundary minus its left boundary
0, //no height--this is the key part of this approach
GetParent(win_clicked), //the parent of the window we are replacing
GetMenu(win_clicked), //the menu assigned to the window we're replacing
GetWindowLong(win_clicked, GWL_HINSTANCE), //formality
NULL); //parameter that we do not need
} //end of "if (hide)"
else // in other words, "if (!hide)"
{
//i'll leave you to write the code for destroying the window we created and showing the old window. hint:
DestroyWindow(myhwnd /*don't know how to retrieve this, you'll have to figure it out*/);
ShowWindow(oldwinhwnd /*don't know how to get this either*/ , SW_SHOW);
} //end of if...else
Idea 3. This could also work, although i don't know exactly how. having never tried anything like it, I don't know how reliable it would be. it seems pretty reliable, though, unless the window, like Windows Media Player, has done something weird with its titlebar. but in that case, Idea 2 wouldn't work very well either. you would probably have to use window regions. something like this...
CPP / C++ / C Code:
//hook handler. win_clicked and hide are the same as before
if (hide)
TITLEBARINFO titleinfo; //will hold some information about the titlebar of the window we are shading
titleinfo.cbSize = sizeof(TITLEBARINFO); //formality
GetTitleBarInfo(win_clicked, &titleinfo);
HRGN region = CreateRectRgnIndirect(titleinfo.rctitlebar); //create our region. you may have to cast titleinfo.rctitlebar to (CONST RECT*)
//so region should now be the handle to a region that includes only the titlebar of the window.
SetWindowRgn(win_clicked, region, true); //set the window region to only the titlebar, and redraw it. nothing outside the window region will be drawn. put 2 and 2 together: only the titlebar gets drawn. yay!
} // end of "if (hide)"
else // i.e. "if (!hide)"
{
SetWindowRgn(win_clicked, NULL, true); //remove the window region and redraw the window so it is all shown.
}
note that i have not compiled any of this code. look at MSDN for all of these functions. I wrote the window region code straight off MSDN so I can't really help you very much there; maybe someone else here can. if you want some more clarification, reply and i and everyone else will try to help you.

[EDIT] i thought of an idea for setting the "hide" variable above. what you could do is insert this code after the call to GetClassInfoEx:
CPP / C++ / C Code:
shadedwincl.szClassName = "__Shaded-Window-Class5673"; //set the class name to this so that the class can be identified later. the weird name is to minimize the possibility that someone else will have chosen the same name.
.
and in the call to CreateWindowEx change clname to "__Shaded-Window-Class5673". then before any of the code i gave you, you would have something like this:
CPP / C++ / C Code:
LPSTR win_clicked_class_name;
GetClassName(win_clicked, win_clicked_class_name, 100);
bool hide = (win_clicked_class_name == "__Shaded-Window-Class5673"); //set hide to whether the window class equals ours
[/EDIT]
Last edited by ubergeek : 17-Apr-2005 at 23:01. Reason: fixed code. silly me. in the last code example, win_clicked_class_name is already a pointer, so the & is unnecessary and will most likely cause a segmentation fault.
  #3  
Old 18-Apr-2005, 13:49
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
sorry, in the second-to-last code box, it should be shadedwincl.lpszClassName
  #4  
Old 18-Apr-2005, 14:36
WillyumYum WillyumYum is offline
New Member
 
Join Date: Apr 2005
Posts: 4
WillyumYum is on a distinguished road
very cool. Thanks for taking the time to type out that reply, i appreciate it much. I'll post in this thread if i need more help. Thanks again.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 3) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
#including resource file causing window procedure to be undeclared??? ubergeek C++ Forum 3 07-Feb-2005 14:39
Changing window start colour Rosdahale C++ Forum 5 19-Jan-2005 15:51
Changing monitors on a Linux machine JdS Computer Software Forum - Linux 10 23-Dec-2004 09:49
Linux Kernel Upgrade Mini Howto dsmith Computer Software Forum - Linux 3 05-Apr-2004 22:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:04.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.