-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWin32.cs
More file actions
58 lines (48 loc) · 1.93 KB
/
Win32.cs
File metadata and controls
58 lines (48 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Runtime.InteropServices;
namespace L4D2DevTools
{
public static class Win32
{
[DllImport("user32.dll")]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern int SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll")]
private static extern IntPtr GetWindow(IntPtr hWnd, GetWindowType uCmd);
[DllImport("user32.dll")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private enum GetWindowType : uint
{
GW_HWNDFIRST = 0,
GW_HWNDLAST = 1,
GW_HWNDNEXT = 2,
GW_HWNDPREV = 3,
GW_OWNER = 4,
GW_CHILD = 5,
GW_ENABLEDPOPUP = 6
}
private const int CB_SHOWDROPDOWN = 0x014F;
private const int CB_SETCURSEL = 0x014E;
private const int WM_SETFOCUS = 0x07;
/// <summary>
/// 设置区域MFC窗口Combobox控件选中索引
/// </summary>
/// <param name="index">0,501</param>
public static void SetComboboxSelectIndex(int index)
{
var regionHandle = FindWindow(null, "区域");
if (regionHandle != IntPtr.Zero)
{
SetForegroundWindow(regionHandle);
var childHandle = GetWindow(regionHandle, GetWindowType.GW_CHILD);
var comboboxHandle = FindWindowEx(childHandle, IntPtr.Zero, "ComboBox", null);
SendMessage(comboboxHandle, CB_SHOWDROPDOWN, 1, 0);
SendMessage(comboboxHandle, CB_SETCURSEL, index, 0);
SendMessage(comboboxHandle, WM_SETFOCUS, 0, 0);
}
}
}
}