[comp.windows.ms.programmer] Activating Dialog Windows

jerry@polygen.uucp (Jerry Shekhel) (06/06/91)

Hello.  Can someone provide a listing of code that, given a window handle,
will (1) restore the window to normal size if it's minimized, (2) raise the
window to the top of the stacking order, (3 [MOST IMPORTANT]) give keyboard
input focus either to the window or to the topmost dialog owned by that window
if there are any.

Thanks in advance.
--
+-------------------+----------------------+---------------------------------+
| JERRY J. SHEKHEL  | POLYGEN CORPORATION  | When I was young, I had to walk |
| Drummers do it... | Waltham, MA USA      | to school and back every day -- |
|    ... In rhythm! | (617) 890-2175       | 20 miles, uphill both ways.     |
+-------------------+----------------------+---------------------------------+
|           ...! [ princeton mit-eddie bu sunne ] !polygen!jerry             |
|                            jerry@polygen.com                               |
+----------------------------------------------------------------------------+

bonneau@hyper.hyper.com (Paul Bonneau) (06/11/91)

In article <1125@stewart.UUCP> jerry@stewart.UUCP (Jerry Shekhel) writes:
>Hello.  Can someone provide a listing of code that, given a window handle,
>will (1) restore the window to normal size if it's minimized, (2) raise the
>window to the top of the stacking order, (3 [MOST IMPORTANT]) give keyboard
>input focus either to the window or to the topmost dialog owned by that window
>if there are any.
>
The following code snippet should work providing every time
you create a dialogs, the parent window is the topmost
dialog.

If you create a popup window that is not a dialog, disable the
topmose dialog or popup, first, else this will not work (it
relies on at most one enable popup at any one time).

Let:
	hwnd be the window handle,
	hins be the instance handle of your application

BOOL FAR PASCAL
FEnumWnd(HWND hwnd, DWORD lParam)
	{
	if ((GetWindowLong(hwnd, GWL_STYLE) & WS_POPUP) &&
	    IsWindowEnabled(hwnd))
		{
		*(HWND FAR *)lParam = hwnd;
		return fFalse;
		}
	return fTrue;
	}


	FARPROC	lpfn;
	HWND	hwndPopup;

	DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L);
	BringWindowToTop(hwnd);
	lpfn = MakeProcInstance(hins, FEnumWnd);
	SetFocus(EnumTaskWindows(hwnd, hwndPopup) ? hwnd : hwndPopup);
	FreeProcInstance(lpfn);

cheers - Paul Bonneau.