Win32汇编---对话框资源的综合应用

这个实验中基本上把改用的对话框资源都用上了,GROUPBOX, AUTOCHECKBOX,COMBOBOX,EDITTEXT,TEXT,SCROLLBAR,PUSHBUTTON...一开始对于控件的位置可能把握不好,但是我想先把一些基本组件的特征写出来,位置,大小都设置为0,保存为RC文件,然后用编译成RES文件,用VC++6.0来编辑这些控件,把位置,大小都弄成合适的大小,保存。也可以另存为一份RC文件,里面把位置,大小的数值都列出来了~~


资源文件Control.rc源代码如下:

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#include        <resource.h>

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#define ICO_MAIN        0x1000

#define DLG_MAIN        1

#define IDB_1           1

#define IDB_2           2

#define IDC_ONTOP       101

#define IDC_SHOWBMP     102

#define IDC_ALOWCHG     103

#define IDC_MODALFRAME  104

#define IDC_THICKFRAME  105

#define IDC_TITLETEXT   106

#define IDC_CUSTOMTEXT  107

#define IDC_BMP         108

#define IDC_SCROLL      109

#define IDC_SBVALUE     110

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

ICO_MAIN        ICON    "Main.ico"

IDB_1           BITMAP  "Picture1.bmp"

IDB_2           BITMAP  "Picture2.bmp"

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DLG_MAIN DIALOG 150, 200, 325, 140

STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME

CAPTION "对话框空间示例"

FONT 9, "宋体"

BEGIN

    GROUPBOX            "选项", -1, 64, 8, 122, 101

    AUTOCHECKBOX        "总在最前", IDC_ONTOP, 74, 23, 100, 8

    AUTOCHECKBOX        "显示图片", IDC_SHOWBMP, 74, 41, 100, 10

    AUTOCHECKBOX        "允许更换图片", IDC_ALOWCHG, 74, 58, 100, 11

    CONTROL             "", -1, "Static", SS_ETCHEDHORZ | WS_VISIBLE | WS_CHILD, 72, 71, 102, 1

    AUTORADIOBUTTON     "模态边框(&Modal Frame)", IDC_MODALFRAME, 74, 78, 100, 10, WS_TABSTOP

    AUTORADIOBUTTON     "可变边框(&Thick Frame)", IDC_THICKFRAME, 74, 92, 72, 10, WS_TABSTOP

 

    GROUPBOX            "标题文字", -1, 201, 8, 123, 101

    COMBOBOX            IDC_TITLETEXT, 208, 23, 102, 70, CBS_DROPDOWNLIST | WS_TABSTOP

    LTEXT               "自定义文字: ", -1, 208, 43, 98, 9

    EDITTEXT            IDC_CUSTOMTEXT, 208, 56, 101, 14

    LTEXT               "请在此选择显示在标题栏上面的文字,或者选择“自定义”后自行输入", -1, 208,75,105,26, WS_BORDER

    CONTROL             "", -1, "Static", SS_ETCHEDHORZ | WS_VISIBLE | WS_CHILD, 0, 115, 325, 1

    DEFPUSHBUTTON       "更换图片(&C)", IDOK, 175, 120, 63, 14

    PUSHBUTTON          "退出(&X)", IDCANCEL, 252, 120, 62, 14

    CONTROL             IDB_1, IDC_BMP, "Static", SS_BITMAP | WS_VISIBLE | WS_CHILD, 11, 8, 43, 100

    SCROLLBAR           IDC_SCROLL, 9, 122, 122, 12

    LTEXT               "0", IDC_SBVALUE, 138, 124, 34, 10

END

 

对于功能函数,对于此例子也学会了对话框的基本性质,以及如何去把握窗口的风格,DS_MODALFRAME 和 WS_THICKFRAME分别可以控制窗口大小是否可变。

      所有控件中,对于SCROLLBAR的控制略显复杂。垂直滚动条发送WM_VSCROLL,水平的则发送WM_HSCROLL消息,对于这两种消息的处理则是大同小异,传参细节如下:

      wParam低16位是nScrollCode   ;动作码

      wParam高16位是nPos             ;滚动条当前位置

      lParam = hwndScrollCode      ;滚动条控件当前句柄

这些大家都可以在MSDN上更详细的看到

Control.asm源代码如下:

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                .386

                .model  flat, stdcall

                option  casemap :none

        

include         windows.inc

include         user32.inc

includelib      user32.lib

include         kernel32.inc

includelib      kernel32.lib

include         gdi32.inc

includelib      gdi32.lib

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

ICO_MAIN        equ     1000h   ;图标

DLG_MAIN        equ     1

IDB_1           equ     1

IDB_2           equ     2

IDC_ONTOP       equ     101

IDC_SHOWBMP     equ     102

IDC_ALOW        equ     103

IDC_MODALFRAME  equ     104

IDC_THICKFRAME  equ     105

IDC_TITLETEXT   equ     106

IDC_CUSTOMTEXT  equ     107

IDC_BMP         equ     108

IDC_SCROLL      equ     109

IDC_VALUE       equ     110

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                .data?

hInstance       dd      ?

hBmp1           dd      ?

hBmp2           dd      ?

dwPos           dd      ?

                .const

szText1         db      "Hello, world!",0

szText2         db      "Win32 Assumbly!",0

szText3         db      "自定义",0

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                .code

_ProcDlgMain    proc    uses ebx edi esi hWnd, uMsg, wParam, lParam

        local   @szBuffer[126]:BYTE     

        

        .if     uMsg == WM_CLOSE

                invoke  EndDialog,hWnd,NULL

                invoke  DeleteObject,hBmp1

                invoke  DeleteObject,hBmp2

        .elseif uMsg == WM_INITDIALOG

                ;====================================设置标题栏图标

                invoke  LoadIcon,hInstance,ICO_MAIN

                invoke  SendMessage,hWnd,WM_SETICON,ICON_BIG,eax

                ;====================================初始化组合框

                invoke  SendDlgItemMessage,hWnd,IDC_TITLETEXT,CB_ADDSTRING,0,addr szText1

                invoke  SendDlgItemMessage,hWnd,IDC_TITLETEXT,CB_ADDSTRING,0,addr szText2

                invoke  SendDlgItemMessage,hWnd,IDC_TITLETEXT,CB_ADDSTRING,0,addr szText3

                invoke  SendDlgItemMessage,hWnd,IDC_TITLETEXT,CB_SETCURSEL,0,0

                invoke  GetDlgItem,hWnd,IDC_CUSTOMTEXT

                invoke  EnableWindow,eax,FALSE

                invoke  LoadBitmap,hInstance,IDB_1

                mov     hBmp1,eax

                invoke  LoadBitmap,hInstance,IDB_2

                mov     hBmp2,eax

                ;====================================初始化单选钮和复选框

                invoke  CheckDlgButton,hWnd,IDC_SHOWBMP,BST_CHECKED

                invoke  CheckDlgButton,hWnd,IDC_ALOW,BST_CHECKED

                invoke  CheckDlgButton,hWnd,IDC_THICKFRAME,BST_CHECKED

                ;====================================初始化滚动条

                invoke  SendDlgItemMessage,hWnd,IDC_SCROLL,SBM_SETRANGE,0,100

                

        .elseif uMsg == WM_COMMAND

                mov     eax,wParam

                .if     ax  ==  IDCANCEL

                        invoke  EndDialog,hWnd,NULL

                        invoke  DeleteObject,hBmp1

                        invoke  DeleteObject,hBmp2

                ;====================================更换图片

                .elseif ax  ==  IDOK

                        mov     eax,hBmp1

                        xchg    eax,hBmp2

                        mov     hBmp1,eax

                        invoke  SendDlgItemMessage,hWnd,IDC_BMP,STM_SETIMAGE,IMAGE_BITMAP,eax

                ;===================================="总在最前"

                .elseif ax  ==  IDC_ONTOP

                        invoke  IsDlgButtonChecked,hWnd,IDC_ONTOP

                        .if     eax ==  BST_CHECKED

                                invoke  SetWindowPos,hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE

                        .else

                                invoke  SetWindowPos,hWnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE

                        .endif

                ;====================================显示或隐藏图片

                .elseif ax  ==  IDC_SHOWBMP

                        invoke  GetDlgItem,hWnd,IDC_BMP

                        mov     ebx,eax

                        invoke  IsWindowVisible,ebx

                        .if     eax

                                invoke  ShowWindow,ebx,SW_HIDE

                        .else   

                                invoke  ShowWindow,ebx,SW_SHOW

                        .endif

                ;===================================允许和灰化"更换图片"按钮

                .elseif ax  ==  IDC_ALOW

                        invoke  IsDlgButtonChecked,hWnd,IDC_ALOW

                        .if     eax ==  BST_CHECKED

                                mov     ebx,TRUE

                        .else

                                xor     ebx,ebx

                        .endif

                        invoke  GetDlgItem,hWnd,IDOK

                        invoke  EnableWindow,eax,ebx

                ;=================================="模态边框" 还是 "可变边框"

                .elseif ax  ==  IDC_MODALFRAME

                        invoke  GetWindowLong,hWnd,GWL_STYLE

                        and     eax,not WS_THICKFRAME

                        invoke  SetWindowLong,hWnd,GWL_STYLE,eax

                .elseif ax  ==  IDC_THICKFRAME

                        invoke  GetWindowLong,hWnd,GWL_STYLE

                        or      eax,WS_THICKFRAME

                        invoke  SetWindowLong,hWnd,GWL_STYLE,eax

                ;==================================处理下拉式组合框

                .elseif ax  ==  IDC_TITLETEXT

                        shr     eax,16

                        .if     ax  ==  CBN_SELENDOK

                                invoke  SendDlgItemMessage,hWnd,IDC_TITLETEXT,CB_GETCURSEL,0,0

                                .if     eax ==  2

                                        invoke  GetDlgItem,hWnd,IDC_CUSTOMTEXT

                                        invoke  EnableWindow,eax,TRUE

                                .else

                                        mov     ebx,eax

                                        invoke  SendDlgItemMessage,hWnd,IDC_TITLETEXT,/

                                                CB_GETLBTEXT,ebx,addr @szBuffer

                                        invoke  SetWindowText,hWnd,addr @szBuffer

                                        invoke  GetDlgItem,hWnd,IDC_CUSTOMTEXT

                                        invoke  EnableWindow,eax,FALSE

                                .endif

                        .endif

                ;=================================在文本框输入文字

                .elseif ax  ==  IDC_CUSTOMTEXT

                        invoke  GetDlgItemText,hWnd,IDC_CUSTOMTEXT,addr @szBuffer,sizeof @szBuffer

                        invoke  SetWindowText,hWnd,addr @szBuffer

                .endif

        ;==========================处理滚动条信息

        .elseif uMsg == WM_HSCROLL

                mov     eax,wParam

                .if     ax  ==  SB_LINELEFT

                        dec     dwPos

                .elseif ax  ==  SB_LINERIGHT

                        inc     dwPos

                .elseif ax  ==  SB_PAGELEFT

                        sub     dwPos,10

                .elseif ax  ==  SB_PAGERIGHT

                        add     dwPos,10

                .elseif ax  ==  SB_THUMBPOSITION || ax == SB_THUMBTRACK ;******

                        mov     eax,wParam

                        shr     eax,16

                        mov     dwPos,eax

                .else

                        mov     eax,TRUE

                        ret

                .endif

                cmp     dwPos,0

                jge     @F

                mov     dwPos,0

                @@:

                cmp     dwPos,100

                jle     @F

                mov     dwPos,100

                @@:

                invoke  SetDlgItemInt,hWnd,IDC_VALUE,dwPos,FALSE

                invoke  SendDlgItemMessage,hWnd,IDC_SCROLL,SBM_SETPOS,dwPos,TRUE ;TRUE表示重绘

        .else

                mov     eax,FALSE

                ret

        .endif

        mov     eax,TRUE

        ret

                

_ProcDlgMain    endp

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

start:

                invoke  GetModuleHandle,NULL

                mov     hInstance,eax

                invoke  DialogBoxParam,hInstance,DLG_MAIN,NULL,addr _ProcDlgMain,NULL

                invoke  ExitProcess,NULL

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<              

                end     start

注释基本上都写上去了,这个实验本也没有什么技术含量,寒假在家没事的时候做了两遍,出于纪念意义还是贴上去吧!由于图片上传功能暂时关闭,等有时间再把图片贴上去吧

参考文献:罗云彬的windows下32位汇编教程

你可能感兴趣的:(Win32)