<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3888093</guid>
        <pubDate>Fri, 17 Mar 2023 12:57:59 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3888093</link>
        <description><![CDATA[macomics: А просто повесить на окно дополнительную функцию-фильтр не катит? <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">oldWindowProc = SetWindowLongPtr(hWnd, GWL_WNDPROC, &amp;newWndProc);</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script> А после в новой функции вызываете старую, отправляя ей не обрабатываемые сообщения<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">//Вместо return DefWindowProc(hWnd, uMsg, wPar, lPar);</div><div class="code_line">return CallWindowProc(oldWindowProc, hWnd, uMsg, wPar, lPar);</div></ol></div></div></div></div>]]></description>
        <author>macomics</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3888061</guid>
        <pubDate>Fri, 17 Mar 2023 08:03:44 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3888061</link>
        <description><![CDATA[izumov: Мое затруднение состоит в том что я не могу определить место нахождения wndProc в моем проекте сделанном в visual studio по шаблону CppCLR_WinForms_GUI.<br>Могли бы Вы мне подсказать в каком месте проекта я могу увидеть эту функцию и скорректировать ее?]]></description>
        <author>izumov</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887904</guid>
        <pubDate>Wed, 15 Mar 2023 16:30:48 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887904</link>
        <description><![CDATA[Qraizer: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=433593&view=findpost&p=3887903'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Qraizer &#064; <time class="tag-quote__quoted-time" datetime="2023-03-15T15:31:17+00:00">15.03.23, 15:31</time></span><div class='quote '>Если запустите несколько экземпляров ожидающего, окна будут дублированы.</div></div>P.S. То же, прочем и для threadClient.exe.]]></description>
        <author>Qraizer</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887903</guid>
        <pubDate>Wed, 15 Mar 2023 15:31:17 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887903</link>
        <description><![CDATA[Qraizer: :angry: Нате на нитках. Ожидающее приложение:<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#include &#60;windows.h&#62;</div><div class="code_line">#include &#60;iostream&#62;</div><div class="code_line">#include &#60;functional&#62;</div><div class="code_line">#include &#60;stdexcept&#62;</div><div class="code_line">#include &#60;thread&#62;</div><div class="code_line">#include &#60;mutex&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">UINT &nbsp;usrMsg;</div><div class="code_line">MSG &nbsp; msg;</div><div class="code_line">DWORD msgThread = 0;</div><div class="code_line">&nbsp;</div><div class="code_line">class Guard</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;std::function&#60;void(void)&#62; fn;</div><div class="code_line">&nbsp;</div><div class="code_line">public:</div><div class="code_line">&nbsp;&nbsp;Guard(const std::function&#60;void(void)&#62;&amp; f): fn(f) {}</div><div class="code_line">&nbsp;~Guard() { fn(); }</div><div class="code_line">};</div><div class="code_line">&nbsp;</div><div class="code_line">std::mutex modal;</div><div class="code_line">&nbsp;</div><div class="code_line">void wndProc(UINT uMsg, WPARAM, LPARAM lParam)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;if (uMsg == usrMsg) modal.lock(), MessageBox(NULL, &quot;сообщение получено&quot;, &quot;threadClient&quot;, MB_OK), modal.unlock();</div><div class="code_line">&nbsp;&nbsp;if (lParam == 1) PostQuitMessage(0);</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">using namespace std::literals;</div><div class="code_line">&nbsp;</div><div class="code_line">void workThread(void) try</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;msgThread = GetCurrentThreadId();</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;HMODULE &nbsp; kernel(LoadLibrary(&quot;KernelBase.dll&quot;));</div><div class="code_line">&nbsp;&nbsp;Guard &nbsp; &nbsp; freeKernel([&amp;]{ FreeLibrary(kernel); });</div><div class="code_line">&nbsp;&nbsp;HRESULT (*SetThreadDescription)(HANDLE, PCWSTR) = nullptr;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;if (kernel == NULL) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw std::runtime_error(&quot;KernelBase.dll isn&#39;t load&quot;s);</div><div class="code_line">&nbsp;&nbsp;SetThreadDescription = reinterpret_cast&#60;HRESULT (*)(HANDLE, PCWSTR)&#62;(GetProcAddress(kernel, &quot;SetThreadDescription&quot;));</div><div class="code_line">&nbsp;&nbsp;if (SetThreadDescription == nullptr)throw std::runtime_error(&quot;SetThreadDescription() isn&#39;t found&quot;s);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;if (FAILED(SetThreadDescription(GetCurrentThread(), L&quot;working message thread&quot;)))</div><div class="code_line">&nbsp;&nbsp; &nbsp;throw std::runtime_error(&quot;SetThreadDescription() fails&quot;s);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;while (GetMessage(&amp;msg, reinterpret_cast&#60;HWND&#62;(-1), 0, 0))</div><div class="code_line">&nbsp;&nbsp; &nbsp;wndProc(msg.message, msg.wParam, msg.lParam);</div><div class="code_line">}</div><div class="code_line">catch(const std::exception&amp; exc)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;std::cerr &#60;&#60; exc.what() &#60;&#60; std::endl;</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">int main()</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;usrMsg = RegisterWindowMessage(&quot;Message for client&quot;);</div><div class="code_line">&nbsp;&nbsp;if (usrMsg == 0)</div><div class="code_line">&nbsp;&nbsp; &nbsp;return std::cout &#60;&#60; &quot;RegisterWindowMessage() fails&quot;,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;INPUT_RECORD inp;</div><div class="code_line">&nbsp;&nbsp;DWORD &nbsp; &nbsp; &nbsp; &nbsp;readed;</div><div class="code_line">&nbsp;&nbsp;std::thread &nbsp;working(workThread);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;for (;;)</div><div class="code_line">&nbsp;&nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp;if (ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &amp;inp, 1, &amp;readed) == 0) break;</div><div class="code_line">&nbsp;&nbsp; &nbsp;if (inp.EventType == KEY_EVENT &amp;&amp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;inp.Event.KeyEvent.bKeyDown == TRUE &amp;&amp; inp.Event.KeyEvent.uChar.AsciiChar == &#39;\x1B&#39; &amp;&amp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; (inp.Event.KeyEvent.dwControlKeyState &amp; (LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED |</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RIGHT_ALT_PRESSED| RIGHT_CTRL_PRESSED|</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ENHANCED_KEY &nbsp; &nbsp; | SHIFT_PRESSED)) == 0) break;</div><div class="code_line">&nbsp;&nbsp;}</div><div class="code_line">&nbsp;&nbsp;while (msgThread == 0 || !modal.try_lock()) Sleep(0);</div><div class="code_line">&nbsp;&nbsp;PostThreadMessage(msgThread, WM_COMMAND, 0, 1);</div><div class="code_line">&nbsp;&nbsp;modal.unlock();</div><div class="code_line">&nbsp;&nbsp;working.join();</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;return 0;</div><div class="code_line">}</div></ol></div></div></div></div>Посылающее приложение.<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#include &#60;windows.h&#62;</div><div class="code_line">#include &#60;tlhelp32.h&#62;</div><div class="code_line">#include &#60;stdexcept&#62;</div><div class="code_line">#include &#60;iostream&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">using namespace std::literals;</div><div class="code_line">&nbsp;</div><div class="code_line">template &#60;typename H, HANDLE Inv = NULL&#62;</div><div class="code_line">class Resource</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;H handle;</div><div class="code_line">&nbsp;</div><div class="code_line">public:</div><div class="code_line">&nbsp;&nbsp;explicit Resource(H h): handle(h) { if (handle == Inv) throw std::runtime_error(&quot;NULL handle&quot;s); }</div><div class="code_line">&nbsp;&nbsp;Resource(const Resource&amp;) &nbsp; &nbsp; &nbsp; = delete;</div><div class="code_line">&nbsp;&nbsp;void operator=(const Resource&amp;) = delete;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;operator H() const { return handle; &nbsp; &nbsp; &nbsp; }</div><div class="code_line">&nbsp;</div><div class="code_line">protected:</div><div class="code_line">&nbsp;~Resource() {}</div><div class="code_line">};</div><div class="code_line">&nbsp;</div><div class="code_line">template &#60;HANDLE Inv = NULL&#62;</div><div class="code_line">class Handle: public Resource&#60;HANDLE, Inv&#62;</div><div class="code_line">{</div><div class="code_line">public:</div><div class="code_line">&nbsp;&nbsp;explicit Handle(HANDLE h): Resource(h) {}</div><div class="code_line">&nbsp;~Handle() { CloseHandle(*this); }</div><div class="code_line">};</div><div class="code_line">&nbsp;</div><div class="code_line">class Hmodule: public Resource&#60;HMODULE&#62;</div><div class="code_line">{</div><div class="code_line">public:</div><div class="code_line">&nbsp;&nbsp;explicit Hmodule(HMODULE h): Resource(h) {}</div><div class="code_line">&nbsp;~Hmodule() { FreeLibrary(*this); }</div><div class="code_line">};</div><div class="code_line">&nbsp;</div><div class="code_line">class Wchar: public Resource&#60;wchar_t*&#62;</div><div class="code_line">{</div><div class="code_line">public:</div><div class="code_line">&nbsp;&nbsp;explicit Wchar(wchar_t *h): Resource(h) {}</div><div class="code_line">&nbsp;~Wchar() { LocalFree(*this); }</div><div class="code_line">};</div><div class="code_line">&nbsp;</div><div class="code_line">int main() try</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;UINT usrMsg = RegisterWindowMessage(&quot;Message for client&quot;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;if (usrMsg == 0)</div><div class="code_line">&nbsp;&nbsp; &nbsp;return std::cout &#60;&#60; &quot;RegisterWindowMessage() fails&quot;,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;Handle&#60;INVALID_HANDLE_VALUE&#62; snapShot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD, 0));</div><div class="code_line">&nbsp;&nbsp;PROCESSENTRY32 proc = { sizeof(proc) };</div><div class="code_line">&nbsp;&nbsp;DWORD &nbsp; &nbsp; &nbsp; &nbsp;procId = 0;</div><div class="code_line">&nbsp;&nbsp;Hmodule &nbsp; kernel(LoadLibrary(&quot;KernelBase.dll&quot;));</div><div class="code_line">&nbsp;&nbsp;HRESULT (*GetThreadDescription)(HANDLE, PWSTR*) = nullptr;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;if (kernel == NULL) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw std::runtime_error(&quot;KernelBase.dll isn&#39;t load&quot;s);</div><div class="code_line">&nbsp;&nbsp;GetThreadDescription = reinterpret_cast&#60;HRESULT (*)(HANDLE, PWSTR*)&#62;(GetProcAddress(kernel, &quot;GetThreadDescription&quot;));</div><div class="code_line">&nbsp;&nbsp;if (GetThreadDescription == nullptr)throw std::runtime_error(&quot;GetThreadDescription() isn&#39;t found&quot;s);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;if (Process32First(snapShot, &amp;proc) != FALSE)</div><div class="code_line">&nbsp;&nbsp; &nbsp;do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (proc.szExeFile == &quot;threadClient.exe&quot;s)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;procId = proc.th32ProcessID;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;while (Process32Next(snapShot, &amp;proc) != FALSE);</div><div class="code_line">&nbsp;&nbsp;if (procId == 0) throw std::runtime_error(&quot;threadClient.exe not found&quot;s);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;THREADENTRY32 thread = { sizeof(thread) } ;</div><div class="code_line">&nbsp;&nbsp;DWORD &nbsp; &nbsp; &nbsp; threadId = 0;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;if (Thread32First(snapShot, &amp;thread) != FALSE)</div><div class="code_line">&nbsp;&nbsp; &nbsp;do</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (thread.th32OwnerProcessID != procId) continue;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Handle&#60;&#62; threadClient(OpenThread(THREAD_QUERY_LIMITED_INFORMATION, FALSE, thread.th32ThreadID));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Wchar &nbsp; &nbsp;buffer([&amp;]{ wchar_t *buffer; GetThreadDescription(threadClient, &amp;buffer); return buffer; }());</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (std::wstring(buffer) == L&quot;working message thread&quot;s)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;threadId = thread.th32ThreadID;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;} while (Thread32Next(snapShot, &amp;thread) != FALSE);</div><div class="code_line">&nbsp;&nbsp;if (threadId == 0) throw std::runtime_error(&quot;working message thread of threadClient.exe not found&quot;s);</div><div class="code_line">&nbsp;&nbsp;PostThreadMessage(threadId, usrMsg, 0, 0);</div><div class="code_line">}</div><div class="code_line">catch(const std::exception&amp; exc)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;std::cerr &#60;&#60; exc.what() &#60;&#60; std::endl;</div><div class="code_line">}</div></ol></div></div></div></div>Писано на коленке, так что плз без претензий. Ожидающее выходит по ESC.<br>
Как найду время, напишу и запосчу на окнах. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2023-03-15T15:40:17+00:00">15.03.23, 15:40</time></span></span><br>
P.S. Забыл пояснить. По идее ожидающее называется threadClient.exe. Если это не так, то переименуйте или измените искомое посылающим имя. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2023-03-15T16:18:14+00:00">15.03.23, 16:18</time></span></span><br>
Нате на окнах. Ожидающее приложение:<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#include &#60;windows.h&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">#define IDM_QUIT 101</div><div class="code_line">#define ICON_ID &nbsp;1</div><div class="code_line">&nbsp;</div><div class="code_line">WNDCLASS wndClass;</div><div class="code_line">MSG &nbsp; &nbsp; &nbsp;msg;</div><div class="code_line">HWND &nbsp; &nbsp; hWnd;</div><div class="code_line">UINT &nbsp; &nbsp; usrMsg, trayMsg;</div><div class="code_line">HMENU &nbsp; &nbsp;hMenu;</div><div class="code_line">&nbsp;</div><div class="code_line">BOOL CreateOwnMenu()</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;if ((hMenu = CreatePopupMenu()) == NULL)</div><div class="code_line">&nbsp;&nbsp; &nbsp;return FALSE;</div><div class="code_line">&nbsp;&nbsp;if (!AppendMenu(hMenu, MF_STRING, IDM_QUIT, &quot;stop it&quot;))</div><div class="code_line">&nbsp;&nbsp; &nbsp;return DestroyMenu(hMenu),</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FALSE;</div><div class="code_line">&nbsp;&nbsp;return TRUE;</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">NOTIFYICONDATA nid;</div><div class="code_line">&nbsp;</div><div class="code_line">LRESULT CALLBACK wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;POINT curPos;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;switch (uMsg)</div><div class="code_line">&nbsp;&nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp;case &nbsp; WM_CREATE:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; usrMsg = RegisterWindowMessage(&quot;Message for client&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trayMsg= RegisterWindowMessage(&quot;Notyfy message&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (usrMsg == 0) &nbsp; &nbsp; &nbsp;return -1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (trayMsg== 0) &nbsp; &nbsp; &nbsp;return -1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!CreateOwnMenu()) return -1;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nid.cbSize = sizeof(nid);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nid.hWnd &nbsp; = hWnd;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nid.uID &nbsp; &nbsp;= ICON_ID;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nid.uCallbackMessage = trayMsg;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nid.hIcon &nbsp;= LoadIcon(NULL, IDI_WARNING);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(nid.szTip, &quot;appClient&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Shell_NotifyIcon(NIM_ADD, &amp;nid);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;case &nbsp; WM_CLOSE:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DestroyMenu(hMenu);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Shell_NotifyIcon(NIM_DELETE, &amp;nid);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DestroyWindow(hWnd);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;case &nbsp; WM_DESTROY:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PostQuitMessage(0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;default:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (uMsg == usrMsg) MessageBox(NULL, &quot;сообщение получено&quot;, &quot;appClient&quot;, MB_OK);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (uMsg == trayMsg)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch(lParam)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD retCmd;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case WM_LBUTTONDOWN:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case WM_RBUTTONDOWN:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetCursorPos(&amp;curPos);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetForegroundWindow(hWnd);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;retCmd = TrackPopupMenu(hMenu, TPM_RETURNCMD, curPos.x, curPos.y,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, hWnd, NULL);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;switch(retCmd)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case IDM_QUIT:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PostMessage(hWnd, WM_CLOSE, 0, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;default:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return DefWindowProc(hWnd, uMsg, wParam, lParam);</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">int WINAPI WinMain(HINSTANCE, HINSTANCE, PSTR, int)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;wndClass.lpfnWndProc &nbsp;= wndProc;</div><div class="code_line">&nbsp;&nbsp;wndClass.cbClsExtra &nbsp; = 0;</div><div class="code_line">&nbsp;&nbsp;wndClass.cbWndExtra &nbsp; = 0;</div><div class="code_line">&nbsp;&nbsp;wndClass.hInstance &nbsp; &nbsp;= GetModuleHandle(NULL);</div><div class="code_line">&nbsp;&nbsp;wndClass.hIcon &nbsp; &nbsp; &nbsp; &nbsp;= LoadIcon &nbsp; &nbsp; &nbsp; (NULL, IDI_WARNING);</div><div class="code_line">&nbsp;&nbsp;wndClass.hCursor &nbsp; &nbsp; &nbsp;= LoadCursor &nbsp; &nbsp; (NULL, IDC_ARROW);</div><div class="code_line">&nbsp;&nbsp;wndClass.hbrBackground= reinterpret_cast&#60;HBRUSH&#62;(COLOR_WINDOW+1);</div><div class="code_line">&nbsp;&nbsp;wndClass.lpszMenuName = NULL;</div><div class="code_line">&nbsp;&nbsp;wndClass.lpszClassName= &quot;appClient class window&quot;;</div><div class="code_line">&nbsp;&nbsp;if (RegisterClass(&amp;wndClass) == 0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 1;</div><div class="code_line">&nbsp;&nbsp;if ((hWnd = CreateWindow(wndClass.lpszClassName, &quot;appClient&quot;, WS_POPUP, 0, 0, 0, 0,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL, NULL, GetModuleHandle(NULL), NULL)) == NULL) return 1;</div><div class="code_line">&nbsp;&nbsp;ShowWindow(hWnd, SW_HIDE);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;while (GetMessage(&amp;msg, 0, 0, 0))</div><div class="code_line">&nbsp;&nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp;TranslateMessage(&amp;msg);</div><div class="code_line">&nbsp;&nbsp; &nbsp;DispatchMessage(&amp;msg);</div><div class="code_line">&nbsp;&nbsp;}</div><div class="code_line">&nbsp;&nbsp;return 0;</div><div class="code_line">}</div></ol></div></div></div></div>Посылающее приложение.<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#include &#60;windows.h&#62;</div><div class="code_line">#include &#60;iostream&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">int main()</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;HWND hWnd = FindWindow(&quot;appClient class window&quot;, &quot;appClient&quot;);</div><div class="code_line">&nbsp;&nbsp;UINT usrMsg = RegisterWindowMessage(&quot;Message for client&quot;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;if (hWnd == NULL)</div><div class="code_line">&nbsp;&nbsp; &nbsp;return std::cout &#60;&#60; &quot;appClient window not found&quot;,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1;</div><div class="code_line">&nbsp;&nbsp;if (usrMsg == 0)</div><div class="code_line">&nbsp;&nbsp; &nbsp;return std::cout &#60;&#60; &quot;RegisterWindowMessage() fails&quot;,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;SendMessage(hWnd, usrMsg, 0, 0);</div><div class="code_line">&nbsp;&nbsp;return 0;</div><div class="code_line">}</div></ol></div></div></div></div>Ожидающее падает в трей и выходит по команде оттуда. Посылающее ищет окно класса &quot;appClient class window&quot; с заголовком &quot;appClient&quot;. Оно скрыто, но это пофик. Если запустите несколько экземпляров ожидающего, окна будут дублированы. Каким экземпляром будут обрабатываться сообщения, афикъегознает.]]></description>
        <author>Qraizer</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887854</guid>
        <pubDate>Wed, 15 Mar 2023 08:28:51 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887854</link>
        <description><![CDATA[Majestio: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=433593&view=findpost&p=3887851'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>DrUnkard &#064; <time class="tag-quote__quoted-time" datetime="2023-03-15T08:13:16+00:00">15.03.23, 08:13</time></span><div class='quote '>Я дал человеку текст на русском языке, шо, заведомо, читабельнее.</div></div><br>
Согласен. К тому же межпроцессное взаимодействие будет еще и более православным&#33; :)]]></description>
        <author>Majestio</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887851</guid>
        <pubDate>Wed, 15 Mar 2023 08:13:16 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887851</link>
        <description><![CDATA[DrUnkard: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=433593&view=findpost&p=3887847'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>B.V. &#064; <time class="tag-quote__quoted-time" datetime="2023-03-15T07:39:59+00:00">15.03.23, 07:39</time></span><div class='quote '>Майкрософт их расписал, полагаю, много раньше Рихтера</div></div><br>
И чо? <br>
Рихтер сам консультировал Микрософт.<br>
Я дал человеку текст на русском языке, шо, заведомо, читабельнее.]]></description>
        <author>DrUnkard</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887847</guid>
        <pubDate>Wed, 15 Mar 2023 07:39:59 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887847</link>
        <description><![CDATA[B.V.: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=433593&view=findpost&p=3887582'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>izumov &#064; <time class="tag-quote__quoted-time" datetime="2023-03-11T10:17:57+00:00">11.03.23, 10:17</time></span><div class='quote '>Каков будет код для передачи пользовательского сообщения другому приложению о котором первому известно только название исполняемого файла?И каков будет код получения и обработки принимающим приложением?</div></div><br>
Оба приложения твои? Что конкретно нужно передать? WM_-сообщение или бинарные данные? Или просто дёрнуть логику &quot;отдал-принял&quot; любым событием? В последнем случае подойдёт самый обычный Event: <a class='tag-url' href='https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-createeventa' target='_blank'>https://learn.microsoft.com/en-us/windows/w...pi-createeventa</a><br>
<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=433593&view=findpost&p=3887695'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>DrUnkard &#064; <time class="tag-quote__quoted-time" datetime="2023-03-12T22:12:22+00:00">12.03.23, 22:12</time></span><div class='quote '>Джеффри Рихтер расписал способы межпроцессного общения</div></div><br>
Майкрософт их расписал, полагаю, много раньше Рихтера: <a class='tag-url' href='https://learn.microsoft.com/en-us/windows/win32/sync/interprocess-synchronization' target='_blank'>https://learn.microsoft.com/en-us/windows/w...synchronization</a>]]></description>
        <author>B.V.</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887760</guid>
        <pubDate>Mon, 13 Mar 2023 17:15:46 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887760</link>
        <description><![CDATA[Qraizer: Пусть ТС сначала определится, что ему надо. Как связать имя исполняемого файла с процессом, объяснено. Перечислить нитки процесса из того же снапшота CreateToolhelp32Snapshot() дело двух кликов мышью по справочнику Process32First(). За посылку сообщений в нить говорилось в соседней теме.<br>Если же нужно окно, то искать процесс вообще не нужно, нужно искать окно. Перечислить все окна верхнего уровня EnumWindows(), в каллбаке которого EnumWindowsProc сравнивать нитку-владельца с результатом GetWindowThreadProcessId(). Как вариант – перебрать все окна нитки EnumThreadWindows(). Как удобнее, ябеспонятия. ИМХО искать окна неблагодарное занятие, если о них ничего не известно.]]></description>
        <author>Qraizer</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887695</guid>
        <pubDate>Sun, 12 Mar 2023 22:12:22 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887695</link>
        <description><![CDATA[DrUnkard: Джеффри Рихтер расписал способы межпроцессного общения<br>
<div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '>Взаимодействие между процессами<br>
Потоки одного процесса не имеют доступа к адресному пространству другого<br>
процесса. Однако существуют механизмы для передачи данных между процессами. </div></div><br>
<a class='tag-url' href='http://library.tsilikin.ru/%D0%A2%D0%B5%D1%85%D0%BD%D0%B8%D0%BA%D0%B0/%D0%98%D0%BD%D1%84%D0%BE%D1%80%D0%BC%D0%B0%D1%86%D0%B8%D0%BE%D0%BD%D0%BD%D1%8B%D0%B5%20%D1%82%D0%B5%D1%85%D0%BD%D0%BE%D0%BB%D0%BE%D0%B3%D0%B8%D0%B8/%D0%9F%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5/Windows/%D0%94%D0%B6%D0%B5%D1%84%D1%84%D1%80%D0%B8%20%D0%A0%D0%B8%D1%85%D1%82%D0%B5%D1%80%20%D0%9F%D1%80%D0%BE%D1%86%D0%B5%D1%81%D1%81%D1%8B%20%D0%B2%20Windows.pdf' target='_blank'>http://library.tsilikin.ru/%D0%A2%D0%B5%D1...2%20Windows.pdf</a><br>
<br>
Тебе, очевидно, более подойдёт инфа на стр 14.<br>
<div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '>Сообщения в Windows (оконные сообщения)</div></div>]]></description>
        <author>DrUnkard</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887593</guid>
        <pubDate>Sat, 11 Mar 2023 14:28:47 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887593</link>
        <description><![CDATA[Qraizer: CreateToolhelp32Snapshot() + Process32First()/Process32Next() + OpenProcess() + QueryFullProcessImageName()<br>Ну и не забыть про CloseHandle()]]></description>
        <author>Qraizer</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887591</guid>
        <pubDate>Sat, 11 Mar 2023 13:41:42 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887591</link>
        <description><![CDATA[izumov: Насколько я вижу ветка называется и win API.А вызов функции sendmessage или postmessage это и есть windows api.И в чем я заблуждаюсь?]]></description>
        <author>izumov</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887586</guid>
        <pubDate>Sat, 11 Mar 2023 12:13:18 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887586</link>
        <description><![CDATA[Feldsher: Это системное программирование, IPC]]></description>
        <author>Feldsher</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887582</guid>
        <pubDate>Sat, 11 Mar 2023 10:17:57 +0000</pubDate>
        <title>Как передать сообщение другому приложению?</title>
        <link>https://forum.sources.ru/index.php?showtopic=433593&amp;view=findpost&amp;p=3887582</link>
        <description><![CDATA[izumov: Каков будет код для передачи пользовательского сообщения другому приложению о котором первому известно только название исполняемого файла?И каков будет код получения и обработки принимающим приложением?То есть стоит задача передать сообщение от одного приложения другому и зафиксировать прием сообщения отображением MessageBox(сообщение полученоMB_OK).]]></description>
        <author>izumov</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      </channel>
      </rss>
	