home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
SHUTDWN3.ZIP
/
SHUTMENU.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-26
|
7KB
|
217 lines
/*
This version attempts to find the id of the Shutdown menuitem
dynamically. The idea is to search the Switch List using
WinQuerySwitchList and search for the title "Desktop Manager";
I then assume that the hwnd member of the SWTCTL structure is
points to the Desktop Manager's frame window. From this, I
try to get the handle of it's action bar by using WinWindowFromID.
Then I want to search the text of the action bar items to find
the "Desktop" item. HOWEVER, when I try to get the MENUITEMs
of the Desktop Manager, WinQueryItem returns TRUE but
the MENUITEM appears to be trash. It never changes even though
the id does. It's also strange that MM_QUERYITEM returns the
correct length for each of the items.
Any assistance or comments would be greatly appreciated. I
usually check the OS/2 Shareware Bulletin board once a week. (703) 385-4325
I also sign on to CompuServe about once a week, but I can't
say that I always visit a certain forum, which means you'd
have to use the CIS mail system to reach me.
Chuck Hipschman 71041,1542
*/
#define INCL_WIN
#define INCL_GPI
#include <os2.h>
#include <string.h>
#include <stdio.h>
#include "shutmenu.h"
#define SZ_DESKTOP_SWTITLE "Desktop Manager"
#define IDM_SHUTDOWN_CMD 0x131
#if defined( DEBUG )
#define D( x ) x
#else
#define D( x )
#endif
MRESULT EXPENTRY ClientWndProc( HWND, USHORT, MPARAM, MPARAM );
HAB hab;
int main( void )
{
HMQ hmq;
HWND hwndFrame, hwndClient;
QMSG qmsg;
static CHAR szClass[] = "Shutdown";
ULONG ctlData = FCF_STANDARD & ~FCF_ACCELTABLE;
hab = WinInitialize( 0 );
hmq = WinCreateMsgQueue(
hab, /* HAB hab; handle of the anchor block */
0); /* SHORT cmsg; size of the message queue */
if ( ! WinRegisterClass(
hab, /* HAB hab; handle of anchor block */
szClass, /* PSZ pszClassName; points to class name */
ClientWndProc, /* PFNWP pfnWndProc; address of window procedure */
CS_SIZEREDRAW, /* ULONG flStyle; window-style flags */
0 ) /* USHORT cbWindowData; amount of reserved data */
)
return ( FALSE );
hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* HWND hwndParent; handle of the parent window */
WS_VISIBLE, /* ULONG flStyle; frame-window style */
&ctlData, /* PULONG pflCreateFlags; creation flags */
szClass, /* PSZ pszClientClass; client-window class name */
"", /* PSZ pszTitle; address of title-bar text */
0L, /* ULONG flClientStyle; client-window style */
0, /* HMODULE hmod; handle of the resource module */
ID_RESOURCE, /* USHORT idResources; frame-window identifier */
&hwndClient ); /* PHWND phwndClient; address of client-window handle */
while ( WinGetMsg( hab, &qmsg, NULL, 0, 0 ) )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow( hwndFrame );
WinDestroyMsgQueue( hmq );
WinTerminate( hab );
return ( 0 );
}
MRESULT EXPENTRY ClientWndProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 )
{
static SHORT cxClient, cyClient;
static SHORT cxChar, cyChar, cxCaps, cyDesc;
static USHORT cTasks;
static PSWBLOCK pswblk;
static CHAR szMenuText[ 10 ];
HPS hps;
SEL sel;
USHORT cbTaskListBuf;
SHORT i;
POINTL ptl;
LONG lRc;
HWND hwndDesktopMgr, hwndDesktopMenu;
SHORT csMenuItems;
SHORT idItem;
switch ( msg )
{
case WM_CREATE:
{
FONTMETRICS fm;
hps = WinGetPS( hwnd );
GpiQueryFontMetrics( hps, (LONG) sizeof fm, &fm );
cxChar = (SHORT) fm.lAveCharWidth;
cyChar = (SHORT) fm.lEmInc;
cxCaps = (SHORT) fm.lMaxBaselineExt;
cyDesc = (SHORT) fm.lMaxDescender;
WinReleasePS( hps );
}
return 0;
case WM_SIZE:
cxClient = SHORT1FROMMP( mp2 );
cyClient = SHORT2FROMMP( mp2 );
return 0;
case WM_PAINT:
hps = WinBeginPaint( hwnd, NULL, NULL );
GpiErase( hps );
ptl.x = cxCaps;
ptl.y = cyClient - cyChar * 2 + cyDesc;
cTasks = WinQuerySwitchList( hab, NULL, 0 );
cbTaskListBuf = ( cTasks * sizeof (SWENTRY) ) + sizeof (HSWITCH);
DosAllocSeg( cbTaskListBuf, &sel, SEG_NONSHARED );
pswblk = MAKEP( sel, 0 );
WinQuerySwitchList( hab, pswblk, cbTaskListBuf );
for ( i = 0; (USHORT) i < cTasks; i++ )
{
if ( _fstrcmp( pswblk -> aswentry[ i ].swctl.szSwtitle,
SZ_DESKTOP_SWTITLE ) == 0 )
break;
}
if ( (USHORT) i >= cTasks )
{
WinMessageBox( HWND_DESKTOP, hwnd,
"Desktop Manager not found in Task List", NULL, 0,
MB_ENTER | MB_ICONEXCLAMATION );
WinPostMsg( hwnd, WM_QUIT, 0L, 0L );
}
hwndDesktopMgr = pswblk -> aswentry[ i ].swctl.hwnd;
/* Try to access the text of the action bar items
It works for the program's own menu, but not for the
Desktop Manager action bar. */
// hwndDesktopMenu = WinWindowFromID( WinQueryWindow( hwnd, QW_PARENT, FALSE ), FID_MENU );
hwndDesktopMenu = WinWindowFromID( hwndDesktopMgr, FID_MENU );
csMenuItems = SHORT1FROMMR (WinSendMsg( hwndDesktopMenu, MM_QUERYITEMCOUNT, 0L, 0L ));
D( printf( "*050* hwndDesktopMenu = %Fp, Items = %d\n", hwndDesktopMenu, csMenuItems ); )
for ( i = 0; i < csMenuItems; i++ )
{
MENUITEM mi;
idItem = SHORT1FROMMR (WinSendMsg( hwndDesktopMenu, MM_ITEMIDFROMPOSITION,
MPFROMSHORT( i ), 0L ));
D( printf( "*060* idItem = %d\n", idItem ); )
lRc = (LONG) WinSendMsg( hwndDesktopMenu,
MM_QUERYITEM,
MPFROM2SHORT( idItem, (BOOL) TRUE ),
(MPARAM) (PMENUITEM) &mi );
D( printf( "*070* MM_QUERYITEM = %ld, Style = %x %x %lx\n", lRc, mi.afStyle, MIS_TEXT, mi.hItem ); )
D( printf( "*071* \t mi.iPosition = %d\n", mi.iPosition ); )
D( printf( "*072* \t mi.afStyle = %x\n", mi.afStyle ); )
D( printf( "*073* \t mi.afAttribute = %x\n", mi.afAttribute ); )
D( printf( "*074* \t mi.id = %d\n", mi.id ); )
D( printf( "*075* \t mi.hwndSubMenu = %Fp\n", mi.hwndSubMenu ); )
D( printf( "*076* \t mi.hItem = %ld\n", mi.hItem ); )
lRc = (LONG) WinSendMsg( hwndDesktopMenu, MM_QUERYITEMTEXT,
MPFROM2SHORT( idItem, 10 ),
MPFROMP( (PSZ) szMenuText ) );
#if defined( DEBUG )
if ( lRc == 0 )
printf( "*081* Menu Item Text Length == 0\n" );
else
printf( "*082* Len = %ld, Item = %s\n", lRc, szMenuText );
#endif
}
#if !defined( DEBUG )
lRc = (LONG) WinSetWindowPos( hwndDesktopMgr, hwnd,
0, 0, 0, 0, SWP_RESTORE );
lRc = (LONG) WinPostMsg( hwndDesktopMgr, WM_COMMAND, MPFROM2SHORT( IDM_SHUTDOWN_CMD, 0 ), 0L );
#endif
WinEndPaint( hps );
return 0;
case WM_CLOSE:
WinPostMsg( hwnd, WM_QUIT, 0L, 0L );
break;
}
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}