|
Oh the google way
Thanks both of you
|
|
|
|
|
I tried to make a project with one Document and 2 views. But I had a problem - i can't switch between them. How to do it?
In InitInstance i did this:
CSingleDocTemplate* pDocTemplate;
CSingleDocTemplate* pDocTemplate1;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSDIMultiViewDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CSDIMultiViewView));
AddDocTemplate(pDocTemplate);
pDocTemplate1 = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSDIMultiViewDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CSDIMultiViewListView));
AddDocTemplate(pDocTemplate1);
|
|
|
|
|
|
|
Hi !
Here is a coding design question.
I defined a class in my application, let's call it CPoint.
In many other classes of my application, I have to manipulate lists of pointeurs on CPoint objects. I need to pass such lists by parameters.
For now, I defined, in each class using a list of CPoint a typedef like this :
typedef vector<CPoint*> PointList_t;
I'm now wondering if, instead of declaring such typedef in each class using a list of CPoint*, if it would be better coding practice to define such typedef in the CPoint class itselt :
class CPoint
{
public:
typedef vector<CPoint*> PointList_t;
...
};
and, in classes using a list of CPoint*, I would do (for example) :
void Foo(CPoint::PointList_t MyPointList)
{
CPoint::PointList_t::iterator It = MyPointList.begin();
...
...
}
The advantage of this new way of doing would be to avoid multiple declaration of the same typedef, the drawback is that I have to put CPoint:: each time I need a PointList_t and that I have to include the CPoint.h in the header of the classes using such typedef where a simple declaration of the class was enough with my first way of doing things.
What is your suggestion ?
Thanks !
Jerome
|
|
|
|
|
I would always put the typedef where it fits best. In your example the best fit is within the CPoint class.
This way as you have stated it is defined only once. This also means that there is one point of maintenance.
IMO the drawbacks you have stated are not really drawbacks, just a little more typing!
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
I have been trying to define a structure and use it with a union, but the bit fields seem to cause the structure to be bigger than I expected.
e.g. ( 4 x 4 bit fileds + 2 float fields + short = 11 bytes)
But what I get is 28 bytes.
typedef struct <br />
{<br />
unsigned data : 4 ; <br />
}W03_SECOND_10_S_;<br />
<br />
typedef struct <br />
{<br />
unsigned data : 4 ; <br />
}W03_SECOND_1_S_;<br />
<br />
typedef struct <br />
{<br />
unsigned data : 4 ; <br />
}W03_SECOND_0_1_S_;<br />
<br />
typedef struct <br />
{<br />
unsigned data : 4 ; <br />
}W03_SECOND_0_01_S_;<br />
<br />
typedef struct <br />
{<br />
float data; <br />
}W05_PRICE;<br />
<br />
typedef struct <br />
{<br />
float data; <br />
}W07_NETCOST;<br />
<br />
typedef struct <br />
{<br />
unsigned short data; <br />
}W08_INDEX;<br />
typedef struct{<br />
W03_SECOND_10_S_ w03_second_10_s_;<br />
W03_SECOND_1_S_ w03_second_1_s_;<br />
W03_SECOND_0_1_S_ w03_second_0_1_s_;<br />
W03_SECOND_0_01_S_ w03_second_0_01_s_;<br />
W05_PRICE w05_price;<br />
W07_NETCOST w07_netCost;<br />
W08_INDEX w08_index;<br />
}TEST1_10;
union<br />
{<br />
TEST1_10 message_data;
unsigned short buffer[32];
}messageStructData;<br />
<br />
int sizeStruct = sizeof(messageStructData);
The size if 64 bytes, but the size of the TEST1_10 structure is 28 bytes (not 11 bytes)so each field of 4 bits is taking up 4 bytes
TEST1_10 message_data1;<br />
int sizeStruct1 = sizeof(message_data1);
sizeStruct1 = 28 bytes.
The short is being padded to 4 bytes as is each 4 bit field.
Is it possible to map bit fields onto a structure and then a union in C++.
|
|
|
|
|
The best you will get is to set the byte alignment for structures to a single byte. Currently you must have it set to 4 bytes.
Look in the Project Settings under Code Generation
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Thanks for your post, I set it to 1 byte and that reduced the count from 28 to 26.
Are they no way that I can used bit fields in the way I intended; i.e.
overlay these bit field and other fileds (short, float etc) with a buffer.
I did remove the wrapping of the bit fields from a struct:
typedef struct{<br />
unsigned data1 : 4 ; <br />
unsigned data2 : 4 ; <br />
unsigned data3 : 4 ; <br />
unsigned data4 : 4 ; <br />
W05_PRICE w05_price;<br />
W07_NETCOST w07_netCost;<br />
W08_INDEX w08_index;<br />
}TEST1_10;
this gave a size of 14 (2 floats, 1 short and 4 x 4 bit fields = 11 bytes)
But each 4 bit field is taking a byte; hence 14 bytes.
Any suggestions to get this scheme working?
|
|
|
|
|
Without combining the fields in the struct I can not see how you can do this.
e.g.
typedef struct{<br />
BYTE data1and2; <br />
BYTE data3and4;<br />
W05_PRICE w05_price;<br />
W07_NETCOST w07_netCost;<br />
W08_INDEX w08_index;<br />
}TEST1_10;
Downside is that will have to do the bit manipulation on data1and2 and data3and4 in order to get the appropriate 4bit values however. Though a couple of functions should be enough to get and set the values.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Contrast what you have with:
#pragma pack(1)
typedef struct
{
unsigned data1 : 4;
unsigned data2 : 4;
unsigned data3 : 4;
unsigned data4 : 4;
float data5;
float data6;
unsigned short data7;
} TEST1_10;
#pragma pack()
TEST1_10 message_data1;
int sizeStruct1 = sizeof(message_data1); What is the value of sizeStruct1 ?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
The size of the structure is 14 bytes.
I assume this is (8 for 2 floats + 2 for the short and 4 for the 4 bit fields)
I am after a size of 11 bytes.
Are they any settings that I have not made?
|
|
|
|
|
You do know that sizeof() cannot be used on bit fields, don't you?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
If I use the following code:-
typedef struct<br />
{ <br />
unsigned short data1;<br />
float data5;<br />
float data6;<br />
unsigned short data7;<br />
}TEST1_101;<br />
#pragma pack()<br />
TEST1_101 message_data1;<br />
int sizeStruct1 = sizeof(message_data1 );
I get size = 12 bytes, which I understand (8 for floats + 2 x 2 for shorts = 12 bytes. But why dont I get 12 for the following:-
typedef struct<br />
{ <br />
unsigned data1 : 4;<br />
unsigned data2 : 4;<br />
unsigned data3 : 4;<br />
unsigned data4 : 4;<br />
float data5;<br />
float data6;<br />
unsigned short data7;<br />
}TEST1_101;<br />
#pragma pack()<br />
TEST1_101 message_data1;<br />
int sizeStruct1 = sizeof(message_data1);
|
|
|
|
|
sweep123 wrote:
But why dont I get 12 for the following:-
I hinted at the fact that you cannot use sizeof() with bit fields. Did you miss that earlier?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
OK, yes I saw your post that stated that, but removed the bit fields and tried a few other things and then put back the bit fields.
I think the overlay works with the union, but the fact that a bug in my program and the sizeof() problem with bitfields led to confusion.
Thanks,
|
|
|
|
|
Hi, I'm having a problem with a dialog. I need my dialog box to recieve/intercept all keyboard events that go on inside, but I'm getting problems where only the controls are reciving the keyboard events. Presumably only the window with the focus can ever recieve keyboard message. My dialog simply does not recieive any OnChar, OnKeyDown, or OnSysChar events. So I implemented OnKillFocus in the dialog like so...
void CMyDialog::OnKillFocus(CWnd* pNewWnd)
{
CWnd::OnKillFocus(pNewWnd);
SetFocus();
} However this seems to make all my buttons totally unclickable! Does anyone have a solution to this at all?
Joel Holdsworth
|
|
|
|
|
You might want to try overriding PreTranslateMessage for your dialog.
|
|
|
|
|
I want write a doc file using Visual c++. I found a lot of microsoft examples but don't work.
Somebody has a project that work that i can use als examples?
Thanks a lot
|
|
|
|
|
|
Thaks a lot but there aren't examples for office 2003.
My problem is that when i select the wrapped class, the file msword*.h and msword*.cpp aren't created but in the project i find only files for single classes that i selected (Capplication.h,CDocments.h,....)
Understand you my problem? Thanks a lot and i hope you understand my english
|
|
|
|
|
Can you give me more details on what you are attempting to do? Are you trying to use a framework such as MFC or just plain Win32 API? Are you trying to use the #import statement?
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
I'm using MFC, and i tryed to use the #import but don't work.
I thing the biggest problem is my office version that is 2003. When i add the wrapped class (type library), there isn't file like msword*.h in my project but only a lot of new class for word (for example CApplication.h, CDocuments.h, CDocument0.h,......).
Undestand you my problem?
thanks
|
|
|
|
|
The article I suggested to you contains sample code to be used with visual studio 6 and I'm assuming you have VS.NET 2002 or 2003. You can still use the sample code with just some minor modifications.
To start with the 'Add Class' wizard generates a header file for each class rather than one file for the whole type library. This means you need to add an include statement for each class you use.
Next the class names have changed. What was _Application in Word2000 is now CApplication in Word2003 likewise _Documents has changed to CDocuments and _Document has changed to CDocument0. If you look at the header file names the class wizard adds to your project you can work it out.
Finally the function names have changed. For instance GetActiveDocument() has changed to get_ActiveDocument() and SetVisible() has changed to put_Visible(). In general the functions are now called get_'property name' to retrieve the value of a property or put_'property name' to set the value of a property.
If you would like a very basic VS.NET 2003 MFC dialog project that generates a word document I would be happy to send one to you.
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
hallo!
very very thanks for your answer!
i don't have now a lot of time but tomorrow i try!
if you can send me your project files it's for me very good!! (my email address is tiziacaia@hotmail.com)
thank a lot another time!
|
|
|
|