-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinctrl.c
112 lines (107 loc) · 3.31 KB
/
pinctrl.c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "pinctrl.h"
#include "msg.h"
#include "utils.h"
#include "about.h"
#include "resource.h"
static HWND hWndPinCtrl;
static HWND hDtr, hRts;
static int axisx, axisy;
extern COMMCONFIG cconfig;
static int dtr[3] = {DTR_CONTROL_DISABLE, DTR_CONTROL_ENABLE, DTR_CONTROL_HANDSHAKE};
static int rts[3] = {RTS_CONTROL_DISABLE, RTS_CONTROL_ENABLE, RTS_CONTROL_HANDSHAKE};
static char *sdtr[3] = {"(1)DTR_CONTROL_DISABLE", "(0)DTR_CONTROL_ENABLE", "(0)DTR_CONTROL_HANDSHAKE"};
static char *srts[3] = {"(1)RTS_CONTROL_DISABLE", "(0)RTS_CONTROL_ENABLE", "(0)RTS_CONTROL_HANDSHAKE"};
INT_PTR CALLBACK PinCtrlDlgProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CLOSE:
{
RECT rc;
GetWindowRect(hWndDlg, &rc);
axisx = rc.left;
axisy = rc.top;
hWndPinCtrl = NULL;
EndDialog(hWndDlg, 0);
return 0;
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_PINCTRL_OK:
if(HIWORD(wParam) != BN_CLICKED)
return 0;
if(msg.hComPort == INVALID_HANDLE_VALUE)
{
MessageBox(hWndDlg, "没有串口设备被打开!", COMMON_NAME, MB_ICONINFORMATION);
return 0;
}
cconfig.dcb.fDtrControl = dtr[ComboBox_GetCurSel(hDtr)];
cconfig.dcb.fRtsControl = rts[ComboBox_GetCurSel(hRts)];
if(!SetCommConfig(msg.hComPort, &cconfig, sizeof(cconfig)))
{
utils.msgerr("设置DTR/RTS时错误!");
return 0;
}
EnableWindow(GetDlgItem(hWndDlg, IDC_PINCTRL_OK), FALSE);
break;
case IDC_CBO_PINCTRL_DTR:
case IDC_CBO_PINCTRL_RTS:
if(HIWORD(wParam) == CBN_SELENDOK)
{
EnableWindow(GetDlgItem(hWndDlg, IDC_PINCTRL_OK), TRUE);
return 0;
}
break;
}
return 0;
}
case WM_INITDIALOG:
{
DWORD size = sizeof(cconfig);
if(msg.hComPort == INVALID_HANDLE_VALUE)
{
utils.msgbox(MB_ICONEXCLAMATION, COMMON_NAME, "请先打开一个串口设备!");
EndDialog(hWndDlg, 0);
return 0;
}
if(!GetCommConfig(msg.hComPort, &cconfig, &size))
{
utils.msgerr("获取串口配置时错误");
EndDialog(hWndDlg, 0);
return 0;
}
hDtr = GetDlgItem(hWndDlg, IDC_CBO_PINCTRL_DTR);
hRts = GetDlgItem(hWndDlg, IDC_CBO_PINCTRL_RTS);
for(;;)
{
int i;
for(i = 0; i < 3; i++)
{
ComboBox_AddString(hDtr, sdtr[i]);
ComboBox_AddString(hRts, srts[i]);
}
ComboBox_SetCurSel(hDtr, cconfig.dcb.fDtrControl);
ComboBox_SetCurSel(hRts, cconfig.dcb.fRtsControl);
break;
}
//...
hWndPinCtrl = hWndDlg;
SetWindowPos(hWndDlg, 0, axisx, axisy, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
return 0;
}
}
UNREFERENCED_PARAMETER(lParam);
return 0;
}
int ShowPinCtrl(void)
{
if(hWndPinCtrl)
{
SetWindowPos(hWndPinCtrl, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
return 0;
}
DialogBoxParam(msg.hInstance, MAKEINTRESOURCE(IDD_DLG_PINCTRL), NULL, PinCtrlDlgProc, 0);
return 0;
}