初学汇编,遇到一个问题,求解~
今天在学习汇编的过程中遇到一个问题,本来想实现一个文件浏览器的功能,但是在一个地方卡主了一下午.
首先我建立了一个ComboBox和一个TreeView,ComboBox用来承载逻辑驱动器,TreeView用于承载文件夹
然后在WM_NOTIFY中捕获TreeView节点展开的事件,到此为止一切正常
但是当我想打印出节点文字的时候出现了问题
invoke MessageBox,hWinMain,[esi].itemNew.pszText,NULL,MB_OK
这里打印出来的总是乱码
一下附上代码,请各位帮忙看下问题到底出在哪里了.
资源文件
#define MANIFEST 24
#define IDD_DLG1 1000
#define IDC_CBO1 1001
#define IDC_TRV1 1002
#define IDC_LSV1 1003
#define IDR_XPMANIFEST1 1
#include "resource.h"
IDD_DLG1 DIALOGEX 6,6,585,306
CAPTION "diskcon"
FONT 8,"MS Sans Serif",0,0,0
STYLE WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|DS_CENTER
BEGIN
CONTROL "",IDC_CBO1,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|CBS_DROPDOWNLIST,3,6,204,12
CONTROL "",IDC_TRV1,"SysTreeView32",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS,3,21,204,279,WS_EX_CLIENTEDGE
CONTROL "",IDC_LSV1,"SysListView32",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,210,6,369,294,WS_EX_CLIENTEDGE
END
IDR_XPMANIFEST1 MANIFEST "xpmanifest.xml"
include windows.inc
include kernel32.inc
include user32.inc
include Comctl32.inc
include shell32.inc
includelib kernel32.lib
includelib user32.lib
includelib Comctl32.lib
includelib shell32.lib
IDD_DLG1equ1000
IDC_CBO1equ1001
IDC_TRV1equ1002
DlgProcPROTO:HWND,:UINT,:WPARAM,:LPARAM
_InitHeapPROTO
_InitDriversPROTO
_DriverChangePROTO
_HasMoreDirPROTO:DWORD
.const
szAllFiledb'*.*',0
szSubDirdb'\*.*',0
szInsTempdb'temp',0
szEdb'展开',0
szCdb'收起',0
.data?
hInstancedd?
hWinMaindd?
hHeapdd?
dwTempdd?
.386
.model flat, stdcall ;32 bit memory model
option casemap :none ;case sensitive
include diskcon.inc
.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke _InitHeap
mov hHeap,eax
invoke InitCommonControls
invoke DialogBoxParam,hInstance,IDD_DLG1,NULL,addr DlgProc,NULL
invoke ExitProcess,0
DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
local @item:TVITEM
.if uMsg == WM_INITDIALOG
push hWin
pop hWinMain
invoke _InitDrivers
invoke _DriverChange
.elseif uMsg == WM_COMMAND
mov eax,wParam
.if ax == IDC_CBO1
shr eax,16
.if ax == CBN_SELCHANGE
invoke _DriverChange
.endif
.endif
.elseif uMsg == WM_NOTIFY
mov esi,lParam
assume esi:ptr NMHDR
.if [esi].idFrom == IDC_TRV1
.if [esi].code == TVN_ITEMEXPANDING
assume esi:ptr NMTREEVIEW
invoke MessageBox,hWinMain,[esi].itemNew.pszText,NULL,MB_OK
.if [esi].action == TVE_EXPAND
;invoke MessageBox,hWinMain,offset szE,NULL,MB_OK
.elseif [esi].action == TVE_COLLAPSE
;invoke MessageBox,hWinMain,offset szC,NULL,MB_OK
.endif
.endif
.endif
assume esi:nothing
.elseif uMsg == WM_CLOSE
invoke EndDialog,hWin,0
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp
_InitHeap proc
invoke GetProcessHeap
ret
_InitHeap endp
_InitDrivers proc
local @buffer:DWORD
local @tmpbuf:DWORD
pushad
invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,512
mov @buffer,eax
invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,128
mov @tmpbuf,eax
invoke GetLogicalDriveStrings,512,@buffer
mov esi,@buffer
mov edi,@tmpbuf
mov ah,1
mov al,0
.while TRUE
mov al,[esi]
.if al == 0
.if ah == 0
.break
.else
mov [edi],al
inc esi
mov edi,@tmpbuf
mov ah,0
invoke SendDlgItemMessage,hWinMain,IDC_CBO1,CB_ADDSTRING,0,@tmpbuf
.endif
.else
mov ah,1
mov [edi],al
inc esi
inc edi
.endif
.endw
invoke HeapFree,hHeap,HEAP_NO_SERIALIZE,@buffer
invoke HeapFree,hHeap,HEAP_NO_SERIALIZE,@tmpbuf
invoke SendDlgItemMessage,hWinMain,IDC_CBO1,LB_GETCOUNT,0,0
.if !eax
invoke SendDlgItemMessage,hWinMain,IDC_CBO1,CB_SETCURSEL,0,0
.endif
popad
ret
_InitDrivers endp
_DriverChange proc
local @hfile:HFILE
local @drivername:DWORD
local @findname:DWORD
local @subdir:DWORD
local @filedata:WIN32_FIND_DATA
local @node:TV_INSERTSTRUCT
local @insered:DWORD
pushad
invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,256
mov @drivername,eax
invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,1024
mov @subdir,eax
invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,1024
mov @findname,eax
;清空TreeView
invoke SendDlgItemMessage,hWinMain,IDC_TRV1,TVM_DELETEITEM,0,0
invoke SendDlgItemMessage,hWinMain,IDC_CBO1,WM_GETTEXT,1024,@drivername
invoke lstrcat,@findname,@drivername
invoke lstrcat,@findname,offset szAllFile
invoke FindFirstFile,@findname,addr @filedata
mov @hfile,eax
.if @hfile != INVALID_HANDLE_VALUE
.repeat
;invoke MessageBox,NULL,addr @filedata.cFileName,NULL,MB_OK
.if (@filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && \
!(@filedata.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
.if @filedata.cFileName != '.'
;插入数据
invoke RtlZeroMemory,addr @node,sizeof @node
invoke RtlZeroMemory,@subdir,1024
mov @node.hParent,NULL
mov @node.hInsertAfter,TVI_LAST
or @node.item._mask,TVIF_TEXT
lea eax,@filedata.cFileName
mov @node.item.pszText,eax
mov @node.item.cchTextMax,MAX_PATH
invoke SendDlgItemMessage,hWinMain,IDC_TRV1,TVM_INSERTITEM,0,addr @node
mov @insered,eax
;查看是否还有子目录,若有子目录则插入临时占位符
invoke RtlZeroMemory,@subdir,1024
invoke lstrcpy,@subdir,@drivername
invoke lstrcat,@subdir,addr @filedata.cFileName
invoke _HasMoreDir,@subdir
.if eax
mov @node.item.pszText,offset szInsTemp
push @insered
pop @node.hParent
invoke SendDlgItemMessage,hWinMain,IDC_TRV1,TVM_INSERTITEM,0,addr @node
.endif
.endif
.endif
invoke FindNextFile,@hfile,addr @filedata
.until eax == FALSE
invoke FindClose,@hfile
.endif
invoke HeapFree,hHeap,HEAP_NO_SERIALIZE,@drivername
invoke HeapFree,hHeap,HEAP_NO_SERIALIZE,@subdir
invoke HeapFree,hHeap,HEAP_NO_SERIALIZE,@findname
popad
ret
_DriverChange endp
_HasMoreDir proc lpszDirName:LPCSTR
local @hfile:HFILE
local @filedata:WIN32_FIND_DATA
local @dirname:DWORD
local @retval:DWORD
mov @retval,0
invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,2048
mov @dirname,eax
invoke lstrcpy,@dirname,lpszDirName
invoke lstrcat,@dirname,offset szSubDir
invoke FindFirstFile,@dirname,addr @filedata
mov @hfile,eax
.if @hfile != INVALID_HANDLE_VALUE
.repeat
.if (@filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(@filedata.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
.if @filedata.cFileName != '.'
mov @retval,1
.break
.endif
.endif
invoke FindNextFile,@hfile,addr @filedata
.until eax == FALSE
invoke FindClose,@hfile
.endif
invoke HeapFree,hHeap,HEAP_NO_SERIALIZE,@dirname
mov eax,@retval
ret
_HasMoreDir endp
end start