0

我尝试使用以下代码在我的 Winform 应用程序中嵌入“Windows Journal”应用程序。它有效,一切看起来都很好。但是,当我开始使用 Windows Journal 应用程序(它已经是我的应用程序的子窗口)时,我发现鼠标的行为不一致。更具体一点,例如,我试图画一条从 (x, y) 到 (x+100, y) 的线,但这条线在 (x-50, y-50) 到 (x, y-50)。我使用“鼠标同步/不一致”、“setparent 后应用程序异常行为”、“子窗口的奇怪行为”等关键字进行谷歌搜索,但尚未找到任何相关解决方案。我也尝试在setParent之前清除WS_POPUP样式,但是没有用。谁能给我一些想法?谢谢。

//IntPtr appWin is the MainWindowHandle of Windows Journal process 
ShowWindowAsync(appWin, SW_SHOWNORMAL);

// Put it into this form
SetParent(appWin, this.Handle);

// Remove border and whatnot
SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE);

// Move the window to overlay it on this window
MoveWindow(appWin, 0, 0, this.Width, this.Height, true);

代码位于名为 JournalControl.cs 的控制器中,而 JournalControl 位于应用程序主窗体中的 splitContainer.Panel 中。因此,当单击主窗体的按钮时,首先打开用户在 Journal 应用程序中指示的 jnt 文件

public void OpenJournal(string JNTPath)
{
    try
    {
        if (File.Exists(JNTPath))
        {
            proc.StartInfo.FileName = @"C:\Program Files\Windows Journal\Journal.exe";
            proc = Process.Start(JNTPath); 

            this.timCheckJournal = new System.Windows.Forms.Timer();
            this.timCheckJournal.Tick += new System.EventHandler(this.timCheckJournal_Tick);          
        }
        else
        {
            MessageBox.Show("Couldn't find  JNTPath: " + JNTPath);
        }
    }
    catch (Exception ex)
    {
        ExceptionPublisher.PublishEx(ex);
    }
} 

然后在 timCheckJournal_Tick() 中,将应用程序放入 Panel

private void timCheckJournal_Tick(object sender, EventArgs e)
{
    timCheckJournal.Enabled = false;
    IntPtr appWin = GetJournalTopWindowHandle();
    if (appWin != IntPtr.Zero)
    {
        ShowWindowAsync(appWin, SW_SHOWNORMAL);

        // Put it into this form
        SetParent(appWin, this.Handle);

        // Remove border and whatnot
        SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE);

        // Move the window to overlay it on this window
        MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
    }
    else
    {
        timCheckJournal.Enabled = true;
    }
}
4

1 回答 1

0

听起来您需要在两个客户区之间执行翻译...

这是首先阅读的链接:http: //support.microsoft.com/kb/11570

你如何实现它在很大程度上取决于鼠标绘图从哪里开始以及它应该在哪里绘图,但是假设你的“托管应用程序”是鼠标监听器,而 Journal 是你想要绘制的东西- 序列可能看起来像(伪代码):

screenCoords = ClientToScreen(mouse coords)
journalCoords = ScreenToClient(screenCoords)

然后无论你在做什么来绘制日记 -WM_MOUSE消息等。

于 2013-01-25T18:59:19.233 回答