这个问题一直纠集着我求指点!
问题点请看代码中的红色(彩色)字体:.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include gdi32.inc
includelib gdi32.lib
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include shell32.inc
includelib shell32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
hWinMain dd ?
.const
szClassName db 'MyClass',0
szCaptionMain db 'My first Window !',0
szText db 'Welcome to fishc.com!',0
szButton db 'button', 0
szButtonText db '鱼C工作室', 0
szOpen db 'open', 0
szURL db 'http://www.fishc.com'
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 窗口过程
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcWinMain proc uses ebx edi esi hWnd,uMsg,wParam,lParam//小甲鱼在Win32汇编32课时说这个"hWnd"是默认存放父窗口句柄的,但我把例子程序的hWnd全部换成了hWinMain(这是全局变量用来存放主窗口句柄的)之后这个子窗口就显示不出来这是为什么呢?它们都是指向同一个窗口句柄啊?
local @stPs:PAINTSTRUCT
local @stRect:RECT
local @hDc
mov eax,uMsg
;********************************************************************
.if eax == WM_PAINT
invoke BeginPaint,hWnd,addr @stPs
mov @hDc,eax
invoke GetClientRect,hWnd,addr @stRect
invoke DrawText,@hDc,addr szText,-1,\
addr @stRect,\
DT_SINGLELINE or DT_CENTER or DT_VCENTER
invoke EndPaint,hWnd,addr @stPs
.elseif eax == WM_COMMAND ;当按下按钮的时候
mov eax, wParam
.if ax == IDOK
invoke ShellExecute, NULL, offset szOpen,\
offset szURL, NULL, NULL, SW_SHOWNORMAL
.endif
;********************************************************************
; 建立一个按钮
;********************************************************************
.elseif eax == WM_CREATE
invoke CreateWindowEx,NULL,\
offset szButton,offset szButtonText,\
WS_CHILD or WS_VISIBLE,\
10,10,88,22,\
hWnd,1,hInstance,NULL
;********************************************************************
.elseif eax == WM_CLOSE
invoke DestroyWindow,hWnd
invoke PostQuitMessage,NULL
;********************************************************************
.else
invoke DefWindowProc,hWinMain,uMsg,wParam,lParam//这里又是用的全局的窗口句柄
ret
.endif
;********************************************************************
xor eax,eax
ret
_ProcWinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain proc
local @stWndClass:WNDCLASSEX
local @stMsg:MSG
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
;********************************************************************
; 注册窗口类
;********************************************************************
invoke LoadCursor,0,IDC_ARROW
mov @stWndClass.hCursor,eax
push hInstance
pop @stWndClass.hInstance
mov @stWndClass.cbSize,sizeof WNDCLASSEX
mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW
mov @stWndClass.lpfnWndProc,offset _ProcWinMain
mov @stWndClass.hbrBackground,COLOR_WINDOW + 1
mov @stWndClass.lpszClassName,offset szClassName
invoke RegisterClassEx,addr @stWndClass
;********************************************************************
; 建立并显示窗口
;********************************************************************
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,offset szCaptionMain,\
WS_OVERLAPPEDWINDOW,\
100,100,600,400,\
NULL,NULL,hInstance,NULL
mov hWinMain,eax
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
invoke UpdateWindow,hWinMain
;********************************************************************
; 消息循环
;********************************************************************
.while TRUE
invoke GetMessage,addr @stMsg,NULL,0,0
.break .if eax == 0
invoke TranslateMessage,addr @stMsg
invoke DispatchMessage,addr @stMsg
.endw
ret
_WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
call _WinMain
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
看大神回答学习学习 _ProcWinMain proc uses ebx edi esi hWnd,uMsg,wParam,lParam
这里面的hWnd不能改成hWinMain吧。。。不然局部变量不就覆盖了全局变量了。。?
_ProcWinMain的hWnd能改为hWinMain吧。。
还有。。就是。。我复制你的代码用RadAsm编译。。。根本不会显示窗口。。。。
←_←。。。
然后。。还是那句话。。这种问题。。。不懂就算了。。。说不定哪天就弄出来了。。。。而且。。。貌似以后也不会用。。汇编写这个窗口的。。学习的话。。知道大概流程就算了。。汇编还是用来嵌入C语言好一点。。。操作系统不就是用C语言嵌入少量汇编么。。。? 向往青莲 发表于 2014-4-8 21:17 static/image/common/back.gif
_ProcWinMain proc uses ebx edi esi hWnd,uMsg,wParam,lParam
这里面的hWnd不能改成hWinMa ...
说得是呢! 学不到···还是等消息看看·
我想这应该是继承的关系吧!如果把hWnd都换成了hWinMain的话,那么子窗口就找不到父窗口的句柄了,这样的话,子窗口自然就心事不出来了!
页:
[1]