For those new to message boards please try to follow a few simple rules when posting your question.
Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
Keep the subject line brief, but descriptive. eg "File Serialization problem"
Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
No advertising or soliciting.
We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
// 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
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
HDC_of_MainWindow = GetDC( Handle_of_MainWindow ) ;
// Now copy the FRONT_BUFFER to the MainWindow.
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.
StretchBlt(HDC_of_FRONT_BUFFER, 0, 0, W, H, HDC_of_Something, 0, 0, W, H, SRCCOPY);
//This does not show up.
How do I add listboxes to a back buffer and use that?
The listbox seems to be there but invisible.
The way that I did it before, the listbox was there but invisible.
I could detect clicking on the area where the listbox was supposed to be was not allowing me to click on the main window.
I click where the listbox is blocking other things, but nothing happens.
It is invisible or just blocking my clicks to the main window. I want to see the listbox and interact with it.
A ListBox is just a Window, so if you call ShowWindow using its handle, then it may cover part of your main window. That in turn will receive a WM_PAINT message and redraw itself, which may well have the effect of hiding the ListBox. I am really having difficulty understanding what you are trying to do here. The most common use of ListBoxes is as part of a DialogBox, or CFormView. If you want it as part of your MainWindow then you need to add it into the client zone, and not overwrite it with the main window.
It is the window (a window) itself which is represented by a listbox that I am interested in being able to place in a buffer and then placing that buffer to the screen.
It could be a textbox (created via a window) or some subclassed window from elsewhere like a subclassed browser window or a subclassed game, etc. I want to be able to put all of this in a buffer before placing the result to the screen. Does that help to explain it?
Here is where this issue was discovered:
I noticed that sometimes on some computers that multiple items show up on the screen one at a time slow enough that I and other people detect a lag in the screen being fully created. Memory overloaded, or cpu overloaded, or too much other programs running for smooth response at the screen level. I do not want that. I prefer that my program places everything in a buffer then places that one cohesive buffer to the screen, and not one piece at a time. I can do this with text. I can do this with bitmaps. I should be able to do this with windows (listboxes, textboxes, subclassed outside windows).
I tried. I studied. I tried placing almost randomly attempts to break through my ignorance of how to do this.
I noticed that sometimes on some computers that multiple items show up on the screen one at a time slow enough that I and other people detect a lag in the screen being fully created. Memory overloaded, or cpu overloaded, or too much other programs running for smooth response at the screen level.
I guess that meant that I was disappointed with my current attempt to add a generic window to a buffer and then to be able to put that buffer to the screen (showing the window).
I have been trying to create or subclass a window (in this example a listbox), and place that window (I guess as a child window?) into or on a buffer, and then place the buffer to the screen. It "did not work." meant that I failed in the attempt.
Same goal of adding a listbox to a back buffer and using that. Generally, the listbox is just an example of some window that I can get a handle of in my attempts.
This approach, even if you somehow managed to get it to work, sounds kludgy at best.
If your program is causing this much lag, it sounds as though way too much work is going on in the UI thread. The main/primary thread should do little else besides UI-related stuff. Everything else should be handled by secondary threads.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
"sounds kludgy" is a start. I can accept that as the beginning of a suggested answer.
I can multi-thread. If you are saying that you know of how to solve this by multi-threading and thus placing a window that is (in this example) a listbox (or some other generic window) to a back buffer, I am ready for that instruction. If you simply did not read my original question and then fired off a general cutting response with no valid logic, then I can understand that and it is ok. I have scanned and responded wrongly myself a few times. If you have a valid solution keeping to answering my first post, then I am ready to read it. If you can this with multi-threading, then please tell me how.
I found this lag in someone else's program that I had nothing to do with coding. I do not recall seeing it in any of my current programs that I wrote. Their program is a really nicely written program that does a lot of things well. But, when their program is running and at the same time some other huge programs (plural) with intense cpu use and intense memory use are running, then I saw a lag that was enough for me to see postings of sections of their program to the screen.
If someone is running my programs then however intense the cpu and memory usage is by any other running programs, I do not want the user to see any lag of sections of my main window being put to the screen. I would prefer that my programs get its work done building a screen buffer before placing anything to the screen.
You guys are great. You seem to have misread what I am asking and yet you still gave an answer that I find useful. Thanks. I could use your suggestion of SetThreadPriority for my screen capture of the listbox (in using a dedicated thread for the capture) if I do not find a way to place the listbox into a buffer. I like this site.
I still would like to be able to put a listbox (or other window) into a graphics buffer.
I am thinking about forcing the effect to get past my not knowing how to buffer a created (or subclassed) window, in this case a simple listbox.
I would like some valid comments on what I am thinking about trying next.
When the listbox's (it is just an example of a generic window) information changes, do a screen capture of the listbox.
Then when my main window changes, bitblt that screen-captured listbox to the buffer that I build before replacing the main window to the screen.
I do not want to do it this way.
I am concerned that I might have to create a new listbox window each time that I need to update the listbox and I do not want to have to do that. If the listbox is rarely updated then this might not be so bad, but if the listbox is updated often then that might mean creating a new window for the listbox often. I really do not want to do that. And, as you have noticed (hopefully) this is not about a listbox only. It is about any window like it, just that I am using a listbox as an example.
I am looking for valid observations and valid suggestions.
I think that David Crow's suggestion was actually valid. Maybe I read his response too quickly and dismissed it too quickly. Sorry. I think that, in a dedicated thread, I can do a screen capture of just the part of the screen where the listbox is and save that for when it is needed. Thanks David Crow.
I`m trying to build a barebones MFC app. I`m used to C# Forms, but I`m having a tough time in MFC though.
I`m creating a new MFC app in the New Project dialog and in the Wizard I pick Dialog based app as app type. However after creation I can`t open the resource (in the resource view) to fill it with controls.
it`s a totally fresh project, no edits after pressing the `Finish` button in the create app wizard/dialog. I`m expecting to be able to add new controls from ToolBox but obviously something is missing...
I do not think MFC apps make use of the Toolbox. If you double-click the resource file (projectname.rc) in Solution Explorer, it should open the Resource Editor where you can add the various controls to your dialog.