Hi,

  It is much simpler than that. IupBackgroundBox *is* a IupCanvas. Just use
it in the same way. No need for HDC access.

Best,
Scuri


Em seg., 21 de jun. de 2021 às 17:59, Isaac Raway <is...@mm.st> escreveu:

> Is there any way to use IupBackgroundBox with CD?
>
> I am currently using an IupCanvas and drawing into it successfully using
> CD. I would like to parent other controls onto this surface (such as
> IupMultitext, IupButton), but retain the ability to draw using CD since I
> have a lot of code written using that.
>
> So if there was a way to copy the result from CD into IupBackgroundBox
> using IupDraw that would seem to do the job, but I can't quite seem to get
> it to work. The only way I could figure out to create a cdCanvas was to
> use CD_NATIVEWINDOW with a new Win32 HWND. The graphics are drawn into the
> HWND but then I can't get it copied out there into the BackgroundBox.
>
> Here's what I have:
>
> void win_create()
> {
>
>     win->notes_graph= IupBackgroundBox();
>
>     IupSetCallback(win->notes_graph, "MAP_CB", (Icallback)graph_mapcb);
>     IupSetCallback(win->notes_graph, "UNMAP_CB", (Icallback)graph_unmapcb);
>     IupSetCallback(win->notes_graph, "RESIZE_CB", (Icallback)graph_resize);
>     IupSetCallback(win->notes_graph, "BUTTON_CB", (Icallback)graph_button);
>     IupSetCallback(win->notes_graph, "MOTION_CB", (Icallback)graph_motion);
>     IupSetCallback(win->notes_graph, "KEYPRESS_CB",
> (Icallback)graph_keypress);
>     IupSetCallback(win->notes_graph, "WHEEL_CB", (Icallback)graph_wheel);
>
>     IupSetCallback(win->notes_graph, "ACTION",
> (Icallback)graph_draw_backbuffer_to_container);
>
> }
>
> int graph_mapcb(_HANDLE_PTR self)
> {
>     tWIN *win = (tWIN *)IupGetAttribute(self, "WIND");
>
>
>    const wchar_t CLASS_NAME[] = L"BACKBUFFER";
>         WNDCLASS wc = { 0 };
>         wc.lpfnWndProc = DefWindowProc;
>         wc.hInstance = 0;
>         wc.lpszClassName = CLASS_NAME;
>         RegisterClass(&wc);
>         HWND hwnd = CreateWindowEx(
>             0,                              // Optional window styles.
>             CLASS_NAME,                     // Window class
>             L"Learn to Program Windows",    // Window text
>             WS_OVERLAPPEDWINDOW,            // Window style
>
>             // Size and position
>             CW_USEDEFAULT, CW_USEDEFAULT, win->screenWidth,
> win->screenHeight,
>
>             NULL,       // Parent window
>             NULL,       // Menu
>             0,  // Instance handle
>             NULL        // Additional application data
>         );
>
>
>       win->notes_cdGraph = cdCreateCanvas(CD_NATIVEWINDOW, hwnd);
>     return IUP_DEFAULT;
> }
>
> // I had to provide this signature for some reason even though I include
> cdim.h
> void cdCanvasGetImImage(cdCanvas* canvas, imImage* image, int x, int y);
>
> int graph_draw_backbuffer_to_container(_HANDLE_PTR self)
> {
>     tWIN* win = (tWIN*)IupGetAttribute(self, "WIND");
>     cdCanvasGetImImage(win->cdGraph, win->backbuffer, 0, 0);
>     Ihandle *iupImage = IupImageFromImImage(win->backbuffer);
>     IupSetHandle("BACKBUFFER", iupImage);
>     IupDrawImage(win->notes_graph, "BACKBUFFER", 0, 0, win->graphWidth,
> win->graphHeight);
>     IupSetHandle("BACKBUFFER", NULL);
>     IupDestroy(iupImage);
> }
>
> _______________________________________________
> Iup-users mailing list
> Iup-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/iup-users
>
_______________________________________________
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to