|
I'm an f-ing idiot at times....
First problem - you've made your image-list local to the PopulateList function - it needs to be alive as long as the list control is alive (makes sense?), so declare it at class scope with the list control variable.
Second problem - the image index refers to the optional icon that can be to the left of the text in the first column. You can only put text in the rest of the columns - that's the bit I should have remembered
To get images in an arbitrary column, you need to use custom-draw. Or a ready-written list control sub-class, like the ones here on CodeProject[^]. This one[^], for example, allows images in any column.
|
|
|
|
|
Thanks again.
I'm still trying to work out the solution after shifting everything to the CQuickList class. Took me a while to figure out how to use the class even with the webpage.
Thanks.
|
|
|
|
|
Hello,
I need to create a transparent overlay window, that goes above another window. The other window is from another vendor. And when the user drags that window mine needs to follow.
WS-CHILD seems like a nice idea but it cannot be combined with WS-EX-LAYERED, which I really need (for transparency). But I still can set a parent without using WS-CHILD.
Parenting does give my winproc notifications (WM-WINDOWPOSCHANGING), but only after dragging is complete, on mouse-up. To give a nice feeling i need to get those notifications (or for example WM-MOVE) continuosly while dragging.
I guess my problem is similar to docking, but the fine docking solution seen fx at CodeProjet uses WS-CHILD. ( http://www.codeproject.com/KB/toolbars/dockwnd.aspx )
I know I could use ::SetWindowsHook(). But that is my final resort. And I guess I could use polling but that is not what I am looking for. I am hoping I have missed something trivial and that somebody can point me in a good direction.
Thanx
........................
Life is too shor
|
|
|
|
|
|
|
|
Currently I'm developping a MFC MDI application using document/view architecture.
I have a CWinThread running in a MDI child window. To stop it prematurely, I use two BOOL variables, bThreadMustStop to request the termination of the thread and another variable bThreadStopped to check if the thread is stopped.
My headaches start when the user closes the MDI child window while the thread is running.
I know several places from where I can control what's going on:
CWinApp::SaveAllModified
CDocument::SaveModified
CChildFrame::OnSysCommand
and several others.
Currently I'm using CChildFrame::OnSysCommand.
Normally I set the bThreadMustStop to TRUE, then enter a loop waiting for bThreadStopped to become TRUE. Just one problem, while the system is executing OnSysCommand, the thread is not running, I don't know why. Because the thread is not running, it cannot read the bThreadMustStop variable, cannot exit and set the bThreadStopped to TRUE so my waiting loop runs infinitely.
To detect if the thread or my waiting loop is running I used TRACE1 statements (with a counter variable). The thread never runs while the waiting loop is running from the inside of OnSysCommand.
Supposing Windows suspended my thread, I tried to call ResumeThread to force the thread to resume, but it returned 0 (thread not suspended).
If I don't wait for the thread termination or if I wait just a limited amount of time, after exiting OnSysCommand, the application will crash. That's because the thread will start running again and will try to acces the objects of a destroyed document.
My question is, what the hell is my thread doing during the execution of CChildFrame::OnSysCommand ? What's its state ? How can I restart it while I'm in OnSysCommand ? What other options do I have to stop the thread and destroy the window gracefully ?
|
|
|
|
|
CString(0xcccccccc) wrote: Normally I set the bThreadMustStop to TRUE, then enter a loop waiting for bThreadStopped to become TRUE
Don't. Set bThreadMustStop to TRUE with InterlockedExchange[^], then wait for the thread to exit using <a href="http://msdn.microsoft.com/en-us/library/ms687032.aspx" rel="nofollow">WaitForSingleObject</a> [^], like this:
InterlockedExchange((LONG*)&bThreadMustStop, (LONG)TRUE);
WaitForSingleObject(hThread, INFINITE); The <a href="http://msdn.microsoft.com/en-us/library/ms687032.aspx" rel="nofollow">WaitForSingleObject</a> yields control to the kernel, allowing the thread to get some processor time, so it can read the flag and then exit. The act of the thread exiting will cause the thread handle to enter a signalled state, terminating the <a href="http://msdn.microsoft.com/en-us/library/ms687032.aspx" rel="nofollow">WaitForSingleObject</a> call.
|
|
|
|
|
Hi All
How can i check text file is open or not?
|
|
|
|
|
By some other applications?
|
|
|
|
|
Try and open it with CreateFile[^], specifying 0 (no sharing) for the dwShareMode parameter. If the file is already open, CreateFile will return INVALID_HANDLE_VALUE and GetLastError will return ERROR_SHARING_VIOLATION.
The code below will fail, printing the value of ERROR_SHARING_VIOLATION if the file a.a is already open.
HANDLE f = CreateFile("a.a", GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (f == INVALID_HANDLE_VALUE)
{
std::cout << GetLastError() << std::endl;
return 0;
}
|
|
|
|
|
You may find your answer over here[^].
Do not trust a computer...
Always check what computer is doing
regards,
Divyang Mithaiwala
Software Engineer
|
|
|
|
|
I don't think that your sample is written in MFC ... but is good to see the solution way.
|
|
|
|
|
hi,
i know how to count number of objects created for class using static variable,
but i came to know that there is other way i.e using container class,
can any one specify how it is and if any code it will be helpfull or even links are
accepted..
iam attending interviews these questions asked for me.. so please helpme.. ( i answered this but dont know how to write code for this).
|
|
|
|
|
Have you heard about Google [^]?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hello pallini ,
i know google is there then y is code project is there c i can even post here right which i fell is the best so never try to answer like this is u dont feel of answering then please never ever try.
( i belive in code project and myself and also internet so no need of ur answers any more)hope u got what i mean.
then if google is there then y code project is needed ?
|
|
|
|
|
hawk23reddy wrote: so never try to answer like this is u dont feel of answering then please never ever try.
And why? Is it the "hawk23reddy's rule"? Do you really think I will follow it?
hawk23reddy wrote: i belive in code project and myself and also internet so no need of ur answers any more
I'm happy about.
hawk23reddy wrote: hope u got what i mean.
Possibly, you know, I'm a "rather dull child"...
hawk23reddy wrote: then if google is there then y code project is needed ?
Both are useful. And they are more useful if you post the right question to the right one, I suppose.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
thankx,, what to do myan iam poor in lang...
|
|
|
|
|
hawk23reddy wrote: thankx,, what to do myan iam poor in lang...
I don't know. On the other hand, I'm pretty sure that your previous post was a bit rude. Anyway I don't care.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
a container or collection holds/stores a number of objects.
The STL library provides a number of containters.
#include <vector>
class MyObject
{
public:
MyObject() {}
void DoSomething() {}
};
void main()
{
std::vector<MyObject*> vecList;
vecList.push_back(new MyObject);
vecList.push_back(new MyObject);
vecList.push_back(new MyObject);
int count = vecList.size();
}
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
Create a static int variable inside the class.
Increment it in the constructor and decrement it in the destructor.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
hi
this code causes segmentation fault can u pleases y.
class ab
{
public:
virtual void abb()=0;
};
class bc : public ab
{
public:
void abb()
{
cout<<"here";
}
};
void get(ab* c)
{
bc *cc = new bc();
c = cc;
}
int main()
{
ab *b = NULL;
get(b);
b->abb();
}
but how can i solve this so that i need to fill derived class object (reference or pointer) to base class in get function only..
[my request]
if u feel iam very poor in basics
for give me plz by only this
i can learn more and attain like u
[/my request]
modified on Tuesday, May 19, 2009 2:03 AM
|
|
|
|
|
First of all, you have forgotten to derive bc from ab here.
hawk23reddy wrote: class bc
Secondly, change the signature of get from
hawk23reddy wrote: void get(ab* c)
to
hawk23reddy wrote: void get(ab** c)
and while calling get, pass address of b as argument.
|
|
|
|
|
Try this:
...
void get(ab* &c)
...
Research passing arguments to functions and especially passing arguments by reference.
|
|
|
|
|