View Full Version: Minimize

C++ Learning Community > win32 api C++ programming > Minimize


Title: Minimize
Description: Close/Destroy/Show Window


IsmAvatar - March 21, 2005 02:36 AM (GMT)
I've been writing a dll that consists of a number of windows functions (for gamemaker should you be concerned), and the biggest issue i've seen has been how to minimize the window should the minimize button not be present.

During my search, I came across 3 functions that come close, but are not quite to my liking.

CloseWindow(hwnd) minimizes the window to a compact window near the bottom of the screen, just above the tray
DestroyWindow(hwnd) hides the window, leaving it still on the Taskbar, and at active size (were it visible), and still capable of being minimized (click the taskbar icon). The window may only be restored to view with another function (not sure which one, but i don't think i'm interested)
and
ShowWindow(hwnd, sw_state) (I have tried all states. For the minimize ones, see CloseWindow)

However, none of these were satisfactory. The desired result should be the same as would occur if you were to click the minimize button. The only resultant trace of the window should be in the taskbar.

If anyone could point me in the right direction, that would be great.

donprogc++ - March 21, 2005 04:01 AM (GMT)
game maker <_<

well it should be ShowWindow(hwnd, SW_MINIMIZED);
you can search www.msdn.com


IsmAvatar - March 21, 2005 10:12 PM (GMT)
You would think so, but

>>Image "not_so_min" removed<<
Is not quite the same result as when you click the minimize button.

a quick msdn search said that ShowWindow should minimize it to an icon. This is indeed what it does, but not the desired result. I don't even want the icon, I just want to minimize to TaskBar, as would happen should you click the minimize button in the top-right.

donprogc++ - March 21, 2005 10:56 PM (GMT)
try this
ShowWindow(hwnd,SW_SHOWMINIMIZED);

IsmAvatar - March 21, 2005 11:49 PM (GMT)
>>Image "not_so_min" removed<<
:P

I appreciate your attempted help, tho.

DeAs91 - March 22, 2005 12:02 AM (GMT)
Could you show the source code, please, I want to look at it :wub:

IsmAvatar - March 22, 2005 01:43 AM (GMT)
of course

CODE

#include <windows.h>

#define GM_EXPORT_VAL extern "C" __declspec(dllexport) double __cdecl

GM_EXPORT_VAL SetWindowMode(double gmWindow)
{
 return(ShowWindow((HWND)(DWORD)gmWindow, SW_SHOWMINIMIZED) ? 0.0 : 1.0);
}


it's quite simple. It's just a dll. If you need an explanation of any of the lines, feel free to ask.

I've chopped it up so you don't have to see all the other functions (which I will not be releasing the source code of; they don't affect the minimize ability)

Darimus - March 22, 2005 03:04 AM (GMT)
It will only do that if the window you're minimizing is a child window...


[Ignore the following... it doesn't work well, check my next post ;)]
If you can't really get the parent window, then I would do SetWindowPos(gmWindow,0,-100,-100,0,0,0);

This will just kinda make it have 0 width, 0 height, and move it off the screen (negative position)

To get it back, use Restore on the context menu of the start bar

donprogc++ - March 22, 2005 03:07 AM (GMT)
i think maybe its just gm's fault that it doesnt work lol

Darimus - March 22, 2005 03:13 AM (GMT)
You should get the parent window, and i'd do it with the window's title or class name...

HWND hWnd=FindWindow(NULL,"Game Maker"); //"Game Maker" should be the target window's title
ShowWindow(hWnd,SW_MINIMIZE);

IsmAvatar - March 22, 2005 09:03 PM (GMT)
@donprogc++: It is partly GM's fault.
@Darimus: You hit the nail on the head.
In GM, I passed the window_handle off, which appearently only supplied the child window. The parent window was found by finding the window's title (a bit of GM coding there), passed it off to the dll, who would then find the hwnd of the window (the resultant parent handle), and then I performed the minimize on it.
This works like a charm. Thanks a bunch.
CODE
#include <windows.h>

#define GM_EXPORT_VAL extern "C" __declspec(dllexport) double __cdecl

GM_EXPORT_VAL SetWindowMode(char* gmWindow)
{
 HWND hWnd=FindWindow(NULL,gmWindow);
 return(ShowWindow(hWnd, SW_MINIMIZE) ? 0.0 : 1.0);
}

InfoProducts - March 24, 2005 04:56 PM (GMT)
instead of passing the gm window's title, pass the gm game's exe name without the .exe and perform a minimize on it...




* Hosted for free by InvisionFree