|
The static members are shared by all instances of the class where it was defined . The scope of this kind of members is in the file where it was defined , and their duration is from the start of the program until the end of the program . So ,because the static members are allocated at the compilation time , you must initilize them at the file scope , even if are private . If you don't specify a value , 0 is implicit.
|
|
|
|
|
I'm creating an interface to program industrial machines and I need to be able to control various kind of documents.
One of those docs. must be viewed using an assistant, how could I do this if the CMultiDoctemplate parameters has to be filled with CMDIChildWnd (or derived) and CView (or derived too).
An example would be very useful.
Thank you in advance.
PD: I beg your pardon if I has written something impolite, but I'm very novice speaking english too.
|
|
|
|
|
After receiving a little bit of help I have solved the problem:
I have created three classes: one document derived, another view derived, and a ChildFrame derived of a CMDIChild, and in this last one I have written:
BOOL CChildFrmS7::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
m_PS->SetWizardMode();
m_PS->Create(this,WS_CHILD | WS_VISIBLE);
m_PS->SetActivePage(0);
CreateView(pContext);
return TRUE;
}
int his way I have got the property sheet in a MDI environment, but there is a little problem:
when the application erases the background, the body of the active page of the propertysheet disappears, I have overriden the OnEraseBackground message, but The window borders are not painted then.
How should I get the borders painted and the contents of the MDIChildwindow don't?
|
|
|
|
|
Is there a way to detect if any sound is currently playing in win98 using MSVC++6?
Thanks in advance!
|
|
|
|
|
Client and Server communicate using CSocket.For the communication, object serialization is used with the help of CArchive class in MFC.
But under high data transmission rates between server and client using serialization, client hangs after calling "Flush" method in CArchive class.
(For each object sending , we use Serialize() method of CObject class and Flush method of CArchive)
I increased the buffer size of CArchive class and tested .
I found that Client has sucessfully sent the object, but Client hasn't got any reply from the server although the server had sent it to client.
In this case client waits without any reply.
The Problem Occurs only when the server resides in a dual processor machine.
|
|
|
|
|
Hi,
I am trying to make a browse for folder dialog with 'Add folder' button ( like in winzip). I succeeded to insert the new folder to the tree view (using
TreeView_InsertItem) but if the parent item is not null (no the root), I receive
an exception from the shell when I try to select the new folder I have just added.
thanks,
Shai
|
|
|
|
|
Hi Shai,
I think that simply adding a tree item cannot work, because the shell uses the tree control only to show directories, while it holds the data in its own structures.
Try creating the directory first, but I think it will not work. When you choose the item just added, the Shell goes searching its own structures but probably it obtains a wrong pointer stored in the item data, so it generates an exception.
I think WinZip uses a custom dialog, not a subclassed BrowseForFolder dialog.
Cheers,
Paolo.
|
|
|
|
|
Subject: MFC Socket problem in Windows2000 environment
Client makes a connection to the Server using CSocket.
Server will be listening for incoming connections from the Client.
When a Client makes a connection to the Server the following takes place in the Server:
1) Calls CSocket::Detach() function to detach the socket handle.
2) Closes the socket handle.
3) Spawns a secondary process to handle the real communication between Server and the Client by passing the socket handle.
Secondary process attaches (using CSocket::Attach()) the socket handle to a new socket inorder to communicate with the Client.
The problem is:
When the Secondary process attaches the socket, a socket notification is sent to the Server.
Then the Server crashes because at that time the socket handle is null in the server as we have already closed it after detaching.
This is prevalent in Windows2000 Server machine which is also a dual processor. We are using MFC sockets for the communication. (VC 6 Environment)
This is running fine in Windows NT environment.
We would like to know why this is happening in Windows2000 Server environment and any solutions to it.
Thanks
Gane
|
|
|
|
|
I'm using MFC and the SDI architecture. I use a control bar with a spin control among others. I'd like to change the properties of the spin control (e.g range) according to the data in the loaded document. Maybe it will be obvious to some of you, but i just cant figure it out !
Thanx for help!
|
|
|
|
|
Assuming that ID_SPINSCTRL is the ID of you spin button, and m_ctrlBar is your control bar
CSpinControl* pCtrl = (CSpinControl*)m_ctrlBar.GetDlgItem(ID_SPINCTRL);
ASSERT(pCtrl);
pCtrl->SetRange(nLower,nUpper);
|
|
|
|
|
I have a class derived from CBitmap which contains a DIBSection, and I'm trying to write a copy function.
Can anyone tell me how, given an instance of my class, which is essentially a DIBSection, how I can create a deep copy of the DIBSection ? I've looked at CreateDIBSection, but I'm unsure where to get the parameters from.
Thanks
Christian
|
|
|
|
|
I would like to capture and print the currently displayed dialog box. Is it possible to do this without pressing the <alt><print screen=""> buttons on the keyboard. If possible, I would like to attach this function to a print button. Any ideas??
|
|
|
|
|
Send the dialog a WM_PRINT message, along with a DC, to print the window to that DC.
|
|
|
|
|
Hi !
I'm developping on Embedded Visual C++, on Pocket PC and CE 2.11
(more or less the same as Visual C++ 6.0 for Desktop PC)
In my application I would like to send some characters to be
displayed in another window in the background
So I would like to send the focus back to another window
(for example the window that had the focus before I launch
my application) while my application remains on the foreground
(but still responding to pointing device)
Does anyone knows how to do that ?
thx in advance !
|
|
|
|
|
Hi,
create your back window in modeless style.
then with your pointer to the dialog use the SetFocus() function.
exp:
COtherWindow *m_pWnd;
.
.
.
m_pWnd->SetFocus();
hope this helps ya
Yaron
|
|
|
|
|
Pleas Help me.
I've already asked the code-gurus, but I've got only very common hints, unnecessary voluminous or so fragmented listing, it didn't help me really. For me as a bloody beginner it is very hard to filter out those parts from the listings, which fits to my following problem:
A self developed external electronic circuit is sending measurement-values (from an external measurement process) as a single serial byte - according to the RS 232 rules - appr. 5 times per millisecond.
I would urgently need a short but complete read-in function for my VC++ program (which is already principally running) to take over the measurements.
My program already performs the opening, initialising and closing of the comm-port properly.
I can set and clear DTR and RTS and so on.
When my external circuit detects the CTS signal - sent from the PC - it starts its transmission of the byte in queue to the comm port. The circuit then repeats this one single serial byte permanently as long as CTS remains HIGH.
BUT I AM NOT ABLE TO READ IN THAT SERIAL BYTE!!
So the function I am so desperately looking for should read in the serial byte which is currently transmitted to the comm port.
In the COMM connector I have shortcut the pins 4 and 6 as well as 7 and 8. So DTR and RTS signals are instantly mirrored back to the PC. Therefore no timeouts or other controls are necessary to perform.
At an average my program is taking access to the COM port every millisecond to read in a new byte. So you see, the function should work a little faster than all the common communication solutions with reading, writing, error-testings time-outs and so on.
If anybody could write me down such a minimized function, it would be great. May be a simple assembler routine would perform the task sufficiently too?
Many thanks in advance an best wishes to you.
|
|
|
|
|
Dieter
Are you using overlapped or non-overlapping i/o on your com port? If you are using overlapped i/o I do have some code which may help you out. I use overlapped i/o because I need simultaneous i/o on multiple COM ports. This is not possible when using non-overlapped i/o, as the relevant WinAPI fns block if two threads try to access them simultaneously.
I have had immense trouble with serial comms myself. Part of the problem I had was getting code that worked both with winNT and win9x - without using conditional compilation. The code below should work with either.
Below is a description of how I deal with serial comms. My code runs in a worker thread which is responsible for comms on one COM port. There are as many worker threads as there are serial devices connected to the PC. The serial devices are typically GSM (cellphone) modems.
I have two functions:
1. UINT CSerialPort::ReadAByte( BYTE &bAcquiredByte)
2. UINT CSerialPort::WaitForCharacter(DWORD dwTimeout)
(BYTE is defined as unsigned char,
DWORD is defined as unsigned long)
ReadAByte() passes back through its bAcquiredByte parameter the byte read in.
The return values that are possible are:
WAIT_OBJECT_0: Byte read in successfully
WAIT_TIMEOUT: No Byte read in
WAIT_FAILED: An error occurred
ReadAByte() calls ::ReadFile() only if there is a byte currently sitting in the incoming byte queue for the COM port. The result of this is that ReadAByte returns immediately with or without a newly acquired byte.
Now when ReadAByte returns WAIT_TIMEOUT what it is really saying is there are no bytes currently in the COM port in queue.
WaitForCharacter() is called with a parameter passed determining timeout in milliseconds.
The return values that are possible are:
WAIT_OBJECT_0: One Byte has arrived at the COM port within the specified timeout.
WAIT_TIMEOUT: No Byte has arrived at the COM Port within the specified timeout.
WAIT_FAILED: An error occurred
Decide on a timeout to use with WaitForCharacter, say 10ms.
To sum up how you would read in a stream of bytes:
1. Call ReadAbyte -
If you get WAIT_OBJECT_0, then a byte has been read in successfully. Call ReadAByte again to get the next byte.
If you get WAIT_TIMEOUT back call WaitForCharacter().
2. If WaitForCharacter() returns WAIT_OBJECT_0, then you're clear to call ReadAByte again (this time there will DEFINITELY be a byte waiting for you).
3. Otherwise, if WaitForCharacter() returns WAIT_TIMEOUT, then no bytes have been received on the port for 10ms.
When you initialise your COM port you need to set the com timeouts and set the comm mask to detect incoming bytes:
(m_hCommPort is the handle to the COM port)
COMMTIMEOUTS TimeOuts = {0,20000,0,0,0 };
::SetCommTimeouts(m_hCommPort, &TimeOuts);
::SetCommMask(m_hCommPort, EV_RXCHAR);
Note that the 20 second timeout ensures that my WaitForCharacter fn times-out before ::ReadFile timesout. (Sometimes I use a timeout value of 10 seconds).
Here's the code, I hope it helps. Remember you will have to change m_hCommPort to whatever your handle name is.
UINT CSerialPort::ReadAByte( BYTE &bAcquiredByte)
{
bAcquiredByte=0;
OVERLAPPED osReader = {0};
osReader.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
if (osReader.hEvent == NULL)
return WAIT_FAILED; // error creating event; abort
DWORD dwResult=0; // used to store the return value
// Use ClearCommError to find out number of bytes in buffer
DWORD dwCommErrors;
COMSTAT Status;
ClearCommError(m_hCommPort,&dwCommErrors,&Status);
if (Status.cbInQue==0)
{
dwResult=WAIT_TIMEOUT; // the COM queue for incoming bytes is empty
}
else
{
// Issue read operation for a single byte
DWORD dwReadBytesCount=0;
if (!::ReadFile(m_hCommPort, &bAcquiredByte, 1, &dwReadBytesCount, &osReader))
{
// Note: It appears that ReadFile always returns TRUE.
// I think this is because we do not call ::ReadFile unless we know there is something
// in the com in queue. Also we have a 20 second time out on the port.
dwResult=WAIT_FAILED;
}
else // Read completed immediately
{
if (dwReadBytesCount==1)
dwResult=WAIT_OBJECT_0; // Exactly one byte read in
else
dwResult=WAIT_FAILED;
}
}
CloseHandle(osReader.hEvent);
return dwResult;
}
UINT CSerialPort::WaitForCharacter(DWORD dwTimeout)
{
DWORD dwRes, dwOvRes;
DWORD dwCommEvent=0;
OVERLAPPED osStatus = {0};
osStatus.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
if (osStatus.hEvent == NULL)
return WAIT_FAILED; // error creating event; abort
// Issue a status check event
if (!WaitCommEvent(m_hCommPort, &dwCommEvent, &osStatus))
{
if (GetLastError() != ERROR_IO_PENDING)
{
// error in WaitCommEvent; abort
CloseHandle(osStatus.hEvent);
return WAIT_FAILED;
}
else
{
// Still waiting for io, so proceed to waitforsingleobject stage
}
}
else
{
// WaitCommEvent returned immediately - a character has been received!
ASSERT(dwCommEvent==EV_RXCHAR);
CloseHandle(osStatus.hEvent);
return WAIT_OBJECT_0;
}
DWORD dwResult=0;
// Wait dwTimeout milliseconds for an event (ie single char received) to occur.
dwRes = WaitForSingleObject(osStatus.hEvent, dwTimeout);
switch(dwRes)
{
case WAIT_OBJECT_0:
{
if (!GetOverlappedResult(m_hCommPort, &osStatus, &dwOvRes, FALSE))
{
// An error occurred in the overlapped operation;
// call ::GetLastError to find out what it was - if you're interested.
CloseHandle(osStatus.hEvent);
dwResult=WAIT_FAILED;
}
else
{
// Status event is stored in the event flag
// specified in the original WaitCommEvent call.
ASSERT(dwCommEvent==EV_RXCHAR);
CloseHandle(osStatus.hEvent);
dwResult=WAIT_OBJECT_0;
}
break;
}
case WAIT_TIMEOUT:
{
// Wait has timed out.
// Cancel the overlapped io operation - vitally important as closing handle to
// osStatus.hEvent does not do this!!!! If we didn't cancel we'd get
// problems with GetOverlappedResult next time we issued a waitforcharacter.
// Using setcommmask is because of the lack of CancelIo in win95/98.
::SetCommMask(m_hCommPort, EV_RXCHAR); // note this cancels any pending WaitCommEvent
CloseHandle(osStatus.hEvent);
dwResult=WAIT_TIMEOUT;
break;
}
default:
{
// Error in the WaitForSingleObject; abort
// This indicates a problem with the OVERLAPPED structure's
// event handle.
CloseHandle(osStatus.hEvent);
dwResult=WAIT_FAILED;
break;
}
}
return dwResult;
}
|
|
|
|
|
I am trying to use funcion keys in dialog boxes. I considered trapping the keys or using an accelerator table but have not found enough information to implement either.
What is the best way to accomplish usage of function keys in dialog boxes.
Thanks,
Rick
|
|
|
|
|
Try using RegisterHotKey(...).
|
|
|
|
|
I am trying to use funcion keys in dialog boxes. I considered trapping the keys or using an accelerator table but have not found enough information to implement either.
What is the best way to accomplish usage of function keys in dialog boxes.
Thanks,
Rick
|
|
|
|
|
Hi
you have 2 possibilities here
if you only want to intercept 1 or 2 function keys use PreTranslateMessage if you want them all use a combination of
LoadAccelTable and PreTranslateMessage.
For the second choice see msdn magazine July 2000
Kurt
|
|
|
|
|
Hello everyone!!!
In my project, I have moved some files around, and all of my classes disappeared from the Class View tree. The Class Wizard only shows objects derived from MFC(no "stand alone" classes and no first siblings of CObject, and I have lots of those). I have discovered that almost any Class Wizard operation(addition of data member, function, message handler, etc.) with any class from Class Wizard's project set would bring that particular class back to the Class View tree. Now, I have all the Class Wizard's classes back in my Class View window, but not those that cannot be seen in Class Wizard.
What is the relationship between Class Wizard and Class View? How can I bring back custom classes to Class View tree?
Thanks.
Kirill.
|
|
|
|
|
Hi Kirill,
try this:
- close your workspace
- delete any .ncb .opt .clw file in your project directory
- re-open the workspace
Cheers,
Paolo.
|
|
|
|
|
Hi ,
supposing that I have two classes : A and B . I declare a nested class in B called C.
class A
{
///
}
class B
{
///
class C
{
///
} ;
}
what is the problem : I want that the C class to be a friend of the A class. I can't write in the def. of class A friend class B::C , because B is not defined .Even if I define the B class before the A def. it's no good . I can't move the code of the B class declaration before the delcaration of A ( some other classes are between them ) .
So , what can I do ?
|
|
|
|
|
Try the following if all three classes are defined in one *.H file.
// forward declaration
class c;
class A
{
friend class C;
///
};
class B
{
///
class C
{
///
};
};
Otherwise, declare all three separately, and include C as the member of B.
|
|
|
|
|