JeanCremers 1 Posted October 27, 2023 (edited) Ok, so one prog does for instance HWND hwnd = FindWindow(NULL, "myprog"); if (hwnd) SendMessage(hwnd, WM_USER, 0, 0); And what exactly should the other prog do? I have this, but it's not working. in form constructor Application->HookMainWindow(&AppHook); bool __fastcall TMainForm::AppHook(TMessage &Message) { if (Message.Msg == WM_USER) { Application->MessageBox("", "", MB_OK); return true; } return false; } But i'm not getting any msg there. Thanks. Edited October 28, 2023 by JeanCremers spelling Share this post Link to post
Remy Lebeau 1393 Posted October 28, 2023 (edited) On 10/27/2023 at 3:08 PM, JeanCremers said: HWND hwnd = FindWindow(NULL, "myprog"); Is "myprog" the title for your program's TApplication window or TForm window? It makes a big difference. I'm suspecting the latter. Quote I have this, but it's not working. ... i'm not getting any msg there. You are installing a message handler for the TApplication window. To handle messages for the TForm window, override the TForm's virtual WndProc() method instead: void __fastcall TMainForm::WndProc(TMessage &Message) { if (Message.Msg == WM_USER) { Application->MessageBox("", "", MB_OK); Message.Result = 1; } else TForm::WndProc(Message); } That being said, WM_USER is not a good choice for inter-process communications. Use WM_APP or RegisterWindowMessage() instead. Edited October 28, 2023 by Remy Lebeau Share this post Link to post
JeanCremers 1 Posted October 28, 2023 (edited) Thanks Remy. I'm getting EOSError 'System Error. Code 1411, Class does not exist.' This is c++builder 6 🙂 Edit, i also tried void __fastcall TAstroClockMainForm::ApplicationEvents1Message(tagMSG &Msg, bool &Handled) { if (Msg.message == WM_APP) Application->MessageBox("", "", MB_OK); } and HWND hwnd = FindWindow("TAstroclockMainForm", NULL); if (hwnd) SendMessage(hwnd, WM_APP, 0, 0); Edited October 28, 2023 by JeanCremers Share this post Link to post
Remy Lebeau 1393 Posted October 28, 2023 (edited) 18 hours ago, JeanCremers said: Thanks Remy. I'm getting EOSError 'System Error. Code 1411, Class does not exist.' Sorry, my bad. I left out the part where the overriden WndProc() needs to pass unhandled messages to the default handler. I have corrected my example. Quote This is c++builder 6 🙂 What I showed applies to all C++Builder versions. Quote i also tried void __fastcall TAstroClockMainForm::ApplicationEvents1Message(tagMSG &Msg, bool &Handled) { if (Msg.message == WM_APP) Application->MessageBox("", "", MB_OK); } That won't work. That event is triggered only for messages that are posted to the main thread message queue. Which your example message is not. Quote and HWND hwnd = FindWindow("TAstroclockMainForm", NULL); if (hwnd) SendMessage(hwnd, WM_APP, 0, 0); That likely won't work, either, because your MainForm's class name is TMainForm not TAstroclockMainForm (unless what you have shown is not your real code). Edited October 28, 2023 by Remy Lebeau Share this post Link to post
JeanCremers 1 Posted October 29, 2023 Thanks a bunch again Remy, i've got it working like a charm. Share this post Link to post
limelect 48 Posted November 29, 2023 use https://torry.net/quicksearchd.php?String=WinPopup&page=1 mdMailSlot it did for me the job Share this post Link to post