R
R
Roman Murman2018-12-19 07:18:59
C++ / C#
Roman Murman, 2018-12-19 07:18:59

How to draw inside process with nodejs?

Is it possible to draw inside a process?
I found 2 libraries with ++
node-ffi and node-gdi
I get the process id

var user32 = new ffi.Library("user32", {
      FindWindowA: [ 'uint32' , [ 'string', 'string' ]]
});

var windowHandle = user32.FindWindowA(null, "ProccessName");

Drawing is possible if you create a new window.
const GDILib = require('gdi');

// create window
const window = GDILib.init({ title: 'GDILib - Example 1.' });

let angle = 0;

window.onPaint(g => {
  // clear screen to gray
  // g.clear(r, g, b)
  g.clear(39, 40, 34); 


  // draw text

  // g.penColor(r, g, b, a = 255)
  g.penColor(255, 255, 255);
  // g.font(name, size, weight)
  g.font('Consolas', 16, 400);
  // g.text(x, y, str)
  g.text(30, 30, 'Hello world from GDILib!');


  // draw colored triangle

  g.penColor(255, 0, 0) ;
  // g.line(startX, startY, endX, endY)
  g.line(400, 30, 500, 200);
  g.penColor(0, 255, 0);
  g.line(400, 30, 300, 200);
  g.penColor(0, 0, 255) ;
  g.line(300, 200, 500, 200);


  // draw rotating rectangle

  // g.rotate(angle, originX, originY)
  g.rotate(angle, 50 + 80, 50 + 80);
  g.penColor(255, 255, 255);

  // g.rectangle (x, y, width, height)
  g.rectangle(80, 80, 100, 100); 

});

setInterval(() => {
  angle += 1;
  window.repaint();
}, 25);

But I don't know how to connect it to be able to do it. I am not a C++ expert, so I would like to implement everything through the node

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question