forked from jps1973/Internet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListBoxWindow.cpp
More file actions
169 lines (118 loc) · 4.41 KB
/
ListBoxWindow.cpp
File metadata and controls
169 lines (118 loc) · 4.41 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// ListBoxWindow.cpp
#include "ListBoxWindow.h"
// Global variables
static HWND g_hWndListBox;
BOOL IsListBoxWindow( HWND hWnd )
{
// See if supplied window is list box window
return( hWnd == g_hWndListBox );
} // End of function IsListBoxWindow
int ListBoxWindowAddString( LPCTSTR lpszString )
{
// Add string to list box window
return SendMessage( g_hWndListBox, LB_ADDSTRING, ( WPARAM )NULL, ( LPARAM )lpszString );
} // End of function ListBoxWindowAddString
int ListBoxWindowAddStringEx( LPCTSTR lpszString )
{
int nResult;
// Add string to list box window
nResult = SendMessage( g_hWndListBox, LB_ADDSTRING, ( WPARAM )NULL, ( LPARAM )lpszString );
// Ensure that string was added to list box window
if( ( nResult != LB_ERR ) && ( nResult != LB_ERRSPACE ) )
{
// Successfully added string to list box window
// Update list box window
UpdateWindow( g_hWndListBox );
} // End of successfully added string to list box window
return nResult;
} // End of function ListBoxWindowAddStringEx
BOOL ListBoxWindowCreate( HWND hWndParent, HINSTANCE hInstance )
{
BOOL bResult = FALSE;
// Create list box window
g_hWndListBox = CreateWindowEx( LIST_BOX_WINDOW_EXTENDED_STYLE, LIST_BOX_WINDOW_CLASS_NAME, LIST_BOX_WINDOW_TEXT, LIST_BOX_WINDOW_STYLE, 0, 0, 0, 0, hWndParent, ( HMENU )NULL, hInstance, NULL );
// Ensure that list box window was created
if( g_hWndListBox )
{
// Successfully created list box window
// Update return value
bResult = TRUE;
} // End of successfully created list box window
return bResult;
} // End of function ListBoxWindowCreate
BOOL ListBoxWindowGetRect( LPRECT lpRect )
{
// Get list box window rect
return GetWindowRect( g_hWndListBox, lpRect );
} // End of function ListBoxWindowGetRect
BOOL ListBoxWindowHandleCommandMessage( WPARAM wParam, LPARAM, BOOL( *lpDoubleClickFunction )( LPCTSTR lpszItemText ), BOOL( *lpStatusFunction )( LPCTSTR lpszItemText ) )
{
BOOL bResult = FALSE;
// Select list box window notification code
switch( HIWORD( wParam ) )
{
case LBN_DBLCLK:
{
// A list box window double click notification code
int nSelectedItem;
// Allocate string memory
LPTSTR lpszSelected = new char[ STRING_LENGTH + sizeof( char ) ];
// Get selected item
nSelectedItem = SendMessage( g_hWndListBox, LB_GETCURSEL, ( WPARAM )NULL, ( LPARAM )NULL );
// Get selected item text
if( SendMessage( g_hWndListBox, LB_GETTEXT, ( WPARAM )nSelectedItem, ( LPARAM )lpszSelected ) )
{
// Successfully got selected item text
// Call double click function
( *lpDoubleClickFunction )( lpszSelected );
} // End of successfully got selected item text
// Free string memory
delete [] lpszSelected;
// Break out of switch
break;
} // End of a list box window double click notification code
case LBN_SELCHANGE:
{
// A list box window selection change notification code
int nSelectedItem;
// Allocate string memory
LPTSTR lpszSelected = new char[ STRING_LENGTH + sizeof( char ) ];
// Get selected item
nSelectedItem = SendMessage( g_hWndListBox, LB_GETCURSEL, ( WPARAM )NULL, ( LPARAM )NULL );
// Get selected item text
if( SendMessage( g_hWndListBox, LB_GETTEXT, ( WPARAM )nSelectedItem, ( LPARAM )lpszSelected ) )
{
// Successfully got selected item text
// Show selected item text on status bar window
( *lpStatusFunction )( lpszSelected );
} // End of successfully got selected item text
// Free string memory
delete [] lpszSelected;
// Break out of switch
break;
} // End of a list box window selection change notification code
default:
{
// Default notification code
// No need to do anything here, just continue with default result
// Break out of switch
break;
} // End of default notification code
}; // End of selection for list box window notification code
return bResult;
} // End of function ListBoxWindowHandleCommandMessage
BOOL ListBoxWindowMove( int nX, int nY, int nWidth, int nHeight, BOOL bRepaint )
{
// Move list box window
return MoveWindow( g_hWndListBox, nX, nY, nWidth, nHeight, bRepaint );
} // End of function ListBoxWindowMove
HWND ListBoxWindowSetFocus()
{
// Focus on list box window
return SetFocus( g_hWndListBox );
} // End of function ListBoxWindowSetFocus
void ListBoxWindowSetFont( HFONT hFont )
{
// Set list box window font
SendMessage( g_hWndListBox, WM_SETFONT, ( WPARAM )hFont, ( LPARAM )TRUE );
} // End of function ListBoxWindowSetFont