English 中文(简体)
Undo / Reset LetSetForegroundWindow(电话)
原标题:Undo / Reset AllowSetForegroundWindow() calls
  • 时间:2012-04-04 14:50:34
  •  标签:
  • c++
  • winapi

是否有办法发出<代码>的电话。 允许SetForegroundWindow(ASFW_ANY)?

大图片:

  • I want a single process of my exe running at a time.
  • To achieve it, the processes communicates with each other using named pipes & if a process already exists, its window has to be brought into front.
  • To be able to do this, the latest process must set AllowSetForegroundWindow() with the existing process id.
    • I do not want to fetch the process id (sorry for my laziness), so what I m planning to do is: 1. call AllowSetForegroundWindow() with ASFW_ANY 2. Just in case some error occurred, undo the call to AllowSetForegroundWindow() so that others cannot steal focus from my process.

简言之,我想允许其他进程从我那里偷走重点,在某个时间窗口中,只有......。

任何人都曾遇到过类似的问题,发现有任何工作关系?

另外,请让我知道,你是否有任何更好的建议。

最佳回答

根据号文件,目标过程(通常包括“任何”)将失去在你打电话<代码>后从你那里偷走重点的能力。 允许SetForegroundWindow。

In other words, it sounds like you can have only one such permission active at a time.

因此,你应该能够取消许可,要求获得一些不存在的身份证,或或许是你自己的程序。 然而,这是理论。

我个人只是把目标过程ID放在指定管道上。

问题回答

如果我理解你的主要要求,只有一次提出申请。 如果你所描述的一切只是符合这一要求的,而不是一些更伟大的计划的一部分,那么实现这一要求的途径就更加简单。

You can create a global named mutex when your application starts. All other instances will see this mutex as set, and simply quit immediately. Here s the quick and dirty of it:

// Multiple instances detection
HANDLE my_mutex = ::CreateMutex(NULL, FALSE, "Global\MyCuteFluffyMutex" );

int create_mutex_error = ::GetLastError();
bool already_running =
          ( my_mutex && ( create_mutex_error == ERROR_ALREADY_EXISTS ))
       || ( create_mutex_error == ERROR_ACCESS_DENIED );

if ( !already_running ) {
  // Run my application
}

::CloseHandle(my_mutex);

欲了解详情,请查阅





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签