|
hi,
does anyone know if a layered window can be a direct3d client window?
Live long and prosper
johny74656@gmail.com
|
|
|
|
|
Using the Win32 API here he is some sample code to get the device context and create a bitmap
HDC hBackDC=NULL;<br />
HDC hdc=GetDC(hWnd);<br />
hBackDC=CreateCompatibleDC(hdc);<br />
<br />
BITMAPINFO bmpInfo;<br />
<br />
ZeroMemory(&bmpInfo,sizeof(bmpInfo));<br />
bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);<br />
bmpInfo.bmiHeader.biBitCount=32;<br />
bmpInfo.bmiHeader.biCompression=BI_RGB;<br />
bmpInfo.bmiHeader.biSizeImage=320*240*4;<br />
bmpInfo.bmiHeader.biPlanes=1;<br />
bmpInfo.bmiHeader.biHeight=240;<br />
bmpInfo.bmiHeader.biWidth=320;<br />
<br />
hBackBitmap=CreateDIBSection(hBackDC,&bmpInfo,DIB_RGB_COLORS,&pBits,NULL,NULL);
where "hWnd" is from LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
I'm wondering how I get the handle of the window (hWnd) in MFC?
Thanks
|
|
|
|
|
bankai123 wrote: I'm wondering how I get the handle of the window (hWnd) in MFC?
See CWnd::GetSafeHwnd()[^]
|
|
|
|
|
bankai123 wrote: HDC hdc=GetDC(hWnd);
There are wrapper classes for such win32 functionalities in MFC .
In this case you can use CDC or derived class.
Prasad
MS MVP - VC++
|
|
|
|
|
Hi,
There's a small problem with my polygons: To create Run codes from my polygon structure I came up with an algorithm that looked up for each horizontal line which polygon lines crossed them and where, then sorting them and going from left to right to check wether the actual point is an entry point, an exit point or a single point that is either ignored (if it's a point that is between two "inside" fractions of the run codes) or results in an one-point run code (if it's a single point between two "outside" fractions. The problem I have is, that I checked for the "entering" the polygon or "leaving" it by checking the pixel to the right of it with a CRgn::PtInRegion. It seemed to work fine, but then (mostly by random) I had a polygon with a horizontal line and had to find out that the pixels on the line seemed to be detected as "outside" by PtInRegion, which resulted in two single-point run codes instead of one run code from the the start point to the end point.
Is there an easy way to check if the point is ON a polygon line, so that I can modify the criterium for the "entering" points by if(PtInRegion(pt) || PtOnLine(pt)), or even better, is there a way to modify the PtInRegion by parameters given to the CRgn object that points on the bounding line are recognized as inside?
Another problem in this context might be the calculation of the crossing points between polygon lines and horizontal lines. If it's not a horizontal line (which means y==y1==y2) I calculate it by a formula x=(x1+(y-y1)*((x2-x1)/(y2-y1))) rounding it to an integer afterwards, but this calculation is too exact, not taking in account the inaccuracy due to alias effects, so some pixels that would be drawn as bounding line for the polygon are not recognized by my algorithm. Is there an easy and fast algorithm that can help me find the min-crossing an max-crossing points to be used in my run code algorithm?
Hope anyone can help
Martin Dietz
|
|
|
|
|
I'm using VC++ 6 under WinXP SP2. After my application exits I get
Detected memory leaks!<br />
Dumping objects -><br />
{61} normal block at 0x02621740, 12 bytes long.<br />
Data: <@ b @ b > 40 17 62 02 40 17 62 02 CD CD CD CD <br />
{60} normal block at 0x02621780, 44 bytes long.<br />
Data: <|h] a] a] b > 7C 68 5D 02 80 61 5D 02 88 61 5D 02 C0 1A 62 02 <br />
Object dump complete.<br />
the same all the time. So, I want to find out, where I'm leaking the memory, so I'm usind _CrtSetBreakAlloc(60) , but it doesn't stop the execution at all. Why it can be so: leak finder reports about leaking in 60th allocation, but fails to stop when it is allocated?! Help me please.
Thank you beforehand.
P.S. Don't worry, I'm building in debug mode.
|
|
|
|
|
And you're using the debug C runtime library?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
How can I make sure that I do?
In "Project settings"|"Link"|"Ignore libraries" I've listed "libc.lib,libcd.lib,msvcrt.lib" some time ago to compile one external project. Does it matter?
|
|
|
|
|
I don't have VC6 but in VS 2003 it's in the
project properties/C++/Code Generation/Runtime Library
It's whatever setting sets the /M compiler option. You'll want
/MTd (multithreaded debug)
or /MDd (multithreaded debug DLL)
or /MLd (singlethreaded debug)
The debug CRT is msvcrtd.lib, not msvcrt.lib.
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Then I do, "Debug Multithreaded", "/MTd" key.
What can be the cause of the problem?
|
|
|
|
|
Hmm i don't know...
First, where are you putting the _CrtSetBreakAlloc() call? You'll want that as early in the
program execution as possible. If you still can't get it to break when you set
_CrtSetBreakAlloc() at the start of Main/WinMain (or your CWinApp constructor in MFC) then maybe
the allocation is occuring in a DLL.
Second, to get more detailed info (file/linenumber where allocation occurred):
Add this to your precompiled header .h file:
#ifdef _DEBUG
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
#else
#define DEBUG_NEW new
#endif
For non-MFC apps add this to the top of ALL your source modules, under the
last #include... line:
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
For an MFC app (as I mentioned before) add this to the top of ALL your source modules, under the
last #include... line:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
I personally use these in EVERY file. The time it's saved me in debugging leaks has been HUGE
compared to the time it took to add these lines to hundreds of source files.
This link may help further: Memory Leak Detection Enabling[^]
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: First, where are you putting the _CrtSetBreakAlloc() call?
In the InitInstance of the application class, then like this:
static struct LeaksLocator<br />
{<br />
LeaksLocator()<br />
{<br />
_CrtSetBreakAlloc(60);<br />
}<br />
} LeaksLocatorInst; <br />
Finally, I've found it!!! You were right, it is in the external DLL. Thanks a lot, but I have a lot of DLLs and all of them have 60th allocation, so I cannot find out, which one is joking at me. I added
#ifdef _DEBUG<br />
#include<br />
#define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)<br />
#else<br />
#define DEBUG_NEW new<br />
#endif
but no more details appeared. What I can do now?
|
|
|
|
|
dum wrote: In the InitInstance of the application class, then like this:
Try to add the statement in StdAfx.h. I frequently use this function and it works for me to find out simple leaks.
dum wrote: static struct LeaksLocator
{
LeaksLocator()
{
_CrtSetBreakAlloc(60);
}
} LeaksLocatorInst;
Is the allocation number of the said leaks matching with the number given to _CrtSetBreakAlloc .
I don't think you need a struct here, I use _CrtSetBreakAlloc function like this.
static int nBreaker = _CrtSetBreakAlloc( 60 );
|
|
|
|
|
A small addition to Mark's post:
These allocations may be taking place in objects that are being created during 'static' initialization, which occurs before any of your code gets called. If you've got global objects (or static objects with file scope), this could be the case. Given that the leaks are at allocations 60 and 61, I would bet this is the case.
Here's an example:
class Object {
public:
Object()
{ Data = new char[128]; };
char *Data;
};
Object GlobalObject;
static Object FileObject; These two declarations will allocate a total of 256 bytes before the application code starts (and _CrtSetBreakAlloc() can be called by mainline code).
Software Zen: delete this;
|
|
|
|
|
i want to know here that when i write a function like this
<br />
int add (int a,int b)<br />
{<br />
int sum=0;<br />
<br />
sum=a+b;<br />
return sum;<br />
}<br />
<br />
i return sum but return sum to where.... that what i hope to know
thank's for all
To Be Or Not To Be
(KARFER)
|
|
|
|
|
The value of sum is returned to the caller of add().
Somewhere else in your code you'd call add...
int SumFromAdd = add(2,3);
//SumFromAdd == 5
You can also choose to igore return values...
add(2,3);
// add() has been called but the return value wasn't used
Note that there's no need to initialize sum to 0 in your function since the next line you
initialize it to the sum of the two passed integers. You could shorten your function to:
int add (int a,int b)
{
return a+b;
}
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Sometimes you need to return value so you use of this cause here is two samples:
int add (int a,int b)
{
int sum;
sum=a+b;
return sum;
}
void test()
{
int c;
c=add(2,2);
}
Cstring add ()
{
CString str;
SYSTEMTIME st;
GetLocalTime(&st);
str.Format("%d:%d:%d:",st.wHour,st.wMinute,st.wSecond);
return str;
}
void test()
{
MessageBox(add());
}
|
|
|
|
|
i want to know here that when i write a function like this
<code>
int add (int a,int b)
{
int sum=0;
sum=a+b;
return sum;
}
</code>
i return sum but return sum to where.... that what i hope to know
thank's for all
To Be Or Not To Be
(KARFER)
|
|
|
|
|
When you need to post a code you can use of
pre
and dont need to post again.;)
|
|
|
|
|
since you are returning an integer data type, you can call the function to an integer like:
int s;
s=add(2,3);
where you pass 2 and 3 as integers and get 5 as the sum which is stored in the variable s.
The add function can be called from any other function or main method.
hope that helps.
|
|
|
|
|
Hey guys, this tutorial helped me a lot http://www.codeproject.com/threads/processes.asp but it enumerates all running processes. Is there a way to only show info of a desired process, lets say notepad.exe?
Thanks
|
|
|
|
|
|
|
hey guys
this is more of a MFC-question than OpenGL I guess, that's why I put it here.
I integrated an OpenGL-control in my MFC-proggy, like from here:
(http://www.codeguru.com/cpp/g-m/opengl/article.php/c5583)
all works fine, except that
"glViewport(0, 0, width, height);"
makes no difference and I cannot get the correct aspect ratio for my OpenGL-viewport (Except my app is squared).
When the app is resized I call the Resize-function of my opengl-class
which looks like this
<br />
void COpenGL::Resize(int posx, int posy, int width, int height)<br />
{<br />
if (height==0) height=1;
}<br />
this->SetWindowPos(&CWnd::wndBottom,<br />
posx,<br />
posy,<br />
width,<br />
height,<br />
NULL);<br />
<br />
<br />
glViewport(0,0,(GLsizei)width,( GLsizei)height);
glMatrixMode(GL_PROJECTION);<br />
glLoadIdentity ();<br />
gluPerspective(45.0f,(float)width/((float)height),0.1f,100.0f);<br />
glMatrixMode(GL_MODELVIEW);<br />
<br />
}<br />
The first part resizes OpenGL-Control... works
The second part should resize the viewport (camera/aspect-ratio)... those commands work fine in a console app using only glut.
any idea?
thx in advance
zqueezy
|
|
|
|
|
so guys,
sorry for posting that early...
the answer is:
the definition has to be done before drawing not in resizing... donnu why, but that works fine...
but thanx for this cool forum
|
|
|
|