|
|
I tested this real quick, and it works fine for me.
This example finds a NotePad instance and Blts the Notepad window
to my window (note that "*pThis" in the callback == the HWND for the dialog window)...
BOOL CALLBACK CMFCTesterDlg::EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
if(hwnd == ::FindWindow(NULL, L"Untitled - Notepad"))
{
CMFCTesterDlg *pThis = (CMFCTesterDlg *)lParam;
HWND hwnddest = *pThis;
RECT rect;
::GetWindowRect(hwnd, &rect);
HDC dc = ::GetDCEx(hwnd, NULL, DCX_WINDOW);
HDC destdc = ::GetDC(hwnddest);
::BitBlt(destdc, 0, 0, rect.right-rect.left, rect.bottom-rect.top, dc, 0, 0, SRCCOPY);
::ReleaseDC(hwnddest, destdc);
::ReleaseDC(hwnd, dc);
};
return TRUE;
}
void CMFCTesterDlg::OnOK()
{
::EnumWindows(&CMFCTesterDlg::EnumWindowsProc, (LPARAM)this);
}
Also, why the search within a search (FindWindow() within an EnumWindows() callback)??
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you Mr.Mark Salsbery. Got it.
|
|
|
|
|
iwdu150
I have tried your Percent Progress Bar, and have use it in a application I am building. What I mean is I am using the DLL and the XML. This application that I am building is for my own use and will not be release to the public. The DLL and XML have really come in handy and I have enjoyed using. You did a good job.
The reason I am contacting you is that I noticed that the word ‘TRIAL’ is tacked onto the name ‘Progress Bar Trial.dll’ and ‘Progress Bar Trial.xml’. This has me a little worried, will it expire or maybe die on me in the near future. If not then great; but if so, please let me know. Also let me know how I can get a good copy of it. Once again, great job, I hope I can use it just the way it is.
Bob Allan
rallan@carolina.rr.com
|
|
|
|
|
|
robertaallan wrote: ...will it expire or maybe die on me in the near future.
Don't you have the source code?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm having a problem positioning dialog boxes on a tab control. I create the dialog box passing it the tab control handle as the parent window.
Here's an image of the results:
Tab Control/Dialog Box Problem[^]
The dialog box covers up the tab buttons. Do I have to manually position the dialog box so that it doesn't cover up the buttons?
Note, I'm not using MFC but straight Win32.
EDIT: Apparently I do have to position the dialog boxes manually in order not to cover up the tab buttons. I adjusted the dialog box's X/Y position to 2/15 and it looks right now.
|
|
|
|
|
From Win32 you can use TabCtrl_GetItemRect[^] to get the rectangle of the tab control.
Best Wishes,
-David Delaune
|
|
|
|
|
Leslie Sanford wrote: I adjusted the dialog box's X/Y position to 2/15 and it looks right now.
TabCtrl_AdjustRect/TCM_ADJUSTRECT will give you the proper
rect that will work regardless of font. Much better than
hard-coded numbers
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: TabCtrl_AdjustRect/TCM_ADJUSTRECT will give you the proper
rect that will work regardless of font. Much better than
hard-coded numbers
Thank you!
Yup, hard-coded numbers are always distasteful.
|
|
|
|
|
In a c++ application I would like to do different printings on different printers but I do not want to
a.) use the print dialog
b.) use the default printer.
So I tried to set up a piece of code but there is a great gab when I want to print on a non-default printer.
The code that I'm using at the moment is looking like this:
//-----------------------------------------------------------------------------------------
iPrintMode = 0; // call PrintDialog
iPrintMode = 1; // use default printer
iPrintMode = 2; // use fixed printer
m_HdcPrint = NULL;
// new class PrintDialog
CPrintDialog *pPrintDlg = new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL);
if (iPrintMode == 0 || iPrintMode == 1)
{
if (iPrintMode == 0)
{
// call the default PrintDialog
pPrintDlg->m_pd.nMinPage = 1;
pPrintDlg->m_pd.nMaxPage = 1;
pPrintDlg->m_pd.nFromPage = 1;
pPrintDlg->m_pd.nToPage = 1;
// start Printer-Dialog
pPrintDlg->DoModal();
}
else if (iPrintMode == 1)
{
// use the default printer of this machine/user
pPrintDlg->GetDefaults(); // fill the internal structure
/*
CString printer;
DEVMODE* pDevMode;
pDevMode = pPrintDlg->GetDevMode();
printer = pDevMode->dmDeviceName ;
*/
}
// Returnwerte abholen: Handle to PrinterDevice
m_HdcPrint = pPrintDlg->GetPrinterDC();
}
else if (iPrintMode == 2)
{
// print on a fix printer (e.g. 'HP Color LaserJet 4650 PCL 6')
/*
* ==========================================================================
* =
* =
* ===> here is a big gap that I do not know how to fill ....
* =
* =
* ==========================================================================
*/
}
else
{
// no printing
m_HdcPrint = NULL;
}
// printing is possible
if (m_HdcPrint != NULL)
{
// Create a CDC and attach it to the default printer.
// neuen Device-Context anlegen
m_PrintDC = new CDC;
// attach the given properties
m_PrintDC->Attach( m_HdcPrint );
//...
// set mode to 1/10 mm
m_PrintDC->SetMapMode(MM_LOMETRIC);
// calculate to independent data
m_PrintDC->DPtoLP(&m_DrawRect);
//...
// begin the document
m_PrintDC->StartDoc(_T("Print_My_Document"));
// Start a new page
m_PrintDC->StartPage();
//...
//... and so on
//-----------------------------------------------------------------------------------------
It's working fine with the print dialog as well as with the default printer.
However I have no idea to get it working with a fixed printer (e.g. 'HP Color LaserJet 4650 PCL 6').
I had a look at a few articles at CodeProject, but as a bloody beginner I had to give it up very soon.
Does anyone have experience with a similar problem or does anybody have some (code)-ideas how to solve this.
Thanks in advance
|
|
|
|
|
I'm needing to add functionality to a class that uses a template. In other words, there is a template class in a library that I'm using, I need to use it (there is no escaping it), but I really need to pass an additional parameter to it either via constructor (my preferred solution) or by using a mutator method. The problem is that the compiler refuses to allow me to do two things: 1) add a parameter to the class, and 2) add a parameter to a constructor or add a new method to my class.
Is there a 'proper' way to do this?
|
|
|
|
|
Patrick G wrote: the compiler refuses to allow me to do two things
We can't understand the compiler errors unless you post them along with the relevant code.
led mike
|
|
|
|
|
Context: I want to have a pointer to an object as a member of a class that uses a template.
All the errors I show below point to the lines of code that I've provided.
Example 1: Add a private parameter and change it using a public mutator.
Here's the private parameter: CommunicationSystem* comms;
Here's the mutator declaration: void setCommSystem(CommunicationSystem* commSystem);
Here's the implementation of the mutator:
void ReactorServiceHandler::setCommSystem(CommunicationSystem* commSystem) {
this->comms = commSystem;
}
Here's the call of the mutator: acceptor.setCommSystem(commSystem); Note it doesn't much matter if I use the "." or the "->", I get identical errors.
Here's 9 errors complaining about it:
Error 1 error C2039: 'setCommSystem' : is not a member of 'Poco::Net::SocketAcceptor<servicehandler>' c:\Documents and Settings\patrick\My Documents\VirtualWorld\Cave\src\ReactorServer.cpp 125
Error 2 error C2061: syntax error : identifier 'CommunicationSystem' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 94
Error 3 error C2143: syntax error : missing ';' before '*' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
Error 6 error C2061: syntax error : identifier 'CommunicationSystem' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 94
Error 7 error C2143: syntax error : missing ';' before '*' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
Error 9 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
</servicehandler>
Switching the parameter from private to public and getting rid of the mutator makes no difference.
Example 2: Add a parameter to the constructor (this is what I really want to be able to do somehow).
Here is the call to the constructor: SocketAcceptor<reactorservicehandler> acceptor(svs, reactor, commSystem);</reactorservicehandler>
Here is the definition of the constructor: ReactorServiceHandler(StreamSocket& socket, SocketReactor& reactor, CommunicationSystem* comms);
Here is the implementation of the constructor:
ReactorServiceHandler::ReactorServiceHandler(StreamSocket& socket, SocketReactor& reactor, CommunicationSystem* comms):
_socket(socket),
_reactor(reactor),
_pBuffer(new char[BUFFER_SIZE]) {
Application& app = Application::instance();
this->comms = comms;
_reactor.addEventHandler(_socket, NObserver<reactorservicehandler,>(*this, &ReactorServiceHandler::onReadable));
_reactor.addEventHandler(_socket, NObserver<reactorservicehandler,>(*this, &ReactorServiceHandler::onShutdown));
}
Here's 12 errors complaining about it:
Error 1 error C2039: 'setCommSystem' : is not a member of 'ReactorServiceHandler' c:\Documents and Settings\patrick\My Documents\VirtualWorld\Cave\src\ReactorServiceHandler.cpp 112
Error 2 error C2673: 'setCommSystem' : global functions do not have 'this' pointers c:\Documents and Settings\patrick\My Documents\VirtualWorld\Cave\src\ReactorServiceHandler.cpp 113
Error 3 error C2227: left of '->comms' must point to class/struct/union/generic type c:\Documents and Settings\patrick\My Documents\VirtualWorld\Cave\src\ReactorServiceHandler.cpp 113
Error 4 error C2661: 'Poco::Net::SocketAcceptor<servicehandler>::SocketAcceptor' : no overloaded function takes 3 arguments c:\Documents and Settings\patrick\My Documents\VirtualWorld\Cave\src\ReactorServer.cpp 124
Error 5 error C2061: syntax error : identifier 'CommunicationSystem' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 67
Error 6 error C2143: syntax error : missing ';' before '*' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
Error 7 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
Error 9 error C2061: syntax error : identifier 'CommunicationSystem' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 67
Error 10 error C2143: syntax error : missing ';' before '*' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
Error 11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
Error 12 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
</servicehandler>
|
|
|
|
|
Wow, Patrick in the first listing of errors #1 and #2 are beginner C++ compiler errors. Also you voted my post as not helpful so I have no motivation to help you. However you need to help yourself first by learning how to program in C++ if you intend to, well, program in C++.
led mike
|
|
|
|
|
Led Mike, I'm sorry if you didn't like me voting your response as not useful, but since it wasn't an answer, I'm afraid it really wasn't useful. That being said, I do appreciate any assistance. Also, I appreciate that people do in take the time to read and help other people out with their problems.
Now, with all of that being said, in my (very long) experience with C++ compilers I've found that when the compiler gets confused it tends to spit out trash for error messages. You mentioned that the errors are "novice" mistakes (since they are referring to semicolons and such). I guarantee that there are no semicolons missing. I know this because when I take out my function calls (listed above, semicolons and all) all the troubles go away. (I should point out that in example 2 I forgot to post the deceleration of my private member variable, it is in the code though, as in example 1). Also, as in the code shown above, the variables that are claimed by the compiler to not be declared in fact are, but seem to be ignored by the compiler. This is actually why I didn't give any errors in my first post and why I only summarized the problem (I figured a print out of nonsensical compiler errors would be a waste of disk space). All of this led me to believe that when a class uses a template that it can't have additional parameters added to it lightly, although I highly doubt that it's impossible.
|
|
|
|
|
Patrick G wrote: but since it wasn't an answer, I'm afraid it really wasn't useful.
But David's post was an answer? Whatever dude, good luck.
DavidCrow wrote: What does line 125 (and possibly the few preceding it) of ReactorServer.cpp look like?
led mike
|
|
|
|
|
Patrick G wrote: Error 1 error C2039: 'setCommSystem' : is not a member of 'Poco::Net::SocketAcceptor' c:\Documents and Settings\patrick\My Documents\VirtualWorld\Cave\src\ReactorServer.cpp 125
What does line 125 (and possibly the few preceding it) of ReactorServer.cpp look like?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Sorry, I should have posted that with my original code. I assume you're referring to the first example. This was the call to the mutator acceptor.setCommSystem(commSystem); . The previous lines of code are initializations for other classes that are irrelevant to this problem with the exception of the call to the constructor just prior to this. That was SocketAcceptor<reactorservicehandler> acceptor(svs, reactor);</reactorservicehandler>
Here's a little summary of the files so that this all makes more sense. ReactorServer is the class that is trying to declare a ReactorServiceHandler which uses the <servicehandler> template. CommunicationSystem* comms (or commSystem, depending on where you read it in the post) is just a pointer to an object that manages these objects (among others) that deal with communications. (It's similar to the Facade design pattern).
|
|
|
|
|
Have you considered trying to reproduce this scenario with a much simpler set of classes? As it is, there's way too much code here, both shown and not, to wade through and have any chance of understanding it.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I create a List ctrl derivered from CListCtrl. In this class, I implement item changed event
class CMyListCtrl :
public CListCtrl
....
BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, &CTrendListCtrl::OnLvnItemchanged)
END_MESSAGE_MAP()
......
void CMyListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
..
}
Then, on my dialog, there's a CMyListCtrl object, like this
CMyListCtrl m_lst;
afx_msg void OnLvnItemchangedList(NMHDR *pNMHDR, LRESULT *pResult);
I try to implement the item changed on that list.
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_GROUP, &CMyDlg::OnLvnItemchangedList)
END_MESSAGE_MAP()
void CMyDlg::OnLvnItemchangedList(NMHDR *pNMHDR, LRESULT *pResult)
{
...
}
The problem is, if I implement (1), then it doesn't run (2). And if I doesn't implement (1), it can run (2).
Actually I want to run both (1) and (2).
What should I do in this case?
Thank you very much, bro.
|
|
|
|
|
Try changing ON_NOTIFY_REFLECT to ON_NOTIFY_REFLECT_EX and return TRUE inside your CMyListCtrl::OnLvnItemchanged handler.
Best Wishes,
-David Delaune
|
|
|
|
|
uhm, I'm not sure that ...
Is this what you mean:
ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, &CMyListCtrl::OnLvnItemchanged)
BOOL CMyListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<lpnmlistview>(pNMHDR);
*pResult = 0;
....
return TRUE;
}
</lpnmlistview>
I cannot see any change .....
|
|
|
|
|
|
uhm, I already tried return FALSE, but it's not better.
.. I will try this a litter bit later.
Thank you very much, David Delaune.
|
|
|
|
|