|
AFAIK, only Vista+ gives you the ability to cancel a synchronous read operation
from another thread (see the CancelSynchronousIo() function).
The correct way to handle this would be to use overlapped I/O.
That would eliminate the need for a second thread as well.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes, as I dig into this I am coming to accept the inevitable.
Thank you once again for your help.
|
|
|
|
|
I am trying to restrict operation to a single instance of my program (per user). Specifically, I create a shortcut in the "Send To" folder. If the program (an MDI program based on the MFC Doc/View architecture) is NOT running, right-clicking on a file in the Send-To context menu correctly runs the program with the file name as a command line argument. It I select the program again from the context Send-To menu a new instance of my program starts. What I would like to happen is that the new file is opened by the running instance of the program in a new MDI window.
Could someone point me in the right direction for this? I did find code that prevents a second instance of the program from running. Unfortunately, it doesn't default to the OpenDocument option in the running instance of my program. (I'm using VS 2005, C++, MFC)
TIA
Ron
|
|
|
|
|
First, maybe check this out: Avoiding Multiple Instances of an Application[^]
Once you determine an instance of your application is already running,
you'll need a way to pass the commandline parameters from the
process launched by the Windows shell to the already-running process.
Some form of interprocess communication can do this, like a named pipe
or sockets. See Interprocess Communications[^]
When the already-running instance of the application receives a command
from the shell-launched instance, then it can open the file as usual.
The shell-launched instance can terminate.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I have a FormView based SDI App with three modeless dialogs embedded in a CTabCtrl. Sometimes I am getting the Program Shutdown while the mouse pointer placed on toolbar. Though this is not happening always, but sometimes the program halts by displaying illegal operation. I know that this happens bcoz of the modeless dialog. It happens that since the focus is changed from child window to toolbar some wierd things are happening.
Any help in this regard is highly appreciated. To give you more info, The Codeproject's CHyperbar Control in Ultimate Toolbox explain this scenario, but I could n't find out any solution.
I remain,
Shanmukha
|
|
|
|
|
hi all
I want to make a search engine using VC++, can any one help me please by any information about this subject?
Thank you
|
|
|
|
|
Do you want to search on the computer?
|
|
|
|
|
hi guys
i have a dialog which has a background image, there is a button and a listctrl, i want to make the button and listctrl semi transparent or transparent so that the dialog background will be visible through listctrl, i can set a background image in list ctrl but tht i dont want.
Swarup
|
|
|
|
|
swarup wrote: ...i want to make the button...transparent...
See here.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hi guys
i have a dialog based application, when i run a time consuming operation, the dialog box hang, becas unless the operation completes my dialog box wont have any focus or will nt be able to recieve any message.
Example: i have a listctrl where i add 10000 records, so unless all records are added my dialog will nt respond. where as while those records being added i want my dialog box to be responsive, i cant let the user to wait till the operation gets over,
any idea,
there is a code sample called backgroundtask dialog here CP, i dont want that way.
Swarup
|
|
|
|
|
|
Doing your lengthy process on a separate thread is the recommended way
to go.
If you don't want to use multiple threads, then your lengthy process needs
to periodically pump all Windows messages so the UI will remain
responsive.
Here's an example MFC message pump (implemented in the application class)
void CMyWinApp::PumpWaitingMessages()
{
MSG msg;
while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if ( !PumpMessage( ) )
{
break;
}
}
}
A Win32 message pump could be something like
MSG msg;
while ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
Note that you'll want to disable any UI components that you don't want the user
to mess with during the lengthy process.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello everyone,
In the case when function in derived class is virtual, but function in base class is not virtual, when we make base class pointer pointing to derived class' instance, the function in base will be invoked.
I am confused why not the function in Derived class is invoked (this is my question).
When making base pointer pointing to derived class' instance, the layout of derived class should begin with vtable of functions of derived class (virtual function of foo in Derived class in the sample), and the base pointer is pointing to the layout, so when invoking the derived class version function could be found in vtable and it should be invoked. How compiler process this situation internally?
class Base {
public:
void foo()
{
cout << "Base foo " << endl;
}
};
class Derived: public Base {
public:
virtual void foo()
{
cout << "Derived foo " << endl;
}
};
int main()
{
Derived d;
Base* pb = dynamic_cast<base*>(&d);
pb->foo();
pb = static_cast<base*>(&d);
pb->foo();
pb = &d;
pb->foo();
return 0;
}
</base*></base*>
thanks in advance,
George
|
|
|
|
|
Hi,
If my memory serves me well,
Because the foo function of the base class isn't virtual, the address isn't placed in the virtual function table. So when te linker needs to link all functions it knowns to uses the known base::foo address. So when you cast an derived object back to the base class it behaves as an object of the base class. It doesn't matter whether there is a function Derived:foo in the vtable the compiler/linker is hardlinked to Base::Foo.
codito ergo sum
|
|
|
|
|
It's nothing to do with the linker. The pointer pb is a pointer to a Base and in Base the foo function isn't virtual .
Steve
|
|
|
|
|
I agree, thanks Steve!
regards,
George
|
|
|
|
|
Thanks BadKarma,
My question is answered.
regards,
George
|
|
|
|
|
pb is a pointer to a Base , and in the Base class the foo function isn't virtual . This is exactly the behaviour you'd expect.
Steve
|
|
|
|
|
Thanks Steve,
My question is answered.
regards,
George
|
|
|
|
|
dear all friends
the following is my code..i would like to assign value of one array to another array, but why gbest_Ind couldn't be assigned value from p? thanks for your help.
minValue = fitness[0];//fitness is a 10 elements array
for (int count = 0;count<10;count++)
{
if (fitness[count] == minValue )
{
minValue = fitness[count];
gbest_Ind = count;//gbest_Ind is an array of [1][3][4]
}
}
for (int j = 0; j<3; j++)
for (int k = 0; k<4; k++)
{
gbest1[gbest_Ind][j][k]=p[gbest_Ind][j][k];//p is an array of [10][3][4],
}
Li Zhiyuan
|
|
|
|
|
gbest_Ind = count;//gbest_Ind is an array of [1][3][4]
is gbest_Ind an array like your comment suggests or is it an int like this line of code suggests?
|
|
|
|
|
gbest_Ind is an int variable which declared in header file,sorry for my previous mistake
and gbest1 is a [1][3][4] array
Li Zhiyuan
|
|
|
|
|
gbest1[gbest_Ind][j][k]=p[gbest_Ind][j][k];//p is an array of [10][3][4],
and
gbest1 is an array of [1][3][4], so the only valid value for gbest_Ind is 0?
|
|
|
|
|
no, actually gbest_Ind valid value is from 0-9, i just want to use one of 10,and then assign one of 10 p value to gbest1[1][3][4], here when gbest_Ind get a value, and then p [10][3][4] use this value to assign the array to gbest1[1][3][4],how to do it? thanks a lot, i cost two days already, still couldn't get solution.
Li Zhiyuan
|
|
|
|
|
Still not sure what the problem is but, try this
this supposes that array p and array gbest1 are declared something like array[10][3][4]
minValue = fitness[0];
for (int count = 0;count<10;count++)<br />
{ <br />
if (fitness[count] <= minValue )
{<br />
minValue = fitness[count];<br />
gbest_Ind = count;
}<br />
}<br />
<br />
for (int j = 0; j<3; j++)<br />
{
for (int k = 0; k<4; k++)<br />
{<br />
gbest1[gbest_Ind][j][k]=p[gbest_Ind][j][k];
} <br />
}
|
|
|
|