当前位置: 代码迷 >> 汇编语言 >> 百思不得其解,关于罗云彬书9.2节,该如何处理
  详细解决方案

百思不得其解,关于罗云彬书9.2节,该如何处理

热度:181   发布时间:2016-05-02 04:43:46.0
百思不得其解,关于罗云彬书9.2节
子程序代码是这样的:
_Resize		proc
local @stRect:RECT,@stRect1:RECT

invoke MoveWindow,hWinStatus,0,0,0,0,TRUE
invoke GetWindowRect,hWinStatus,addr @stRect
invoke GetClientRect,hWinMain,addr @stRect1
mov ecx,@stRect1.right
sub ecx,@stRect1.left
mov eax,@stRect1.bottom
sub eax,@stRect1.top
sub eax,@stRect.bottom
add eax,@stRect.top
invoke MoveWindow,hWinEdit,0,0,ecx,eax,TRUE
ret

对话框过程中调用Resize的语句是:
WM_INITDIALOG
mov eax,hWnd
mov hWinMain,eax

invoke CreateStatusWindow,WS_CHILD OR WS_VISIBLE OR \
SBS_SIZEGRIP,NULL,hWinMain,ID_STATUSBAR
mov hWinStatus,eax
invoke SendMessage,hWinStatus,SB_SETPARTS,4,offset dwStatusWidth
mov lpsz1,offset sz1
mov lpsz2,offset sz2
invoke SendMessage,hWinStatus,SB_SETTEXT,2,lpsz1

invoke CreateWindowEx,WS_EX_CLIENTEDGE,addr szClass,NULL,\
WS_CHILD or WS_VISIBLE or ES_MULTILINE or ES_WANTRETURN or WS_VSCROLL or ES_AUTOHSCROLL,\
0,0,0,0,hWnd,ID_EDIT,hInstance,NULL
mov hWinEdit,eax

call _Resize


我的问题是:
1.为什么在WM_INITDIALOG消息中,一定要调用_Resize,也就是这一句call _Resize,eidt控件才会显示在窗口内?
2.问题集中在_Resize这个子程序中
invoke	MoveWindow,hWinStatus,0,0,0,0,TRUE  ;这里设4个0是不是因为即使为0,状态栏也会自动调节大小尺寸?
invoke GetWindowRect,hWinStatus,addr @stRect ;
invoke GetClientRect,hWinMain,addr @stRect1 ;这是算客户区的尺寸,这我能看明白
mov ecx,@stRect1.right
sub ecx,@stRect1.left
mov eax,@stRect1.bottom
sub eax,@stRect1.top
sub eax,@stRect.bottom
add eax,@stRect.top    ;上面这6句代码干嘛的呢,为什么一定要这么算,算出来的又是什么的尺寸呢?不明白,算客户区的高度直接用@stRect1.bottom-@stRect1.top不就行了吗?
[email protected]@stRect.top之间的差值(也就是状态栏的高呢)? 
invoke MoveWindow,hWinEdit,0,0,ecx,eax,TRUE  ;


------解决方案--------------------
1. 因为创建的那个 Edit 窗口初始大小为 0,0 所以没可显示的;故而通过 _Resize 子程来根据主窗口大小进行调整设置以占据主窗口。
2. _Resize 子程里对 StatusBar 窗口的 Move 是没有任何作用的,对状态栏而言,其位置和大小是固定的,没见那个程序的状态栏能跑顶上或其它位置的吧,或者,你注释了那个 MoveWindows() 看看效果如何;后面的几行,不就是计算主窗口的大小,再减去 StatusBar 窗口的大小,这样就是 Edit 窗口的大小了,用来设置 Edit 窗口的;Edit 和 StatusBar 都是共同占据着主窗口的 Client 区域的,所以要减去 Status 的大小。
  相关解决方案