|
Hi Johan,
Thank you for the support. I will be working on this problem this weekend. Sadly, printing is my weakest skills but this project will force me to be better. I guess I have put off printing long enough. Thnx again.
|
|
|
|
|
It's not much different from working with the screen, actually. The big problem is designing drawing code that makes no assumptions regarding the output resolution.
|
|
|
|
|
My question concerns the setting of controls on "not-yet visited" property pages.
I have a PropertySheet dialog with 3 property pages. I have followed the common convention of creating this property sheet as found here at CP and also in the MSDN Library. The operation of this works good and I would say the creation of the Sheet/Pages is good too, except for what I want to do.
I am reading an external config file (text) and would like to pre-load my pages with values read from the config file. I can do this for the first page with no problems. When I try to load values into controls on other pages, it crashes with undefined window handles. HOWEVER, if I visit each page first and then pre-load my pages, everything is fine - what gives???
I have tried to circumvent the OnInitDialog() for each page, but this proved unsuccessful - same results.
Can anyone help me with what I want to do?
Thank you,
John John
|
|
|
|
|
|
Michael describes the default behaviour correctly. But if you're using version 4.71 or higher, you can specify PSP_PREMATURE as one of the values assigned to the dwFlags member of each PROPSHEETPAGE structure. Each page that has this value toggled on will be created when the property sheet is created (as opposed to waiting until it is first changed to).
|
|
|
|
|
|
I have a SDI application that I have added other classes to. Sometimes I need to access the doc file from those classes to update a document variable. I am not sure if I can get to the mainframe from one of the classes and access the doc file that way, or if I should use forward referencing to send messages directly to the doc file. Forward referencing sounds like it should be do-able, but I dont know how to capture the doc object in my other classes.
Thanks.
Jerry
|
|
|
|
|
If you have other classes that need to update a document, then I suggest that you put a pointer to the docuemtn in the classes from the beginning.
For window-based classes, you might want to consider sending messages to the main window using AfxGetMainWnd , this would probably feel natural for others reading/maintaining your code.
|
|
|
|
|
I have a client application that connects to a server application using connection based sockets. Is there any particular error message that I could capture on the client if the network cable is broken or broken and reconnected? I know there are some error message that can let you know if the network is down or unreachable.
Thanks.
Jerry
|
|
|
|
|
|
Does anyone know a TreeCtrl that will display and allow you to run files (via double click), that will integrate into a MFC dialog (Modeless).
I did find CTreeFileCtrl in this site but could not get it into my dialog, it seems that it works for SDI applications and could not figure out how to integrate it.
I have found a few Tree controls but again all seem to be for MDI or SDI applications.
grahamfff
|
|
|
|
|
Grahamfff wrote:
I did find CTreeFileCtrl in this site but could not get it into my dialog, it seems that it works for SDI applications and could not figure out how to integrate it.
From the article[^]:
To use CTreeFileCtrl, include FileTreeCtrl.cpp / .h in your project (in addition to SortedArray.h) and #include "FileTreeCtrl.h" in the module you want to instantiate it in. You can use the usual MFC ways of hooking up the class. If you are using the class in a dialog resource, then you can use the DDX function provided or call the CWnd::SubclassWindow() function directly. You can also create the control dynamically by calling its parent classes CTreeCtrl::Create() method.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
I am struggling with CPropertySheet / CPropertyPage to create a tabbed dialog box.
After creating a project, I Project/Add Component / VisualC++ Component / PropertySheet. Then, I selected a PropertySheet (instead of Wizard) with 3 tabs. The tabs showed up in the project as CMyPropertyPage1, 2, 3.
The CPropertyPage1 (2,3) is :: public CPropertyPage (subclass)
If I look at the header file CPropertyPage1.h, I see soemthing like:
// Dialog Data
//{{AFX_DATA(CMyPropertyPage1)
enum { IDD = IDD_PROPPAGE1 };
// NOTE - ClassWizard will add data members here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_DATA
Now, if I add some controls on any page, and double click on it for the handler code, Visual C++ asks me to create new class. Then, a new class is created based on CDialog. Assume its name is CMyPage1
CMyPage1 is :: public CDialog, and is also bound on the same dialog template:
// Dialog Data
//{{AFX_DATA(CPage1)
enum { IDD = IDD_PROPPAGE1 };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
So, my question is:
Both CPropertyPage1 and CMyPage1 are refering to the same dialog template (IDD_PROPPAGE1). MyPropertySheet adds the CPropertyPage-typed variables in its constructor. CMyPage processes the handler code.
What is the relationship between CMyPage1 and CPropertyPage1 ? It seems to me that they are 2 parts of each tab. Why the hell do we need to have 2 separate classes that refer to the same thing ?
Thanks a lot for enlightening me.
|
|
|
|
|
hongheo76 wrote:
Now, if I add some controls on any page, and double click on it for the handler code, Visual C++ asks me to create new class. Then, a new class is created based on CDialog. Assume its name is CMyPage1
The class wizard should have given you the option of using an existing class. Take that option and select the correct CPropertyPage* class. You should have only one class per page, not two.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
I have a dialog-based MFC application within which I need to do some serial I/O. Basically, I need to wait for a certain character to come in on the serial port. I'm successfully creating a file for the port in overlapped mode and starting ReadFile with a valid overlapped structure and event handler. Also, I'm using WaitForSingleObject() with a short timeout to check whether the event has been set or I've timed out.
What I want to do is cause my dialog to perform message handling (specifically redrawing) whenever WaitForSingleObject times out. That way the user will see a properly repainting display while we're waiting for the serial characters instead of what looks like a hung application. Any suggestions would be greatly appreciated.
Best Regards,
pHaze426
|
|
|
|
|
Put the serial port stuff in a separate thread and the GUI will remain responsive.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I could do that, but I'd still have to have the function launching the thread wait until the serial read completed before continuing with its tasks. Otherwise, I'd have to hook a callback function or something to handle a state machine that's called after each read. I just wondered if there was any other option as far as a function I could call to do processing while I'm waiting.
Best Regards,
Phaze426
|
|
|
|
|
pHaze426 wrote:
I could do that, but I'd still have to have the function launching the thread wait until the serial read completed before continuing with its tasks.
Nothing wrong with that (except for the "wait" part). Once the secondary thread has completed, it would post a message to the primary thread indicating it is done. At that point, the primary thread could do what it needed with the serial port data. No waiting is necessary. Make sense?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
pHaze426 wrote:
I'm using WaitForSingleObject() with a short timeout to check whether the event has been set or I've timed out.
How are you doing that continuously without multiple threads and without blocking the UI thread? In a mesasge loop?
pHaze426 wrote:
What I want to do is cause my dialog to perform message handling (specifically redrawing) whenever WaitForSingleObject times out
Then use SendMessage() or PostMessage()
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
I guess I am using threads in a roundabout sort of way. When I call CreateFile to open the serial port, I specify the OVERLAPPED I/O flag. Then, when I call ReadFile() I pass it an overlapped structure with an event handle. When it's done, it sets that event handle. (I guess this means that internally, Windows is spawning another thread for ReadFile). Anyhow. WaitForSingleObject just waits until the event handle is set, or its own timeout has expired. So... if I give the call to ReadFile a timeout of 10 seconds and the call to WaitForSingleObject a timeout of 100ms, I will get a chance to do something every 100ms until the serial I/O completes, or readfile times out after 10s.
Along the SendMessage lines, I've used:
this->SendMessage(WM_PAINT, 0, 0); from within this wait loop to no avail. Is there another message I should be sending?
|
|
|
|
|
Well if you don't need to send any data the just call CWnd::Invalidate() that will cause a Paint to occur.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Just for everyone's reference, I figured out a way to do this (granted, this way isn't all that clean and is probably more of a 16-bit windows style of doing things, but it works). Rather than using WaitForSingleObject to wait for the I/O to complete, I stuck in this:
while (MsgWaitForMultipleObjects(1,
&ol.hEvent,
FALSE,
10,
QS_ALLINPUT) !=
WAIT_OBJECT_0) {
while ( PeekMessage ( &msg, NULL, 0, 0, PM_REMOVE)) {
DispatchMessage ( &msg);
}
}
So... I just keep dispatching all the messages I received until the serial even becomes signalled. This seems to work well.
|
|
|
|
|
Ok, I have a CArray container like so:
<br />
CArray <myObject, myObject> objectList;<br />
and I declared a dynamic array in a separate class like so:
<br />
class SelectionBox<br />
{<br />
public:<br />
void AddContent(myObject *);
<br />
protected:<br />
myObject *content;
unsigned long numContents;
}<br />
So now I built my AddContent() function like this:
<br />
void SelectionBox::AddContent(myObject *c)<br />
{<br />
unsigned long counter;<br />
myObject *tempObject;<br />
tempObject = new myObject[numContents];<br />
<br />
tempObject = content;<br />
<br />
content = new myObject[numContents + 1];<br />
<br />
for(counter = 0; counter < numContents; counter++)<br />
{<br />
content[counter] = tempObject[counter];<br />
}<br />
<br />
content[numContents] = c;<br />
<br />
<br />
numContents++;<br />
delete [] tempObject;<br />
} <br />
Finally, in another part of the program, I shoot the address of one of the objects stored in the CArray to the AddContent function.
At first the function appeared to be working.. That is until I later tried to manipulate the original objects in the CArray by manipulating what I thought was the pointer to them in my SelectionBox class. Then I found out that I had copies of data stored and not a pointer to the CArray data. I can't for the life of me figure out how to declare the function and pass the data so that I can store an array of pointers/addresses to the data in the CArray container. Can someone show me an example, or maybe a link to a relevant tutorial?
|
|
|
|
|
|
That worked perfectly!!!! Thanks Pete.. I didn't even know that container existed, .. which will help a quite a few more problems I've been facing. Thanks Again
|
|
|
|