|
Is there a way to find out whether a rectangle or a point (given in screen coordinates) is contained in any monitor currently attached to the system?
The background of my question is this: During shutdown, my dialog based MFC application stores its current screen coordinates in the registry. When I open the application the next time, it fetches the coordinates and moves the window to where it had been during the most recent session.
If I move the dialog to my secondary monitor and close it, then unplug the monitor and restart the application, the dialog displays itself on an invisible part of the desktop . In this case, I'd prefer to use the default location - the center of the primary monitor.
|
|
|
|
|
There are several functions that would work.
MonitorFromPoint /MonitorFromRect will give you a handle to the monitor.
You can then use this handle in the function GetMonitorInfo to get more information.
Here is an example from MSDN on how it could be done -
Positioning Objects on a Multiple Display Setup[^]
|
|
|
|
|
Superman, that was a superfast and supergood answer. It works Thanks!
|
|
|
|
|
|
If say a process creates a semaphore/mutex etc then will this semaphore get created in its address space?
If yes then how an another process which wants to acquire this semaphore(created by the first process) will access the first process address space to acquire the semaphore?
Anybody can pls explain me this?
|
|
|
|
|
Semaphores, Mutexes etc. are kernel objects and memory is allocated in the kernel address space.
The processes that access these kernel objects which open handles to the objects.
The kernel object will be deallocated when the last handle referencing the object is closed.
|
|
|
|
|
superman does this reply my question?
|
|
|
|
|
Each process has its own handle table.
When you create a new mutex, memory is allocated elsewhere, but a handle is held within each process that references this mutex.
|
|
|
|
|
Thanks Superman for the inputs.
Ok so this means that the mutex/semaphore will not be allocated in the process address space but in some other shared address space where it will be shared by multiple process/threads. Am I correct?
So when an another thread/process tries to access a shared resource then it will see that the particular resource is protected by a certain mutex/semaphore and then it will try to get the handle to the mutex/semaphore using some mechanism. Is my thinking ok?
|
|
|
|
|
Process/Thread synchronization has to be handled by the programmer.
What I mean is that, for any shared resource intended to be protected by a mutex or semaphore, the wait functions[^] must be used on the handles of these objects so that these resources remain synchronized.
The wait functions will block access till a mutex or semaphore is release using ReleaseMutex or ReleaseSemaphore respectively.
|
|
|
|
|
Hi,
LoadAccelerators function is returning NULL value. im using the following code:
HACCEL m_hAccelTable1;
m_hAccelTable1 = LoadAccelerators(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR2));
GetLastError function is returning 1814 error value which states that "The specified resource name cannot be found in the image file". The accelerator table is present in the resource file. Anyone please tell me where i did the mistake?
Thanks,
|
|
|
|
|
Check if IDR_ACCELERATOR2 is the right value to pass.
You could even check if that is the right value by opening the .RC file in text mode.
|
|
|
|
|
It is there in the resource file:
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_ACCELERATOR2 ACCELERATORS DISCARDABLE
BEGIN
"V", IDC_BMP_VIEW, VIRTKEY, NOINVERT
END
|
|
|
|
|
Is the accelerator table resource part of the EXE project or any other DLL that the EXE loads?
|
|
|
|
|
it is in a dll,but i have added the accelerator table in dll only. Another exe loads it.
|
|
|
|
|
In that case the error is in using the AfxGetInstanceHandle function.
Instead use GetModuleHandle with the name of the DLL as parameter.
|
|
|
|
|
|
Is it posible to create accelerator keys in a dll?
|
|
|
|
|
Yeah, accelerator tables can be stored in executables (PE files) as resources (if that's what you're asking). In fact it where they're normally stored. They're loaded with the LoadAccelerators[^] function.
Steve
|
|
|
|
|
Check the HINSTANCE handle is referring to the correct DLL.
Steve
|
|
|
|
|
|
I am currently using the Visual Studio 2010 Release Candidate and have ordered a full version ... but ... my order seems to be stuck "On Order". The expected dispatch date is today but I am not holding my breath. I have eight days left on the RC and I am beginning to get a little nervous.
Does anyone know if I can upgrade from the RC to the trial version to cover the gap? Any experiences or pointers worth sharing?
Paul Hooper
If you spend your whole life looking over your shoulder, they will get you from the front instead.
|
|
|
|
|
Code:
class MyClass
{
public:
MyClass(int iType);
};
class YourClass
{
public:
YourClass();
MyClass mys[2];
};
How to init constructor of MyClass for array mys[2] at:
YourClass::YourClass()
{
}
Impossible?
modified on Sunday, June 20, 2010 7:44 PM
|
|
|
|
|
You can create an Init method and call it for each element in the array.
|
|
|
|
|
Good question. I can't believe I've never ran into this before. I don't see any clean way around it.
Steve
|
|
|
|