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

📄 dlggraphic.asm

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

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

  DisplayProc                   PROTO :HWND, :UINT, :WPARAM, :LPARAM
  ShowContextMenu_GraphicDialog PROTO :HMENU, :DWORD, :DWORD, :HWND
  SaveDisplayAsBitmap           PROTO :LPSTR 

.code

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

GraphicDialogProc 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    hDialogGraphic, eax


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


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

        ;---------------------------------------------------------------------------------
        ;-- Combo boxes
        invoke GetDlgItem, hWnd, IDDI_CB_ALGORITHM
        mov    hGraphicDialog_CB_Algorithm, eax

        invoke GetDlgItem, hWnd, IDDI_CB_DATA
        mov    hGraphicDialog_CB_Data, eax

        invoke GetDlgItem, hWnd, IDDI_CB_ELEMENTS
        mov    hGraphicDialog_CB_Elements, eax

        invoke GetDlgItem, hWnd, IDDI_CB_DELAY
        mov    hGraphicDialog_CB_Delay, eax

        invoke GetDlgItem, hWnd, IDDI_CB_DELAYPOS
        mov    hGraphicDialog_CB_DelayPos, eax

        invoke GetDlgItem, hWnd, IDDI_CB_INITVALUE2
        mov    hGraphicDialog_CB_InitValue2, eax


        ;---------------------------------------------------------------------------------
        ;-- Static control
        invoke GetDlgItem, hWnd, IDDI_DISPLAY
        mov    hGraphicDialog_S_Display, eax


        ;---------------------------------------------------------------------------------
        ;-- Buttons
        invoke GetDlgItem, hWnd, IDDI_B_START
        mov    hGraphicDialog_B_Start, eax

        invoke GetDlgItem, hWnd, IDDI_B_GENERATE
        mov    hGraphicDialog_B_Generate, eax

        invoke GetDlgItem, hWnd, IDDI_B_OPTIONS2
        mov    hGraphicDialog_B_Options2, eax


        ;---------------------------------------------------------------------------------
        ;-- Status bar
        invoke GetDlgItem, hWnd, IDDI_SB_GRAPHIC
        mov    hGraphicDialog_SB, eax


      ;-----------------------------------------------------------------------------------
      ;-- Divide the status bar.
      invoke SendMessage, hGraphicDialog_SB, SB_SETPARTS, 3, OFFSET sbPartsGraphic


      ;-----------------------------------------------------------------------------------
      ;-- Fill the algorithms combo box.
      mov    eax, OFFSET AlgorithmsInfo

      @@:
        push   eax

          ;-------------------------------------------------------------------------------
          ;-- Insert an item.
          invoke SendMessage, hGraphicDialog_CB_Algorithm, CB_ADDSTRING, NULL, DWORD PTR [eax]

        pop    eax

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


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


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

      @@:
        push   eax

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

        pop    eax

        inc    eax
        cmp    BYTE PTR [eax], 0
      jnz    @B


      ;-----------------------------------------------------------------------------------
      ;-- Fill the delay combo box (number of milliseconds).
      mov    eax, OFFSET AllowedDelays

      @@:
        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 szCatStr, OFFSET Buffer, lpSTR_MS
          invoke SendMessage, hGraphicDialog_CB_Delay, CB_ADDSTRING, NULL, OFFSET Buffer

        pop    eax

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


      ;-----------------------------------------------------------------------------------
      ;-- Fill the delay combo box (position).
      invoke SendMessage, hGraphicDialog_CB_DelayPos, CB_ADDSTRING, NULL, lpSTR_CBI_EACHPASS
      invoke SendMessage, hGraphicDialog_CB_DelayPos, CB_ADDSTRING, NULL, lpSTR_CBI_EACHCOMPARISON
      invoke SendMessage, hGraphicDialog_CB_DelayPos, CB_ADDSTRING, NULL, lpSTR_CBI_EACHEXCHANGE


      ;-----------------------------------------------------------------------------------
      ;-- Select the first entries of each combo box and set the corresponding
      ;-- values.
      invoke SendMessage, hGraphicDialog_CB_Algorithm, CB_SETCURSEL, 0, NULL


      invoke SendMessage, hGraphicDialog_CB_Data, CB_SETCURSEL, 0, NULL
      mov    SortInfo.direction, 0


      invoke SendMessage, hGraphicDialog_CB_Elements, CB_SETCURSEL, 0, NULL
      xor    eax, eax
      mov    al, GRAPHIC_AllowedElements[0]
      mov    SortInfo.numElements, eax

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


      invoke SendMessage, hGraphicDialog_CB_Delay, CB_SETCURSEL, 0, NULL
      mov    eax, AllowedDelays[0*4]
      mov    SortInfo.delay, eax


      invoke SendMessage, hGraphicDialog_CB_DelayPos, CB_SETCURSEL, 0, NULL
      mov    SortInfo.fDelayPosition, 0


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


      ;-----------------------------------------------------------------------------------
      ;-- Create the needed brushes and pens.
      invoke GetStockObject, WHITE_BRUSH
      mov    hBrush_Background, eax

      invoke CreatePen, PS_SOLID, 0, 0FFFFFFh
      mov    hPen_BackgroundFrame, eax

      invoke CreatePen, PS_SOLID, 2, 0FFFFFFh
      mov    hPen_Background, eax

      invoke CreatePen, PS_DOT, 1, 00000FFh
      mov    hPen_ComparedElement, eax


      ;-----------------------------------------------------------------------------------
      ;-- Create an array in which the pens for painting the elements are saved.
      mov    eax, 0A5FE00h
      mov    ecx, 127

    @@:
      push   eax

        ;---------------------------------------------------------------------------------
        ;-- Create a pen with the specified color.
        push   ecx
          invoke CreatePen, PS_SOLID, 2, eax
        pop    ecx


        ;---------------------------------------------------------------------------------
        ;-- Save the pen.
        mov    DWORD PTR [OFFSET hPens_Array + ecx*4], eax

      pop    eax
      sub    eax, 000200h
      dec    ecx
      jns    @B


      ;-----------------------------------------------------------------------------------
      ;-- Retrieve and save the height and width of the display window.
      invoke GetClientRect, hGraphicDialog_S_Display, OFFSET Rect
      mov    eax, Rect.right
      mov    Display_Right, eax

      mov    eax, Rect.bottom
      mov    Display_Bottom, eax


      ;-----------------------------------------------------------------------------------
      ;-- Subclass the display window.
      invoke SetWindowLong, hGraphicDialog_S_Display, GWL_WNDPROC, OFFSET DisplayProc
      mov    lpDisplayProcOld, eax


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


      ;-----------------------------------------------------------------------------------
      ;-- Create the elements.
      mov    SortInfo.lpElements, OFFSET ElementsArr
      invoke CreateElements


      ;-----------------------------------------------------------------------------------
      ;-- 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_OPTIONS2

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


              ;---------------------------------------------------------------------------
              ;-- Get the coordinates of the options button.
              invoke GetWindowRect, hGraphicDialog_B_Options2, 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, hGraphicDialog_B_Options2, OFFSET PT


              ;---------------------------------------------------------------------------
              ;-- Show the popup menu.
              invoke ShowContextMenu_GraphicDialog, hMENU_Options2, PT.x, PT.y, hWnd


           .ELSEIF ax == IDDI_B_START

              ;---------------------------------------------------------------------------
              ;-- Start/cancel the sorting process.


              .IF !SortInfo.fSorting

                  ;-----------------------------------------------------------------------
                  ;-- Start the sorting process.

                  invoke StartSorting


                  ;-----------------------------------------------------------------------
                  ;-- Set the focus to the delay combo box.
                  invoke SetFocus, hGraphicDialog_CB_Delay

              .ELSE

                  ;-----------------------------------------------------------------------
                  ;-- Terminate the sorting process.
                  invoke CancelSorting

              .ENDIF


          .ELSEIF (ax == IDDI_B_GENERATE) && !SortInfo.fSorting

              mov    eax, TRUE

          @Generate:
              ;---------------------------------------------------------------------------

⌨️ 快捷键说明

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