⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgtable.asm

📁 一个演示了用汇编语言编写的数据排序算法,源代码非常详细
💻 ASM
📖 第 1 页 / 共 3 页
字号:

;-----------------------------------------------------------------------------------------
; Prototypes.
;-----------------------------------------------------------------------------------------

  Listview_WndProc            PROTO :HWND, :UINT, :WPARAM, :LPARAM
  ShowContextMenu_TableDialog PROTO :HMENU, :DWORD, :DWORD, :HWND
  DeleteSelectedItems         PROTO :HWND


.code

;-----------------------------------------------------------------------------------------
; The procedure of the dialog for the tabular representation.
;-----------------------------------------------------------------------------------------

TableDialogProc PROC USES ebx esi edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

  mov    eax, uMsg

  .IF eax == WM_INITDIALOG

      ;-----------------------------------------------------------------------------------
      ;-- Save the handle of this dialog.
      mov    eax, hWnd
      mov    hDialogTable, eax


      ;-----------------------------------------------------------------------------------
      ;-- Load the options-menu and save its handle.
      invoke LoadMenu, hInstance, IDM_OPTIONS
      invoke GetSubMenu, eax, 0
      mov    hMENU_Options, eax


      ;-----------------------------------------------------------------------------------
      ;-- Load the item-options-menu and save its handle.
      invoke LoadMenu, hInstance, IDM_ITEMOPTIONS
      invoke GetSubMenu, eax, 0
      mov    hMENU_ItemOptions, eax


      ;-----------------------------------------------------------------------------------
      ;-- Retrieve the handles of the dialog items.

        ;---------------------------------------------------------------------------------
        ;-- List-Views
        invoke GetDlgItem, hWnd, IDDI_LV_ALGORITHMS
        mov    hTableDialog_LV_Algorithms, eax

        invoke GetDlgItem, hWnd, IDDI_LV_RESULT
        mov    hTableDialog_LV_Result, eax


        ;---------------------------------------------------------------------------------
        ;-- Buttons
        invoke GetDlgItem, hWnd, IDDI_B_SELECTALL
        mov    hTableDialog_B_SelectAll, eax

        invoke GetDlgItem, hWnd, IDDI_B_SELECTNONE
        mov    hTableDialog_B_SelectNone, eax

        invoke GetDlgItem, hWnd, IDDI_B_START2
        mov    hTableDialog_B_Start, eax

        invoke GetDlgItem, hWnd, IDDI_B_OPTIONS
        mov    hTableDialog_B_Options, eax


        ;---------------------------------------------------------------------------------
        ;-- Combo boxes
        invoke GetDlgItem, hWnd, IDDI_CB_DATA2
        mov    hTableDialog_CB_Data, eax

        invoke GetDlgItem, hWnd, IDDI_CB_ELEMENTS2
        mov    hTableDialog_CB_Elements, eax

        invoke GetDlgItem, hWnd, IDDI_CB_INITVALUE
        mov    hTableDialog_CB_InitValue, eax


        ;---------------------------------------------------------------------------------
        ;-- Statusbar
        invoke GetDlgItem, hWnd, IDDI_SB_TABLE
        mov    hTableDialog_SB, eax


      ;-----------------------------------------------------------------------------------
      ;-- Divide the status bar.
      invoke SendMessage, hTableDialog_SB, SB_SETPARTS, 3, OFFSET sbPartsTable


      ;-----------------------------------------------------------------------------------
      ;-- Add a column to the algorithm list-view.

        ;---------------------------------------------------------------------------------
        ;-- Compute its width.
        invoke GetWindowRect, hTableDialog_LV_Algorithms, OFFSET Rect
        mov    eax, Rect.right
        sub    eax, Rect.left
        sub    eax, 25


        ;---------------------------------------------------------------------------------
        ;-- Add the column.
        mov    LVcol.imask, LVCF_WIDTH or LVCF_FMT
        mov    LVcol.fmt, LVCFMT_LEFT
        mov    LVcol.lx, eax
        invoke SendMessage, hTableDialog_LV_Algorithms, LVM_INSERTCOLUMN, 0, OFFSET LVcol


      ;-----------------------------------------------------------------------------------
      ;-- Add the columns to the result list-view.
      mov    LVcol.imask, LVCF_TEXT or LVCF_WIDTH or LVCF_FMT
      mov    LVcol.fmt, LVCFMT_LEFT

      mov    eax, OFFSET LVResultInfo
    @@:
      ;-----------------------------------------------------------------------------------
      ;-- Get the standard width of the column.
      mov    ebx, DWORD PTR [eax]

      ;-----------------------------------------------------------------------------------
      ;-- Check whether the column shall be visible or not.

      test   ebx, LVCol_VISIBLE
      .IF ZERO?

          ;-------------------------------------------------------------------------------
          ;-- This column is hidden.
          mov    LVcol.lx, 0

      .ELSE

          ;-------------------------------------------------------------------------------
          ;-- This column is visible.
          and    ebx, LVCol_VISIBLE XOR 0FFFFFFFFh
          mov    LVcol.lx, ebx

      .ENDIF

      ;-----------------------------------------------------------------------------------
      ;-- Get the offset to the column title.
      add    eax, 4
      mov    ebx, DWORD PTR [eax]
      mov    ebx, DWORD PTR [ebx]
      mov    LVcol.pszText, ebx

      push   eax

        ;---------------------------------------------------------------------------------
        ;-- Get the column index and insert the column.
        mov    eax, DWORD PTR [eax + 4]
        invoke SendMessage, hTableDialog_LV_Result, LVM_INSERTCOLUMN, eax, OFFSET LVcol

      pop    eax

      ;-----------------------------------------------------------------------------------
      ;-- Have all columns been processed?
      add    eax, 8
      cmp    DWORD PTR [eax], NULL
      jnz    @B


      ;-----------------------------------------------------------------------------------
      ;-- Yes. Set the extended list-view styles.
      invoke SendMessage, hTableDialog_LV_Algorithms, LVM_SETEXTENDEDLISTVIEWSTYLE, STYLES_LV_ALGORITHMS, STYLES_LV_ALGORITHMS
      invoke SendMessage, hTableDialog_LV_Result, LVM_SETEXTENDEDLISTVIEWSTYLE, STYLES_LV_RESULT, STYLES_LV_RESULT


      ;-----------------------------------------------------------------------------------
      ;-- Fill the algorithm list-view.
      mov    LVitem.imask, LVIF_TEXT
      mov    LVitem.iSubItem, NULL

      mov    eax, OFFSET AlgorithmsInfo
      xor    ecx, ecx

      @@:
        push   eax
        push   ecx

          ;-------------------------------------------------------------------------------
          ;-- Insert an item.
          mov    LVitem.iItem, ecx
          mov    eax, DWORD PTR [eax]
          mov    LVitem.pszText, eax
          invoke SendMessage, hTableDialog_LV_Algorithms, LVM_INSERTITEM, NULL, OFFSET LVitem

        pop    ecx
        pop    eax

        inc    ecx
        add    eax, 8
        cmp    DWORD PTR [eax], 0
      jnz    @B


      ;-----------------------------------------------------------------------------------
      ;-- Fill the data combo box (presorting).
      invoke SendMessage, hTableDialog_CB_Data, CB_ADDSTRING, NULL, lpSTR_UNSORTED
      invoke SendMessage, hTableDialog_CB_Data, CB_ADDSTRING, NULL, lpSTR_SORTEDASC
      invoke SendMessage, hTableDialog_CB_Data, CB_ADDSTRING, NULL, lpSTR_SORTEDDESC


      ;-----------------------------------------------------------------------------------
      ;-- Fill the elements combo box (number of elements).
      mov    eax, OFFSET TABLE_AllowedElements

      @@:
        push   eax

          ;-------------------------------------------------------------------------------
          ;-- Get a number, convert it to an ASCII-string and add an item.
          mov    ebx, DWORD PTR [eax]
          invoke dwtoa, ebx, OFFSET Buffer
          invoke SendMessage, hTableDialog_CB_Elements, CB_ADDSTRING, NULL, OFFSET Buffer

        pop    eax

        add    eax, 4
        cmp    DWORD PTR [eax], 0
      jnz    @B


      ;-----------------------------------------------------------------------------------
      ;-- Select the first entries of each combo box.
      invoke SendMessage, hTableDialog_CB_Data, CB_SETCURSEL, 0, NULL
      invoke SendMessage, hTableDialog_CB_Elements, CB_SETCURSEL, 0, NULL


      ;-----------------------------------------------------------------------------------
      ;-- Subclass the algorithm list-view.
      invoke SetWindowLong, hTableDialog_LV_Algorithms, GWL_WNDPROC, OFFSET Listview_WndProc
      invoke SetWindowLong, hTableDialog_LV_Result, GWL_WNDPROC, OFFSET Listview_WndProc
      mov    lpWndProc_ListviewOld, eax


      ;-----------------------------------------------------------------------------------
      ;-- Load the language strings for this dialog.
      invoke LoadLanguageStrings, IDD_TABLE


      ;-----------------------------------------------------------------------------------
      ;-- Do not let Windows assign the default keyboard focus (return NULL in EAX).


  .ELSEIF eax == WM_COMMAND

      mov    eax, wParam
      mov    edx, eax
      shr    edx, 16

      .IF dx == BN_CLICKED

          .IF ax == IDDI_B_SELECTALL

              ;---------------------------------------------------------------------------
              ;-- Check all items in the algorithm list-view.


              ;---------------------------------------------------------------------------
              ;-- Get the number of items in the list-view.
              invoke SendMessage, hTableDialog_LV_Algorithms, LVM_GETITEMCOUNT, NULL, NULL
              dec    eax

              mov    LVitem.imask, LVIF_STATE
              mov    LVitem.state, 8192
              mov    LVitem.stateMask, 8192 or 4096

            @@:
              push   eax

                ;-------------------------------------------------------------------------
                ;-- Check the item.
                invoke SendMessage, hTableDialog_LV_Algorithms, LVM_SETITEMSTATE, eax, OFFSET LVitem

              pop    eax

              dec    eax
              jns    @B


          .ELSEIF ax == IDDI_B_SELECTNONE

              ;---------------------------------------------------------------------------
              ;-- Uncheck all items in the algorithm list-view.


              ;---------------------------------------------------------------------------
              ;-- Get the number of items in the list-view.
              invoke SendMessage, hTableDialog_LV_Algorithms, LVM_GETITEMCOUNT, NULL, NULL
              dec    eax

              mov    LVitem.imask, LVIF_STATE
              mov    LVitem.state, 4096
              mov    LVitem.stateMask, 8192 or 4096

            @@:
              push   eax

                ;-------------------------------------------------------------------------
                ;-- Uncheck the item.
                invoke SendMessage, hTableDialog_LV_Algorithms, LVM_SETITEMSTATE, eax, OFFSET LVitem

              pop    eax

              dec    eax
              jns    @B


           .ELSEIF ax == IDDI_B_OPTIONS

              ;---------------------------------------------------------------------------
              ;-- Show the options menu.


              ;---------------------------------------------------------------------------
              ;-- Get the coordinates of the options button.
              invoke GetWindowRect, hTableDialog_B_Options, OFFSET Rect


              ;---------------------------------------------------------------------------
              ;-- Convert the coordinates of the left lower edge to screen coordinates.
              mov    PT.x, 0
              mov    eax, Rect.bottom
              sub    eax, Rect.top
              mov    PT.y, eax
              invoke ClientToScreen, hTableDialog_B_Options, OFFSET PT


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -