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

📄 dlgframe.asm

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


.code

;-----------------------------------------------------------------------------------------
; The procedure of the frame dialog (contains the tab control and the main menu)
;-----------------------------------------------------------------------------------------

FrameDialogProc 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    hDialogFrame, eax


      ;-----------------------------------------------------------------------------------
      ;-- Retrieve the handle of the main menu.
      invoke GetMenu, hWnd
      mov    hMENU_Program, eax


      ;-----------------------------------------------------------------------------------
      ;-- Load and show the program icon.
      invoke LoadIcon, hInstance, IDI_PROGRAM
      invoke SendMessage, hWnd, WM_SETICON, ICON_BIG, eax


      ;-----------------------------------------------------------------------------------
      ;-- Select a language.
      invoke GetUserDefaultLangID
      .IF al == LANG_GERMAN
          mov    eax, IDMI_LANG_GERMAN
      .ELSE
          mov    eax, IDMI_LANG_ENGLISH
      .ENDIF
      invoke SwitchLanguage, eax


      ;-----------------------------------------------------------------------------------
      ;-- Insert the tabs in the tab control.
      invoke GetDlgItem, hWnd, IDDI_TABCONTROL
      mov    hTabControl, eax

      mov    TCI.imask, TCIF_TEXT
      mov    TCI.pszText, NULL
      invoke SendMessage, hTabControl, TCM_INSERTITEM, TABINDEX_TABLE, OFFSET TCI

      mov    TCI.pszText, NULL
      invoke SendMessage, hTabControl, TCM_INSERTITEM, TABINDEX_GRAPHIC, OFFSET TCI


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


      ;-----------------------------------------------------------------------------------
      ;-- Create the dialogs for both tabs.
      invoke CreateDialogParam, hInstance, IDD_GRAPHIC, hWnd, OFFSET GraphicDialogProc, NULL
      invoke CreateDialogParam, hInstance, IDD_TABLE, hWnd, OFFSET TableDialogProc, NULL


      ;-----------------------------------------------------------------------------------
      ;-- Show the dialog with the tabular representation.
      mov    hCurrentDialog, eax
      invoke ShowWindow, eax, SW_SHOW


      ;-----------------------------------------------------------------------------------
      ;-- Let Windows assign the default keyboard focus.
      mov    eax, TRUE
      ret


  .ELSEIF eax == WM_NOTIFY

      mov    eax, lParam
      mov    ecx, (NMHDR ptr [eax]).code

      .IF ecx == TCN_SELCHANGE

          ;-------------------------------------------------------------------------------
          ;-- Another tab than the current one has been selected.

          .IF SortInfo.fSorting

              ;---------------------------------------------------------------------------
              ;-- If the sorting process is running the tab cannot be changed.

              mov    eax, hCurrentDialog
              .IF eax == hDialogTable
                  mov    eax, TABINDEX_TABLE
              .ELSE
                  mov    eax, TABINDEX_GRAPHIC
              .ENDIF


              ;---------------------------------------------------------------------------
              ;-- Restore the previous selected tab.
              invoke SendMessage, hTabControl, TCM_SETCURSEL, eax, NULL


              ;---------------------------------------------------------------------------
              ;-- Play a waveform sound to draw attention to the running sorting process.
              invoke MessageBeep, MB_OK


              ;---------------------------------------------------------------------------
              ;-- This message has been processed.
              xor eax, eax
              ret

          .ENDIF


          ;-------------------------------------------------------------------------------
          ;-- The sorting process is not running. Hide the currently shown dialog.
          invoke ShowWindow, hCurrentDialog, SW_HIDE


          ;-------------------------------------------------------------------------------
          ;-- Show the other dialog.
          mov    eax, hCurrentDialog

          .IF eax == hDialogGraphic

              ;---------------------------------------------------------------------------
              ;-- The dialog with the tabular representation shall be shown.
              mov    SortInfo.fGraphic, FALSE


              ;---------------------------------------------------------------------------
              ;-- Load the dialog handle.
              mov    eax, hDialogTable

          .ELSE

              ;---------------------------------------------------------------------------
              ;-- The dialog with the graphical representation shall be shown.
              mov    SortInfo.fGraphic, TRUE

              ;---------------------------------------------------------------------------
              ;-- Get the selected presorting.
              invoke SendMessage, hGraphicDialog_CB_Data, CB_GETCURSEL, NULL, NULL
              mov    SortInfo.direction, al


              ;---------------------------------------------------------------------------
              ;-- Get the number of elements.
              invoke SendMessage, hGraphicDialog_CB_Elements, CB_GETCURSEL, NULL, NULL
              xor    ebx, ebx
              mov    bl, BYTE PTR [eax + OFFSET GRAPHIC_AllowedElements]
              mov    SortInfo.numElements, ebx

              dec    ebx
              mov    SortInfo.maxValue, ebx
              mov    SortInfo.minValue, 0


              ;---------------------------------------------------------------------------
              ;-- Create an initialization value for the random number generator.
              invoke GetTickCount
              mov    SortInfo.randInitValue, eax


              ;---------------------------------------------------------------------------
              ;-- Load the offset of the array containing the elements that shall be
              ;-- sorted.
              mov    SortInfo.lpElements, OFFSET ElementsArr


              ;---------------------------------------------------------------------------
              ;-- Get the delay.
              invoke SendMessage, hGraphicDialog_CB_Delay, CB_GETCURSEL, NULL, NULL
              mov    eax, AllowedDelays[eax*4]
              mov    SortInfo.delay, eax


              ;---------------------------------------------------------------------------
              ;-- Get the wanted position of the delay. 
              invoke SendMessage, hGraphicDialog_CB_DelayPos, CB_GETCURSEL, NULL, NULL
              mov    SortInfo.fDelayPosition, al


              ;---------------------------------------------------------------------------
              ;-- Load the dialog handle.
              mov    eax, hDialogGraphic

          .ENDIF

          ;-------------------------------------------------------------------------------
          ;-- Show the dialog.
          mov    hCurrentDialog, eax
          invoke ShowWindow, eax, SW_SHOW

      .ENDIF


  .ELSEIF eax == WM_COMMAND

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

      .IF !dx
          ;-------------------------------------------------------------------------------
          ;-- A menu item has been selected.
          .IF ax == IDMI_EXIT

              ;---------------------------------------------------------------------------
              ;-- Quit the program.
              jmp    @Exit


          .ELSEIF ax == IDMI_INFO

              ;---------------------------------------------------------------------------
              ;-- Show the About-dialog.
              invoke DialogBoxParam, hInstance, IDD_INFO, hWnd, OFFSET InfoDialogProc, 0


          .ELSEIF (ax == IDMI_LANG_GERMAN) || (ax == IDMI_LANG_ENGLISH)

              ;---------------------------------------------------------------------------
              ;-- The language shall be changed.
              xor    ebx, ebx
              mov    bx, ax
              invoke SwitchLanguage, ebx


          .ELSEIF ax == IDMI_HELP_GERMAN

              ;---------------------------------------------------------------------------
              ;-- Open the german help file.
              invoke ShellExecute, NULL, OFFSET OperationOpen, lpSTR_HELP_GERMAN, NULL,
                                   NULL, SW_MAXIMIZE


          .ELSEIF ax == IDMI_HELP_ENGLISH

              ;---------------------------------------------------------------------------
              ;-- Open the english help file.
              invoke ShellExecute, NULL, OFFSET OperationOpen, lpSTR_HELP_ENGLISH, NULL,
                                   NULL, SW_MAXIMIZE


          .ENDIF

      .ENDIF

  .ELSEIF eax == WM_NCACTIVATE

      cmp    wParam, FALSE
      je     @Return

      invoke UpdateWindow, hWnd

  .ELSEIF eax == WM_CLOSE
  @Exit:
      cmp    SortInfo.fSorting, FALSE
      je     @F
      
      ;-----------------------------------------------------------------------------------
      ;-- A sorting process is running. Ask the user whether he really wants to quit the
      ;-- program.
      invoke MessageBox, hWnd, lpSTR_SORTINGPROCESSRUNNING, lpSTR_TITLE_PROGRAM, MB_YESNO or MB_ICONQUESTION or MB_DEFBUTTON2
      cmp    eax, IDYES
      jne    @Return


    @@:
      ;-----------------------------------------------------------------------------------
      ;-- Quit the program.
      invoke EndDialog, hWnd, 0

  .ENDIF


@Return:
  xor eax, eax
  ret
FrameDialogProc ENDP

⌨️ 快捷键说明

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