Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello,
O have this console application
C++
void main()
{
    double i,c,d,f,g,e;
	HDC hdc = GetDC(GetDesktopWindow());
    DWORD ret = GetDeviceCaps(hdc, HORZSIZE);
    DWORD ret2 = GetDeviceCaps(hdc, VERTSIZE);
    std::cout << "Your screen size in inches is " << ret/25.4 << "\" x " << ret2/25.4 << "\" \n";
    ReleaseDC(GetDesktopWindow(), hdc);
	i=ret/25.4;
	c=ret2/25.4;
d=0;
f=0;
d=((i*i)+(c*c));
g=sqrt(d);

Works correct, but in mfc I get an error here
C++
HDC hdc = GetDC(GetDesktopWindow());

says "cannot take 1 argument" is there any wrong typing in code, it is different in mfc?

And a second question : in c++ win forms application can I add as a dll pure native c++?

thank you
Posted
Comments
Sergey Alexandrovich Kryukov 12-Dec-14 17:27pm    
What you wrote cannot be related to MFC. I just don't see what did you link to the project and what did you #include.
Windows API's GetDC takes exactly one argument.
—SA
cariolihome 12-Dec-14 17:30pm    
Try add :: (which means global context) to function calls:
::GetDC(::GetDesktopWindow())
Yes, You can:
http://msdn.microsoft.com/en-us/library/ms235282.aspx
Sergey Alexandrovich Kryukov 12-Dec-14 17:44pm    
Exactly, but I'm not sure OP understands what it means; I provided more detailed answer, please see Solution 1.
I credited your comment, of course.
—SA
Richard MacCutchan 13-Dec-14 6:04am    
There is nothing connected to MFC in your code. And you are missing an #include <windows.h>.

For your first question, please see my comment to the question; see also:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd144871%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633504%28v=vs.85%29.aspx[^].

Don't use MFC at this point. See the comment to the question by cariolihome: you can use scope operator '::', to indicate the use of the global namespace:
http://www.cplusplus.com/doc/tutorial/operators[^],
http://msdn.microsoft.com/en-us/library/5cb46ksf.aspx[^],
http://www.cplusplus.com/doc/tutorial/namespaces[^].

With MFC, you should have the instance of some window, so you don't need a HWND argument; instead, the instance "this" is used: http://msdn.microsoft.com/en-us/library/71eseab0.aspx[^].

(Do you understand how instance function calls work? You do have one extra (only one in this case) argument "this", which is implicit. It is used to pass the instance of the type to the method. And than, the implementation "knows" the HWND of this objects and uses it in the call to the Windows API's GetDC(HWND) I referenced above. Please see also my past answer: Catch 22 - Pointers to interface objects die when function using them is made static.[^].)
As to your second question…

Probably, you don't mean C++, but C++/CLI you could use with in .NET in general, System.Windows.Forms in particular. If so, you can use some unmanaged code in such project, too. The usual way is to use P/Invoke, but, with C++/CLI, you don't have to do it; it makes everything much simpler. You can create a mixed-mode (managed + unmanaged) project where you can freely combine .NET and unmanaged code. However, I would advise to keep some discipline. Separate your project in at least 3 distinct parts or layers: pure .NET (managed) part, pure unmanaged part, and the layer where you wrap unmanaged types in managed "ref" classes. Please see:
http://en.wikipedia.org/wiki/C%2B%2B/CLI[^],
http://www.ecma-international.org/publications/standards/Ecma-372.htm[^],
http://www.gotw.ca/publications/C++CLIRationale.pdf[^].

—SA
 
Share this answer
 
v4
Comments
Member 3892343 13-Dec-14 1:54am    
#include "stdafx.h"
#include "tttest.h"
#include "tttestDlg.h"
#include <windows.h>
#include <iostream>
#include <complex>
added
just want the monitor dimensions in MFC
XML
#include "stdafx.h"
#include "tttest.h"
#include "tttestDlg.h"
#include <windows.h>
#include <iostream>
#include <complex>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900