|
Hi,
I need to capture the image from a window into a CBitmap. The code I have written just produces a black bitmap (correct size though )
Can anyone see what I have done wrong? The bimap is created with the correct bits/pixel (32).
CRect rect(0, 0, 100, 100);
CBitmap bmpCap;
CBitmap *pBmpOld = NULL;
CWnd* pWnd = GetDlgItem(IDC_SUCN_CHART);
pWnd->GetWindowRect(&rect);
ScreenToClient(rect);
CDC* pdcScreen = pWnd->GetDC();
CDC memDC;
BOOL bResult = memDC.CreateCompatibleDC(pdcScreen);
bResult = bmpCap.CreateCompatibleBitmap(pdcScreen, rect.Width(), rect.Height());
BITMAP bm;
bmpCap.GetBitmap(&bm);
pBmpOld = memDC.SelectObject(&bmpCap);
bResult = memDC.BitBlt( 0, 0, rect.Width(), rect.Height(), pdcScreen, rect.left, rect.top, SRCCOPY );
|
|
|
|
|
Hi,
You can call CWnd::PrintClient[^] and ask the window to draw itself into the destination device context.
CBitmap bmpCap;
CBitmap *pBmpOld = NULL;
CWnd* pWnd = GetDlgItem(IDC_SUCN_CHART);
pWnd->GetWindowRect(&rect);
ScreenToClient(rect);
CDC* pdcScreen = pWnd->GetDC();
CDC memDC;
memDC.CreateCompatibleDC(pdcScreen);
bmpCap.CreateCompatibleBitmap(pdcScreen, rect.Width(), rect.Height());
pBmpOld = memDC.SelectObject(&bmpCap);
pWnd->PrintClient(&memDC,PRF_NONCLIENT|PRF_CHILDREN);
memDC.SelectObject(pBmpOld);
pWnd->ReleaseDC(pdcScreen);
bmpCap.DeleteObject();
memDC.DeleteDC();
|
|
|
|
|
Wow thats cool
It looks like my problem was selecting the bitmap into the printer DC because it was not compatible. Using CWnd::PrintClient() should get me around this problem and its less code.
Thanks again, you have saved me hour of work trying to get thie code working.
|
|
|
|
|
Can someone help. I am not sure but I think i read about this before. I can't find it when I need it.
I am looking for anything that will help me compare 2 images of diferent sizes using VC++.
The following only tell me the sizes are different. However I already know that they are different.
BYTE image1[ImageSize];
BYTE image2[ImageSize];
if( memcmp(image1,image2,sizeof(image1)) == 0)
else
Thanks a million
|
|
|
|
|
Hi Fish,
The real question is how much accuracy do you require. If I wanted a quick and dirty image compare I would probably create a histogram of the colors[^] in both images. If you need greater accuracy then maybe you could use a library specifically designed for computer vision.
Integrating Vision Toolkit[^]
VLFeat[^]
Best Wishes,
-David Delaune
|
|
|
|
|
|
I have various Processes that are used in many of my programs. I want to put those Processes into "dills" so that I can load those dills when the User selects one in a program. This would illuminate the need to re-create the same processes in each program. The dills would need to contain it's own resources since they contain dialogs(the processes) and the program would not know in advance the resources. Is this possible? If so are there any tutorials on this subject using MFC?
Thanks in advance.
A C++ programming language novice, but striving to learn
|
|
|
|
|
|
I checked out some DILL articles. Nowhere is it explained whether a DILL can contain it's own resources. Can someone explain whether your DILL can contain Dialogs; and if so how can this be provided for linkage in a program.?
Since I don't know C#, or use the #include <windows.h> (because I use MFC exclusively), the articles you provided are useless to me. Thanks anyway.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: I checked out some DILL articles. Nowhere is it explained whether a DILL can contain it's own resources. Can someone explain whether your DILL can contain Dialogs; and if so how can this be provided for linkage in a program.?
Absolutely, you can add dialogs to a resource DLL. In fact a DLL doesn't even need to have code, it can contain resources only.
Creating a Resource-Only DLL[^]
Codeproject Resource-Only DLL[^]
Larry Mills Sr wrote: Since I don't know C#, or use the #include <windows.h> (because I use MFC exclusively), the articles you provided are useless to me. Thanks anyway.
I should have been more specific, I will try harder in the future. Let me see if I can find a C++ plugin framework that will work with MFC using the link I provided:
http://www.codeproject.com/info/search.aspx?artkw=plugin[^]
Oh wow... the first link goes to a cross-platform plugin implementation:
DynObj - C++ Cross Platform Plugin Objects[^]
The third link goes to a Win32 implementation and it looks like its using mostly ISO standards.
There are many other pages in my codeproject search, I am starting to believe that maybe you didn't even take the time to look.
Btw, you can use the 'Advanced filter' at the top to filter out C# and other language/platform articles.
Best Wishes,
-David Delaune
|
|
|
|
|
Any idea why this code doesn't compile?
#include "stdafx.h"
#include <bitset>
#include <iostream>
#include <ctime>
using namespace System;
int main(array<System::String ^> ^args)
{
const int N = 2000000;
clock_t cstart = clock();
bitset<N + 1> b;
int count = 0;
int i;
for (i = 2; i <= N; i++)
b.set(i);
i = 2;
while (i * i <= N)
{
if (b.test(i))
{
count++;
int k = 2 * i;
while (k <= N)
{
b.reset(k);
k += i;
}
}
i++;
}
while (i <= N)
{
if (b.test(i)) count++;
i++;
}
clock_t cend = clock();
double millis = 1000.0 * (cend - cstart) / CLOCKS_PER_SEC;
cout << count << " primes \n" << millis << " milliseconds\n";
return 0;
}
Errors:
Error 4 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes
Error 5 error C2228: left of '.set' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes
Error 6 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes
Error 7 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes
Error 8 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes
Error 9 error C2228: left of '.reset' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes
Error 10 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes
Error 11 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes
Error 12 error C2065: 'cout' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 46 SieveOfErathostenes
NOTE:
1. Core Java Vol I 8th Ed. Pg. 713 (727)
Jon
|
|
|
|
|
Probably you get errors because are in the wrong forum (better luck here [^], maybe).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The first error I get is this:
a.cpp(14) : error C2065: 'bitset' : undeclared identifier
This is because you use bitset without prefixing it with std:: , which is the namespace it lives in. Similarly, cout needs a std:: prefix, because that's where it lives.
[edit]Fix those two, and your code compiles fine. It runs as well.[/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Resolved that by including 'using namespace std;'. Now it reads:
C1010 - unexpected eof. Says it needs a header file, but I "forgot" what to include. Afiak the header file includes:
#pragma once
...
...and the headers of the methods used in my case...
int main...
However, it's strange that the default template created by visual studio with a main method did not require a .header file.
#include <bitset>
#include <iostream>
#include <ctime>
using namespace System;
using namespace std;
int main(array<System::String ^> ^args)
{
const int N = 2000000;
clock_t cstart = clock();
std::bitset<N + 1> b;
int count = 0;
int i;
for (i = 2; i <= N; i++)
b.set(i);
i = 2;
while (i * i <= N)
{
if (b.test(i))
{
count++;
int k = 2 * i;
while (k <= N)
{
b.reset(k);
k += i;
}
}
i++;
}
while (i <= N)
{
if (b.test(i)) count++;
i++;
}
clock_t cend = clock();
double millis = 1000.0 * (cend - cstart) / CLOCKS_PER_SEC;
cout << count << " primes \n" << millis << " milliseconds\n";
return 0;
}
Sieve.h
#pragma once
#include <iostream>
int main(array<System::String ^> ^args);
Related links:
C++ Header files[^]
Jon
|
|
|
|
|
jon_80 wrote: C1010 - unexpected eof. Says it needs a header file, but I "forgot" what to include. Afiak the header file includes:
stdafx.h - it's probably got pre-compiled headers enabled if it's a VS project.
You don't need the Sieve.h file.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
To be true, I have never used dllimport in my code while using a module. What's the actual use of it? No matter we use it or not, we are able to access the exported symbol right?
----------------------------
286? WOWW!
|
|
|
|
|
Hi 8086,
Raymond Chen wrote a series about imports and exports[^] and its implementation history. Its an excellent read and I think you will enjoy it.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks for the Pointer Randor!
----------------------------
286? WOWW!
|
|
|
|
|
Hi Randor,
Just found this in MSDN :
Using __declspec(dllimport) is optional on function declarations, but the compiler produces more efficient code if you use this keyword. However, you must use __declspec(dllimport) for the importing executable to access the DLL's public data symbols and objects. Note that the users of your DLL still need to link with an import library.
Thanks for your reply.
----------------------------
286? WOWW!
|
|
|
|
|
Thats a fair but short description of dllimport. I apologize for sending you off to do your own research. Its just that sometimes I feel like I am answering the same questions over and over. Here is a thread from 2008 where dllimport was discussed. You can be surprised with what a well-formed codeproject search will find.
http://www.codeproject.com/Messages/2431922/Re-import-library.aspx[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hi
We know that, WinMain is buried in the MFC Framework. OK but how can Windows call it?
I opened MFC project in VC++ and tried to find out how it imports the dll(Mfc90ud.dll) and functions in that dll. But i couldn't find it. I also disassembled the mfc90ud.dll but there is no function like WinMain in exported function list. Function names are just numbers.
So, I have 2 questions.
1-) How does VS knows that Mfc90ud.dll must be imported and Windows know that it must call a function in a dll that is imported by EXE?
2-) If i import a dll and although i do not use one of the imported function in that dll, OS can still call that function? Or OS can only call imported dll functions which are used by exe?? If the function doesn't import by exe, it is never be called?
Thanks...
|
|
|
|
|
Normally WinMain is not exported in DLLs. What happens is that WinMain is not called directly by the loader (and main(), likewise). The code that calls it, is a bootloading code, which is addressed by a DLL/EXE entry point. This code does all the initialization and at the end of it calls into WinMain/main(), the address of which is known during compilation.
|
|
|
|
|
sawerr wrote: We know that, WinMain is buried in the MFC Framework. OK but how can Windows call it?
The linker tries to locate and execute an entry-point in your code, which may be dependent on the type of application you are building: WinMain (or wWinMain if built for Unicode) or main (or wmain if built for Unicode). The former is for windowed applications and the latter is for console applications. If no entry point is defined in your application, you will get an undeclared identifier from the linker.
sawerr wrote: If i import a dll and although i do not use one of the imported function in that dll, OS can still call that function? Or OS can only call imported dll functions which are used by exe?? If the function doesn't import by exe, it is never be called?
That depends. There are DLLs that you may not reference directly from your code but Windows will load and execute code from those libraries. This is because some of the functions in those libraries may be indirectly referenced. Other than that, only what you are calling from your code will be loaded or executed.
The fact is that this is a larger topic to be discussed in a thread like this. If you really are wanting to read up on how programs work and how Windows work, I'll recommend the book by Jeffrey Richter and Christopher Nasarre (every edition of the book gets a new name. The latest one is called Windows Via C/C++).
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Thanks for answers.
I know that loader must fill IAT with imported functions. If I don't import a function so function can't be placed in IAT. So even this function is exported from dll, Windows can't call it. But i'm not sure about that so i started that thread.
I understand that winmain(or whatever) isn't added to import section by exe, this is special case for entry point. A function can be called without adding IAT is entry point. This is valid just for entry point. Is that right?
|
|
|
|
|
Exported functions can be called (or, rather, located and addressed) from the outside - so, whenever you need a function to be addressable from the outside you (or compiler/linker) make it exported. This is the only rule
|
|
|
|