• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當(dāng)自強(qiáng)而不息

            游戲腳本的實(shí)現(xiàn)(3)

             

            本篇是游戲腳本的實(shí)現(xiàn)(2)的續(xù)篇。

             

            MLS編輯器的使用

            MLS系統(tǒng)僅使用到數(shù)字:代表行為的編號(hào),隨后條目的數(shù)量,以及代表?xiàng)l目數(shù)據(jù)的編號(hào)。計(jì)算機(jī)特別擅長(zhǎng)處理數(shù)字的工作,但我們的需要更多。需要將腳本構(gòu)造成易于理解的文本行,并讓腳本編輯器將鍵入的文本轉(zhuǎn)變?yōu)槟_本系統(tǒng)可以處理的一系列數(shù)字。

            在編輯一個(gè)腳本期間,并不處理任何數(shù)字方面的問(wèn)題,所以編輯器的工作還包括加載數(shù)字并將它們轉(zhuǎn)換回易于閱讀理解的文本行。因此,也可以這么說(shuō),僅需要使用一系列的文本命令構(gòu)造一個(gè)腳本,然后使用腳本編輯器將這些命令轉(zhuǎn)換成代表它們數(shù)值,反之亦然。

            MLS編輯器導(dǎo)入那些代表行為的文本行,并賦予用戶能力去編輯行為列表,以及在空白條目點(diǎn)填上行為,MLS編輯器的外觀如下圖所示:

            下表詳細(xì)解釋了腳本編輯器每個(gè)按鈕的用途:

            將行為添加到腳本中時(shí)(添加腳本或插入腳本),請(qǐng)注意行為的文本將被擴(kuò)展,并添加到腳本列表框中(位于腳本編輯器頂端的列表框)。腳本行為從上到下進(jìn)行存儲(chǔ),根節(jié)點(diǎn)存儲(chǔ)了最頂端的腳本行為,腳本從頂端開(kāi)始往下處理,與典型的C/C++代碼非常類似。

            請(qǐng)注意,每次添加、插入、或編輯一個(gè)腳本條目時(shí),修改行為條目的對(duì)話框?qū)⒊霈F(xiàn)(如下圖所示),將使用這個(gè)對(duì)話框去修改腳本行為的條目。

             

            MLS編輯器的創(chuàng)建

            首先,我們?cè)O(shè)計(jì)MLS編輯器主窗口的界面:

            接著我們?cè)O(shè)計(jì)修改腳本的對(duì)話框:

             

            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
             

             

            我們首先定義一些全局變量和輔助函數(shù):

            #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 charstring)
            {
                
            // 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 charstring)
            {
                
            // 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, charstring)
            {
                
            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);    
            }

            posted on 2007-11-03 17:54 lovedday 閱讀(1064) 評(píng)論(0)  編輯 收藏 引用

            公告

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評(píng)論

            久久久午夜精品| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 理论片午午伦夜理片久久 | 亚洲欧洲中文日韩久久AV乱码| 久久国产乱子伦精品免费午夜| 精品国产婷婷久久久| 99蜜桃臀久久久欧美精品网站| 精品国产VA久久久久久久冰| 国产精品热久久毛片| 97香蕉久久夜色精品国产| 97久久久精品综合88久久| 国产成人精品久久综合| 香蕉久久久久久狠狠色| 久久中文娱乐网| 日日躁夜夜躁狠狠久久AV| 久久精品国产精品亚洲人人| 人妻丰满AV无码久久不卡| 久久久久亚洲AV无码专区桃色| 久久丫精品国产亚洲av不卡| 国产精品嫩草影院久久| 国产三级久久久精品麻豆三级| 丁香五月网久久综合| 国产亚洲精品美女久久久| 精品乱码久久久久久夜夜嗨| 亚洲乱码精品久久久久..| 久久久久亚洲精品无码网址| 精品久久久久中文字幕日本| 久久精品中文无码资源站| 精品久久人人做人人爽综合| 久久久久免费精品国产| 久久久国产精品亚洲一区 | 久久久受www免费人成| 久久婷婷久久一区二区三区| 99国产欧美久久久精品蜜芽| 久久精品国产99久久久古代| 日韩美女18网站久久精品| 99久久99久久精品国产片| 精品国产一区二区三区久久| 亚洲精品第一综合99久久| 久久综合久久性久99毛片| 久久久精品人妻无码专区不卡|