|
Hello, folks,
I got one problem for setting the printing orientation programmedly(i.e, landscape or portait ) on my pop-up printer dialog.
My printer dialog is using class CPrintDialog and I know it has one member m_pd is of type PRINTDLG. And I also know structure PRINTDLG has a member called hDevMode, and its type is HGLOBAL and of type DEVMODE. And, DEVMODE has a member like this:
union {
struct {
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
};
POINTL dmPosition;
So, I know I can set the printing orientation here by setting the value of member dmOrientation.
My problem is, how to allocate memory for setting this orientation parameter ?
Could somebody give me a simple example ?
Any response would be appreciated !
|
|
|
|
|
hi,
=>
To get the orientation u can do:
void GetInitOrientation()
{
PRINTDLG pd;
pd.lStructSize = (DWORD) sizeof(PRINTDLG);
if( GetPrinterDeviceDefaults(&pd)) {
DEVMODE FAR* pDevMode = (DEVMODE FAR*)::GlobalLock(m_hDevMode);
if(pDevMode) {
nStartupOrientation = pDevMode->dmOrientation;
::GlobalUnlock(m_hDevMode);
}
}
}
=>
To set the orientation:
This does not actually invoke the print dialog
void SetOrientation(int mode)
{
PRINTDLG pd;
pd.lStructSize = (DWORD) sizeof(PRINTDLG);
if( GetPrinterDeviceDefaults(&pd)) {
DEVMODE FAR* pDevMode = (DEVMODE FAR*)::GlobalLock(m_hDevMode);
if(pDevMode) {
switch (mode)
{
case 1:
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
break;
case 0:
default:
pDevMode->dmOrientation = DMORIENT_PORTRAIT;
break;
};
::GlobalUnlock(m_hDevMode);
}
}
}
hope this helps,
Sharad Ganesh
|
|
|
|
|
Ok so I have setup a managed c++ class with a Constructor.
I noted that you can also create a Destructor "method" for the class by prefixing ~ onto the method name (which =s the class name.) e.g.
CPBrief()
{
}
~CPBrief()
{
}
Is that a good way to tidy things up when a class goes out of scope?
Also will the garbage collector (in C# or MC++) automatically call that Destructor? Or do I have to call it manually at a certain point?
Some of this is covered in MSDN, but I am not sure if it is "best practice" usage.
Thanks
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge
Alison Pentland wrote:
I now have an image of you in front of the mirror in the morning, wearing your knickers, socks and shoes trying to decided if they match!
|
|
|
|
|
The ~() is called when:
1. Object goes out of scope.
2. <if dinamically="" alloctade="" by="" 'new'="" operator=""> Using 'delete' operator.
3. Can be called manually.
* It's a good way for deallocating the object's resources inside the ~().
Hope this helps.
--BlackSmith--
"With the help of all mighty", 2001, Me.
|
|
|
|
|
When we used to use the Win32 API and normal C++, you would clean up everything in the destructor that was allocated within the class, e.g. delete all the memory you'd used for an array or something:
class MyClass
{
public:
int *m_pMyArray;
MyClass() { printf("Hello!\n"); m_pMyArray = new int[200]; }
~MyClass() { printf("Bye!\n"); delete[] m_pMyArray; }
}; You'd probably put error checking in there too of course. Anyway, if we used this class as follows:
int main()
{
MyClass mc;
printf("In the middle of main...\n");
} we would get this output:
Hello!
In the middle of main...
Bye! However, and don't quote me on this, I believe that you have to use the Finalize (don't you hate those American spellings?) method instead, and treat it as if it were a destructor. This is due to the garbage collection that takes place. The difference between the destructor in C++ and the Finalize method in MC++ is that Finalize could be called at an indeterminate time after the object goes out of scope.
Phew! Nish will probably be able to give you a better summary of the managed side of things than me.
--
Andrew.
|
|
|
|
|
Andrew Peace wrote:
Phew! Nish will probably be able to give you a better summary of the managed side of things than me
LOL, no you did a great job Andrew, so thank you
Chris was telling me about that weird "when shall she blow?" behaviour fo Finalize. Seems awfully dodgy if you ask me hehe.
There is a lot of "slipping through the cracks" stuff in C++ that I have NEVER come across in other languages. VB and C# are water tight (unless you do really daft stuff) but C++ has wyrd waters flowing through it's veins.
Thanks Andrew, will give what you said a bash.
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge
Alison Pentland wrote:
I now have an image of you in front of the mirror in the morning, wearing your knickers, socks and shoes trying to decided if they match!
|
|
|
|
|
in my application ,all the controls are loaded by reading a file.and in that file i specify the control type,ID ,dimension and styles...In some editbox i want to restrict the user to enter only the numbers...i found many edit styles such as ES_CENTER,ES_LEFT,ES_MULTILINE etc..which one is for the the Editbox which accept only the numbers?? any idea???????
Renjith-CPian.
|
|
|
|
|
ES_NUMBER
#define ES_NUMBER 0X2000L
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks Arends....
Renjith-CPian.
|
|
|
|
|
Hello everyone,
I have a question about the STL auto_ptr class. The following code works:
auto_ptr <complex> testPass();
int main()
{
cout << "Program started. Tesing complex numbers... \n";
cout << testPass()->Im() <<"\n";
return 0;
}
auto_ptr<complex> testPass()
{
auto_ptr <complex> test1(new Complex(3.0, 4.0));
cout << test1->Im() << "\n";
return test1;
}
How is it that I can pass an auto_ptr between functions. Shouldn't the test1 object go out of scope now and hence get destroyed. If the auto_ptr does get passed between scopes, when does it get out of scope and the destructor for Complex is called??
Thanks ,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
pankajdaga wrote:
ow is it that I can pass an auto_ptr between functions. Shouldn't the test1 object go out of scope now and hence get destroyed. If the auto_ptr does get passed between scopes, when does it get out of scope and the destructor for Complex is called??
This is because std::auto_ptr maintains an owner flag. Always the last auto_ptr that has been used as L-value is the current owner, all other do not destroy the object.
In your TestPass you use a local variable and return it. At this moment a new instance is created via the copy-constructor and gains ownership. Afterwards the local auto_ptr is destroyed, but does not delete the object because it is not the owner any more.
--
Daniel Lohmann
http://www.losoft.de
|
|
|
|
|
Is there a way to create a Multi-SDI appication with MFC? WTL is supported it. I've made a search at the www.google.com, but haven't managed to find examples or articles. Does this mean that MFC have some internal problems to apply such a technique?
|
|
|
|
|
Could you please explain what Multi-SDI means? Is that MDI?
Best regards,
Alexandru Savescu
|
|
|
|
|
Multi-SDI is not MDI.
It's a group of SDI applications running in the context of single process. So the can share all the internal data and structures and this way save memory and other resources. Good example of a Multi-SDI application is Internet Explorer
|
|
|
|
|
Create an SDI app with MFC App Wizard.
Go to you app init instance and look for this code:
pDocTemplate = new CSingleDocTemplate(<br />
IDR_MAINFRAME,<br />
RUNTIME_CLASS(CMSDIDoc),<br />
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CMSDIView));<br />
AddDocTemplate(pDocTemplate);
Make a copy of that code and paste it right below it. That should be enough to get you started. Your code should now look like this:
<br />
<br />
CSingleDocTemplate* pDocTemplate;<br />
pDocTemplate = new CSingleDocTemplate(<br />
IDR_MAINFRAME,<br />
RUNTIME_CLASS(CMSDIDoc),<br />
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CMSDIView));<br />
AddDocTemplate(pDocTemplate);<br />
<br />
pDocTemplate = new CSingleDocTemplate(<br />
IDR_MAINFRAME,<br />
RUNTIME_CLASS(CMSDIDoc),<br />
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CMSDIView));<br />
AddDocTemplate(pDocTemplate);<br />
<br />
<br />
CCommandLineInfo cmdInfo;<br />
ParseCommandLine(cmdInfo);<br />
<br />
James
Drinking In The Sun
Forgot Password?
|
|
|
|
|
Thank you!
Good trick, but it's still not the stuff which I need. It uses one thread and I can open as many new windows as many times I called AddDocTemplate. And when I close first window the rest of windows close too.
|
|
|
|
|
MFC7 has this as in Office 2000 apps.
|
|
|
|
|
I've generated an ActiveX with Visual C++, it works fine on TestContainer and Visual Basic Forms, but when I put it on a SDI Visual C++ Project in a CFormView it doesn´t work fine.
The buttoms contained in the control ActiveX doesn´t work and it goes to sleep.
Please, Can anybody help me???
Thanks in advance!!!!!
|
|
|
|
|
In the control's OnCreate function, put ModifyStyleEx(WS_EX_CONTROLPARENT);
Try it. It may work.
Best of luck,
Rejeesh.T.S
|
|
|
|
|
<code></code>eg. How do I assign tc1.x = 20; in TestFunction2() ?
class TestClass1
{
public:
int x;
int y;
}
class TestClass2
{
public:
CArray<TestClass1, TestClass1&> arr;
}
void TestClass2::TestFunction1()
{
TestClass1 tc1;
for(int i=0; i<5; i++)
{
tc1.x = 5;
tc1.y = 10;
arr.Add(tc1);
}
}
void TestClass2::TestFunction2()
{
for(int i=0; i<tc1.GetSize(); i++)
{
tc1.x = 20; // does not work !!!
}
}
rsg_dj
|
|
|
|
|
|
GetAt will return a copy of the object, not the object itself.
Use ElementAt or operator[]
Best regards,
Alexandru Savescu
|
|
|
|
|
You can use this:
SetAt(index, element);
Moreover, it's useful to use SetSize(size) for initializes the Array before using it. Frequent re-allocations thus are avoided...
Hello World!!!
from Raphaël
|
|
|
|
|
Well, of course.
Moreover, it's better to use a std::vector don't you think?
Best regards,
Alexandru Savescu
|
|
|
|
|
Really better... ;);)
Hello World!!!
from Raphaël
|
|
|
|