home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PMDEBUG.ZIP / TEST.C < prev    next >
C/C++ Source or Header  |  1990-03-05  |  4KB  |  176 lines

  1. /*-----------------------------------------------------
  2.    PMSTUB.C -- A Program that Creates a Client Window
  3.   -----------------------------------------------------*/
  4.  
  5. #define INCL_DOS
  6. #define INCL_GPI
  7. #define INCL_WIN
  8. #include "os2.h"
  9.  
  10. #include <stdio.h>
  11. #include <stdarg.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14.  
  15. #define PASFAR pascal far
  16.  
  17. HAB hab;
  18. HPS hps;
  19. HWND hwndframe, hwndclient, hwmsgbox;
  20.  
  21. int PASFAR debug_puts(char far *txt);
  22.  
  23. MRESULT EXPENTRY wndproc (HWND, USHORT, MPARAM, MPARAM) ;
  24.  
  25. int main (void)
  26. {
  27.    static CHAR  name [] = "pmstub" ;
  28.    static ULONG fl = FCF_TITLEBAR      | FCF_SYSMENU |
  29.                                FCF_SIZEBORDER    | FCF_MINMAX  |
  30.                                FCF_SHELLPOSITION | FCF_TASKLIST ;
  31.    HMQ          hmq ;
  32.    QMSG         qmsg ;
  33.  
  34.    printf("\n*** START TEST ***\n");
  35.    hab = WinInitialize (0) ;
  36.    hmq = WinCreateMsgQueue (hab, 0) ;
  37.  
  38.    WinRegisterClass (
  39.                   hab,                /* Anchor block handle */
  40.                   name,               /* Name of class being registered */
  41.                   wndproc,            /* Window procedure for class */
  42.                   0L,                 /* Class style */
  43.                   0) ;                /* Extra bytes to reserve */
  44.  
  45.    hwndframe = WinCreateStdWindow (
  46.                   HWND_DESKTOP,       /* Parent window handle */
  47.                   WS_VISIBLE,         /* Style of frame window */
  48.                   &fl,                /* Pointer to control data */
  49.                   name,               /* Client window class name */
  50.                   NULL,               /* Title bar text */
  51.                   0L,                 /* Style of client window */
  52.                   NULL,               /* Module handle for resources */
  53.                   0,                  /* ID of resources */
  54.                   &hwndclient) ;      /* Pointer to client window handle */
  55.  
  56.    while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  57.         WinDispatchMsg (hab, &qmsg) ;
  58.  
  59.    WinDestroyWindow (hwndframe) ;
  60.    WinDestroyMsgQueue (hmq) ;
  61.    WinTerminate (hab) ;
  62.    printf("\n***  END  TEST ***\n");
  63.    return 0 ;
  64. }
  65.  
  66. int printf(const char *txt,...)
  67. {
  68.    char _buffer[400], *p;
  69.    va_list array;
  70.  
  71.    if (strchr(txt,'%'))
  72.    {
  73.       va_start(array,txt);
  74.       vsprintf(_buffer, txt, array);
  75.    }
  76.    else
  77.       strcpy(_buffer,txt);
  78.    debug_puts(_buffer);
  79. }
  80.  
  81. writequeue(char far *txt, USHORT mode, USHORT len)
  82. {
  83.    SEL selector, qownersel;
  84.    char far *p;
  85.    char far *ptr;
  86.    int i;
  87.    static HQUEUE hq=NULL;
  88.    static char queuename[] = "\\QUEUES\\PMDEBUG";
  89.    static int pid;
  90.  
  91.    if (!hq && DosOpenQueue((USHORT*)&pid, &hq, queuename))
  92.       return -1;
  93.  
  94.    if (DosAllocSeg( len, &selector,SEG_GIVEABLE))
  95.       return -2;
  96.  
  97.    ptr = MAKEP(selector,0);
  98.  
  99.    for (i=0; i<len; i++)
  100.       ptr[i] = txt[i];
  101.  
  102.    if (DosGiveSeg(selector, pid, &qownersel))
  103.       return -3;
  104.  
  105.    ptr = MAKEP(qownersel,0);
  106.  
  107.    if(DosWriteQueue(hq ,mode, len, (PBYTE)ptr,0))
  108.       return -4;
  109.  
  110.    DosFreeSeg(selector);
  111. }
  112.  
  113. int PASFAR debug_puts(char far *txt)
  114. {
  115.    USHORT i; char far *p;
  116.  
  117.    p = txt;
  118.    i = 0;
  119.  
  120.    while (*p)  { p++; i++; } 
  121.    return writequeue(txt,0,i);
  122. }
  123.  
  124. int PASFAR debug_logmessage(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2, char far *txt)
  125. {
  126.    QMSG q;
  127.    int i; char far *p;
  128.    p = txt;
  129.    i = 0;
  130.  
  131.    while (*p)  { p++; i++; } 
  132.  
  133.    if (i = writequeue(txt,0,i)) return i;
  134.  
  135.    q.msg  = msg;
  136.    q.hwnd = hwnd;
  137.    q.mp1 = mp1;
  138.    q.mp2 = mp2;
  139.  
  140.    if (i = writequeue((void far *) &q, 1, sizeof(QMSG)))
  141.       return i;
  142.    return 0;
  143. }
  144.  
  145. MRESULT EXPENTRY wndproc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  146. {
  147.    char buff[100];
  148.          debug_logmessage(hwnd, msg, mp1,mp2,"hello   ");
  149.    switch (msg)
  150.    {
  151.       case WM_CREATE:
  152.          break;
  153.  
  154.       case WM_SIZE:
  155.          break;
  156.  
  157.       case WM_PAINT:
  158.          hps = WinBeginPaint(hwnd, NULL, NULL);
  159.          GpiErase(hps);
  160.          WinEndPaint(hps);
  161.          break;
  162.  
  163.       case WM_CHAR:
  164.          printf("KEY pressed !!mp1=%08lXh, mp2=%08lXh\n",mp1,mp2);
  165.          break;
  166.   
  167.       case WM_TIMER:
  168.          break;
  169.  
  170.       case WM_COMMAND:
  171.          break;
  172.  
  173.    }
  174.    return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  175. }
  176.