|
The standard way to do something like this in C++ is to make the variable private, add a public method to get it and a protected method to set it. In this way, the class itself and derived classes can modify the value, while it remains visible but unchangeable externally.
|
|
|
|
|
Yes, that I know. I was trying to find some other way without having to use function calls. But I think that is not possible under c++... but thx anyway!
|
|
|
|
|
Hi All,
I'm working on an SDI application that has a CEditView as one of it's views. While I can use the default printing to print the document, things like the margins, the font etc. need to be set. I would like some details about how to do this.
Thanks!
Mark
"Nothing is impossible. Remember once upon a time the world was flat."
|
|
|
|
|
Hi,
Check this[^]
Bye
Cool Ju
Vote for Cool Ju
|
|
|
|
|
No disrespect intended but the linked article does little to help me understand the document view printing process. The code has almost no comments so I don't know what I'm looking at. Looks like a lot of extra work on specialized printing classes.
Thanks anyway,
Mark
|
|
|
|
|
I am using Visual C++ 6.0 MFC Document/View. I need to convert my logical units to pixals. In my myCView's OnDraw(pDC) function I am calling a myCDocument function pDoc->DisplayMyStuff(pDC) which in turn calls the function DisplayMapSetup(pDC, WaferRect). In the DisplayMyStuff(pDC) function I define a CRect to be WaferRect. I then can get the height = myCRect.Height() in logical units but I want them in pixels. If after I define WaferRect, I call pDC->LPtoDP(WaferRect) before calling WaferRect.Height() I still get the height in logical units. I have also tried pDC->LPtoDP(&WaferRect) and several different mapping modes. Here's a little snippet.
void CWaferMapDoc::DisplayMapSetup(CDC* pDC, CRect WaferRect)
{
pDC->LPtoDP(&WaferRect);
int height = WaferRect.Height();
Is there something I am missing in order to convert the logical unitis to pixels?
Thanks,
Buck
|
|
|
|
|
Hi,
What mapping mode are you using and the settings of the origins and extents for the window and viewport? Bcoz LPToDP and DPToLP depend on these settings.
If u r using MM_TEXT mapping mode, then the logical unit is equal to device unit. 1 unit = 1 pixel.
Bye
Cool Ju
Vote for Ju
|
|
|
|
|
Thanks Ju,
I think I know what's going on now. I use a map mode of MM_ANISOTROPIC in my zoom class but otherwise I don't set it (defaulting to MM_TEXT). I'm defining my document size to be CSize(1100, 850) to represent an 8.5 inch by 11 inch page size but I don't set the map mode to MM_LOENGLISH. My brain was thinking 8.5 x 11 inches when in reality it was 1100 x 850 pixels. This would explain it.
Buck
|
|
|
|
|
Hi all,
I am looking for a small sample of code that saves bitmap after getting it from DC.
Can anyone help?
Thanks,
Max
Sincerely,
Max Pastchenko
|
|
|
|
|
Your best bet is to use GDI+ in your application, then you can save as jpg, etc.
I have a number of articles on GDI+ here on CP.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Consider the following:
class A
{
recipient;
queue;
};
class B
{
recipient;
queue;
text;
from;
};
A a;
B b;
if (some_condition)
modify a.recipient, a.queue;
else
modify b.recipient, b.queue, b.text, b.from;
...
if (some_condition)
modify a.recipient, a.queue;
else
modify b.recipient, b.queue, b.text, b.from; This code that modifies the various members is repeated dozens of times. I would like to somehow instantiate just one of either A or B so that the code that modifies the common member variables can do so without having to use a runtime condition. Something like:
modify b.recipient, b.queue;
if (some_condition)
modify b.text, b.from; I thought that I could put the common member variables into a base class and derive A and B from that, but nothing I tried would satisy the compiler. Modify the member variables through the base class and it would complain about text and from . Modify the member variables through the derived class and it would complain about recipient and queue .
One or other of the two classes will eventually be sent to another computer. That computer is expecting data of a certain size. In other words, I can't operate on B if the other computer is expecting A and vice versa.
Thanks,
DC
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
From the top of my head, what about a virtual function to do the modify operation? I know that goes against your requirement of having to use a runtime condition, but that's the best or most consistent runtime condition to rely on, I think.
Chris Meech
I am Canadian. [heard in a local bar]
Remember that in Texas, Gun Control is hitting what you aim at. [Richard Stringer]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Derive B from A. Try operating from the derived class. Now I think you can access all member variables of A as well as B.
Just a thought.
<marquee direction="up" height="30" scrolldelay="1" step="1" scrollamount="1" hspace="0" vspace="0">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
If the computer that will eventually receive this data is expecting A and I send it (a larger) B, those extra bytes will cause all sorts of data loss due to everything being shifted.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: If the computer that will eventually receive this data is expecting A and I send it (a larger) B, those extra bytes will cause all sorts of data loss due to everything being shifted.
Well now you are adding contraints that weren't in your original question.
Also your comment above isn't true, it depends on how your network code is set up.
The simplest way would be to add a Serialize method to A/B to read/write the object state to a blob of memory (e.g. in XML format) and then send the blob across the network.
But this issue (sending the data across a network) is unrelated to the original problem of optimizing your code.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
cmk wrote: Well now you are adding contraints that weren't in your original question.
This constraint was not mentioned as it is irrelevant as far as my question goes.
cmk wrote: Also your comment above isn't true, it depends on how your network code is set up.
It's entirely true. I know how the data has to be packaged before it can be sent.
My question was nothing more than a C++ question. It has nothing to do with the network.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: If the computer that will eventually receive this data is expecting A and I send it (a larger) B, those extra bytes will cause all sorts of data loss due to everything being shifted.
Hi David,
If you have to get it working then it has to be like this. This is the proper way.
<marquee direction="up" height="30" scrolldelay="1" step="1" scrollamount="1" hspace="0" vspace="0">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
Owner drawn wrote: If you have to get it working then it has to be like this. This is the proper way.
I disagree. Your suggestion is not a solution to my problem.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
One way:
- Derive B from A and add text, from.
- Define an Attrib class:
class Attrib {
CString Name;
CString Value;
};
- Define virtual bool Mod( Attrib *AL, ulong NBR ); in A, override in B.
Where you pass an array of attribs to modify.
- Then:
A a;
B b;
Attrib at[4];
A *p = (some_condition) ? &a : &b;
p->Mod(at, 4);
A::Mod() will only look for/understand r, q attributes and ignore t, f
B::Mod() will only look for/understand r, q, t, f
C::Mod() (in the future) will only ...
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I'm wanting use a VC++ DLL and call a function to it in VC++. The only info I have about the function or the DLL is some VB.NET code that I pulled from a sample app. Here is the code from the sample VB.NET app:
/* VB.NET CODE */
Declare Auto Function GetAllData Lib "RANDOMNAME.dll" _
( _
ByRef bstrDATA1 As String, _
ByRef bstrDATA2 As String, _
ByRef bstrDATA3 As String, _
ByRef bstrDATA4 As String, _
ByRef bstrDATA5 As String, _
ByRef lDATA6 As Int16, _
ByRef bstrDATA7 As String _
) As Int16
/* END VB.NET CODE */
I've made an attempt to convert things over to VC++ but have had no luck. The app compiles just fine but when I call the DLL's function the app crashes. Here is the code I've converted:
/* VC++ CODE */
void CTesterDlg::OnBtnDowork()
{
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibrary("\\RANDOMNAME.dll");
/* get pointer to the function in the dll*/
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL), "GetAllData");
/* Define the Function in the DLL for reuse. This is just prototyping
the dll's function. A mock of it. Use "stdcall" for maximum compatibility.*/
typedef int (__stdcall * pICFUNC)(BSTR,BSTR,BSTR,BSTR,BSTR,int,BSTR);
BSTR bstrDATA1=NULL,bstrDATA2=NULL,bstrDATA3=NULL,bstrDATA4=NULL,bstrDATA5=NULL,bstrDATA7=NULL;
int lDATA6;
pICFUNC GetAllData;
GetAllData= pICFUNC(lpfnGetProcessID);
/* The actual call to the function contained in the dll */
int intMyReturnVal = GetAllData(bstrDATA1,bstrDATA2,bstrDATA3,bstrDATA4,bstrDATA5,lDATA6,bstrDATA7);
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
}
/* END VC++ CODE */
This is my first real try at using external DLL's so go easy on me! I know that there are many other things that could be causing this app to crash. The Application Error that I'm gettings is:
The instruction at "0x00000000" referenced memory at "0x00000000". The memeory could not be "read".
What I'm really looking for is confirmation of my code. ...does it look right? ...am I missing something simple? Thanks to everyone in advance for all your help!
|
|
|
|
|
Hello.
For one, the VB code says "Int16", and you use int as a substitution.
An int is 32 bits (4 bytes) long. That could be the reason for the crash.
Declare lDATA6 and intMyReturnVal as short int instead.
A short int is 16 bits (in VC6 anyway).
Kakan
|
|
|
|
|
I have a few properties and a function set as a web method ....
When I very the information in my browser I only get the description of the function.... the properties don't even show... however it did before when I used VS.net2003 (I'm using VS.net05 final now)
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
I'm a veteren developer who is still trying to get his brain to absorb all of mfc before .net becomes obsolete Anyway, I've read and studied John's excellent article, but there are some issues that make me go hmmm :
I understand WHY you don't do UI stuff in the worker threads, but I have a situation where I work that we seem to defy that logic. The application is a simple SDI which mainly uses its view to display dialog data. When the user presses the "make it so" button, a worker thread is launched that does all of the long work. Part of the information that is passed to this worker thread is a global to the view object. When the worker thread wishes to update the UI with status info, it simply:
pView->WhateverItNeedsToDo(arguments);
and the display is updated. Now, this just seems wrong to me.
The view should be owned by the main application thread - a UI thread - accessing the object just seems like the end of the world should occur.
But it works. Is the application just lucky?
C. Gilley
Will program for food...
My son's PDA is an M249 SAW.
-- modified at 12:45 Thursday 17th November, 2005
|
|
|
|
|
CharlieG wrote: I understand WHY you don't do UI stuff in the worker threads, but I have a situation where I work that we seem to defy that logic.
Does it actually work or does it just appear to work?
CharlieG wrote: The view should be owned by the main application thread - a UI thread - accessing the object just seems like the end of the world should occur.
I believe the operative word is could.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
David,
In this case, yes . It appears to and does work - basically, we update a progress bar when this happens.
Could/should - true. Your comment seems to imply we got lucky.
C. Gilley
Will program for food...
My son's PDA is an M249 SAW.
|
|
|
|