window之 WM_COPYDATA

  • Post author:
  • Post category:其他


wchar_t winCaption[_MAX_PATH] = { 0 };

caption.toWCharArray(winCaption);

HWND receiveWindow = ::FindWindow(NULL, winCaption);

if (receiveWindow == NULL)

break;

wchar_t data[_MAX_PATH] = { 0 };

int length = filePath.toWCharArray(data);

COPYDATASTRUCT copyData = { 0 };

copyData.lpData = data;

copyData.cbData = (length + 1) * sizeof(wchar_t);

::SendMessage(receiveWindow, WM_COPYDATA, (WPARAM)winId(), (LPARAM)&copyData);

注意在vista,win7不同进程中,需要过滤消息。