-
Notifications
You must be signed in to change notification settings - Fork 2
/
guiutil.cpp
82 lines (70 loc) · 2.02 KB
/
guiutil.cpp
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <winsock2.h>
#include <iphlpapi.h>
#pragma comment (lib, "ws2_32.lib")
#pragma comment(lib, "IPHLPAPI.lib")
#include <windowsx.h>
#include <commctrl.h> // Include header
#pragma comment(lib, "comctl32.lib") // Include library
#pragma warning( disable : 4995 )
#if defined _MSC_VER
#include <strsafe.h>
#endif
#include "util.h"
#include "hpsdr.h"
#include "log.h"
#include "guievent.h"
#include "guiutil.h"
const char * GuiError :: show() {
MessageBox (NULL, (LPCTSTR)p_, TEXT("Error"), MB_OK);
return p_;
}
void AppendText(const GuiEvent &ge /*HWND hDlg, int id, */, const char *pTxt)
{
HWND hCtrl = GetDlgItem(ge.hWnd, ge.id);
int length = GetWindowTextLength(hCtrl);
if (length > 0) {
char* tempChar;
tempChar = (char*)GlobalAlloc(GPTR, length + 1 + strlen(pTxt));
GetDlgItemText(ge.hWnd, ge.id, (LPSTR)tempChar, length + 1);
strcpy_s(tempChar + strlen(tempChar), length + 1 + strlen(pTxt), pTxt);
strcpy_s(tempChar, length + 1 + strlen(pTxt), pTxt);
SetWindowText(hCtrl, (LPCSTR)tempChar);
}
}
void AppendTextToEditCtrl(const GuiEvent & ge, const char * pszText)
{
HWND hCtl = GetDlgItem(ge.hWnd, ge.id);
int nLength = GetWindowTextLength(hCtl);
SendMessage(hCtl, EM_SETSEL, (WPARAM)nLength, (LPARAM)nLength);
SendMessage(hCtl, EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)pszText);
}
BOOL GetCheckBoxState(HWND hDlg, int id)
{
HWND hCtrl = GetDlgItem(hDlg, id);
if (hCtrl != NULL)
return (SendMessage(hCtrl, BM_GETSTATE, 0, 0) == BST_CHECKED);
else
return FALSE;
}
bool GetCheckBoxState(const GuiEvent& ge)
{
HWND hCtrl = GetDlgItem(ge.hWnd, ge.id);
if (hCtrl != NULL)
return (SendMessage(hCtrl, BM_GETSTATE, 0, 0) == BST_CHECKED);
else
return false;
}
void AppendWinTitle(const GuiEvent& ge, const char *p)
{
char szBuf[1024] = {0};
char szNew[2028] = {0};
if (GetWindowText(ge.hWnd, szBuf, sizeof (szBuf)) > 0) {
snprintf(szNew, sizeof(szNew), "%s%s", szBuf, p);
SetWindowText(ge.hWnd, szNew);
}
}