0

WinAPI 呼び出しを介してアプリケーション B を制御するアプリケーション A (.NET/WPF) があります。

要件によれば、アプリケーション A は常に最上位のウィンドウである必要があります。この意味は

  • アプリケーション A のウィンドウがアプリケーション B のウィンドウと同じ位置にある場合、
  • 次に、アプリケーション A のウィンドウが表示されます。
  • アプリケーション B のウィンドウが表示されないようにする必要があります。

この要件は、1 つを除くすべてのケースで満たされます。アプリケーション A がアプリケーション B のコンボ ボックスからプログラムによって要素を選択すると、そのコンボ ボックスが一瞬表示されます。要素を選択すると、再び非表示になります。

ただし、コンボ ボックスが (たとえ一瞬でも) 表示されることは、要件に違反しています。

アプリケーション A のウィンドウが常に最上位のウィンドウであることを確認するにはどうすればよいですか(コンボ ボックス項目の選択中であっても)。

注: アプリケーション A は、200 ミリ秒ごとにフォーカスを取り戻します (それ自体をアクティブにします)。その間隔を 100 ミリ秒に短縮しようとしましたが、役に立ちませんでした。

更新 1:コンボ ボックス項目は、次の WinAPI 呼び出しを使用して選択されます。

SendMessage(Self.MyFlightComboBox, CB_SHOWDROPDOWN, WPARAM(true), 0);

ItemIndex := SendMessage(Self.MyFlightComboBox, CB_FINDSTRING, -1, integer(@MyValue[1]));

OutputDebugString(PChar('ItemIndex: ' + IntToStr(ItemIndex)));


SendMessage(Self.MyFlightComboBox, CB_SETCURSEL, ItemIndex, 0);
SendMessage(Self.MyFlightComboBox, CN_COMMAND, MakeWParam(0, CBN_SELCHANGE), 0);


SendMessage(Self.MyFlightComboBox, WM_LBUTTONDOWN, 0, -1);
SendMessage(Self.MyFlightComboBox, WM_LBUTTONUP, 0, -1);
4

1 に答える 1

0

There's no need to show a drop down list for a background combo box item selection, so remove the first line with the CB_SHOWDROPDOWN message sending (what might be a cause of your problem) and remove also the last two lines, where you're simulating left mouse button click (on a nonsense position, anyway), there's no reason to do so at all.

So, to select an item in combo box by a found text, it's enough to use the following pseudo-code (written in Delphi and slightly modified from your original version, since you should definitely check the results of the messages you send):

ItemIndex := SendMessage(Self.MyFlightComboBox, CB_FINDSTRING, -1, LPARAM(@MyValue[1]));
if ItemIndex <> CB_ERR then
  if SendMessage(Self.MyFlightComboBox, CB_SETCURSEL, ItemIndex, 0) <> CB_ERR then
    SendMessage(Self.MyFlightComboBox, CN_COMMAND, MakeWParam(0, CBN_SELCHANGE), 0);
于 2012-11-01T11:41:57.950 に答える