|
I've created an application that loads a bitmap, and draws on it using various graphics functions (text, bitmap, etc) depending on various things that the user does (pressing keys, clicking buttons, etc). I was able to implement most everything I wanted to do, but there are problems related to not having used OnPaint, so when other windows cover my window, as expected the graphics I drew disappear. I understand the reason this happens, but I'm not quite sure what the simple work around is.
I can't do all my drawing in OnPaint, because well that would be weird.
I've started with a standard MFC Dialog App with a CStatic control. Here's fake code basics of what I have in OnInit():
CBitmap bmpIntro;
bmpIntro.LoadBitmap(IDB_Intro);
CStatic c_Image;
c_Image.SetBitmap(bmpIntro);
Now, problem #1 is that I want to put some intro text on this bitmap to appear when the window first opens. Putting it in OnInit() or OnPaint() doesn't seem to work.
The other problem is that as things progress, I'm using c_Image.GetDC() to draw all kinds of stuff into the CStatic control, and at any given moment, anything could be displayed depending on what the user initiated. Too much for OnPaint() to know what to recreate.
Since the CStatic already knows how to OnPaint() the original bitmap back into the dialog, is there a way I can draw into the original bitmap, so I don't have to worry about OnPaint() myself? And then somehow tell the CStatic to update itself? Or possibly I draw everything twice, once into the CStatic, and once into the original bitmap it is using.
Again, this seems kludgy, surely there's a more sensible way? And then how also to resolve problem #1?
modified on Monday, July 13, 2009 10:43 PM
|
|
|
|
|
dhomas wrote: I can't do all my drawing in OnPaint, because well that would be weird.
It is not weird for Windows.
If all your drawing is in the CStatic control, derive your own class class from CStatic, override its OnPaint method and do your drawing there.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
That would be very complex, since OnPaint() wil have no idea what it has to draw as I explained already.
|
|
|
|
|
In this scenario what would be appropriate is to set a variable to different values depending on user actions.
And in the OnPaint you could have a switch statement.
switch (action)
{
case 1:
break;
case 2:
break;
.
.
.
}
Whenever the user initiates an action -
action = 1;
static.Invalidate();
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
And how does that resolve repainting when another window overlaps this application. It still has no idea what to draw. Keeping a list of all the actions is simply not sensible. The simple approach seems to somehow be in drawing into the original bitmap, and copying from that back into the control when repainting is needed. But, I can't figure out how to do that. And can't find any other approach.
|
|
|
|
|
I don't understand your exact requirement, but how would you do a reverse of a particular user action if you draw into the original bitmap.
Let us say the user clicked a check box and you want to display the text "Image checked" on the bitmap.
Now you want to remove the text if the user unchecks the checkbox.
If you do not have such a situation where an action will be undone, you could draw onto the original bitmap.
To modify the bitmap, I guess you just need to create a CDC object and use CDC::SelectObject to select the CBitmap object into it. Now you could use the drawing function of the CDC class to draw on the bitmap.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I don't need to reverse any actions. Okay here's an analogy...
You have a black chalkboard. It's got nothing on it. A bunch of people go up to the chalkboard and write all over it. At some point, someone pulls down a screen in front of part of the chalkboard. The problem is... when the screen is put back up, the part of the chalkboard that was covered is now erased.
How do I code to resolve that issue.
|
|
|
|
|
dhomas wrote: when the screen is put back up
This is what I meant by reverse an action.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
|
Hello
I am working on a Win32 Application in Visual Studio 2003 environment.
I want the whole app to wait until USER click an OK button on the screen.
This app has multiple threads running simultaneously. So is it possible to stop the whole app until an OK button is pressed?
|
|
|
|
|
you could suspend[^] all your threads (EXCEPT the UI thread, of course!) when you start the wait and resume[^] them if OK is pressed?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
why we can't overload .,->, :: operators?
|
|
|
|
|
The -> operator can be overloaded. The others cannot. See here for why.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Thnx very good link....i got many things cleared
|
|
|
|
|
Hello,
I'm having problems with minimizing all windows within an MDI at the same time. I can loop through all open windows and minimize them one at a time (but that causes lots of delay with more than 5 windows, as they all go one after the other).
I can minimize the whole application with:
::SendMessage(pMainFrame->m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
or I can minimize individual active frames with:
::SendMessage(pMainFrame->GetActiveFrame()->m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
But how do I minimize them all at once?
Thanks for your help,
Dave
|
|
|
|
|
That's not a standard message but an application-specific thing. As far as I know, closing them one at a time is your only option.
Just for grins, what would happen if you posted the message instead:
::PostMessage(pMainFrame->GetActiveFrame()->m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0); or
pMainFrame->GetActiveFrame()->PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Both just minimize the active frame (window), and not all frames.
I thought there would be something more standard(MFC) I could just send to the mainFrame which handles it all, similar to the way MFC handles tiling or cascading windows.
|
|
|
|
|
blueflame213 wrote: Both just minimize the active frame (window), and not all frames.
Didn't you put it in a loop?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Sorry, I may not have been clear enough,
When minimizing a window, it shows the animation of the window title bar being minimized to the bottom.
When looping through all windows to minimize, the delay of having to watch each window individually be minimized becomes significant with many windows open.
I was wondering if there was something which would minimize all windows at once, without having to sit through each window displaying its "minimization animation".
I appreciate your help so far!
|
|
|
|
|
blueflame213 wrote: Sorry, I may not have been clear enough,
No, you were perfectly clear. It's just that you said in the initial post, "I can loop through all open windows and minimize them one at a time" but in your last post you said, "Both just minimize the active frame (window), and not all frames." I assumed you removed the loop in the latter post, hence my confusion.
My suggestion to post the message instead of sending it was not meant to solve the problem but rather to minimize the perception of a delay.
If you had an example of an application that minimizes all open frames at once, you might could spy on it and see what messages, if any, are being used.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Found a solution with using
ShowWindow(SW_HIDE) first and then ShowWindow(SW_MINIMIZE),
This way XP doesn't show it's "minimizing animation" while minimizing, and it speeds everything up significantly!
Thanks for all of your help!!
|
|
|
|
|
Good find.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
I am writing a c++ code for converting bmp file into jpeg....
The algorithm i have followed is:
1)Convert RGB color space to Y,Cb,Cr..
2)Down sample Cb and Cr by 2..that means for each square block of 2*2 there is 4 different Y
value but 1 Cb and 1 Cr value..
3)Apply DCT to data units of each 8*8 pixels...
4)Then apply quantization on DCT coefficient by using standard quantization table of Cb and Cr.
5)Do zigzag ordering.
6)Encode the DC and AC coefficient separately using huffman encoding.
7)Write proper header and write huffman encoded value to the file...
By doing all this things correctly(cross checked for various imaged and values) I am still not getting
the jpeg image correctly displayed.
Then i made a small 8*8 24 bit(color depth) bmp file completly filled with color value R=10 B=10
and G=100...all 64 pixels are of same color..
The data that i m getting at every step is as follows...
Bmp Image Header:
size of header 40
width 8
height 8
no of planes 1
no of bits per pixel 24
image size 194
x resolution pixel per meter 2834
y resolution pixel per meter 2834
no of colors 0
no of imp colors 0
The Y Cb Cr conversion of (R,B,G)=(10,10,100) is (62,-29,-37)
so lets consider Y component first..
The DCT coefficient for Y component is :
495 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
After Quantization, the zig zag ordering of single data unit that i m getting is this, for Y component.
30 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
Now the huffman coding of above zig zag order array is :
Y dc coding: 00111110
Y ac coding: 1010 (for ac huffman table(luminance Y) EOB value is 1010)
Similary huffman coding of Cb and Cr components is as follows:
cb dc coding: 11000010
cb ac coding: 01 (for ac huffman table(chrominance Cb,Cr) EOB value is 01)
cr dc coding: 110101110
cr ac coding: 01
Final Huffman code that i get is:
001111101010110000100111010111001 Length 33
so to make it divisible by 8 padding of 1 is done.
0011111010101100001001110101110011111111 Length 40.
Here each single 0 or 1 is actually a bit that needs to be stored as it is in the jpeg file but since we
cant write bit by bit into file, a total of 8 bit is taken and converted into a integer value in base 10
and stored that into a character which now takes 1 byte.
So this is all procedure and some specific data that i have shown here...but still i m not getting my
image shown correctly..
can somebody help me out on this!!!!!!!!!
|
|
|
|
|
|
You don't need code.
Use Win32 Shell api (1 line of code)
|
|
|
|