|
I had problems with my previous project too. If it doesn't matter you, I think it will be better if you use a View/Doc app insteads of DialogBox app. The view has more functionality than a dialog box. When I changed it, it worked 2,3 times faster with my programm.
If you centralize all datas in the document, and use different views for showing whatever you need, I think it will be faster.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
I thought of implementing in Doc/View architecture, but I have soo many displays embedded into my main display, I am not sure how I can implement soo many views. Not to say the least, I am not that familiar with Doc/View implementation, any good resources on it which are simple and straight away rather than jumping from one part to another part??
thanks
|
|
|
|
|
About how to jump between the views, look for messages related that I wrote. I have asked about how to create different views with different menus more than once. The last, a few days ago.
But if you think is going to be difficult for you to go clear with the Doc/View... then u should try it as you think is better for you.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Any time you select an object into a DC, you should save the
previously selected object. When you're done with the DC, select the original
object back into the DC.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I need some help/advice on modifying a part of my existing code. I have this application where I use the libraries provided by one of our hardware manufacturers through which we grab a frame from a monochrome camera into a memory (BYTE*) defined/assigned to that library and it displays the captured frame into the window handle that we assign to it. But for some more processing I would like to display the captured frame using my own dc object. But how can I display a 8 bit (monochrome) data into a dc ??
-thanks
PKNT
|
|
|
|
|
The easiest and most flexible way to do that is to create a DIBsection and copy your pixel bits
into it. That gives you an HBITMAP you can select into DCs, and also a pointer to the pixel
bits so you can directly manipulate them.
Here's an example of the basic stuff for creating an 8bpp grayscale DIBSection:
LONG lImageWidth = 640;
LONG lImageHeight = 480;
WORD wBitsPerPixel = 8;
LONG lStride = (((lImageWidth * (long)wBitsPerPixel + 31L) & (~31L)) / 8L);
BITMAPINFO *bm = (BITMAPINFO *)new BYTE[sizeof(BITMAPINFO) + 255 * sizeof(RGBQUAD)];
bm->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bm->bmiHeader.biWidth = lImageWidth;
bm->bmiHeader.biHeight = lImageHeight;
bm->bmiHeader.biPlanes = 1;
bm->bmiHeader.biBitCount = wBitsPerPixel;
bm->bmiHeader.biCompression = BI_RGB;
bm->bmiHeader.biSizeImage = 0;
bm->bmiHeader.biXPelsPerMeter = 0;
bm->bmiHeader.biYPelsPerMeter = 0;
bm->bmiHeader.biClrUsed = 0;
bm->bmiHeader.biClrImportant = 0;
for (int color_index = 0; color_index < 256; color_index++)
{
bm->bmiColors[color_index].rgbBlue = color_index;
bm->bmiColors[color_index].rgbGreen = color_index;
bm->bmiColors[color_index].rgbRed = color_index;
bm->bmiColors[color_index].rgbReserved = 0;
}
BYTE *pBitmapBits;
HBITMAP hBitmap = ::CreateDIBSection(NULL, bm, DIB_RGB_COLORS, (void**)&pBitmapBits, NULL, 0);
if (hBitmap)
{
::DeleteObject(hBitmap);
}
delete[] (BYTE *)bm; Copy your captured 8-bit pixel data to the array pointed to by pBitmapBits.
lStride is the length of each row in bytes - there may be extra bytes at the
end of each row so make sure you take that into account.
You can use hBitmap just like any DDB. You can select it into a memory DC and draw on it
with GDI functions, blt it to the screen, etc.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
I'm rewriting my console application in MFC. The applications is a port scanner and it works very fine in as a console application. However, when writing it in MFC I get an unhandled exception where it isn't supposed to be.
<br />
void CNetScanMfcDlg::OnBnClickedButton1()<br />
{<br />
LPTSTR host = m_host.GetBuffer(255);
PortScanner portScanner((char*) host, m_startPort, m_endPort);<br />
}<br />
PortScanner::PortScanner(char* sHost, int startPort, int endPort) {<br />
address.sin_family = AF_INET;<br />
hostent* host = gethostbyname(sHost);<br />
address.sin_addr.s_addr = (unsigned long) atoi(host->h_addr_list[0]);
this->startPort = startPort;<br />
this->endPort = endPort;<br />
}<br />
gethostbyname() appears to return NULL, but it's not a problem with the host itself if I put gethostbyname("localhost") it works fine. I believe the string conversion causes this problem.
|
|
|
|
|
Since gethostbyname() expects a const char* , why are you using a char* instead? That in itself is not bad, but your use of GetBuffer() is unnecessary.
Mike Borozdin wrote: hostent* host = gethostbyname(sHost);
What is the value of sHost at this point? If gethostbyname() is returning NULL , are you calling WSAGetLastError() to find out why?
Mike Borozdin wrote: address.sin_addr.s_addr = (unsigned long) atoi(host->h_addr_list[0]); //this leads to an exception
Is host non-NULL at this point?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The value of sHost is correct, that is if I enter "localhost" in the edit box it will be "localhost", but host is NULL , but if I put "localhost" instead of sHost it won't be NULL , so it makes me thing that there is something wrong in string conversion. Anyway I worked it out, I found a solution here. However, I'm still going to see what was wrong with my piece of code, probably I should have added a traling zero.
|
|
|
|
|
Mike Borozdin wrote: Anyway I worked it out, I found a solution here.
Resulting in what change?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
It made it work
|
|
|
|
|
Ok, so my question was a bit ambiguous. I meant, what change was required in your code?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I replaced:
<br />
LPTSTR host = m_host.GetBuffer(255);
PortScanner portScanner((char*) host, m_startPort, m_endPort);<br />
with:
<br />
size_t CharactersConverted = 0;<br />
char host[100];<br />
wcstombs_s(&CharactersConverted, host, m_host.GetLength()+1, m_host, _TRUNCATE);<br />
PortScanner portScanner(host, m_startPort, m_endPort);<br />
|
|
|
|
|
This looks to be a Unicode vs. ANSI issue. Which are you using?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Sorry for a lame question, but how do I find out which one I'm using?
|
|
|
|
|
If you are using Unicode, you'll have UNICODE and _UNICODE defined either in the stdafx.h file, or in the project settings (/D).
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yes, it's UNICODE .
By the way, MessageBox((LPCTSTR) "Wrong host") shows rubbish, while MessageBox(_T("Wrong host")) works fine.
|
|
|
|
|
Mike Borozdin wrote: Yes, it's UNICODE.
That might explain why gethostbyname() does not work. It's Ansi only. Try this:
void CNetScanMfcDlg::OnBnClickedButton1()
{
PortScanner portScanner(m_host, m_startPort, m_endPort);
}
PortScanner::PortScanner(LPCTSTR sHost, int startPort, int endPort)
{
address.sin_family = AF_INET;
USES_CONVERSION;
hostent *host = gethostbyname(T2A(sHost));
address.sin_addr.s_addr = (unsigned long) atoi(host->h_addr_list[0]);
this->startPort = startPort;
this->endPort = endPort;
} Mike Borozdin wrote: By the way, MessageBox((LPCTSTR) "Wrong host") shows rubbish...
Since you are using Unicode, try:
MessageBox(L"Wrong host"); Using the _T() macro is the preferred method, however.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I hope making it work also included checking if host is NULL before using it...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Sure, I will add the input validation, having a web development background I know how it's important .
|
|
|
|
|
I am working on an application which needs to respond to any DDE message intended for any DDE application if a certain file is being opened.
I have written the app so far to respond to the WM_DDE_INITIATE with WM_DDE_ACK and then get the filename from the WM_DDE_EXECUTE message, the problem I have now is how do I terminate the conversation and let the intended application receive the message if I do not want to process it? Is this possible?
|
|
|
|
|
Hello,
here is a description of what I want to do, to which I will need some pointers.
(A) I have an application that needs to detect when an arbitrary application calls the system standard dialog to save a file with a different name.
(B) Once detected it needs to extend it by adding some custom controls on it, and allowing the user to change some parameters in those controls.
(A) - trying to implement using system wide hooks, but not sure what to what WH_xxx to subscribe to.
(B) - I know that there is a OPENFILENAME that comes when an application calls GetSaveFile(), and this might somehow work.
Questions:
1 - how to implement correctly (A) ?
2 - once done that, will the initial idea ever work to have it work for an arbitrary application ? becaue till now all I saw is that people do this but only for Save Dialogs that are part of their application.
thanks
|
|
|
|
|
for A I think the besst option is with hooks. how? Sorry but there I can't help you
for B I would subclass the CFileDialog with your custom controls and depending on what the hook says, you choose one or the other to answer the call.
But I don't understand what do you want to change for example in the Word "save as.." to make it different of the Access "save as..."
You dont have access to the serialize functions of third party programms, so... for what do u want to customize the save as...? If you modify something in the parameters of the CFileDialog that has relevance with the programm that called him, you will may have compatibility problems with the saved datas.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
it seems with hooks this is not possible.
what I did is tryin to have system wide API spy, and when there is a GetSaveFileName() called I just override the flags in the OPENFILENAME structure by adding the hook function and custom dialog.
will see if this helps.
|
|
|
|
|
But the most important questions is...
how do you want to save the datas when a third party programm wants to "save as..."????
I mean, Adobe saves the data in different way than Office, Paint vs Photoshop, and so on...
If you don't have access to the serialize or the data structure of the programm that is wanting to save as... how do you want to save the data??? And how do you want the other programms to respond to your customized controls in the second dialog? They will mos probably not recognise their functionability.
I think what you want to do (detecting the Save as.. from other programms) is posible, but to use it correctly afterwards...
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|