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

📄 dlggraphic.asm

📁 一个演示了用汇编语言编写的数据排序算法,源代码非常详细
💻 ASM
📖 第 1 页 / 共 3 页
字号:
              ;-- Generate new elements (only possible if the sorting process is not
              ;-- running).


              ;---------------------------------------------------------------------------
              ;-- Get the specified initialization value for the random number generator.
              invoke GetInitializationValue, hWnd, hGraphicDialog_CB_InitValue2, eax
              test   eax, eax
              jz     @Return


              ;---------------------------------------------------------------------------
              ;-- Create the elements.
              invoke CreateElements


              ;---------------------------------------------------------------------------
              ;-- Paint the elements.
              invoke PaintElements, -1, NULL, FALSE

          .ENDIF


      .ELSEIF dx == CBN_EDITCHANGE

          .IF ax == IDDI_CB_INITVALUE2

              xor    eax, eax
              jmp    @Generate

          .ENDIF

      .ELSEIF dx == CBN_SELCHANGE

          ;-------------------------------------------------------------------------------
          ;-- The selection of a combo box was changed.
          .IF ax == IDDI_CB_DELAY

              ;---------------------------------------------------------------------------
              ;-- The delay (number of milliseconds) was changed.


              ;---------------------------------------------------------------------------
              ;-- Get the new value and save it.
              invoke SendMessage, hGraphicDialog_CB_Delay, CB_GETCURSEL, NULL, NULL
              mov    eax, DWORD PTR [eax*4 + OFFSET AllowedDelays]
              mov    SortInfo.delay, eax

          .ELSEIF ax == IDDI_CB_DELAYPOS

              ;---------------------------------------------------------------------------
              ;-- The delay (position) was changed.


              ;---------------------------------------------------------------------------
              ;-- Get the new position and save it.
              invoke SendMessage, hGraphicDialog_CB_DelayPos, CB_GETCURSEL, NULL, NULL
              mov    SortInfo.fDelayPosition, al


          .ELSEIF !SortInfo.fSorting

              ;---------------------------------------------------------------------------
              ;-- The following settings can only be changed when the sorting process is
              ;-- not running.

              .IF ax == IDDI_CB_DATA

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


                  ;-----------------------------------------------------------------------
                  ;-- Create new elements.
                  xor    eax, eax
                  jmp    @Generate

              .ELSEIF ax == IDDI_CB_ELEMENTS

                  ;-----------------------------------------------------------------------
                  ;-- Get the number of elements and save it.
                  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


                  ;-----------------------------------------------------------------------
                  ;-- Create new elements.
                  xor    eax, eax
                  jmp    @Generate

              .ENDIF

          .ENDIF

      .ENDIF


  .ELSEIF (eax == WM_TIMER) || (eax == WM_APP)

      ;-----------------------------------------------------------------------------------
      ;-- Show the progress of the sorting process.


      ;-----------------------------------------------------------------------------------
      ;-- Convert the comparison counter to a string and show it in the status
      ;-- bar.
      invoke szCopy, lpSTR_SB_COMPARISONS, OFFSET Buffer
      invoke StrLen, OFFSET Buffer
      add    eax, OFFSET Buffer
      invoke QW2ASCII, OFFSET SortInfo.cmpCounter, eax
      invoke SendMessage, hGraphicDialog_SB, SB_SETTEXT, SB_PART_CMPCOUNTER, OFFSET Buffer


      ;-----------------------------------------------------------------------------------
      ;-- Convert the exchange counter to a string and show it in the status bar.
      invoke szCopy, lpSTR_SB_EXCHANGES, OFFSET Buffer
      invoke StrLen, OFFSET Buffer
      add    eax, OFFSET Buffer
      invoke QW2ASCII, OFFSET SortInfo.movCounter, eax
      invoke SendMessage, hGraphicDialog_SB, SB_SETTEXT, SB_PART_MOVCOUNTER, OFFSET Buffer

  .ENDIF


@Return:
  xor eax, eax
  ret
GraphicDialogProc ENDP



;-----------------------------------------------------------------------------------------
; The procedure of the display window (belongs to the graphic dialog).
;-----------------------------------------------------------------------------------------

DisplayProc PROC hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

  LOCAL PS:PAINTSTRUCT

  .IF uMsg == WM_PAINT

      ;-----------------------------------------------------------------------------------
      ;-- Prepare the display window for painting and retrieve the handle to a display
      ;-- device context.
      invoke BeginPaint, hWnd, ADDR PS


      ;-----------------------------------------------------------------------------------
      ;-- Redraw all elements.
      push   eax
        invoke PaintElements, -1, eax, FALSE
      pop    eax


      ;-----------------------------------------------------------------------------------
      ;-- Redraw the compared elements (if any).
      .IF Element1 != -1
          push   eax
            invoke PaintElements, Element1, eax, TRUE
          pop    eax
          .IF Element2 != -1
              invoke PaintElements, Element2, eax, TRUE
          .ENDIF
      .ENDIF


      ;-----------------------------------------------------------------------------------
      ;-- The window is painted.
      invoke EndPaint, hWnd, ADDR PS

  .ELSEIF uMsg == WM_CONTEXTMENU

      ;-------------------------------------------------------------------------------
      ;-- Show the context menu of the display window.

      mov    eax, lParam
      xor    ebx, ebx
      mov    bx, ax
      shr    eax, 16

      ;-------------------------------------------------------------------------------
      ;-- Convert the mouse coordinates to client coordinates of the result
      ;-- list-view.
      mov    LVHTI.pt.x, ebx
      mov    LVHTI.pt.y, eax
      invoke ScreenToClient, hGraphicDialog_S_Display, OFFSET LVHTI.pt


      ;-------------------------------------------------------------------------------
      ;-- Show the popup menu.
      mov    eax, lParam
      xor    ebx, ebx
      mov    bx, ax
      shr    eax, 16

      invoke ShowContextMenu_GraphicDialog, hMENU_Options2, ebx, eax, hWnd

  .ELSE

      ;-----------------------------------------------------------------------------------
      ;-- Pass the arguments to the old window procedure.
      invoke CallWindowProc, lpDisplayProcOld, hWnd, uMsg, wParam, lParam
      ret

  .ENDIF


@Return:
  xor eax, eax
  ret
DisplayProc ENDP



;-----------------------------------------------------------------------------------------
; Purpose:     Shows a context menu a evaluates the selection.
;
; Inputs:      hMENU - handle to the menu that shall be shown
;              x, y  - coordinates for the menu
;              hWnd  - handle of the owner window
;
; Outputs:     depending on the selection
;
; Notes:       none
;-----------------------------------------------------------------------------------------

ShowContextMenu_GraphicDialog PROC hMENU:HMENU, x:DWORD, y:DWORD, hWnd:DWORD

  ;---------------------------------------------------------------------------------------
  ;-- Set the menu item states.
  .IF fDisplayLines

      mov    eax, MF_BYCOMMAND or MF_CHECKED
      mov    ebx, MF_BYCOMMAND or MF_UNCHECKED

  .ELSE

      mov    eax, MF_BYCOMMAND or MF_UNCHECKED
      mov    ebx, MF_BYCOMMAND or MF_CHECKED

  .ENDIF

  push   ebx
    invoke CheckMenuItem, hMENU, IDMI_LINES, eax
  pop    ebx
  invoke CheckMenuItem, hMENU, IDMI_POINTS, ebx


  ;---------------------------------------------------------------------------------------
  ;-- Show the popup menu and track the selection.
  invoke TrackPopupMenu, hMENU, TPM_LEFTALIGN  or TPM_TOPALIGN or TPM_RIGHTBUTTON or TPM_RETURNCMD, x, y, NULL, hWnd, NULL


  ;---------------------------------------------------------------------------------------
  ;-- Was an menu item selected?
  test   eax, eax
  jz     @Return


  ;---------------------------------------------------------------------------------------
  ;-- Yes, but which?
  .IF eax == IDMI_LINES

      ;-----------------------------------------------------------------------------------
      ;-- Display lines.
      mov    fDisplayLines, TRUE

      jmp    @DrawElements

  .ELSEIF eax == IDMI_POINTS

      ;-----------------------------------------------------------------------------------
      ;-- Display points.
      mov    fDisplayLines, FALSE

      jmp    @DrawElements

  .ELSEIF eax == IDMI_SAVEASBITMAP

      ;-----------------------------------------------------------------------------------
      ;-- Save the content of the display window as bitmap.
      ;-- First get the filename.
      mov    OFN.lStructSize,        SIZEOF OFN
      mov    eax, hWnd
      mov    OFN.hWndOwner,          eax
      mov    eax, hInstance
      mov    OFN.hInstance,          eax
      mov    OFN.lpstrFilter,        OFFSET FILTER_SaveAsBMP
      mov    OFN.lpstrFile,          OFFSET filenameBMP
      mov    OFN.nMaxFile,           SIZEOF filenameBMP
      mov    eax, lpSTR_TITLE_SAVEAS
      mov    OFN.lpstrTitle,         eax
      mov    OFN.Flags,              OFN_EXPLORER or OFN_LONGNAMES or \
                                     OFN_HIDEREADONLY or OFN_PATHMUSTEXIST or \
                                     OFN_OVERWRITEPROMPT
      mov    OFN.nFilterIndex,       0

      invoke GetSaveFileName, OFFSET OFN


      ;-----------------------------------------------------------------------------------
      ;-- Did the user press cancel?
      test   eax, eax
      jz     @Return


      ;-----------------------------------------------------------------------------------
      ;-- No. Get the length of the filename.
      invoke StrLen, OFFSET filenameBMP
      

      ;-----------------------------------------------------------------------------------
      ;-- Check whether the filename ends with '.bmp' .
      cmp    eax, 4
      jna    @F

        add    eax, OFFSET filenameBMP - 4
        invoke szCmpi, eax, EXTENSION_BMP, 4
        test   eax, eax
        jz     @F


        ;---------------------------------------------------------------------------------
        ;-- Append the extension 'bmp' including the dot (=> '.bmp').
        invoke szCatStr, OFFSET filenameBMP, EXTENSION_BMP

⌨️ 快捷键说明

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