Skip to content

Instantly share code, notes, and snippets.

@igotit-anything
Created September 6, 2024 09:09
Show Gist options
  • Save igotit-anything/09747a0a25fc7cc2befe8cb9ca3977fe to your computer and use it in GitHub Desktop.
Save igotit-anything/09747a0a25fc7cc2befe8cb9ca3977fe to your computer and use it in GitHub Desktop.
/*
MetaTrader5 language MQL5
- Only for 64bit environment
file : CCy_IPC_WindowMessage_1.mqh
author : igotit . https://igotit.tistory.com
*/
#define WM_USER 0x0400 // Windows Message User 정의
#import "user32.dll"
long FindWindowW(string lpClassName,string lpWindowName); //HWND FindWindowW(LPCWSTR lpClassName,LPCWSTR lpWindowName);
long SendMessageW(long hWnd, int Msg, long wParam, long lParam); // LRESULT SendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
long PostMessageW(long hWnd, int Msg, long wParam, long lParam); // LRESULT PostMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
#import
class CCy_WindowMessage
{
private:
string m_NameWndTgt; // 대상윈도우 이름.
int m_Msg; // 예 : 사용자 메시지인 경우 WM_USER + 1
public:
CCy_WindowMessage(string name_wnd_tgt, int msg = WM_USER+1)
:m_NameWndTgt(name_wnd_tgt), m_Msg(msg)
{}
~CCy_WindowMessage() {}
long FindWindow()
{
long hwnd_tgt = FindWindowW(NULL,m_NameWndTgt); // 대상 윈도우 핸들 받기.
if(hwnd_tgt == 0){
Print("[CCy_WindowMessage] Not Found Target Window Name = ", m_NameWndTgt);
}
return hwnd_tgt;
}
void SendMessage(long wparam, long lparam)
{
long hwnd_tgt = FindWindow();
if(hwnd_tgt == 0 ) return;
SendMessageW(
hwnd_tgt // long hwnd
, m_Msg // int msg
, wparam // long wparam
, lparam // long lparam
);
}
void PostMessage(long wparam, long lparam)
{
long hwnd_tgt = FindWindow();
if(hwnd_tgt == 0 ) return;
PostMessageW(
hwnd_tgt // long hwnd
, m_Msg // int msg
, wparam // long wparam
, lparam // long lparam
);
}
}; // class CCy_WindowMessage
@igotit-anything
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment