home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
sftick.zip
/
adv
/
popup
/
POPUP.C
< prev
next >
Wrap
Text File
|
1994-04-20
|
7KB
|
225 lines
#define INCL_WIN
#include <os2.h>
#include "popup.h"
#include "stdlib.h"
MRESULT EXPENTRY ClientWndProc ( HWND hwnd,
ULONG msg,
MPARAM mp1,
MPARAM mp2 ) ;
#define CLS_CLIENT "MyClass"
/* window structure to hold various
static data to be stored in window word*/
typedef struct {
HWND hwndMenu ;
HPOINTER hptrFileIcon ;
} MENUDATA, *PMENUDATA ;
INT main ( VOID )
{
HAB habAnchor ;
HMQ hmqQueue ;
ULONG ulFlags ;
HWND hwndFrame ;
HWND hwndClient ;
QMSG qmMsg ;
/* initialization */
habAnchor = WinInitialize ( 0 ) ;
hmqQueue = WinCreateMsgQueue ( habAnchor, 0 ) ;
/* register the client class */
WinRegisterClass ( habAnchor,
CLS_CLIENT,
ClientWndProc,
CS_SIZEREDRAW,
sizeof ( PVOID )) ;
ulFlags = FCF_TASKLIST | FCF_TITLEBAR | FCF_SYSMENU |
FCF_MINMAX | FCF_SIZEBORDER ;
/* create a basic window */
hwndFrame = WinCreateStdWindow ( HWND_DESKTOP,
0,
&ulFlags,
CLS_CLIENT,
"Popup Menu Example",
0,
NULLHANDLE,
0,
&hwndClient ) ;
/* size and place window */
WinSetWindowPos( hwndFrame,
HWND_TOP,
10, 10, /* x and y coordinates */
100, 200, /* width and height */
SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ACTIVATE ) ;
/* generic message processing loop */
if ( hwndFrame != NULLHANDLE ) {
while( WinGetMsg ( habAnchor,
&qmMsg,
NULLHANDLE,
0,
0 ))
WinDispatchMsg ( habAnchor, &qmMsg ) ;
WinDestroyWindow ( hwndFrame ) ;
} /* endif */
/* clean-up */
WinDestroyMsgQueue ( hmqQueue ) ;
WinTerminate ( habAnchor ) ;
return 0 ;
}
MRESULT EXPENTRY ClientWndProc ( HWND hwndWnd,
ULONG ulMsg,
MPARAM mpParm1,
MPARAM mpParm2 )
{
PMENUDATA pmdMenuData ;
switch ( ulMsg ) {
case WM_CREATE:
{
pmdMenuData = malloc ( sizeof ( MENUDATA )) ;
WinSetWindowPtr ( hwndWnd, 0, pmdMenuData ) ;
pmdMenuData->hptrFileIcon = WinLoadFileIcon (
"POPUP.EXE",
FALSE ) ;
}
break ;
case WM_DESTROY:
/* get window data */
pmdMenuData = WinQueryWindowPtr ( hwndWnd, 0 ) ;
/* free everything */
if ( pmdMenuData ) {
if ( pmdMenuData->hptrFileIcon ) {
WinFreeFileIcon ( pmdMenuData->hptrFileIcon ) ;
if ( pmdMenuData->hwndMenu )
WinDestroyWindow( pmdMenuData->hwndMenu ) ;
} /* endif */
free ( pmdMenuData ) ;
} /* endif */
break ;
case WM_PAINT:
{
HPS hpsPaint ;
RECTL rclInvalid ;
/* get window data */
pmdMenuData = WinQueryWindowPtr ( hwndWnd, 0 ) ;
/* begin painting */
hpsPaint = WinBeginPaint ( hwndWnd,
NULLHANDLE,
&rclInvalid ) ;
/* clear out window */
WinFillRect ( hpsPaint,
&rclInvalid,
SYSCLR_WINDOW ) ;
/* draw the icon */
if ( pmdMenuData->hptrFileIcon != NULLHANDLE ) {
WinDrawPointer ( hpsPaint,
50,
50,
pmdMenuData->hptrFileIcon,
DP_NORMAL ) ;
} /* endif */
WinEndPaint ( hpsPaint ) ;
}
break ;
case WM_CONTEXTMENU:
{
RECTL rclIcon ;
HAB habAnchor ;
BOOL bInside ;
BOOL bKeyboardUsed ;
POINTL ptlMouse ;
pmdMenuData = WinQueryWindowPtr ( hwndWnd, 0 ) ;
habAnchor = WinQueryAnchorBlock ( hwndWnd ) ;
bKeyboardUsed = SHORT1FROMMP ( mpParm2 ) ;
//--------------------------------------------------------
// If the mouse was used, check to see if the pointer
// is over the icon, else always display the menu.
//--------------------------------------------------------
if ( ! bKeyboardUsed ) {
/* find out size and width of system icons, and
use that info to determine if mouse is over icon */
rclIcon.xLeft = 50 ;
rclIcon.xRight = rclIcon.xLeft +
WinQuerySysValue ( HWND_DESKTOP, SV_CXICON ) ;
rclIcon.yBottom = 50 ;
rclIcon.yTop = rclIcon.yBottom +
WinQuerySysValue ( HWND_DESKTOP, SV_CYICON ) ;
ptlMouse.x = ( LONG ) SHORT1FROMMP ( mpParm1 ) ;
ptlMouse.y = ( LONG ) SHORT2FROMMP ( mpParm1 ) ;
bInside = WinPtInRect ( habAnchor,
&rclIcon,
&ptlMouse ) ;
} else {
/* if keyboard was used, we know they want the
context menu */
bInside = TRUE ;
ptlMouse.x = 50 ;
ptlMouse.y = 50 ;
} /* endif */
if ( bInside ) {
/* load the menu */
pmdMenuData->hwndMenu = WinLoadMenu ( hwndWnd,
NULLHANDLE,
IDM_POPUP ) ;
/* OS/2 do-all function for popping up menu */
WinPopupMenu ( hwndWnd,
hwndWnd,
pmdMenuData->hwndMenu,
ptlMouse.x,
ptlMouse.y,
0,
PU_KEYBOARD |
PU_MOUSEBUTTON1 | PU_MOUSEBUTTON2 ) ;
} /* endif */
}
break ;
default:
return WinDefWindowProc ( hwndWnd,
ulMsg,
mpParm1,
mpParm2 ) ;
} /* endswitch */
return MRFROMSHORT ( FALSE ) ;
}