Annotation of pmsdk/samples/clipbd/clipput.c, revision 1.1.1.1

1.1       root        1: /*--------------------- file identification ------------------------*/
                      2: 
                      3: /*
                      4:         cliptest.c
                      5: 
                      6:         Puts a short string onto the clipboard in response
                      7:         to a Copy menu command.
                      8: 
                      9:         This program is used in combination with clip.exe
                     10:         to test the capabilities of the pm clipboard.
                     11: 
                     12:         Wed April 6, 1988
                     13:         Dan Weston  (c-danw)
                     14: 
                     15:         POTENTIAL PROBLEMS:  pm version 4.19
                     16: 
                     17:             --The whole clipboard mechanism does not work
                     18:             unless there is some sort of shell (pmshell or funtest)
                     19:             running first. ( This is not really a problem, just
                     20:             something to look out for. )
                     21: 
                     22:         SEE  ALSO:
                     23: 
                     24:             the program clipshow.exe will put retrieve the
                     25:             current contents of the clipboard.
                     26: 
                     27: */
                     28: 
                     29: 
                     30: /*---------------------- include files -----------------------------*/
                     31: #define INCL_PM
                     32: #define INCL_GPI
                     33: #define INCL_DOS
                     34: #include <string.h>
                     35: #include <os2.h>
                     36: #include "clipput.h"
                     37: 
                     38: /*-------------------------- global variables ----------------------*/
                     39: 
                     40: /* clipboard stuff */
                     41: CHAR    szClipMessage[256] = "";
                     42: 
                     43: /* message stuff */
                     44: HMQ     hmqTheMessageQueue;
                     45: HAB     habTheAnchorBlock;
                     46: 
                     47: /* window stuff */
                     48: char    szClassName[] = "cliptest";      /* our window class name */
                     49: HWND    hwndClient;                 /* handle to the client */
                     50: HWND    hwndFrame;                  /* handle to the frame window */
                     51: HWND    hwndEdit;
                     52: 
                     53: /* measurement variables */
                     54: RECTL   rclRun;
                     55: USHORT  cxChar,cyChar;
                     56: 
                     57: /*------------------------------ main ------------------------------*/
                     58: 
                     59: BOOL    main() 
                     60: 
                     61:         {
                     62: /*
                     63:  * local constants
                     64:  */
                     65:         #define USE_DEF_QUEUE_SIZE 0
                     66: 
                     67: /*
                     68:  * local variables
                     69:  */
                     70:         QMSG qmsg;
                     71: 
                     72: /*
                     73:  * initialize this application thread's use of the PM
                     74:  */
                     75:         habTheAnchorBlock = WinInitialize (NULL) ;
                     76:        
                     77: /*
                     78:  * create a message queue for this application thread
                     79:  */
                     80:         hmqTheMessageQueue = WinCreateMsgQueue
                     81:                                 (habTheAnchorBlock, USE_DEF_QUEUE_SIZE) ;
                     82:  /*
                     83:   * initialize the application
                     84:   */
                     85:         if (!GenericInit())
                     86:                 return(FALSE);          /* failed loading */
                     87: 
                     88:  /*
                     89:   * run the main event loop
                     90:   */
                     91:         while ( WinGetMsg ( (HAB)NULL, &qmsg, (HWND)NULL, 0, 0 ) )
                     92:                 WinDispatchMsg( (HAB)NULL, &qmsg );
                     93: 
                     94: 
                     95:   /*
                     96:    * kill the window
                     97:    */
                     98:         WinDestroyWindow( hwndFrame );
                     99: 
                    100:   /*
                    101:    * PM cleanup
                    102:    */
                    103:         WinDestroyMsgQueue( hmqTheMessageQueue );
                    104:         WinTerminate( habTheAnchorBlock );
                    105:         }
                    106: 
                    107: 
                    108: /*--------------------- GenericInit -------------------------*/
                    109: BOOL GenericInit() {
                    110:     ULONG   lControlStyle = FCF_TITLEBAR | FCF_SYSMENU |
                    111:                             FCF_SIZEBORDER | FCF_MINMAX | FCF_MENU;
                    112: 
                    113: 
                    114:     if (!WinRegisterClass( habTheAnchorBlock,
                    115:             szClassName,
                    116:             (PFNWP)GenericWndProc,
                    117:             CS_SIZEREDRAW,
                    118:             0))
                    119:         return( FALSE );
                    120: 
                    121:     hwndFrame = WinCreateStdWindow( HWND_DESKTOP,
                    122:         0L,
                    123:         &lControlStyle,
                    124:         szClassName,
                    125:         "cliptest",
                    126:         0L,
                    127:         NULL,
                    128:         ID_RESOURCE,                  /* resource ID from .rc file */
                    129:         &hwndClient);
                    130: 
                    131:     WinSetWindowPos(hwndFrame,          /* window */
                    132:                     HWND_TOP,           /* window behind */
                    133:                     50,                 /* x pos */
                    134:                     50,                 /* y pos */
                    135:                     300,                /* x size */
                    136:                     100,                /* y size */
                    137:                     SWP_ACTIVATE|SWP_SIZE|SWP_MOVE|SWP_SHOW);   /* flags */
                    138: 
                    139:     WinQueryWindowRect(hwndFrame,&rclRun);
                    140:     /* Create the edit control now that we've sized */
                    141:     hwndEdit = WinCreateWindow(hwndClient, WC_ENTRYFIELD, (PSZ)NULL,
                    142:             WS_VISIBLE | ES_AUTOSCROLL | ES_MARGIN,
                    143:             5 * cxChar, ((rclRun.yTop - rclRun.yBottom) / 2)- cyChar,
                    144:             cxChar * 27, cyChar,
                    145:             hwndClient, HWND_TOP,
                    146:             WID_EDIT, (PVOID)NULL, (PVOID)NULL);
                    147: 
                    148: 
                    149:     WinSetFocus(HWND_DESKTOP,hwndEdit);
                    150: 
                    151:     if (!hwndFrame)
                    152:         return(FALSE);
                    153:    
                    154:     return(TRUE);
                    155: }
                    156: 
                    157: /*---------------- the main window procedure --------------------------*/
                    158: MRESULT FAR PASCAL GenericWndProc( hwnd, usMessage, mp1, mp2 )
                    159: HWND   hwnd;
                    160: USHORT usMessage;
                    161: MPARAM  mp1;
                    162: MPARAM  mp2;
                    163: {
                    164:     HPS     hps;
                    165:     RECTL    rect;
                    166:     FONTMETRICS fm;
                    167: 
                    168:     switch (usMessage) {
                    169:         case WM_CREATE:
                    170:             hps = WinGetPS(hwnd);
                    171:             GpiQueryFontMetrics(hps, (ULONG)sizeof(FONTMETRICS), &fm);
                    172:             WinReleasePS(hps);
                    173: 
                    174:             cxChar = fm.lAveCharWidth;
                    175:             cyChar = fm.lMaxBaselineExt - fm.lMaxDescender;
                    176:             break;
                    177: 
                    178:         case WM_PAINT:
                    179:             hps = WinBeginPaint(hwnd,NULL,&rect);
                    180:             WinFillRect(hps,&rect,CLR_WHITE);
                    181:             WinEndPaint(hps);
                    182:             break;
                    183: 
                    184:         case WM_COMMAND:
                    185:             DoMenuCommand(hwnd,LOUSHORT (mp1));
                    186:             break;
                    187:         default:
                    188:             return( WinDefWindowProc( hwnd, usMessage, mp1, mp2 ) );
                    189:     }
                    190:     return(0L);
                    191: }
                    192: 
                    193: /*--------------------------- AboutProc -----------------------------*/
                    194: MRESULT FAR PASCAL  AboutProc (hwnd, usMessage,
                    195:                                 mp1, mp2)
                    196:         
                    197:     HWND    hwnd ;
                    198:     USHORT  usMessage ;
                    199:     MPARAM   mp1 ;
                    200:     MPARAM   mp2 ;
                    201:         
                    202:     {
                    203:     /* case out on the message */
                    204:     switch (usMessage)
                    205:         {
                    206:         case WM_COMMAND:
                    207:                switch (LOUSHORT (mp1))
                    208:                     {
                    209:                      case DID_OK:
                    210:                         WinDismissDlg(hwnd,0);
                    211:                         break;
                    212:                     }
                    213:             break;
                    214:         default:
                    215:             return ( WinDefDlgProc (hwnd, usMessage,
                    216:                                        mp1, mp2) ) ;
                    217:         }
                    218:     return (0L) ;
                    219:     }
                    220: 
                    221: /*---------------------------- DoMenuCommand -----------------------*/
                    222: ULONG DoMenuCommand(hwnd, usMenuID)
                    223: 
                    224:     HWND    hwnd;
                    225:     USHORT  usMenuID;
                    226:     {
                    227:            SEL  sel;
                    228:            PSZ  pszDest,pszSrc;
                    229:            BOOL     fSuccess;
                    230:            USHORT   usSuccess;
                    231:            USHORT   usLen;
                    232: 
                    233:            switch (usMenuID)
                    234: 
                    235:                 {
                    236:                 case IDM_ED_COPY:
                    237:                     if (WinOpenClipbrd(habTheAnchorBlock))
                    238:                         {
                    239:                         /* copy the edit window to the clip message string */
                    240:                         usLen = WinQueryWindowText(hwndEdit,80,szClipMessage);
                    241:                         usSuccess =DosAllocSeg(usLen + 1,
                    242:                                                &sel,
                    243:                                                SEG_GIVEABLE);
                    244:                         pszDest = MAKEP(sel,0);
                    245:                         pszSrc = &szClipMessage[0];
                    246:                         while (*pszDest++ = *pszSrc++);
                    247:                         WinEmptyClipbrd(habTheAnchorBlock);
                    248:                         fSuccess = WinSetClipbrdData(habTheAnchorBlock,
                    249:                                                     (ULONG)sel,
                    250:                                                     CF_TEXT,
                    251:                                                     CFI_SELECTOR);
                    252:                         WinCloseClipbrd(habTheAnchorBlock);
                    253: 
                    254:                         }
                    255:                     break;
                    256:                 case IDM_FI_QUIT:
                    257:                     /* Don't use WinSENDMsg here */
                    258:                     WinPostMsg(hwnd,WM_CLOSE,0L,0L);
                    259:                     break;
                    260:                 case IDM_FI_ABOUT:
                    261:                     /* this is a modal dialog */
                    262:                     WinDlgBox(HWND_DESKTOP ,
                    263:                               hwndFrame,
                    264:                               (PFNWP)AboutProc,
                    265:                               NULL,
                    266:                               IDD_ABOUT,
                    267:                               NULL);
                    268:                     break;
                    269: 
                    270:                 default:
                    271:                     break;
                    272: 
                    273:                 }
                    274:     }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.