|
You need to get the window to draw itself in order to save it. If it's not being drawn to the screen, where do you expect to pull the bitmap from ?
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Any one has idea for how to do this via code and the apis to use.
thanks in advance.
|
|
|
|
|
I have looked in C books but I cannot find threads available in C. So I guess I will have to use someone’s library to get thread functionality in my C programs. Can some please tell me from where can I download such a library? My basic problem is that I have made a real time scheduler in C with custom functions working as threads, the problem is that in order to have complete functionality of real time one must be able to stop the function at any time and latter resume them. That functionality is only possible with threads but simple C does not has this functionality built in. I have to compile it on windows. Please Help.
If such a solution is not possible then I will have to make a sort of a parser that will parse the functions and perform every single addition, multiplication, and division through a set of variables that I will consider registers. By storing those registers and resuming their value I might be able to achieve thread functionality. But there is another problem with that; firstly I store the functions as function pointers in an array, and latter after scheduling I pick them up from there. So is there a way that I can convert the contents of the function by that function pointer to a string so that latter I can parse the contents of the function or do I have to follow another approach. Please help with this problem as my deadline is nearing.
OnlyHuman23
|
|
|
|
|
|
I need to create an image list for a drag and drop thing I'm doing. I thought the problem was that I wasn't getting the wm_mousemove message. I was but it also wasn't create the image list. The code:
CImageList* m_pDragImage;
m_pDragImage = CreateDragImage( m_hItemDrag ); I know m_hItemDrag is good because I can do GetItemText(m_hItemDrag) and it gives me the proper text. CreateDragImage just returns NULL so something isn't working. Any ideas?
-Raffi
|
|
|
|
|
Right. What sort of an object are you working with? A CTreeCtrl ? A CListCtrl ? And do you have an image list associated with the control?
--------
PMGRE --Shog9 --
|
|
|
|
|
Does anyone know if it's possible to pass arguments to the constructor of array elements?
For example: I have a class Cfoo
class Cfoo
{
public:
Cfoo( int arg1 = 0 );
private:
int m_arg1;
}
I want to create an array of 200 Cfoo's, and initialise them with Cfoo(-1). I've tried
aFoo = new Cfoo(-1)[200];
aFoo = new Cfoo[200](-1);
I've run out of ideas
Is it impossible to call ctors on members of dynamically declared arrays?
TIA,
Pete
|
|
|
|
|
If you were to use vector, then it would be easy. But what you're trying to do is not possible AFAIK.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
just to expand on what the previous poster said:
here's an example (from google):
class Foo() { ... Foo(int, long, char, char*) { } ... };
vector<Foo> myArray(10, Foo(1, 2, 3, "hello"));
unless you have a *very* specific reason for using "new []", std::vector is usually a better way to go.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
well it should work
memset (aFoo, -1, 200);
i guess this should work...
bernhard
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
Thanks for the input guys.
It seems that most of my questions on CP these days lead to a new appreciation for the STL
Thanks again,
Pete
|
|
|
|
|
...does the following code hang and or lock up my app. I'm using the MSComm32 ocx for serial communications, and m_Comm is a member variable to my Control Class. If I trace out the "input" I'll see the correct data flowing through, and If I monitor the serial port it shows the connect but, my app just hangs there.
BOOL bConnected = FALSE;
CString sInput;
while(!bConnected)
{
if (m_Comm.GetInBufferCount() > 0)
{
sInput = m_Comm.GetInput();
sInput.MakeLower();
if (sInput.Find("connect") != -1)
bConnected = TRUE;
}
}
As far as I can tell, this should work. But it doesnt.
Thanks,
Frank
|
|
|
|
|
You've traced this through and sInput does indeed contain the word 'connect' ???
Why are you using a BOOL instead of a bool ?
Personally I'd also include a timeout in code like the above. What if m_Comm.GetInBufferCount() remains 0, or sInput.Find("connect") continues to be -1 ?
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Christian Graus wrote:
Why are you using a BOOL instead of a bool ?
This may sound stupid...but, um...what the difference?
Christian Graus wrote:
Personally I'd also include a timeout in code like the above. What if m_Comm.GetInBufferCount() remains 0, or sInput.Find("connect") continues to be -1 ?
Its in my TODO list.
Seriously, I've got 2 of these while loops. The only way I've even remotely been able to get them to exit properly is to include a 'break' after the if returns true.
Thanks Christian,
Frank
PS, whats the weather going to be like tomorrow?
|
|
|
|
|
Frank Deo wrote:
This may sound stupid...but, um...what the difference?
Fair enough. A BOOL is a typedef'd int, created for C programmers. C++ has an intrinsic bool type. It is more reliable, because it is only able to be set to true or false. An int can have any value, so checking for TRUE or FALSE may in fact not catch the value something is set to.
Frank Deo wrote:
The only way I've even remotely been able to get them to exit properly is to include a 'break' after the if returns true.
Have you tried setting a break point to see if any of the conditions you're checking for ever come about ?
Frank Deo wrote:
PS, whats the weather going to be like tomorrow?
*sigh* rain, rain, rain.....
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Christian Graus wrote:
A BOOL is a typedef'd int, created for C programmers. C++ has an intrinsic bool type. It is more reliable, because it is only able to be set to true or false. An int can have any value, so checking for TRUE or FALSE may in fact not catch the value something is set to.
Cool, thanks for the insight.
Christian Graus wrote:
Have you tried setting a break point to see if any of the conditions you're checking for ever come about ?
Yea. Everywhere. When the app locks, and I break it its always on the while statement (the top of it). Dunno why.
Thanks again Christian,
Frank
|
|
|
|
|
|
Hi,
i have 3 objects derived from CObject.
These objects are the data source for my tree control. I want to find out which object is selected so i tried to use RUNTIME_CLASS macro.
CObject *selectedItem = ( CObject * ) m_treeMain.GetItemData( m_treeMain.GetSelectedItem() );
if( selectedItem )
{
if( selectedItem->IsKindOf( RUNTIME_CLASS( CBand ) ) )
{
AfxMessageBox( "so far so good" );
}
}
This code causes two errors :
1) error C2039: 'classCBand' : is not a member of 'CBand'
2) error C2065: 'classCBand' : undeclared identifier
What is this classCBand anyway?
I included Band.h into this function's file. And when i replace CBand with another class name such as CObject or CTreeCtrl, it works. So what's wrong with my class? What should i do to retrieve the runtime class ?
Thanks in advance.
|
|
|
|
|
There is a macro you need to include in your class for this stuff to be declared. I was forced to use this crap by a former employer, it is at best a hack. You should instead use dynamic_cast, which works for anything, not just CObject derived stuff.
CBand *selectedItem = dynamic_cast<CBand*>( m_treeMain.GetItemData( m_treeMain.GetSelectedItem() ));
if( selectedItem )
{
AfxMessageBox( "so far so good" );
}
dynamic_cast returns NULL if the cast is invalid, otherwise the object requested. It also tells you at compile time if the cast you are attempting is unreasonable.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
If you use dynamic_cast, check up option "Enable Run-Time type info" in your project settings. It is switched off by default, AFAIK
|
|
|
|
|
That is true. I forgot that one, sorry.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Thank you both for your help. It's working fine now.
But i had to do a minor change in your code sample.
CBand *selectedItem = dynamic_cast<cband*>( (CObject*)
m_treeMain.GetItemData(
m_treeMain.GetSelectedItem() ));
if( selectedItem )
{
AfxMessageBox( selectedItem->GetBandName() );
}
I don't know why but it didn't directly cast from DWORD to CBand and gave the following message :
error C2681: 'unsigned long' : invalid expression type for dynamic_cast
So i decided to cast it to CObject* first. Frankly, i didn't quite understand why this change made it work, but it did, so i just moved on
Anyway, thanks again.
|
|
|
|
|
hi all,
I found an article about I have an excel automation dos based application . I take an article,
Automate excel from c++ without using mfc or #import (Q216686) as an example.
then based on another article Automate excel and then know the use closed it(Q192348)
I changed my code again. actually, i added,
<br />
<br />
HWND hWnd;<br />
char buf[1024];<br />
hWnd = ::FindWindow("XLMain",NULL);<br />
if(NULL==hWnd)<br />
{<br />
long lErr = GetLastError();<br />
sprintf(buf, "FindWindow Error code = %d",lErr);<br />
AfxMessageBox(buf);<br />
}<br />
<br />
DWORD pid;<br />
DWORD dThread;<br />
DWORD dwReason;<br />
dThread = ::GetWindowThreadProcessId(hWnd,&pid);<br />
HANDLE hProcess;<br />
hProcess = ::OpenProcess(SYNCHRONIZE|PROCESS_ALL_ACCESS,TRUE,pid);<br />
<br />
dwReason = ::WaitForSingleObject(hProcess,INFINITE);<br />
::CloseHandle(hProcess);<br />
everything is fine except
dwReason = ::WaitForSingleObject(hProcess,INFINITE);
is waiting forever because in windows task manager's processes tab, you will find EXCEL.EXE eventhough you have closed ms excel application.
if you command the line
dwReason = ::WaitForSingleObject(hProcess,INFINITE);
you will not find EXCEL.EXE in windows task manager's processes tab.
why is that?
|
|
|
|
|
can someone help me please
|
|
|
|
|
G'Day Win,
I use the same code successfully. What I discovered was that as I developed the application I would run it and terminate it prematurely with Excel open. This of course did not close down excel properly. So that when I started the application again I had 2 versions of excel running etc. Thus when I had a 'real' excel application running and I tested my program and shut excel down this code failed because I had closed down a different excel to the one being watched. I think this is what may be happening in your case. So terminate all excel processes with task manager, run excel and then your application and see if it works then.
Hope that is of some help,
Richard.
|
|
|
|