|
|
amitmistry_petlad wrote: When user try to stretch the window with any boundary of window it can resize accordingly. Please can any body help me for doing so?
I guess you want to do layout management...
See here[^].
|
|
|
|
|
I have a VC++ SDI motor control application that communicates with a motor control board over a serial cable. The application is multi-threaded. Communication with the board uses sending and receiving threads. I can send commands and receive status without issues. The design is a 2 pane, split-window application. Generally the leftmost pane is a FormView containing motor controls and the rightmost pane is a CScrollView to show motor status graphically.
The OpenLp feature of the App allows the user to manipulate sliders in the leftmost pane while viewing actual motor speed in the rightmost pane. This portion of the App is selected via a menu {Window/OpenLp} which starts a thread to periodically update the right pane by issuing motor commands to get status and calling UpdateAllViews() to show the results.
My problem: When I try to use a periodic call to UpdateAllViews(NULL) within this thread to accomplish the graphics in the rightmost pane it causes an immediate ASSERT.
Line: (ASSERT(pMap != NULL);
Routine: CWnd::AssertValid()
File:
|
|
|
|
|
Ack! Doc/view architecture really gets in the way here
Dalfxxx wrote: Q1: Can UpdateAllViews(NULL) be called in a thread that is not the main thread?
Not safely
Dalfxxx wrote: does anyone have a suggestion as to how I can accomplish the graphics?
You're going to have these problems using MFC because windows are associated with the thread they
are created in.
There's nothing wrong with updating windows on different threads BUT it's up to you to synchronize
access to GDI, which is NOT thread safe. This would apply even if UpdateAllViews worked.
Assuming you've made your painting thread safe, you could
1) Provide a direct method in the window classes to do redrawing
2) Use Invalidate()/UpdateWindow() combination to force the windows to be redrawn immediately via
WM_PAINT
3) Just use Invalidate() on the widows and let the UI thread post the WM_PAINT messages.
etc...
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Usually, I implement a special custom message in the mainframe window that will call UpdateAllViews and I post this message to the mainframe window from the other worker threads. This gets the 'porocessing' of the views into the main UI thread - away from the worker threads.
|
|
|
|
|
I completely agree. Much of my personal window refreshing is realtime multimedia-related so
I'm pretty used to multithreaded GDI The postmessage is certainly the easiest and safest
IMO.
Cheers!
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Mark,
Thank you very much for your reply. You have enabled me to take a different approach and stop banging my head against the wall. I have tried replacing the UpdateAllViews() call with a call to InvalidateRect(NULL,NULL,TRUE). I think that this is what you suggest in (3) and it appears to work - although it appears to expose some other problems which I can probably take care of.
Could you elaborate a bit on your comment:
"Assuming you've made your painting thread safe"?
My OnDraw code (which I don't call directly) uses MoveTo(), LineTo(), TextOutA(), CreatePen(), etc. I can visualize two or more threads using this code because of WM_PAINT. Is this what you meant? Can I make the OnDraw code "thread safe" by using a CriticalSection? If not, what would you suggest?
Thanks Again,
Stan
|
|
|
|
|
Dalfxxx wrote: Could you elaborate a bit on your comment:
"Assuming you've made your painting thread safe"?
I meant if you are calling your painting method(s) directly from multiple threads then any GDI
calls there need to be synchronized. A critical section works fine
If you're relying on WM_PAINT (which is the case if you use InvalidateRect() to mark the window
for repainting) then you should be ok. All of those messages will go through your UI thread.
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Hi, I got a question about Named pipe question on WIndows wondering anyone can help me.
I am doing some studies for Named Pipe and I want to try to make two processes on Windows talk to each othe. From MSDN I saw this example
http://msdn2.microsoft.com/en-us/library/aa365588.aspx
With minor changes I got it (server and client)working on XP using VS 2005 Express.
My questions are,
1. The named pipe is defined by :
LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\mynamedpipe");
Since named pipe is part of the file system, how can I actually see the file. I think in UNIX, you can actually use "ls " to see the pipe file, can I do that in Windows?
2. I am new to this, but if named pipe is part of the file system, what happens if the server crashes? the file will still be left out there? worst, power failure?
Thanks for you help
|
|
|
|
|
mhp130 wrote: Since named pipe is part of the file system, how can I actually see the file. I think in UNIX, you can actually use "ls " to see the pipe file, can I do that in Windows?
I don't believe it's part of the file system. Named pipes are used for interprocess
communication. Thanks to "opaque" handles, the common ReadFilexx/WriteFilexx APIs can be used
for pipe communication (as well as sockets). Anyway, the name doesn't specify a file.
It's used to uniquely identify a pipe by combining a server/machine name with a unique name.
mhp130 wrote: what happens if the server crashes?
You'd probably get a broken pipe (or other) error on the next read/write operation.
I suppose if we were meant to see the data between endpoints they would have called them
perforated pipes
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
I created an application that contains a dialog box and a menu. This dialog box contains a tab control with two tabs. Each tab contains a dialog box. How can I associate the menu with the dialog boxes on the tab control?
Thanks
Trevy
|
|
|
|
|
Trevy wrote: How can I associate the menu with the dialog boxes on the tab control?
Only Popup windows can have menus.
AFAIK if it's on a tab control then it's not a popup window.
|
|
|
|
|
I have a class A and it has x,y and z integer attributes
I have created a list sequence container which has a type A
list<a*> alist
I want to sort the elements in this list according to y value. How can i do that?
alist.sort() only sorts the elements according to the first attribute defined in the constructor.
|
|
|
|
|
You have a number of options. The first is to define an operator < for your class:
bool operator<(const A &lhs, const A &rhs)
{
return lhs.y < rhs.y;
}
You would make it a friend of class A if it needs access to private members of the class.
Another option is to define a predicate function and pass it to the std::list<...>::sort function. This option would enable you to have multiple sort orders. Example:
class A
{
public:
static bool SortByYPred(const A &lhs, const A &rhs)
{
return lhs.y < rhs.y;
}
};
Now call std::list<...>::sort like this:
alist.sort(&A::SortByYPred);
mehmetned wrote: alist.sort() only sorts the elements according to the first attribute defined in the constructor.
The constructor has nothing to do with sort order.
Steve
|
|
|
|
|
How do we convert from base class object to sub class object in c++?
|
|
|
|
|
A cast will do the trick (pBase is a pointer to the base class).
The fastest way if you're sure it's safe:
static_cast<Dervied*>(pBase);
The safest way (runtime checked):
dynamic_cast<Dervied*>(pBase);
You could use Boost's polymorphic_downcast[^] for a solution that uses dynamic_cast in debug builds and static_cast in release builds.
Steve
|
|
|
|
|
Hi
I Have a MFC dll .. that will be called.. by another progam written in PASCAL,
my dll has a function that has tu return a bitmap, or a pointer to an byte array or something of the bitmap
I Hva e a BITMAPINFO and a BITMAPFILEHEADER i need to put those in a memory buffer and return it.. so if the guy to which i return it wants to dump it to a file.. to be a wealthy .bmp file
cand anyone show how to do it please??
|
|
|
|
|
CFile file;<br />
<br />
if( !file.Open( _T("C:\\Temp.bmp"), CFile::modeWrite|CFile::modeCreate) )<br />
return bRet;<br />
<br />
BITMAPFILEHEADER hdr;
LPBITMAPINFOHEADER lpbi;
<br />
<br />
int nColors = 1 << lpbi->biBitCount;<br />
<br />
hdr.bfType = ((WORD) ('M' << 8) | 'B');
hdr.bfSize = GlobalSize (hDIB) + sizeof( hdr );<br />
hdr.bfReserved1 = 0;<br />
hdr.bfReserved2 = 0;<br />
hdr.bfOffBits = (DWORD) (sizeof( hdr ) + lpbi->biSize +<br />
nColors * sizeof(RGBQUAD));<br />
<br />
file.Write( &hdr, sizeof(hdr) );<br />
<br />
file.Write( lpbi, GlobalSize(hDIB) );<br />
<br />
file.Close();
|
|
|
|
|
thanks for repley
but i dont wanna write it down to a hard drive... i just wanna have it as a full .bmp file but in memory
you see i will proces 14 frames per sec.. so using the HDD will slow me down.. i need to compose those bitmap form the structures in memory , i mean put it in a buffer or something
|
|
|
|
|
so instead of writing it to hard drive, pass the buffer (pointer) to the recipient.
|
|
|
|
|
what buufer... u are using.,, File.Write method for writing header and then info
but i want to return a pointer to a buufer witch contains both header and info one after another..
where is the buffer of CFile??
|
|
|
|
|
hi,
i hav to implement a sliger for the GUI of my project in VC++
can u help me in its implementation plaese....
|
|
|
|
|
Have you seen this? Trackbar Control Reference[^]
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Use:
HWND hwndTrack = CreateWindowEx(..., TRACKBAR_CLASS, ...);
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Newbie question.
If an application has an SDK for C++, does it matter which version of VC++ I use to create an app using that SDK (as long as I am not using CLR in VS2005)? I am under the impression that it doesn't because it is still C++. On the other hand, I have heard there are some differences between the compilers, so I am not sure.
Thanks for your help with this simple (-minded) question
Brad
The secret to creativity is knowing how to hide your sources. - Albert Einstein
|
|
|
|