本篇是游戏脚本的实现(2)的续篇。
MLS编辑器的使用
MLS系统仅使用到数字:代表行为的编号,随后条目的数量,以及代表条目数据的编号。计算机特别擅长处理数字的工作,但我们的需要更多。需要将脚本构造成易于理解的文本行,并让脚本编辑器将键入的文本转变为脚本系统可以处理的一系列数字。
在编辑一个脚本期间,并不处理任何数字方面的问题,所以编辑器的工作还包括加载数字并将它们转换回易于阅读理解的文本行。因此,也可以这么说,仅需要使用一系列的文本命令构造一个脚本,然后使用脚本编辑器将这些命令转换成代表它们数值,反之亦然。
MLS编辑器导入那些代表行为的文本行,并赋予用户能力去编辑行为列表,以及在空白条目点填上行为,MLS编辑器的外观如下图所示:
下表详细解释了脚本编辑器每个按钮的用途:
将行为添加到脚本中时(添加脚本或插入脚本),请注意行为的文本将被扩展,并添加到脚本列表框中(位于脚本编辑器顶端的列表框)。脚本行为从上到下进行存储,根节点存储了最顶端的脚本行为,脚本从顶端开始往下处理,与典型的C/C++代码非常类似。
请注意,每次添加、插入、或编辑一个脚本条目时,修改行为条目的对话框将出现(如下图所示),将使用这个对话框去修改脚本行为的条目。
MLS编辑器的创建
首先,我们设计MLS编辑器主窗口的界面:
接着我们设计修改脚本的对话框:
resource.h的定义:
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by MlsEdit.rc
//
#define IDD_MAIN 101
#define IDD_MODIFY 102
#define IDC_SCRIPT 1000
#define IDC_SCRIPTLIST 1001
#define IDC_SCRIPT_ADDR 1001
#define IDC_ADD 1002
#define IDC_PREV 1002
#define IDC_DELETE 1003
#define IDC_NEXT 1003
#define IDC_UP 1004
#define IDC_OK2 1004
#define IDC_DOWN 1005
#define IDC_ACTIONS 1006
#define IDC_ACTION 1006
#define IDC_EDIT 1007
#define IDC_SAVE 1008
#define IDC_LOAD 1009
#define IDC_INSERT 1010
#define IDC_LOADACTIONS 1013
#define IDC_NEW 1014
#define IDC_TRUE 1015
#define IDC_FALSE 1016
#define IDC_VALUE 1017
#define IDC_MIN 1018
#define IDC_MAX 1019
#define IDC_TEXT 1020
#define IDC_CHOICE 1023
#define IDC_OK 1024
#define IDC_CANCEL 1025
#define IDC_APPLY 1027
#define IDC_ACTIONTEXT 1028
#define IDC_FRAME 1029
#define IDC_NUM 1033
#define IDC_STATIC_MIN 1034
#define IDC_STATIC_VALUE 1035
#define IDC_STATIC_MAX 1036
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1042
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
MlsEdit.rc的定义:
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_MAIN DIALOGEX 0, 0, 381, 262
STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU
CAPTION "MLS Editor"
CLASS "mls edit class"
FONT 11, "Segoe UI", 400, 0, 0x0
BEGIN
LISTBOX IDC_SCRIPT,10,17,296,93,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Add to Script",IDC_ADD,312,150,55,15
PUSHBUTTON "Delete",IDC_DELETE,312,15,55,15
PUSHBUTTON "Move Up",IDC_UP,312,75,55,15
PUSHBUTTON "Move Down",IDC_DOWN,312,95,55,15
PUSHBUTTON "Edit",IDC_EDIT,312,35,55,15
PUSHBUTTON "Save Script",IDC_SAVE,247,115,55,15
PUSHBUTTON "Load Script",IDC_LOAD,127,115,55,15
PUSHBUTTON "Load Actions",IDC_LOADACTIONS,312,200,55,15
PUSHBUTTON "New Script",IDC_NEW,10,115,55,15
LISTBOX IDC_ACTION,10,150,296,97,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Insert in Script",IDC_INSERT,312,175,55,15
GROUPBOX " Script ",IDC_STATIC,7,7,367,128
GROUPBOX " Actions ",IDC_STATIC,7,138,367,117
LISTBOX IDC_SCRIPT_ADDR,155,86,89,102,LBS_NOINTEGRALHEIGHT | NOT WS_VISIBLE | WS_VSCROLL | WS_TABSTOP
END
IDD_MODIFY DIALOGEX 0, 0, 241, 138
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION
CAPTION "Modify Action Entry"
FONT 11, "Segoe UI", 400, 0, 0x0
BEGIN
LTEXT "Static",IDC_ACTIONTEXT,7,5,227,35,WS_BORDER
DEFPUSHBUTTON "OK",IDC_OK,51,117,50,14
LTEXT "Entry #",IDC_STATIC,5,45,25,8
GROUPBOX " TITLE ",IDC_FRAME,7,60,227,56
EDITTEXT IDC_VALUE,97,96,60,12,ES_AUTOHSCROLL
LTEXT "Min.",IDC_STATIC_MIN,50,70,20,10
LTEXT "Max.",IDC_STATIC_MAX,50,80,20,10
LTEXT "Value",IDC_STATIC_VALUE,50,98,20,10
LTEXT "MIN#",IDC_MIN,97,70,60,8
LTEXT "MAX#",IDC_MAX,97,81,60,8
EDITTEXT IDC_TEXT,35,80,165,12,ES_AUTOHSCROLL
COMBOBOX IDC_CHOICE,35,80,165,60,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Cancel",IDC_CANCEL,126,117,50,14
RTEXT "# of #",IDC_NUM,48,45,30,8
PUSHBUTTON "<--",IDC_PREV,86,45,20,10
PUSHBUTTON "-->",IDC_NEXT,111,45,20,10
CONTROL "TRUE",IDC_TRUE,"Button",BS_AUTORADIOBUTTON,69,84,34,10
CONTROL "FALSE",IDC_FALSE,"Button",BS_AUTORADIOBUTTON,128,84,36,10
PUSHBUTTON "OK",IDC_OK2,85,117,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_MAIN, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 374
TOPMARGIN, 7
BOTTOMMARGIN, 255
END
IDD_MODIFY, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 234
TOPMARGIN, 7
BOTTOMMARGIN, 131
END
END
#endif // APSTUDIO_INVOKED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
我们首先定义一些全局变量和辅助函数:
#include <windows.h>
#include <stdio.h>
#include "resource.h"
#include "action.h"
#pragma warning(disable : 4312 4313 4996)
//////////////////////////////////// global variable ////////////////////////////////////
HWND g_hwnd;
ACTION_TEMPLATE g_action_template;
long g_num_script;
BOOL g_show_cancel;
SCRIPT_PTR g_root_script;
SCRIPT_PTR g_modify_script; // pointer to script to modify
// The OPENFILENAME structure contains information that the GetOpenFileName and GetSaveFileName
// functions use to initialize an Open or Save As dialog box. After the user closes the dialog box,
// the system returns information about the user's selection in this structure.
OPENFILENAME g_ofn;
char g_action_file[MAX_PATH];
char g_script_file[MAX_PATH];
HWND g_script_wnd;
HWND g_script_addr_wnd;
HWND g_action_wnd;
BOOL CALLBACK modify_dialog_proc(HWND hwnd, UINT msg_id, WPARAM word_param, LPARAM long_param);
//////////////////////////////////// function ////////////////////////////////////
//-----------------------------------------------------------------------------------
// Remove all items from list box.
//-----------------------------------------------------------------------------------
void reset_listbox(HWND listbox)
{
// An application sends an LB_RESETCONTENT message to remove all items from a list box.
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns LRESULT in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) LB_RESETCONTENT, // message ID
// (WPARAM) wParam, // = (WPARAM) () wParam;
// (LPARAM) lParam // = (LPARAM) () lParam; );
//
// wParam:
// Not used; must be zero.
//
// lParam:
// Not used; must be zero.
//
// This message does not return a value.
SendMessage(listbox, LB_RESETCONTENT, 0, 0);
}
//-----------------------------------------------------------------------------------
// Return index of current selected item in listbox.
//-----------------------------------------------------------------------------------
LRESULT get_listbox_selected(HWND listbox)
{
// Send an LB_GETCURSEL message to retrieve the index of the currently selected item, if any,
// in a single-selection list box.
//
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns LRESULT in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) LB_GETCURSEL, // message ID
// (WPARAM) wParam, // = (WPARAM) () wParam;
// (LPARAM) lParam // = (LPARAM) () lParam;
// );
//
// wParam:
// Not used; must be zero.
//
// lParam:
// Not used; must be zero.
//
// Return Value
// In a single-selection list box, the return value is the zero-based index of the currently
// selected item. If there is no selection, the return value is LB_ERR.
return SendMessage(listbox, LB_GETCURSEL, 0, 0);
}
//-----------------------------------------------------------------------------------
// Set current selected item in listbox.
//-----------------------------------------------------------------------------------
LRESULT set_listbox_selected(HWND listbox, int selection)
{
// An application sends an LB_SETCURSEL message to select a string and scroll it into view, if necessary.
// When the new string is selected, the list box removes the highlight from the previously selected string.
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns LRESULT in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) LB_SETCURSEL, // message ID
// (WPARAM) wParam, // = (WPARAM) () wParam;
// (LPARAM) lParam // = (LPARAM) () lParam;
// );
//
// wParam:
// Specifies the zero-based index of the string that is selected.
// If this parameter is -1, the list box is set to have no selection.
//
// Microsoft Windows 95/Windows 98/Windows Millennium Edition (Windows Me) :
// The wParam parameter is limited to 16-bit values. This means list boxes cannot contain more
// than 32,767 items. Although the number of items is restricted, the total size in bytes of the
// items in a list box is limited only by available memory.
//
// lParam:
// This parameter is not used.
//
// Return Value:
// If an error occurs, the return value is LB_ERR. If the wParam parameter is –1, the return value
// is LB_ERR even though no error occurred.
//
// Remarks:
// Use this message only with single-selection list boxes. You cannot use it to set or remove a
// selection in a multiple-selection list box.
return SendMessage(listbox, LB_SETCURSEL, selection, NULL);
}
//-----------------------------------------------------------------------------------
// Get text of current selected item in listbox.
//-----------------------------------------------------------------------------------
LRESULT get_listbox_text(HWND listbox, int index, char* text)
{
// An application sends an LB_GETTEXT message to retrieve a string from a list box.
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns LRESULT in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) LB_GETTEXT, // message ID
// (WPARAM) wParam, // = (WPARAM) () wParam;
// (LPARAM) lParam // = (LPARAM) () lParam;
// );
//
// wParam:
// Specifies the zero-based index of the string to retrieve.
//
// Microsoft Windows 95/Windows 98/Windows Millennium Edition (Windows Me) :
// The wParam parameter is limited to 16-bit values. This means list boxes cannot contain more than
// 32,767 items. Although the number of items is restricted, the total size in bytes of the items
// in a list box is limited only by available memory.
//
// lParam:
// Pointer to the buffer that will receive the string; it is type LPTSTR which is subsequently cast to
// an LPARAM. The buffer must have sufficient space for the string and a terminating null character.
// An LB_GETTEXTLEN message can be sent before the LB_GETTEXT message to retrieve the length, in TCHARs,
// of the string.
//
// Return Value:
// The return value is the length of the string, in TCHARs, excluding the terminating null character.
// If wParam does not specify a valid index, the return value is LB_ERR.
//
//Remarks
// If you create the list box with an owner-drawn style but without the LBS_HASSTRINGS style,
// the buffer pointed to by the lParam parameter will receive the value associated with the item
// (the item data).
return SendMessage(listbox, LB_GETTEXT, index, (LPARAM)text);
}
//-----------------------------------------------------------------------------------
// Count listbox items number.
//-----------------------------------------------------------------------------------
LRESULT count_listbox(HWND listbox)
{
// An application sends an LB_GETCOUNT message to retrieve the number of items in a list box.
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns LRESULT in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) LB_GETCOUNT, // message ID
// (WPARAM) wParam, // = (WPARAM) () wParam;
// (LPARAM) lParam // = (LPARAM) () lParam;
// );
//
// wParam:
// Not used; must be zero.
//
// lParam:
// Not used; must be zero.
//
// Return Value:
// The return value is the number of items in the list box, or LB_ERR if an error occurs.
//
// Remarks:
// The returned count is one greater than the index value of the last item (the index is zero-based).
return SendMessage(listbox, LB_GETCOUNT, 0, 0);
}
//-----------------------------------------------------------------------------------
// Add string to listbox.
//-----------------------------------------------------------------------------------
LRESULT add_string_to_listbox(HWND listbox, const char* string)
{
// An application sends an LB_ADDSTRING message to add a string to a list box. If the list box does not have
// the LBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into
// the list and the list is sorted.
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns LRESULT in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) LB_ADDSTRING, // message ID
// (WPARAM) wParam, // = (WPARAM) () wParam;
// (LPARAM) lParam // = (LPARAM) () lParam;
// );
//
// wParam:
// This parameter is not used.
//
// lParam:
// Pointer to the null-terminated string that is to be added.
//
// If you create the list box with an owner-drawn style but without the LBS_HASSTRINGS style,
// this parameter is stored as item data instead of the string to which it would otherwise point.
// You can send the LB_GETITEMDATA and LB_SETITEMDATA messages to retrieve or modify the item data.
//
// Return Value:
// The return value is the zero-based index of the string in the list box. If an error occurs,
// the return value is LB_ERR. If there is insufficient space to store the new string, the return value
// is LB_ERRSPACE.
return SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)string);
}
//-----------------------------------------------------------------------------------
// Insert string into listbox at specified position.
//-----------------------------------------------------------------------------------
LRESULT insert_string_to_listbox(HWND listbox, int index, const char* string)
{
// An application sends an LB_INSERTSTRING message to insert a string into a list box.
// Unlike the LB_ADDSTRING message, the LB_INSERTSTRING message does not cause a list with
// the LBS_SORT style to be sorted.
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns LRESULT in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) LB_INSERTSTRING, // message ID
// (WPARAM) wParam, // = (WPARAM) () wParam;
// (LPARAM) lParam // = (LPARAM) () lParam;
// );
//
// wParam:
// Specifies the zero-based index of the position at which to insert the string.
// If this parameter is –1, the string is added to the end of the list.
//
// Microsoft Windows 95/Windows 98/Windows Millennium Edition (Windows Me) :
// The wParam parameter is limited to 16-bit values. This means list boxes cannot contain more
// than 32,767 items. Although the number of items is restricted, the total size in bytes of
// the items in a list box is limited only by available memory.
//
// lParam:
// Pointer to the null-terminated string to be inserted. If you create the list box with an
// owner-drawn style but without the LBS_HASSTRINGS style, the value of the lParam parameter is
// stored as item data instead of the string it would otherwise point to. You can send the
// LB_GETITEMDATA and LB_SETITEMDATA messages to retrieve or modify the item data.
//
// Return Value:
// The return value is the index of the position at which the string was inserted.
// If an error occurs, the return value is LB_ERR. If there is insufficient space to store the new
// string, the return value is LB_ERRSPACE.
//
// Remarks:
// The LB_INITSTORAGE message helps speed up the initialization of list boxes that have a large
// number of items (more than 100). It reserves the specified amount of memory so that subsequent
// LB_INSERTSTRING messages take the shortest possible time. You can use estimates for the wParam
// and lParam parameters. If you overestimate, the extra memory is allocated; if you underestimate,
// the normal allocation is used for items that exceed the requested amount.
//
// If the list box has WS_HSCROLL style and you insert a string wider than the list box, send an
// LB_SETHORIZONTALEXTENT message to ensure the horizontal scrollbar appears.
//
// Microsoft Windows NT/Windows 2000/Windows XP : For an ANSI application, the system converts the text
// in a list box to Unicode using CP_ACP. This can cause problems. For example, accented Roman characters
// in a non-Unicode list box in Japanese Windows will come out garbled. To fix this, either compile
// the application as Unicode or use an owner-drawn list box.
return SendMessage(listbox, LB_INSERTSTRING, index, (LPARAM)string);
}
//-----------------------------------------------------------------------------------
// Delete string in specified index from listbox.
//-----------------------------------------------------------------------------------
LRESULT delete_listbox_string(HWND listbox, int selection)
{
// An application sends an LB_DELETESTRING message to delete a string in a list box.
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns LRESULT in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) LB_DELETESTRING, // message ID
// (WPARAM) wParam, // = (WPARAM) () wParam;
// (LPARAM) lParam // = (LPARAM) () lParam;
// );
//
// wParam:
// Specifies the zero-based index of the string to be deleted.
//
// Microsoft Windows 95/Windows 98/Windows Millennium Edition (Windows Me) : T
// he wParam parameter is limited to 16-bit values. This means list boxes cannot contain more than
// 32,767 items. Although the number of items is restricted, the total size in bytes of the items
// in a list box is limited only by available memory.
//
// lParam:
// This parameter is not used.
//
// Return Value:
// The return value is a count of the strings remaining in the list. The return value is LB_ERR if
// the wParam parameter specifies an index greater than the number of items in the list.
//
// Remarks:
// If an application creates the list box with an owner-drawn style but without the LBS_HASSTRINGS style,
// the system sends a WM_DELETEITEM message to the owner of the list box so the application can free
// any additional data associated with the item.
return SendMessage(listbox, LB_DELETESTRING, selection, 0);
}
//-----------------------------------------------------------------------------------
// Set button state.
//-----------------------------------------------------------------------------------
LRESULT set_button_state(HWND button, UINT state)
{
// An application sends a BM_SETCHECK message to set the check state of a radio button or check box.
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns LRESULT in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) BM_SETCHECK, // message ID
// (WPARAM) wParam, // = (WPARAM) () wParam;
// (LPARAM) lParam // = 0; not used, must be zero
// );
//
// wParam:
// Specifies the check state. This parameter can be one of the following values.
//
// BST_CHECKED:
// Sets the button state to checked.
// BST_INDETERMINATE:
// Sets the button state to grayed, indicating an indeterminate state.
// Use this value only if the button has the BS_3STATE or BS_AUTO3STATE style.
// BST_UNCHECKED:
// Sets the button state to cleared.
//
// lParam:
// This parameter is not used.
//
// Return Value
// This message always returns zero.
//
//Remarks
// The BM_SETCHECK message has no effect on push buttons.
return SendMessage(button, BM_SETCHECK, state, 0);
}
//-----------------------------------------------------------------------------------
// Return button state.
//-----------------------------------------------------------------------------------
LRESULT get_button_state(HWND button)
{
return SendMessage(button, BM_GETCHECK, 0, 0);
}
//-----------------------------------------------------------------------------------
// Reset combo box.
//-----------------------------------------------------------------------------------
LRESULT reset_combo_content(HWND combo)
{
// An application sends a CB_RESETCONTENT message to remove all items from the list box and edit
// control of a combo box.
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns CB_OKAY in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) CB_RESETCONTENT, // message ID
// (WPARAM) wParam, // = 0; not used, must be zero
// (LPARAM) lParam // = 0; not used, must be zero
// );
//
// wParam:
// Not used; must be zero.
// lParam:
// Not used; must be zero.
//
// Return Value:
// This message always returns CB_OKAY.
//
// Remarks:
// If you create the combo box with an owner-drawn style but without the CBS_HASSTRINGS style,
// the owner of the combo box receives a WM_DELETEITEM message for each item in the combo box.
return SendMessage(combo, CB_RESETCONTENT, 0, 0);
}
//-----------------------------------------------------------------------------------
// Add string to combo box.
//-----------------------------------------------------------------------------------
LRESULT add_string_to_combo(HWND combo, char* string)
{
return SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)string);
}
//-----------------------------------------------------------------------------------
// Set current selction in combo box.
//-----------------------------------------------------------------------------------
LRESULT set_combo_cur_sel(HWND combo, UINT cur_sel)
{
// An application sends a CB_SETCURSEL message to select a string in the list of a combo box.
// If necessary, the list scrolls the string into view. The text in the edit control of the
// combo box changes to reflect the new selection, and any previous selection in the list is removed.
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns LRESULT in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) CB_SETCURSEL, // message ID
// (WPARAM) wParam, // = (WPARAM) () wParam;
// (LPARAM) lParam // = 0; not used, must be zero
// );
//
// wParam:
// Specifies the zero-based index of the string to select. If this parameter is –1,
// any current selection in the list is removed and the edit control is cleared.
//
// lParam:
// This parameter is not used.
//
// Return Value:
// If the message is successful, the return value is the index of the item selected.
// If wParam is greater than the number of items in the list or if wParam is –1,
// the return value is CB_ERR and the selection is cleared.
return SendMessage(combo, CB_SETCURSEL, cur_sel, 0);
}
//-----------------------------------------------------------------------------------
// Get current selction in combo box.
//-----------------------------------------------------------------------------------
LRESULT get_combo_cur_sel(HWND combo)
{
// An application sends a CB_GETCURSEL message to retrieve the index of the currently selected item,
// if any, in the list box of a combo box.
//
// To send this message, call the SendMessage function as follows.
//
// lResult = SendMessage( // returns LRESULT in lResult
// (HWND) hWndControl, // handle to destination control
// (UINT) CB_GETCURSEL, // message ID
// (WPARAM) wParam, // = 0; not used, must be zero
// (LPARAM) lParam // = 0; not used, must be zero
// );
//
// wParam:
// Not used; must be zero.
//
// lParam:
// Not used; must be zero.
//
// Return Value:
// The return value is the zero-based index of the currently selected item.
// If no item is selected, it is CB_ERR.
return SendMessage(combo, CB_GETCURSEL, 0, 0);
}