home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / pmvnc100.zip / main.c < prev    next >
C/C++ Source or Header  |  1999-09-10  |  4KB  |  214 lines

  1. /*
  2.  * main.c - PM VNC Viewer, program entry
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #define INCL_DOS
  10. #define INCL_PM
  11. #include <os2.h>
  12.  
  13. #include "pmvncdef.h"
  14. #include "pmvncres.h"
  15.  
  16. /*
  17.  * Name and Version of this Program
  18.  */
  19.  
  20. UCHAR   ProgramVers[] = "PM VNC Viewer, Version 1.00" ;
  21.  
  22. /*
  23.  * Error Notify
  24.  */
  25.  
  26. void    errMessage(PSZ msg)
  27. {
  28.     WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, msg, ProgramVers, 0, MB_OK) ;
  29. }
  30.  
  31. /*
  32.  * Place Dialog near the mouse pointer
  33.  */
  34.  
  35. void    dialogAtMouse(HWND hwndDialog, int target)
  36. {
  37.     HWND    hwndTarget = WinWindowFromID(hwndDialog, target) ;
  38.     POINTL  pt ;
  39.     SWP     posDlg ;
  40.     SWP     posScr ;
  41.     SWP     posCtl ;
  42.  
  43.     WinQueryPointerPos(HWND_DESKTOP, &pt)    ;
  44.     WinQueryWindowPos(HWND_DESKTOP, &posScr) ;
  45.     WinQueryWindowPos(hwndDialog,   &posDlg) ;
  46.  
  47.     if (hwndTarget != NULLHANDLE) {
  48.         WinQueryWindowPos(hwndTarget, &posCtl) ;
  49.     } else {
  50.         posCtl.x  = posCtl.y  = 0 ;
  51.         posCtl.cx = posCtl.cy = 0 ;
  52.     }
  53.  
  54.     posDlg.x = pt.x - posCtl.x ;
  55.     posDlg.y = pt.y - posCtl.y - (posCtl.cy / 2) ;
  56.  
  57.     if (posDlg.x < 0) {
  58.         posDlg.x = 0 ;
  59.     }
  60.     if (posDlg.y < 0) {
  61.         posDlg.y = 0 ;
  62.     }
  63.     if ((posDlg.x + posDlg.cx) > posScr.cx) {
  64.         posDlg.x = posScr.cx - posDlg.cx ;
  65.     }
  66.     if ((posDlg.y + posDlg.cy) > posScr.cy) {
  67.         posDlg.y = posScr.cy - posDlg.cy ;
  68.     }
  69.     WinSetWindowPos(hwndDialog, NULLHANDLE,
  70.                     posDlg.x, posDlg.y, 0, 0, SWP_MOVE) ;
  71. }
  72.  
  73. /*
  74.  * Place Dialog at Center of Screen
  75.  */
  76.  
  77. void    dialogAtCenter(HWND hwndDialog)
  78. {
  79.     SWP     posDlg ;
  80.     SWP     posScr ;
  81.  
  82.     WinQueryWindowPos(HWND_DESKTOP, &posScr) ;
  83.     WinQueryWindowPos(hwndDialog,   &posDlg) ;
  84.  
  85.     posDlg.x = (posScr.cx - posDlg.cx) / 2 ;
  86.     posDlg.y = (posScr.cy - posDlg.cy) / 2 ;
  87.  
  88.     WinSetWindowPos(hwndDialog, NULLHANDLE,
  89.                     posDlg.x, posDlg.y, 0, 0, SWP_MOVE) ;
  90. }
  91.  
  92. /*
  93.  * myname - trim and save Program Names
  94.  */
  95.  
  96. UCHAR   ProgramPath[256] ;
  97. UCHAR   ProgramName[256] ;
  98. UCHAR   ProfilePath[256] ;
  99.  
  100. static  void    myname(PSZ me)
  101. {
  102.     PUCHAR  p, last ;
  103.  
  104.     /*
  105.      * full pathname of program
  106.      */
  107.  
  108.     for (p = me, last = NULL ; *p ; p++) {
  109.         if (*p == '/' || *p == '\\') {
  110.             last = p ;
  111.         }
  112.     }
  113.     if (last != NULL) {
  114.         strcpy(ProgramPath, me) ;
  115.     } else if (DosSearchPath(7, "PATH", me, ProgramPath, 256) != 0) {
  116.         strcpy(ProgramPath, me) ;
  117.     }
  118.  
  119.     /*
  120.      * basename of program
  121.      */
  122.  
  123.     for (p = ProgramPath, last = NULL ; *p ; p++) {
  124.         if (*p == '/' || *p == '\\') {
  125.             last = p ;
  126.         }
  127.     }
  128.     if (last == NULL) {
  129.         strcpy(ProgramName, ProgramPath) ;
  130.     } else {
  131.         strcpy(ProgramName, &last[1]) ;
  132.     }
  133.     if ((p = strrchr(ProgramName, '.')) != NULL) {
  134.         *p = '\0' ;
  135.     }
  136.  
  137.     /*
  138.      * pathname of Profile
  139.      */
  140.  
  141.     strcpy(ProfilePath, ProgramPath) ;
  142.  
  143.     if ((p = strrchr(ProfilePath, '.')) == NULL) {
  144.         strcat(ProfilePath, ".ini") ;
  145.     } else {
  146.         strcpy(p, ".ini") ;
  147.     }
  148. }
  149.  
  150. /*
  151.  * Program Start here
  152.  */
  153.  
  154. int     main(int ac, char *av[])
  155. {
  156.     HAB     hab  ;
  157.     HMQ     hmq  ;
  158.     QMSG    qmsg ;
  159.  
  160.     /*
  161.      * Initializing
  162.      */
  163.  
  164.     _wildcard(&ac, &av) ;
  165.     myname(av[0]) ;
  166.  
  167.     sessParse(ac, av) ;
  168.     
  169.     hab = WinInitialize(0) ;
  170.     hmq = WinCreateMsgQueue(hab, 0) ;
  171.     
  172.     if (winCreate(hab) != TRUE) {
  173.         errMessage("failed to create window") ;
  174.     WinDestroyMsgQueue(hmq) ;
  175.     WinTerminate(hab) ;
  176.     return 1 ;
  177.     }
  178.     if (sessSetup(hab) != TRUE) {
  179.     winDispose(hab) ;
  180.     WinDestroyMsgQueue(hmq) ;
  181.     WinTerminate(hab) ;
  182.     return 1 ;
  183.     }
  184.     if (netStartup(hab) != TRUE) {
  185.     winDispose(hab) ;
  186.     WinDestroyMsgQueue(hmq) ;
  187.     WinTerminate(hab) ;
  188.     return 1 ;
  189.     }
  190.     
  191.     /*
  192.      * Window Processing
  193.      */
  194.      
  195.     while (WinGetMsg(hab, &qmsg, 0, 0, 0)) {
  196.         WinDispatchMsg(hab, &qmsg) ;
  197.     }
  198.  
  199.     sessSaveProfile(hab) ;
  200.     kmapFree() ;
  201.     
  202.     /*
  203.      * Dispose Resources
  204.      */
  205.  
  206.     netFinish(hab)  ;
  207.     winDispose(hab) ;
  208.     
  209.     WinDestroyMsgQueue(hmq) ;
  210.     WinTerminate(hab) ;
  211.  
  212.     return 0 ;
  213. }   
  214.