Click here to Skip to main content
14,546,974 members

C / C++ / MFC

 
GeneralRe: void type Pin
fearless_11-Apr-20 10:25
Memberfearless_11-Apr-20 10:25 
GeneralRe: void type Pin
Member 798912211-Apr-20 11:36
MemberMember 798912211-Apr-20 11:36 
GeneralRe: void type Pin
Richard MacCutchan11-Apr-20 23:40
mveRichard MacCutchan11-Apr-20 23:40 
GeneralRe: void type Pin
Member 798912211-Apr-20 12:01
MemberMember 798912211-Apr-20 12:01 
GeneralRe: void type Pin
Greg Utas12-Apr-20 0:20
professionalGreg Utas12-Apr-20 0:20 
GeneralRe: void type Pin
leon de boer11-Apr-20 21:51
Memberleon de boer11-Apr-20 21:51 
GeneralRe: void type Pin
fearless_11-Apr-20 21:47
Memberfearless_11-Apr-20 21:47 
QuestionHow do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 5:57
MemberPotatoSoup6-Apr-20 5:57 
C++11 or previous.
Not C#.
Not Visual C++.
Not .NET anything.

Hello.

I have the following code. It shows a blank listbox. I would like to be able to use multiple listboxes, etc. and put them in a buffer to show later.

//HWND Handle_of_ListBox; // A global defined earlier.

Handle_of_ListBox = CreateWindowEx(
  WS_EX_CLIENTEDGE, // extended window styles
  L"LISTBOX", // list box window class name
  nullptr,
  WS_CHILD | WS_VISIBLE, // window styles
  MainWindow_Width - 400,   // horizontal position
  MainWindow_Height - 300,  // vertical position
  300, // width
  200, // height
  Handle_of_MainWindow,
  nullptr,
  hInstance,
  nullptr
);


I can use the following to show or hide the listbox in the winmain, but I want to show or hide it in a pre-screen buffer.
//ShowWindow(Handle_of_ListBox, SW_SHOW);
//ShowWindow(Handle_of_ListBox, SW_HIDE);


I use the following to initialize a buffer.
void Initialize_FRONT_BUFFER()
    {
	//    I already created these a globals
	//
	//    HDC	HDC_of_FRONT_BUFFER;
	//    HBITMAP	Canvas_for_FRONT_BUFFER;
	//    int		FRONT_BUFFER_WIDTH;
	//    int		FRONT_BUFFER_HEIGHT;
	//    int		FRONT_BUFFER_Temp;


                // The HDC_of_MainWindow was released in elsewhere. So, get it again.
                HDC_of_MainWindow = GetDC( Handle_of_MainWindow );

                // Create the HBITMAP "canvas", or surface on which we will draw.
                Canvas_for_FRONT_BUFFER = CreateCompatibleBitmap( HDC_of_MainWindow, FRONT_BUFFER_WIDTH, FRONT_BUFFER_HEIGHT );

                if (Canvas_for_FRONT_BUFFER == NULL)
                    {
                        MessageBox(nullptr,L"failed to create Canvas_for_FRONT_BUFFER",L"Error!",MB_ICONEXCLAMATION | MB_OK);
                    }

                // Create the HDC "device context", or collection of tools
                //    and brushes that we can use to draw on our canvas.
                HDC_of_FRONT_BUFFER = CreateCompatibleDC( HDC_of_MainWindow );

                if (HDC_of_FRONT_BUFFER == NULL)
                    {
                        MessageBox(nullptr,L"failed to create the HDC_of_FRONT_BUFFER",L"Error!",MB_ICONEXCLAMATION | MB_OK);
                    }

                // Permanently associate the surface on which to draw the
                //    ("canvas") (HBITMAP), with the "set of brushes" (HDC).

                // "select in" the Canvas_for_FRONT_BUFFER into the HDC_of_FRONT_BUFFER.
                HBITMAP Temporary_HBITMAP = (HBITMAP)SelectObject( HDC_of_FRONT_BUFFER, Canvas_for_FRONT_BUFFER );

                // Delete the "canvas" that the HDC_of_FRONT_BUFFER was going to draw to.
                DeleteObject ( Temporary_HBITMAP );

                /// Release the dc of the main window itself
                ReleaseDC ( Handle_of_MainWindow, HDC_of_MainWindow );
    }


I use the following
void Draw_Something_To_FRONT_BUFFER()
    {

        int W=FRONT_BUFFER_WIDTH;
        int H=FRONT_BUFFER_HEIGHT;

        StretchBlt(HDC_of_FRONT_BUFFER, 0, 0, W,  H, HDC_of_Something, 0, 0, W,  H, SRCCOPY);   

    }


Then I put it all to the screen with
void Draw_From_FRONT_BUFFER_To_MainWindow()
    {

        HDC_of_MainWindow = GetDC( Handle_of_MainWindow ) ;

        // Now copy the FRONT_BUFFER to the MainWindow.
        BitBlt
            (
                HDC_of_MainWindow,	// destination buffer, in this case the front buffer.
                0,                  // Horizontal start for drawing.
                0,	                // Vertical   start for drawing.
                FRONT_BUFFER_WIDTH,       // Width to draw.
                FRONT_BUFFER_HEIGHT,       // Height to draw.
                HDC_of_FRONT_BUFFER,  // SOURCE buffer.  We are taking from that back canvas.
                0,                  // Horizontal start copying from.
                0,		            // Vertical   start copying from.
                SRCCOPY             // Just want a straight copy.
            );

        ReleaseDC( Handle_of_MainWindow, HDC_of_MainWindow ) ;

    }


I want the listbox to be added to the front buffer (this is not the screen). It is a collection of buffers that I am combining then later placing them to the screen.

Why does the following not work? It works without the ShowWindow part added. It does not show the listbox this way. What should I be doing to put the listbox in the buffer? I do not want to put a final buffer to the screen and then (after that) put the listbox to the screen. I want it all in the buffer and then the buffer alone to be put to the screen.

void Draw_Something_To_FRONT_BUFFER()
    {

        int W=FRONT_BUFFER_WIDTH;
        int H=FRONT_BUFFER_HEIGHT;

        StretchBlt(HDC_of_FRONT_BUFFER, 0, 0, W,  H, HDC_of_Something, 0, 0, W,  H, SRCCOPY);   

        //This does not show up.
        ShowWindow(Handle_of_ListBox, SW_SHOW);

    }


How do I add listboxes to a back buffer and use that?

Thanks.
AnswerRe: How do I add listboxes to a back buffer and use that? Pin
Richard MacCutchan6-Apr-20 6:21
mveRichard MacCutchan6-Apr-20 6:21 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 6:46
MemberPotatoSoup6-Apr-20 6:46 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
Richard MacCutchan6-Apr-20 7:04
mveRichard MacCutchan6-Apr-20 7:04 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 7:26
MemberPotatoSoup6-Apr-20 7:26 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
Victor Nijegorodov6-Apr-20 8:24
MemberVictor Nijegorodov6-Apr-20 8:24 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 8:43
MemberPotatoSoup6-Apr-20 8:43 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
Victor Nijegorodov6-Apr-20 8:49
MemberVictor Nijegorodov6-Apr-20 8:49 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 11:07
MemberPotatoSoup6-Apr-20 11:07 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
leon de boer6-Apr-20 21:06
Memberleon de boer6-Apr-20 21:06 
SuggestionRe: How do I add listboxes to a back buffer and use that? Pin
David Crow6-Apr-20 8:59
MemberDavid Crow6-Apr-20 8:59 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 11:31
MemberPotatoSoup6-Apr-20 11:31 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
Greg Utas6-Apr-20 12:39
professionalGreg Utas6-Apr-20 12:39 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 12:52
MemberPotatoSoup6-Apr-20 12:52 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
Greg Utas6-Apr-20 12:55
professionalGreg Utas6-Apr-20 12:55 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
PotatoSoup6-Apr-20 18:58
MemberPotatoSoup6-Apr-20 18:58 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
Greg Utas7-Apr-20 0:05
professionalGreg Utas7-Apr-20 0:05 
GeneralRe: How do I add listboxes to a back buffer and use that? Pin
Victor Nijegorodov6-Apr-20 20:42
MemberVictor Nijegorodov6-Apr-20 20:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.