|
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.
|
|
|
|
|
My VC++5 application has eight small toolbars. They're normally docked 4 to a line so that users see 2 rows of toolbars:
[bar1] [bar2] [bar3] [bar4]
[bar5] [bar6] [bar7] [bar8]
This looks great until the user adjusts the width of the main frame window. MFC then takes it upon itself to re-arrange these toolbars so that they all remain visible. For example, halving the window size might give:
[bar1] [bar2]
[bar3] [bar4]
[bar5] [bar6]
[bar7] [bar8]
Does anyone know how to ask/force MFC to stop doing this and leave the docked toolbars alone ?
|
|
|
|
|
|
Does anyone know how to pass a CRecordset pointer thro the clipboard to another application? I am able to pass the pointer using Global memory but the database handle gets screwed up.
|
|
|
|
|
I don't know what you mean with Global memory, as in Win32 you can't access memory owned by other processes. Anyway, you can't pass a pointer to an object to another process, as your application will crash when it tries to use it. Furthermore, you shouldn't pass a pointer to a CRecordset from one thread to another, as many of the CObject derived classes store data in the Thread Local Storage, and your app will crash after some time of well working.
Sorry for my English!
|
|
|
|
|
If you create a shared data segment in a DLL, then you CAN access and share memory among multiple processes in Win32.
Typically, these variables have constant lifetime - the entire time the DLL is loaded by any process.
I have not found a way to make 'dynamically allocated' shared memory available, however, without using memory mapped files.
The way I send data back and forth among threads is to create a data structure that contains the relevant data. Pass the pointer to the data structure to the other thread, and the object should have a member function or else a constructor that can accept a pointer to the data structure for copying the data to itself. So you have this assignment step, which is generally safe, it is just the CObject part of the object that usually does not transfer well among threads.
|
|
|
|
|
I need to disable the CD rom drive during my app runtime.
Does anybody know how can i do it without rebooting? Is there an API call or a registry key to set?
Thanks in advance
|
|
|
|
|
I want to write VxD to access the PCI Card. can anyone help me in DDK usage with Visual C++ 6.0.
if you can tell me the URLs from where i can get something for VxD writing.
|
|
|
|
|
I have created an image list with ILC_COLOR32.It is working propertly when my system supports 16777216 colors.When I change color support to 65536 colors, nothind is displayed.In this case case, the image list ceation is success, but Add() and Draw() fails.
|
|
|
|
|
Hi,
I am experiencing some strange problems. I am getting a whole bunch of access violations when I run
my program. The program doesn't crash but in the debug window you can see about 200 access violation
messages. I tracked this down to CMainFrame::OnCreate(). Infact, all of these access violations occur
at the point where the CToolBar's CreateEx function get called. Here is what App Wizard created for
my project for the CToolBar,
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
The Toolbar get created, but with a whole bunch of access violations along the way. Another thing,
this doesn't happen all the time. I would guess three out of five times I run the program, I get all of these
access violations. Anyway, I hope someone know why this is happening. I would really appreciate the help. Just in case someone was interested, here is a look at what the violation message looks like
First-chance exception in Plas.exe (GDI32.DLL): 0xC0000005: Access Violation.
Thanks
|
|
|
|
|
I don't know if this is the case, but I experieced some problems with AppWizard generated applications if they had a Toolbar but not a StatusBar, because even if I unselected the StatusBar in the Wizard page, some generated code still made use of it. Don't know why, but it's true.
It seems, however, that your problem is a little different. You wrote of the toolbar creation, so I thought of my past troubles with it.
Cheers,
Paolo
|
|
|
|
|
I am surprised that your program continues to run after an access violation. Perhaps VC 6 has something new for debugging that allows a program to continue execution in spite of an access violation; if so, I would not know about it since I still use VC 5. You might check to see if it is possible to get the debugger to stop when an access violation occurs. If you can do that then you can look at the stack and you might get a good indication of the problem.
Are you sure you are working with a debug version of your program? You should, if you are getting errors like that.
|
|
|
|
|
When you get your access violation don't cancel let it go into the debugger and look thru call stack window
and start putting break points in in only the cpp's that you made not the one's from MS.
|
|
|
|
|