|
Hi, i need draw a fog background, i search Internet find a source, but it run slow, how to optimize these code let it run fast( i nill malloc memory in twice, i want to unite DrawGradient function and ApplyTransformation function). or tell me other draw example.
Thanks.
<br />
#if !defined(AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_)<br />
#define AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_<br />
<br />
#if _MSC_VER > 1000<br />
#pragma once<br />
#endif // _MSC_VER > 1000<br />
<br />
class CGradientRender <br />
{<br />
private:<br />
unsigned char* m_Data;<br />
void ApplyTransformation(int width, int height);<br />
<br />
public:<br />
void DrawGradient( HDC hDC, RECT& rect, COLORREF startColor, COLORREF endColor);<br />
<br />
CGradientRender();<br />
virtual ~CGradientRender();<br />
<br />
};<br />
<br />
#endif // !defined(AFX_GRADIENTRENDER_H__9B3090DB_F7D0_4D23_8BDA_9CFAC9A64ABE__INCLUDED_)
<br />
#include "stdafx.h"<br />
#include "GradientRender.h"<br />
#include "math.h"<br />
<br />
#ifdef _DEBUG<br />
#undef THIS_FILE<br />
static char THIS_FILE[]=__FILE__;<br />
#define new DEBUG_NEW<br />
#endif<br />
<br />
<br />
CGradientRender::CGradientRender()<br />
{<br />
m_Data = NULL;<br />
}<br />
<br />
CGradientRender::~CGradientRender()<br />
{<br />
if ( m_Data != NULL )<br />
delete m_Data;<br />
}<br />
<br />
void CGradientRender::DrawGradient( HDC hDC, RECT& rect, COLORREF startColor, COLORREF endColor)<br />
{<br />
int i, j;<br />
double r;<br />
int X, Y;<br />
double fi;<br />
int width = rect.right - rect.left;<br />
int height = rect.bottom - rect.top;<br />
int size = height*width*4;<br />
double radius = sqrt( pow(height/2,2) + pow(width/2,2) );<br />
double R = sqrt( pow(width/4,2) + pow(height/4,2) );<br />
<br />
m_Data = new unsigned char[size];<br />
<br />
for ( i=0; i<height; i++ )<br />
{<br />
for ( j=0; j<width; j++ )<br />
{<br />
r = sqrt( pow(double(i-height/2)/radius,2) + pow(double(j-width/2)/radius,2) );<br />
if ( r <= 1.0 )<br />
{<br />
m_Data[i*width*4 + j*4] = (unsigned char)(r*GetBValue(endColor) + (1-r)*GetBValue(startColor));<br />
m_Data[i*width*4 + j*4+1] = (unsigned char)(r*GetGValue(endColor) + (1-r)*GetGValue(startColor));<br />
m_Data[i*width*4 + j*4+2] = (unsigned char)(r*GetRValue(endColor) + (1-r)*GetRValue(startColor));<br />
}<br />
else<br />
{<br />
m_Data[i*width*4 + j*4] = GetBValue(endColor);<br />
m_Data[i*width*4 + j*4+1] = GetGValue(endColor);<br />
m_Data[i*width*4 + j*4+2] = GetRValue(endColor);<br />
}<br />
<br />
}<br />
}<br />
<br />
<br />
ApplyTransformation( width, height );<br />
<br />
HBITMAP hBitmap = (HBITMAP)CreateBitmap( width, height, 1, 32, m_Data );<br />
<br />
HDC hMemDC = CreateCompatibleDC(hDC);<br />
HBITMAP hOldBitmap = (HBITMAP)SelectObject( hMemDC, hBitmap );<br />
<br />
BitBlt( hDC, rect.left, rect.top, width, height, hMemDC, 0, 0, SRCCOPY );<br />
<br />
SelectObject( hMemDC, hOldBitmap );<br />
DeleteDC(hMemDC);<br />
DeleteObject(hBitmap);<br />
delete m_Data;<br />
m_Data = NULL;<br />
}<br />
<br />
void CGradientRender::ApplyTransformation(int width, int height)<br />
{<br />
int X, Y;<br />
double r, fi;<br />
double R = sqrt( pow(width/4,2) + pow(height/4,2) );<br />
<br />
int size = height*width*4;<br />
unsigned char* newBuffer = new unsigned char[size];<br />
memcpy( newBuffer, m_Data, size );<br />
<br />
for ( int i=0; i<height; i++ )<br />
{<br />
for ( int j=0; j<width; j++ )<br />
{<br />
fi = atan(double(i-height/2)/double(j-width/2));<br />
r = sqrt( pow((i-height/2),2) + pow((j-width/2),2) );<br />
X = int((pow(r,2)/R)*cos(fi));<br />
Y = int(fabs((pow(r,2)/R)*sin(fi))) % height;<br />
newBuffer[i*width*4 + j*4] = m_Data[Y*width*4 + X*4];<br />
newBuffer[i*width*4 + j*4+1] = m_Data[Y*width*4 + X*4+1];<br />
newBuffer[i*width*4 + j*4+2] = m_Data[Y*width*4 + X*4+2];<br />
}<br />
}<br />
<br />
memcpy( m_Data, newBuffer, size );<br />
delete newBuffer;<br />
}
|
|
|
|
|
How about the GDI+. check the Graphics classs and LinerGradientBrush in the GDI+.
|
|
|
|
|
Oh, thanks. But i don't want use GDI+.
|
|
|
|
|
|
Those Question source code, copy from CGradientRender.
|
|
|
|
|
HOW WHAT wrote: but it run slow, how to optimize these code let it run fast( i nill malloc memory in twice, i want to unite DrawGradient function and ApplyTransformation function). or tell me other draw example.
Use GradientFill .
|
|
|
|
|
But how to use GradientFill draw fog background...
|
|
|
|
|
How can i set my LAN network bandwidth to a specific value ?
BEST REGARDS
|
|
|
|
|
I dont want to use WMI. How can i get datas of :
1. RAM
2. Ethernet
3. Harddisk and other optical disks on my system
4. PCI Devices
5. USB Devices
Thank you very much.
|
|
|
|
|
|
Hi
Please help me do a query based on date.
I have m_pSet (a pointer to CRecordset) and a filter m_strFilter
my date is a ColeDateTime in the form of "mm/dd/yyyy"
I need to set: m-pSet->m_strFilter to select records with birthday >= 1/1/1970
Any idea.
Thanks
Dan
|
|
|
|
|
I've got a parent dialog with a picture control linked to a .bmp file. Then I've got a child dialog that opens in the parent. When I open the child dialog the bitmap of the parent overlaps the child window. Any ideas?
|
|
|
|
|
What are the style and extended style flags used when creating the child dialog?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
childDlg = new cChildDlg;
childDlg->Create(cChildDlg::IDD, this);
childDlg->SetWindowPos(NULL, a, b, c, d, SWP_SHOWWINDOW);
|
|
|
|
|
I meant the window styles
Try using wndTop as the first parameter to childDlg->SetWindowPos().
You may also want to try editing the child dialog resource and set the clip siblings property to
true.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
aquawicket wrote: childDlg->SetWindowPos(NULL, a, b, c, d, SWP_SHOWWINDOW);
if you specify the first parameter as NULL, you must specify the SWP_NOZORDER flag also.
|
|
|
|
|
Also call
childDlg->BringWindowToTop()
|
|
|
|
|
Hmmm... So far I've tried all of the above, nothing does it yet...
In the resource editor, the dialog type is set to child. All of my other modal and modeless dialogs overlap the bitmap on the parent ok. It's just these child dialogs.
|
|
|
|
|
You stated "Then I've got a child dialog that opens in the parent."
How is this dialog created? Modal? Modeless?
Try using MoveWindow() instead of SetWindowPos(). MoveWindow doesn't mess with Z-order and your
most recent created child should be at the top of the z-order unless you've made another child
alwaysontop.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Good man mark... It was definetly a Z-order issue.. MoveWindow() works it out..
Thank you very very much..
|
|
|
|
|
This IMPLEMENT_DYNCREATE / DECLARE_DYNCREATE pair uses only default, protected and without parameters constructor. The macro uses class name as a paramater.
Is there any way to get around this?
Thanks for reading
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: Is there any way to get around this?
Yes - implement your own version of the macros
There's a few reasons doing this doesn't make sense and/or is impossible:
Since the macros help implement a method of creating objects given only a class name, the only
possible constructor to use is a default one.
If you know enough about the class to know that the constructor takes a parameter then creation
by classname wouldn't be necessary.
Even if you implemented a different constructor, MFC wouldn't be able to use it.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi,
My application gets some information from the command line and need to check if some string include in this command line.
I don't know how to check/analyze if some specific string is in this command line -
What i mean is if i need to know if the string "abcd" is in the command line - how can i do it ?
I can use CString and use the CString method Find(...) - but i don't allow to do so.
Is there is other way smart way ? ( some C/C++ method maybe)
Thanks.
|
|
|
|
|
The strstr()/wcsstr() runtime library function does what CString::Find() does.
Is there a specific part you are having trouble with?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
You can include stdlib.h in your file and then can access __argc and __argv. Alternatively, you can use the MFC way which is CCommandLineInfo. If you look at the implementation of CCommandLineInfo (in appcore.cpp) you will find that it builds up its string using __argc and __targv which is the TCHAR variant of __argv.
|
|
|
|