|
You should also send the DM_SETDEFID message to the dialog window, with WPARAM set to the control ID of the cancel button. Otherwise it visually changes, but the behaviour doesn't necessarily...
Steve S
|
|
|
|
|
OK, say I have two classes: class A and class B and I need both classes to be able to refer to each other. In class A I have #include "b.h" and in class B I have #include "a.h" .
In each file the #include statements are within a #ifndef block like so
#ifndef _A_H
#define _A_H
#include "b.h"
class A
{
.
.
.
};
#endif
to prevent each class being redefined.
But... this throws compilation errors! For example, in class B it says class A is not defined. I feel it's a prob with the #ifndef stuff I've got going on there. Some of you smart guys must know a better way to do this and one with which I will not get these feckin' errors. Any ideas? Any help much appreciated! Thanks.
Eoge
Dublin, Ireland
|
|
|
|
|
You need to forward declare the classes being used.
eg.
class A;
class B
{
A* m_pA;
...
};
This works where you are using pts to the associated classes. It won't work if instances of each class are defined with the other class. My guess is that isn't possible.
As an aside I have to wonder why you have two classes so tightly coupled to each other in this way.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
Excellent! That's solved my problem. Thank you so much.
I'm still a little confused though... why does this work? I thought that with a #include statement I was effectively forward declaring that class. For example, if I write
#include "a.h"
class A;
class B
{
A* m_pA;
...
};
don't I effectively have
class A
{
...
};
class A;
class B
{
A* m_pA;
...
};
?
On your aside as to why I may desire / require such a thing:
Well, it's a question I've been asking myself actually. I'm writing a simulation application that has an Environment object which contains a list of Person objects. These Person objects need to access some resources contained within the Environment object in which they reside. To do this, my Person object has a pointer back to the Environment so that it may access these resources.
So, do you think that this is an awkward way to go about solving this problem?
Thanks again.
Eoge
Dublin, Ireland
|
|
|
|
|
eoge wrote:
I thought that with a #include statement I was effectively forward declaring that class
#include is a preprocessor directive. The preprocessor runs before the compiler. You have to think of #include as if it takes the contents of the file and inserts it at that point in the code. Once all of the include's have been performed, then the compiler starts. #include has nothing to do with the class being declared.
Forward declarations are perfectly appropriate when you have objects that refer to each other. For example, suppose we have a class 'Parent'. This class could contain a list of objects of class 'Child'. At the same time, each 'Child' object could have two pointers of type 'Parent', one called 'Mother' and the other 'Father':
class Child;
class Parent {
Child *ChildrenList;
};
class Child {
Parent *Mother;
Parent *Father;
};
Software Zen: delete this;
|
|
|
|
|
have you tried
#pragma once
instead of the #ifndef block.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
I am creating an app based on CDialog, but whenever I press escape or return, it exits. How do I stop this from happening??
Øivind
|
|
|
|
|
Add OnOK() and OnCancel() handlers and don't call the base class handlers. Ie,
void CMyDialog::OnOK()
{
CDialog::OnOK(); }
just comment out the Wizard generated call to CDialog::OnOK() and all will work as you expect.
Rob Manderson
Colin Davies wrote: I'm sure Americans could use more of it, and thus reduce the world supply faster. This of course would be good, because the faster we run out globally, the less chance of pollution there will be. (Talking about the price of petrol) The Soapbox, March 5 2004
|
|
|
|
|
|
Alternatively you can override PreTranslateMessage
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if ((pMsg->wParam == 13) || (pMsg->wParam == 27))
{
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
Sorry cant remember the VK defns (its too late!)
Ant.
|
|
|
|
|
I would like to know the basic Difference Between CListCtrl and CListView.
Does each of them behave differently ?
laiju
|
|
|
|
|
The CListCtrl wraps a Win32 Common Controls List View. It's a straight control. The CListView is actually derived from CView and wraps the List View so that it can be used in the Document / View architecture of MFC. The controls behave the same, the difference is the intended use.
|
|
|
|
|
First I do appreciate your help .But iam sorry to say that I have not understood the basic difference between CListView and CListCtrl.
I would appreciate if you could elaborate on the fundamentals.
laiju
|
|
|
|
|
CListCtrl is the MFC wrapper class for a Windows list control.
CListView is the corresponding 'view' class in MFC, when you want one of the views in your document/view application to be implemented using a list control. One of the member functions of CListView returns a reference to the underlying CListCtrl.
If you are building a document/view application, and want one of your views to be a list control, you will use CListView. Within dialog boxes, you use CListCtrl.
Software Zen: delete this;
|
|
|
|
|
In the MFC SDI applications how can get a pointer to the frame object from the view or documect object?
|
|
|
|
|
AfxGetMainWnd()
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
I use the following code to set the cursor of a window:
HCURSOR cursor = theApp.LoadStandardCursor(IDC_ARROW);<br />
<br />
SetClassLongPtr(GetDlgItem(IDC_COLORDISPLAY)->GetSafeHwnd(),<br />
GCL_HCURSOR,<br />
(LONG) cursor);<br />
The problem is that I get the following compiler warning:
warning C4311: 'type cast' : pointer truncation from 'HCURSOR' to 'LONG'
How do I do this the right way??
Øivind
|
|
|
|
|
Original function is:
ULONG_PTR SetClassLongPtr(
HWND hWnd,
int nIndex,
LONG_PTR dwNewLong
);
That mean the you have poenter on cursor and need write:
SetClassLongPtr(GetDlgItem(IDC_COLORDISPLAY)->GetSafeHwnd(),
GCL_HCURSOR,
(LONG_PTR) &cursor);
HCURSOR is "typedef unsigned int HCURSOR" but you need poenter on address.
|
|
|
|
|
With your code, I don't get any warnings, but the cursor doesn't change.. =(
SetClassLongPtr(GetDlgItem(IDC_COLORDISPLAY)->GetSafeHwnd(), <br />
GCL_HCURSOR,<br />
(LONG_PTR) &cursor);
|
|
|
|
|
Weee! I got it right. I only needed to cast the cursor to (LONG_PTR) and not reference it:
SetClassLongPtr(GetDlgItem(IDC_COLORDISPLAY)->GetSafeHwnd(), <br />
GCL_HCURSOR,<br />
(LONG_PTR) cursor);
|
|
|
|
|
I made an empty Win32 project in VC++ v7, and then added a C++ file to it. I made an exact copy of one of the Direct3D working tutorials and pasted it into the empty C++ file. I copied all of the DirectX include files and library's into the directories tbat VC++ uses. When I try to build it, it gives me the following errors:
Linking...
AnotherOne.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "long __cdecl InitD3D(struct HWND__ *)" (?InitD3D@@YAJPAUHWND__@@@Z)
AnotherOne.obj : error LNK2019: unresolved external symbol _D3DXCreateTextureFromFileA@12 referenced in function "long __cdecl InitGeometry(void)" (?InitGeometry@@YAJXZ)
AnotherOne.obj : error LNK2019: unresolved external symbol _D3DXLoadMeshFromXA@32 referenced in function "long __cdecl InitGeometry(void)" (?InitGeometry@@YAJXZ)
AnotherOne.obj : error LNK2019: unresolved external symbol _D3DXMatrixPerspectiveFovLH@20 referenced in function "void __cdecl SetupMatrices(void)" (?SetupMatrices@@YAXXZ)
AnotherOne.obj : error LNK2019: unresolved external symbol _D3DXMatrixLookAtLH@16 referenced in function "void __cdecl SetupMatrices(void)" (?SetupMatrices@@YAXXZ)
AnotherOne.obj : error LNK2019: unresolved external symbol _D3DXMatrixRotationY@8 referenced in function "void __cdecl SetupMatrices(void)" (?SetupMatrices@@YAXXZ)
AnotherOne.obj : error LNK2019: unresolved external symbol __imp__timeGetTime@0 referenced in function "void __cdecl SetupMatrices(void)" (?SetupMatrices@@YAXXZ)
Debug/AnotherOne.exe : fatal error LNK1120: 7 unresolved externals
Yes, I named the project "AnotherOne," this is because of several attempts If anyone could help me out, that would be great.
-Dev578
|
|
|
|
|
did you set the lib that needs to be linked to use DirectX.
i dont know the lib name, you can either put in the link section in the project settings or
#pragma comment(lib,"libname.lib")
in stdafx.h
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
did you linked the libraries for D3D
(in OpenGl : glaux.lib...)
|
|
|
|
|
You should specify the directX libs in the project settings.
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
Hi everyone,
i'm trying to write a real-time image processing program.I've made the following class, how can i improve it further?
array[] contains all the image bits from a CBitmap
using GetBitmapBits. First 8 bits=Blue, next 8 Green,
next 8 Red and next 8 unused.
BitDepth=4;
How can i improve the Threshold, Grayscale & Rotate functions? It must be timecritical.
Usage,
uImage image;
image.Create(bmp_x_width,bmp_y_width,32);
image.GetImage(&memDCLoad);
image.Grayscale();
image.Rotate(45);
image.SetImage(&memDCLoad);
pDC->StretchBlt(243,30,stretch_x,stretch_y,&memDCLoad,0,0,bmp_x_width,bmp_y_width,SRCCOPY);
class uImage
{
private:
int height_y;
int width_x;
int bitDepth;
int imgDepth;
public:
BYTE *array;
BYTE *array_copy;
CBitmap *pBitmap;
void Create(int x,int y,int depth);
void GetImage(CDC *MemDC);
void SetImage(CDC *MemDC);
void Delete();
BYTE GetR(int x,int y);
BYTE GetG(int x,int y);
BYTE GetB(int x,int y);
void SetR(int x,int y, BYTE value);
void SetG(int x,int y, BYTE value);
void SetB(int x,int y, BYTE value);
void Threshold(int value);
void Grayscale();
void Rotate(double degree);
};
void uImage::GetImage(CDC *MemDC)
{
pBitmap =MemDC->GetCurrentBitmap();
pBitmap->GetBitmapBits(bitDepth*width_x*height_y,array);
}
void uImage::SetImage(CDC *MemDC)
{
pBitmap =MemDC->GetCurrentBitmap();
pBitmap->SetBitmapBits(bitDepth*width_x*height_y,array);
}
void uImage::Create(int x,int y, int depth)
{
bitDepth=depth/8;
imgDepth=depth;
array=new BYTE[x*y*bitDepth];
array_copy=new BYTE[x*y*bitDepth];
height_y=y;
width_x=x;
}
void uImage::Delete()
{
delete[] array;
delete[] array_copy;
}
BYTE uImage::GetR(int x, int y)
{
return array[(x+y*width_x)*bitDepth+2];
}
BYTE uImage::GetG(int x, int y)
{
return array[(x+y*width_x)*bitDepth+1];
}
BYTE uImage::GetB(int x, int y)
{
return array[(x+y*width_x)*bitDepth+0];
}
void uImage::SetR(int x, int y, BYTE value)
{
array[(x+y*width_x)*bitDepth+2]=value;
}
void uImage::SetG(int x, int y, BYTE value)
{
array[(x+y*width_x)*bitDepth+1]=value;
}
void uImage::SetB(int x, int y, BYTE value)
{
array[(x+y*width_x)*bitDepth+0]=value;
}
void uImage::Threshold(int value)
{
BYTE gray;
int temp;
for(int i=0;i<width_x*height_y;i++)
{
="" temp="i*4;
" gray="array[temp];
" if(gray<="value)
" array[temp++]="0;//blue
" }
="" else
="" }
}
void="" uimage::grayscale()
{
=""
="" byte="" gray;
="" int="" temp;
for(int="" i="0;i<width_x*height_y;i++)
" +array[temp+2]*0.299);
="" array[temp]="gray;
" array[temp+1]="gray;
" array[temp+2]="gray;
" }
}
void="" uimage::rotate(double="" degree)
{
double="" pi="3.1415926535897932384626433832795;
double" angle_rad="PI/180*degree;
double" cos="cos(angle_rad);
double" sin="sin(angle_rad);
int" center_x="width_x/2;
int" center_y="height_y/2;
int" xs;
int="" ys;
for(int="" xd="0;xd<width_x;xd++)
" for(int="" yd="0;yd<height_y;yd++)
" xs="(int)" (xd*cos-yd*sin+center_x*(1-cos)+center_y*sin);
="" ys="(int)" (xd*sin+yd*cos-center_x*sin+center_y*(1-cos));
="" if(!((xs<0)||(ys<0)||(xs="">(width_x-1))||(ys>(height_y-1))))
{
array_copy[(xd+yd*width_x)*bitDepth]=array[(xs+ys*width_x)*bitDepth];
array_copy[(xd+yd*width_x)*bitDepth+1]=array[(xs+ys*width_x)*bitDepth+1];
array_copy[(xd+yd*width_x)*bitDepth+2]=array[(xs+ys*width_x)*bitDepth+2];
}
else
{
array_copy[(xd+yd*width_x)*bitDepth]=255;
array_copy[(xd+yd*width_x)*bitDepth+1]=255;
array_copy[(xd+yd*width_x)*bitDepth+2]=255;
}
}
array=array_copy;
}
|
|
|
|