作者:战庄 此贴贴于2012-5-20 21:53:29,已被阅读459次/回复1 
谢谢,我用自己的方法把工具栏做出来了,但是又有新问题,工具栏只有大半截,为什么是这样呢?

下载...
<Img src=upfile/2012520214732_截图00.jpg>
附上源程序(我用的是RADASM+MASM32V11)
.586
.model flat,stdcall
option casemap:none

include     windows.inc
include     user32.inc
include     kernel32.inc
include        gdi32.inc
include        masm32.inc
include        comctl32.inc

includelib    gdi32.lib
includelib     user32.lib
includelib     kernel32.lib
includelib    masm32.lib
includelib    comctl32.lib
include        macros.asm    

.const
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;资源定义
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;________菜单________
IDR_MENU        equ        10000
IDM_FILE            equ        10001
IDM_NEW        equ        10006
IDM_OPEN        equ        10004
IDM_SAVE        equ        10005
IDM_PAGE        equ        10010
IDM_PRINT        equ        10011
IDM_QUIT        equ        10013
IDM_OPTION        equ        10002
IDM_HELP        equ        10003
IDM_MAINHELP    equ        10007
IDM_ABOUT        equ        10008
;________图标_______
MAIN_ICO        equ        100
;_______工具栏______
TB_BMP            equ         200
ID_TOOLBAR        equ         1
IDC_TBN            equ         101
IDC_TBO            equ         102
IDC_TBS            equ         103
IDC_TBP            equ         104
IDC_TBT            equ         105
IDC_TBJ            equ         106
IDC_TBX            equ         107

SToolbar                            TBBUTTON <0,IDC_TBN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0>
                                TBBUTTON <1,IDC_TBO,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0>
                                TBBUTTON <2,IDC_TBS,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0>
                                TBBUTTON <3,IDC_TBP,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0>
                                TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0>
                                TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0>
                                TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0>
                                TBBUTTON <4,IDC_TBT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0>
                                TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0>
                                TBBUTTON <5,IDC_TBJ,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0>
                                TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0>
                                TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0>
                                TBBUTTON <0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0>
                                TBBUTTON <6,IDC_TBX,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0>
NTBNS            equ         14

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
WinMain                             PROTO    :HINSTANCE,:HINSTANCE,:LPSTR,:DWORD
WndProc                             PROTO    :HWND,:UINT,:WPARAM,:LPARAM

.data
ClassName         db     "MainWinClass",0
AppName          db     "ok",0
EditClass            db    "edit",0

szToolBarClass    db 'ToolbarWindow32',0

TD60            db   "甲子乙丑丙寅丁卯戊辰己巳庚午辛未壬申癸酉甲戌乙亥丙子丁丑戊寅己卯庚辰辛巳壬午癸未甲申乙酉丙戌丁亥戊子己丑庚寅辛卯壬辰癸巳甲午乙未丙申丁酉戊戌己亥庚子辛丑壬寅癸卯甲辰乙巳丙午丁未戊申己酉庚戌辛亥壬子癸丑甲寅乙卯丙辰丁巳戊午己未庚申辛酉壬戌癸亥",0
JQ12        dd    "立春","惊蛰","清明","立夏","芒种","小暑","立秋","寒露","白露","立冬","大雪","小寒",0

.data?
hInstance         HINSTANCE     ?
CommandLine     LPSTR        ?
hwndEdit        HWND        ?
hwndToolbar        dd            ?
hMenu            dd            ?
hIcon            dd            ?
H_TB_BMP        dd            ?
File_o1            dd            ?
File_o2            dd            ?
Y_jq                dw            5    dup(?)            ;一年节气变量    
    
;.Const

;TD60            dd   "甲子乙丑丙寅丁卯戊辰己巳庚午辛未壬申癸酉甲戌乙亥丙子丁丑戊寅己卯庚辰辛巳壬午癸未甲申乙酉丙戌丁亥戊子己丑庚寅辛卯壬辰癸巳甲午乙未丙申丁酉戊戌己亥庚子辛丑壬寅癸卯甲辰乙巳丙午丁未戊申己酉庚戌辛亥壬子癸丑甲寅乙卯丙辰丁巳戊午己未庚申辛酉壬戌癸亥",0
.code


WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
    LOCAL     wc:WNDCLASSEX
    LOCAL     msg:MSG
    LOCAL     hwnd:HWND
    ;--------------------
    LOCAL    estyle:DWORD
    
    invoke    InitCommonControls                    ;初始通用控件
    mov       wc.cbSize,SIZEOF WNDCLASSEX
    mov       wc.style, CS_HREDRAW or CS_VREDRAW
    mov       wc.lpfnWndProc, OFFSET WndProc
    mov       wc.cbClsExtra,NULL
    mov       wc.cbWndExtra,NULL
    
    ;mov        hIcon,eax
    invoke    LoadMenu,hInstance,IDR_MENU            ;加入菜单
    mov     hMenu,eax
    invoke    LoadAccelerators,hInstance,IDR_MENU    ;加入快捷键
    push      hInstance
    pop       wc.hInstance
    mov       wc.hbrBackground,COLOR_BTNFACE+1
    mov       wc.lpszMenuName,NULL
    mov       wc.lpszClassName,OFFSET ClassName
    
    ;invoke     LoadIcon,NULL,IDI_APPLICATION
    invoke    LoadIcon,hInstance,MAIN_ICO            ;加入图标
    mov       wc.hIcon,eax
    mov       wc.hIconSm,eax
    
    invoke     LoadCursor,NULL,IDC_ARROW
    mov       wc.hCursor,eax
    
    invoke     RegisterClassEx, addr wc
    invoke     CreateWindowEx,NULL,addr ClassName,addr AppName,\
                           WS_OVERLAPPEDWINDOW,\
                           0,0,1024,600,NULL,hMenu,hInst,NULL
    mov       hwnd,eax
    ;____________
    ;mov        Mainhwnd,eax
    ;____________
    invoke    SendMessage,hwnd,WM_SETICON,ICON_BIG,hIcon        ;载入图标

    invoke     ShowWindow, hwnd,SW_MAXIMIZE
    invoke     UpdateWindow, hwnd
    
    .while     TRUE
        invoke GetMessage, addr msg,NULL,0,0
        .break .if (!eax)
        invoke TranslateMessage, addr msg
        invoke DispatchMessage, addr msg
    .endw
    
    mov     eax,msg.wParam
    ret
WinMain endp

;DoToolBar proc hInst:DWORD,hOwner:HWND
;    ret
;DoToolBar endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    .if uMsg    ==    WM_DESTROY
        invoke     PostQuitMessage,NULL
        
    .elseif uMsg == WM_CREATE
        ;-------------------------------------------------------------------------
        ;建立工具栏
        
        invoke    LoadBitmap,hInstance,TB_BMP
        mov        H_TB_BMP,eax
    
        invoke    CreateToolbarEx,hWnd, WS_VISIBLE or WS_CHILD   or TBSTYLE_TOOLTIPS  \ 
                 ,ID_TOOLBAR,7,NULL,H_TB_BMP,offset SToolbar,NTBNS,32,32,32,32,sizeof TBBUTTON
        mov        hwndToolbar,eax
        ;-------------------------------------------------------------------------
        
        ;-------------------------------------------------------------------------
        ;建立编辑框
         invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClass,NULL,\ 
                        WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or\ 
                        ES_AUTOHSCROLL,\ 
                        2,45,608,510,hWnd,8,hInstance,NULL
                 mov  hwndEdit,eax
        ;-------------------------------------------------------------------------
    .elseif uMsg == WM_COMMAND        
    .else
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam        
        ret
        
    .endif
    
    xor eax,eax
    ret
WndProc endp

start:
    invoke     GetModuleHandle, NULL
    mov        hInstance,eax    
    invoke     GetCommandLine
    mov        CommandLine,eax    
    invoke     WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
    invoke     ExitProcess,eax
    
end start


我爱汇编

此贴的父贴(直接):
从我代码里复制出来的你凑合看吧= 。=514 MengXP 2012-5-19 17:20:37 16694 正常
此贴的回复贴(直接):
发送一个消息给工具栏,TB_BUTTONCOUNT,将结果dec eax,然后发送TB_GETITEMRECT,eax,offset rt,得到最佳的高与宽,然后movewindow.来设定工具栏的高宽。423 我爱汇编 2012-5-24 19:04:06 0 正常