How do I add listboxes to a back buffer and use that?
-
Painting information to the screen should be in the WM_PAINT handler. If you do it in other parts of the program then you will not always get the correct information in the display.
Do you mean like this?
case WM\_PAINT: { PAINTSTRUCT ps; HDC\_of\_MainWindow = BeginPaint(hwnd, &ps); Draw\_From\_FRONT\_BUFFER\_To\_MainWindow(); **ShowWindow(Handle\_of\_ListBox, SW\_SHOW);** EndPaint(hwnd, &ps); return 0; } break;
I tried that already. 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.
-
Do you mean like this?
case WM\_PAINT: { PAINTSTRUCT ps; HDC\_of\_MainWindow = BeginPaint(hwnd, &ps); Draw\_From\_FRONT\_BUFFER\_To\_MainWindow(); **ShowWindow(Handle\_of\_ListBox, SW\_SHOW);** EndPaint(hwnd, &ps); return 0; } break;
I tried that already. 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. -
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.Before I go any further. Thank you for your help. I am using a listbox just as an example. 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. How to do it?
-
Before I go any further. Thank you for your help. I am using a listbox just as an example. 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. How to do it?
PotatoSoup wrote:
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.
First of all remove the calls such as
ShowWindow(Handle_of_ListBox, ...);
from the WM_PAINT message handlers.
-
PotatoSoup wrote:
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.
First of all remove the calls such as
ShowWindow(Handle_of_ListBox, ...);
from the WM_PAINT message handlers.
OK. I put things back they way they were. Now i have tried using
SetFocus(Handle\_of\_ListBox);
But that did not work. I can tell that something is still there because I can not click on that area of the main window.
-
OK. I put things back they way they were. Now i have tried using
SetFocus(Handle\_of\_ListBox);
But that did not work. I can tell that something is still there because I can not click on that area of the main window.
PotatoSoup wrote:
Now i have tried using
SetFocus(Handle_of_ListBox);
But that did not work.
I'll ask you again: define "did not work." :suss:
-
Before I go any further. Thank you for your help. I am using a listbox just as an example. 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. How to do it?
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
-
PotatoSoup wrote:
Now i have tried using
SetFocus(Handle_of_ListBox);
But that did not work.
I'll ask you again: define "did not work." :suss:
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. "did not work." = "I failed at this again."
-
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. Thank you for asking.
-
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 Canv
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. Please. 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.
-
"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. Thank you for asking.
Perhaps
SetThreadPriority
if you're concerned about competing with CPU pigs?Robust Services Core | Software Techniques for Lemmings | Articles
-
Perhaps
SetThreadPriority
if you're concerned about competing with CPU pigs?Robust Services Core | Software Techniques for Lemmings | Articles
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.
-
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'm sorry, but that's all I can offer. I write pure C++ with a thin adapter for Windows, so I've never done MFC things. I just tossed it out there because it seemed to address your most recent post.
Robust Services Core | Software Techniques for Lemmings | Articles
-
I'm sorry, but that's all I can offer. I write pure C++ with a thin adapter for Windows, so I've never done MFC things. I just tossed it out there because it seemed to address your most recent post.
Robust Services Core | Software Techniques for Lemmings | Articles
"I write pure C++ with a thin adapter for Windows". That is one of the most impressive comments that I have read on this and most programming sites within the last year. That reads like an advisable goal. How would you approach a quest like this as my first post explains? Thank you.
-
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 Canv
Not exactly Following what you are trying to do so can I provide a reference sample GitHub - LdB-ECM/ListPlay: Windows ListBox Sample[^] That has a gradient and icons etc as sort of a complex example .. so can you explain what you are trying to do better. I don't understand why you would capture the screen image like not ever it's always faster to just draw stuff or hide/show stuff. Perhaps describe or draw a rough image of what you are trying to do on screen.
In vino veritas
-
I'm sorry, but that's all I can offer. I write pure C++ with a thin adapter for Windows, so I've never done MFC things. I just tossed it out there because it seemed to address your most recent post.
Robust Services Core | Software Techniques for Lemmings | Articles
The OP's code has nothing to do with MFC. It is a plain Win32 code.
-
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. Please. 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.
You do not need to recreate a new listbox window NOT EVER, you can simply change the contents of the window by exchange messages and then asking the existing listbox to update. It works that way for every windows type. You see that in standard file open dialogs the directory names change in the listboxes and they aren't making new listboxes. Anyhow I gave you reference of a fairly complex listbox example on the post below for you to look at just look at main.cpp So you seem to be deeply confused about something with Windows. I am half thinking you may be talking about an Undo/Redo function for a window but not know to call it that. If you are trying to do that it is done by creating a history structure and you are creating a history window.
In vino veritas
-
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. "did not work." = "I failed at this again."
I am still suggesting you are doing this all wrong but I can fix this problem if you really are manually drawing the list. To me it sounds like the listbox should be a child within some other window and you are just trying to do this in some crazy manual way. If it was child it would draw itself when needed with zero code needed from you. However if you are manually doing it you could try this Copy all the code in the WM_PAINT function of your listbox and place it inside a function like so
void PaintMyList (HWND Handle_of_ListBox, HDC Dc)
{
// Paste your current list box WM_PAINT code here
}Now replace the PaintStruct stuff and simply us the HDC passed on the interface and use Handle_of_ListBox where you need a handle .. okay check it all compiles. So we are clear all you are using from the PaintStruct is the DC and the DC you are to use is declared on that function interface so you can remove all references to the PaintStruct. Now use a variant you posted above with the one call change
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC_of_MainWindow = BeginPaint(hwnd, &ps);
Draw_From_FRONT_BUFFER_To_MainWindow();
PaintMyList(Handle_of_ListBox, ps.hdc); // <=== Now the list paints on the DC from the paintstruct
EndPaint(hwnd, &ps);
return 0;
}
break;In vino veritas
-
Before I go any further. Thank you for your help. I am using a listbox just as an example. 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. How to do it?
PotatoSoup wrote:
How to do it?
Simple, make the ListBox a child of the main window and size it to the client area. That is the standard Windows paradigm that has worked since the 1990s. No need for complicated backdoor processing or multiple device contexts. The ListBox will happily repaint itself whenever necessary.
-
"I write pure C++ with a thin adapter for Windows". That is one of the most impressive comments that I have read on this and most programming sites within the last year. That reads like an advisable goal. How would you approach a quest like this as my first post explains? Thank you.
Victor states that you're not doing anything with MFC, so I must have jumped to the wrong conclusion when I saw your code creating a window. I just run my stuff as a console app that ultimately uses nothing but
std::cin
, although it can also read commands from a file.Robust Services Core | Software Techniques for Lemmings | Articles