|
|
Microsoft OS/2 SDK PM 08-08-1988
/*--------------------- file identification ------------------------*/
/*
cliptest.c
Puts a short string onto the clipboard in response
to a Copy menu command.
This program is used in combination with clip.exe
to test the capabilities of the pm clipboard.
Wed April 6, 1988
Dan Weston (c-danw)
POTENTIAL PROBLEMS: pm version 4.19
--The whole clipboard mechanism does not work
unless there is some sort of shell (pmshell or funtest)
running first. ( This is not really a problem, just
something to look out for. )
SEE ALSO:
the program clipshow.exe will put retrieve the
current contents of the clipboard.
*/
/*---------------------- include files -----------------------------*/
#define INCL_PM
#define INCL_GPI
#define INCL_DOS
#include <string.h>
#include <os2.h>
#include "clipput.h"
/*-------------------------- global variables ----------------------*/
/* clipboard stuff */
CHAR szClipMessage[256] = "";
/* message stuff */
HMQ hmqTheMessageQueue;
HAB habTheAnchorBlock;
/* window stuff */
char szClassName[] = "cliptest"; /* our window class name */
HWND hwndClient; /* handle to the client */
HWND hwndFrame; /* handle to the frame window */
HWND hwndEdit;
/* measurement variables */
RECTL rclRun;
USHORT cxChar,cyChar;
/*------------------------------ main ------------------------------*/
BOOL main()
{
/*
* local constants
*/
#define USE_DEF_QUEUE_SIZE 0
/*
* local variables
*/
QMSG qmsg;
/*
* initialize this application thread's use of the PM
*/
habTheAnchorBlock = WinInitialize (NULL) ;
/*
* create a message queue for this application thread
*/
hmqTheMessageQueue = WinCreateMsgQueue
(habTheAnchorBlock, USE_DEF_QUEUE_SIZE) ;
/*
* initialize the application
*/
if (!GenericInit())
return(FALSE); /* failed loading */
/*
* run the main event loop
*/
while ( WinGetMsg ( (HAB)NULL, &qmsg, (HWND)NULL, 0, 0 ) )
WinDispatchMsg( (HAB)NULL, &qmsg );
/*
* kill the window
*/
WinDestroyWindow( hwndFrame );
/*
* PM cleanup
*/
WinDestroyMsgQueue( hmqTheMessageQueue );
WinTerminate( habTheAnchorBlock );
}
/*--------------------- GenericInit -------------------------*/
BOOL GenericInit() {
ULONG lControlStyle = FCF_TITLEBAR | FCF_SYSMENU |
FCF_SIZEBORDER | FCF_MINMAX | FCF_MENU;
if (!WinRegisterClass( habTheAnchorBlock,
szClassName,
(PFNWP)GenericWndProc,
CS_SIZEREDRAW,
0))
return( FALSE );
hwndFrame = WinCreateStdWindow( HWND_DESKTOP,
0L,
&lControlStyle,
szClassName,
"cliptest",
0L,
NULL,
ID_RESOURCE, /* resource ID from .rc file */
&hwndClient);
WinSetWindowPos(hwndFrame, /* window */
HWND_TOP, /* window behind */
50, /* x pos */
50, /* y pos */
300, /* x size */
100, /* y size */
SWP_ACTIVATE|SWP_SIZE|SWP_MOVE|SWP_SHOW); /* flags */
WinQueryWindowRect(hwndFrame,&rclRun);
/* Create the edit control now that we've sized */
hwndEdit = WinCreateWindow(hwndClient, WC_ENTRYFIELD, (PSZ)NULL,
WS_VISIBLE | ES_AUTOSCROLL | ES_MARGIN,
5 * cxChar, ((rclRun.yTop - rclRun.yBottom) / 2)- cyChar,
cxChar * 27, cyChar,
hwndClient, HWND_TOP,
WID_EDIT, (PVOID)NULL, (PVOID)NULL);
WinSetFocus(HWND_DESKTOP,hwndEdit);
if (!hwndFrame)
return(FALSE);
return(TRUE);
}
/*---------------- the main window procedure --------------------------*/
MRESULT FAR PASCAL GenericWndProc( hwnd, usMessage, mp1, mp2 )
HWND hwnd;
USHORT usMessage;
MPARAM mp1;
MPARAM mp2;
{
HPS hps;
RECTL rect;
FONTMETRICS fm;
switch (usMessage) {
case WM_CREATE:
hps = WinGetPS(hwnd);
GpiQueryFontMetrics(hps, (ULONG)sizeof(FONTMETRICS), &fm);
WinReleasePS(hps);
cxChar = fm.lAveCharWidth;
cyChar = fm.lMaxBaselineExt - fm.lMaxDescender;
break;
case WM_PAINT:
hps = WinBeginPaint(hwnd,NULL,&rect);
WinFillRect(hps,&rect,CLR_WHITE);
WinEndPaint(hps);
break;
case WM_COMMAND:
DoMenuCommand(hwnd,LOUSHORT (mp1));
break;
default:
return( WinDefWindowProc( hwnd, usMessage, mp1, mp2 ) );
}
return(0L);
}
/*--------------------------- AboutProc -----------------------------*/
MRESULT FAR PASCAL AboutProc (hwnd, usMessage,
mp1, mp2)
HWND hwnd ;
USHORT usMessage ;
MPARAM mp1 ;
MPARAM mp2 ;
{
/* case out on the message */
switch (usMessage)
{
case WM_COMMAND:
switch (LOUSHORT (mp1))
{
case DID_OK:
WinDismissDlg(hwnd,0);
break;
}
break;
default:
return ( WinDefDlgProc (hwnd, usMessage,
mp1, mp2) ) ;
}
return (0L) ;
}
/*---------------------------- DoMenuCommand -----------------------*/
ULONG DoMenuCommand(hwnd, usMenuID)
HWND hwnd;
USHORT usMenuID;
{
SEL sel;
PSZ pszDest,pszSrc;
BOOL fSuccess;
USHORT usSuccess;
USHORT usLen;
switch (usMenuID)
{
case IDM_ED_COPY:
if (WinOpenClipbrd(habTheAnchorBlock))
{
/* copy the edit window to the clip message string */
usLen = WinQueryWindowText(hwndEdit,80,szClipMessage);
usSuccess =DosAllocSeg(usLen + 1,
&sel,
SEG_GIVEABLE);
pszDest = MAKEP(sel,0);
pszSrc = &szClipMessage[0];
while (*pszDest++ = *pszSrc++);
WinEmptyClipbrd(habTheAnchorBlock);
fSuccess = WinSetClipbrdData(habTheAnchorBlock,
(ULONG)sel,
CF_TEXT,
CFI_SELECTOR);
WinCloseClipbrd(habTheAnchorBlock);
}
break;
case IDM_FI_QUIT:
/* Don't use WinSENDMsg here */
WinPostMsg(hwnd,WM_CLOSE,0L,0L);
break;
case IDM_FI_ABOUT:
/* this is a modal dialog */
WinDlgBox(HWND_DESKTOP ,
hwndFrame,
(PFNWP)AboutProc,
NULL,
IDD_ABOUT,
NULL);
break;
default:
break;
}
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.