QT window interaction with win32 window

来源:互联网 发布:iis 配置sql server 编辑:程序博客网 时间:2024/06/07 03:44

caller is a QT program.

example:

#include <QtWidgets/QMainWindow>#include "ui_QtGuiApplication1.h"class QtGuiApplication1 : public QMainWindow{Q_OBJECTpublic:QtGuiApplication1(QWidget *parent = Q_NULLPTR);signals:void eventData(const QString & data);private: bool nativeEvent(const QByteArray & eventType, void * message, long *result);private slots:void on_pushButton_clicked();void on_SendMsgBtn_clicked();private:Ui::QtGuiApplication1Class ui;};
void QtGuiApplication1::on_pushButton_clicked() {_cwprintf(L"  on_Chrome_clicked \n" );HWND  wind = (HWND)winId();_cprintf("calling hwnd   %d  \n", wind);std::wstringstream  s;//s << "--use-views   ";s << "--url=F:\\medias\\second.mp4";s << "    ";s << "  --caller=" << (unsigned long)wind;HINSTANCE  res = ShellExecute(NULL,L"open",L"D:\\visual projects\\QtGuiApplication1\\Win32\\Debug\\cef\\cefsimple.exe",s.str().c_str(),NULL,SW_SHOWNORMAL);_cwprintf(L"  on_Chrome_clicked %d \n", res);//MessageBox(wind, L"Hello world!", L"Message", MB_OK);}bool QtGuiApplication1::nativeEvent(const QByteArray & eventType, void * message, long *result) { MSG* msg = reinterpret_cast<MSG*>(message);if (msg->message == WM_COPYDATA) {HWND reciverhwnd = (HWND)msg->wParam;PCOPYDATASTRUCT pcds = (PCOPYDATASTRUCT)msg->lParam;_cwprintf(L"nativeEvent  WM_COPYDATA   %d, %x, %d --->\n", reciverhwnd, reciverhwnd, pcds->dwData);*result = 0;return true;}return false;}

The callee is cefsimple, do some moficication;

typedef struct tagMYREC{char  s1[80];char  s2[80];DWORD n;} MYREC;COPYDATASTRUCT MyCDS;MYREC MyRec;void SimpleHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {  CEF_REQUIRE_UI_THREAD();  // Add to the list of existing browsers.  browser_list_.push_back(browser);  MessageBox(NULL, L"OnAfterCreated", L"Message", MB_OK);  if (hcaller != NULL) {  SendMessage(hcaller,  WM_COPYDATA,  NULL,  NULL);  }  MyRec.n = 10;  MyCDS.dwData = 1;          // function identifier  MyCDS.cbData = sizeof(MyRec);  // size of data  MyCDS.lpData = &MyRec;           // data structure   if (hcaller != 0) {  SendMessage(hcaller,  WM_COPYDATA,  (WPARAM)(HWND)browser->GetHost()->GetWindowHandle(),  (LPARAM)(LPVOID)&MyCDS);  }}void SimpleApp::OnContextInitialized() {  .............  std::wstring outstr;  StringToWString(outstr, caller);  std::string::size_type sz;  hcaller = (HWND)std::stol(caller, &sz);  // MessageBox(NULL, outstr.c_str(), L"Message", MB_OK);  //if (hcaller != NULL) { // SendMessage(hcaller,//  WM_COPYDATA,//  NULL,//  NULL);  //}  }  // SimpleHandler implements browser-level callbacks.  CefRefPtr<SimpleHandler> handler(new SimpleHandler(use_views, hcaller));....}



原创粉丝点击