Ejemplo n.º 1
0
/* EXPORT-> MakeXGraf: Create and open window, initialization */
void MakeXGraf(char *wname, int x, int y, int w, int h, int bw)
     /* WIN32: bw is ignored. */
{
   WNDCLASS WindowClass;
   char sbuf[256], *hgraf = "HGraf";
   HDC dc;
     
   if (winCreated)
      HError(6870, "MakeXGraf: Attempt to recreate the graphics window");
     
   WindowClass.hInstance = GetModuleHandle(NULL);
   WindowClass.lpszClassName = hgraf;
   WindowClass.lpfnWndProc = HGWinFunc;
   WindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
   WindowClass.hIcon = NULL;
   WindowClass.hCursor = LoadCursor(NULL,IDC_ARROW);
   WindowClass.lpszMenuName = NULL;
   WindowClass.cbClsExtra = 0;
   WindowClass.cbWndExtra = 0;
   WindowClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
     
   RegisterClass(&WindowClass);
     
   strcpy(sbuf, hgraf);  strcat(sbuf, ": ");  strcat(sbuf, wname);
     
   theWindow = 
      CreateWindow(hgraf, sbuf, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                   x,y, w,h, HWND_DESKTOP, NULL,
                   WindowClass.hInstance,       NULL);
     
   /* adjust window size so that the client rectangle is the size requested */
   /* by the caller of MakeXGraf() --- Win32 interprets w and h as the dimensions */
   /* of the overall window. */
   GetClientRect(theWindow,&ClientRect);
   MoveWindow(theWindow,x,y,w+w-ClientRect.right,h+h-ClientRect.bottom,TRUE); 
   GetClientRect(theWindow,&ClientRect);
     
   /* Obtain and initialize device contexts */
   dc = GetDC(theWindow);
   memDC = CreateCompatibleDC(dc);
   SetArcDirection(memDC,AD_COUNTERCLOCKWISE);
   SetArcDirection(dc,AD_COUNTERCLOCKWISE);
   SetPolyFillMode(memDC,WINDING);
   SetPolyFillMode(memDC,WINDING);
   SetTextAlign(memDC,TA_BASELINE | TA_LEFT);
   SetTextAlign(dc,TA_BASELINE | TA_LEFT);
   SetBkMode(memDC,TRANSPARENT);
   SetBkMode(dc,TRANSPARENT);
   theBitmap = CreateCompatibleBitmap(dc,w,h);
   SelectObject(memDC,theBitmap);
   ReleaseDC(theWindow,dc);
   CreateHeap(&btnHeap, "Button heap", MHEAP, sizeof(HButton), 1.0, 100, 100);
     
   InitGlobals();
   InstallColours();
     
   winCreated = TRUE;
   HSetColour(WHITE);
   HFillRectangle(0,0,ClientRect.right,ClientRect.bottom);
}
Ejemplo n.º 2
0
/* EXPORT-> MakeXGraf: Connect to the X-server and init globals */
void MakeXGraf(char *wname, int x, int y, int w, int h, int bw)
{
   char sbuf[MAXSTRLEN], *hgraf = "HGraf";
   Window window, parent;
   XSetWindowAttributes setwinattr;
   unsigned long vmask;
   
   if (winCreated)
      HError(6870, "MakeXGraf: Attempt to recreate the graphics window");
   if ((theDisp = XOpenDisplay(NULL)) == NULL)
      HError(6870, "MakeXGraf: cannot connect to X server %s", XDisplayName(NULL));
   InitGlobals();
   InstallFonts();
   InstallColours();
   parent = RootWindow(theDisp, theScreen);
   window = XCreateSimpleWindow(theDisp, parent, x, y, w, h, bw, black, white );
   /* allow for backing up the contents of the window */
   vmask = CWBackingStore;  setwinattr.backing_store = WhenMapped;
   XChangeWindowAttributes(theDisp, window, vmask, &setwinattr);
   /* set the size hints for the window manager */
   hints.flags = PPosition | PSize | PMaxSize | PMinSize;
   hints.y = y;              hints.x = x;
   hints.width  = w;         hints.height = h;
   hints.min_width  = w;     hints.min_height = h;
   hints.max_width  = w;     hints.max_height = h;
   /* compose the name of the window */
   strcpy(sbuf, hgraf);  strcat(sbuf, ": ");  strcat(sbuf, wname);
   XSetStandardProperties(theDisp, window, sbuf, hgraf, None, NULL, 0, &hints);
   /* select events to receive */
   XSelectInput(theDisp, window, ExposureMask | KeyPressMask | ButtonPressMask | 
                ButtonReleaseMask | PointerMotionHintMask | PointerMotionMask);
   XMapWindow(theDisp, theWindow = window);
   InitGCs(); 
   HSetXMode(GCOPY); HSetFontSize(0); HSetLineWidth(0); HSetColour(BLACK);
   /* wait for the first expose event - cannot draw before it has arrived */
   do 
      XNextEvent(theDisp, &report); 
   while (report.type != Expose);
   XSendEvent(theDisp,window,False,ExposureMask,&report);
   /* Create heap for buttons */
   CreateHeap(&btnHeap, "Button heap", MHEAP, sizeof(HButton), 1.0, 100, 100);
   winCreated = TRUE;
}