首页
社区
课程
招聘
[原创]做了个学习笔记, 和大家分享下... 呵呵
发表于: 2009-11-26 00:15 6096

[原创]做了个学习笔记, 和大家分享下... 呵呵

2009-11-26 00:15
6096

初学罗云彬的那本win32汇编程序设计, 前些天听从朋友的建议, 读书就该做个学习笔记, 可以加强理解, 的确, 呵呵, 所以不才就拿上来和大家分享下学习的过程, 希望大家可以给我多提提意见, 让我进步快些... 呵呵... 这个程序在第13章的过程控制里... 为 Process.asm

程序从start开始执行, 调用GetModuleHandle函数获取程序模块句柄, 存入hInstance, 调用DialogBoxParam函数创建一个对话框… 对话框过程为 : _ProcDlgMain…
程序进入对话框过程执行….
_ProcDlgMain函数传递四个参数 hWnd, wMsg, wParam, lParam, 定义了两个局部变量
@dwThreadID 和 @stOF ; 其中@stOF参数的结构为OPENFILENAME(This structure contains information the operating system uses to initialize the system-defined Open or Save As dialog box. After the user closes the dialog box, the system returns information about the user's selection in this structure.)函数首先处理WM_INITDIALOG消息, 将对话框句柄存入hWinMain中, 调用SendDlgItemMessage函数给”文件名”窗口发送消息, 扩展编辑框的长度; 调用SendDlgItemMessage函数给”命令行”窗口发送消息, 扩展编辑框的长度. 当用户按下浏览按钮的时候, 对话框过程处理IDC_BROWSE消息, 调用RtlZeroMemory函数将@stOF参数初始化,
mov       @stOF.lStructSize, sizeof @stOF
(@stOF.lStructSize  : Specifies the length, in bytes, of the structure.)
push      hWinMain
pop       @stOF.hWndOwner
(hWndOwner: Handle to the window that owns the dialog box.)
mov       @stOF.lpstrFilter, offset szFileExt
(lpstrFilter : Long pointer to a buffer that contains pairs of null-terminated filter strings)
mov       @stOF.lpstrFile, offset szFileName
(lpstrFile : Long pointer to a buffer that contains a file name used to initialize the File Name edit control.)
mov       @stOF.nMaxFile, MAX_PATH
(nMaxFile : Specifies the size, in bytes (ANSI version) or 16-bit characters (Unicode version), of the buffer pointed to by lpstrFile.)
mov       @stOF.Flags, OFN_FILEMUSTEXIST or OFN_PATHMUSTEXI
(OFN_FILEMUSTEXIST 打开的文件必须存在, OFN_PATHMUSTEXIST打开的路径必须存在)
调用GetOpenFileName函数创建一个寻找文件对话框
(
This function creates a system-defined dialog box that enables the user to select a file to open.
BOOL GetOpenFileName(
  LPOPENFILENAME lpofn
);
lpofn  [in] Long pointer to an OPENFILENAME structure that contains information used to initialize the dialog box. When GetOpenFileName returns, this structure contains information about the user's file selection.
Flags : If this member is set to the OFN_PROJECT value, the GetOpenFileName function opens the Folder dialog box. Otherwise, the function opens the Open dialog box.
lpstrFile : When GetOpenFileName returns successfully, this member is used to retrieve full path of the selected file name.
lpstrFileTitle : When GetOpenFileName returns successfully, this member is used to retrieve the project folder name only.
lpstrInitialDir : Pointer to a string that receives the initial folder name, but not the full path name.
)
如果找到文件, 则调用SetDlgItemText函数将”文件名”编辑框的内容设置为 找到的文件名…
当用户在”文件名”编辑框输入的时候, 调用GetWindowTextLength函数取得文本长度.
(This function retrieves the length, in characters, of the specified window's title bar text — if the window has a title bar. If the specified window is a control, the function retrieves the length of the text within the control.
Return Values : The length, in characters, of the text indicates success. Under certain conditions, this value may actually be greater than the length of the text. For more information, see the following Remarks section. Zero indicates that the window has no text. To get extended error information, call GetLastError.
)
将返回值存入ebx, 调用GetDlgItem函数获得”执行窗口句柄”, 如果输入了文件名则是执行窗口有效…
当用户按下”执行”按钮的时候, 函数处理IDOK消息
调用CreateThread函数创建一个线程, 线程函数为_ProcExec, 函数返回, 调用CloseHandle函数将线程句柄关闭, 释放线程对象…
线程开始执行… 参数格式 : _ProcExec          proc      uses ebx esi edi _lParam
调用GetDlgItem函数取得”文件名”编辑框的句柄, 并将编辑框灰化, 调用GetDlgItem函数取得”命令行”编辑框句柄, 并将编辑框灰化… 调用GetDlgItem函数”浏览”按钮灰化, 调用SetDlgItemText函数将”执行”按钮的文本设置为”终止”
调用GetDlgItemText函数获得”文件名”编辑框中的文件名存入szFileName; 调用GetDlgItemText函数将”命令行”编辑框中的文本存入szCmdLine中, 调用lstrcpy文件名存入@szBuffer中, 如果szCmdLine中有命令行参数, 则调用lstrcat函数先将空格加到@szBuffer中, 然后再将命令行参数加到@szBuffer后面…
调用GetStartupInfo函数初始化 stStartUP…
(GetStartupInfo : Retrieves the contents of the STARTUPINFO structure that was specified when the calling process was created.)
然后再调用CreateProcess函数创建一个进程(
invoke    CreateProcess, NULL, addr @szBuffer, NULL, NULL, NULL, \
                  NORMAL_PRIORITY_CLASS, NULL, NULL, addr stStartUp, addr stProcInfo
This function is used to run a new program. It creates a new process and its primary thread. The new process executes the specified executable file.
pszImageName  [in] Pointer to a null-terminated string that specifies the module to execute.
pszCmdLine : [in, out] Pointer to a null-terminated string that specifies the command line to execute.
psaProcess : [in] Not supported; set to NULL.
psaThread : [in] Not supported; set to NULL.
fInheritHandles : [in] Not supported; set to FALSE.
fdwCreate : [in] Specifies additional flags that control the priority and the creation of the process.
pvEnvironment : [in] Not supported; set to NULL.
pszCurDir : [in] Not supported; set to NULL.
psiStartInfo : [in] Not supported; set to NULL.
pProcInfo : [out] Pointer to a PROCESS_INFORMATION structure that receives identification information about the new process.

Return Values : Nonzero indicates success, Zero indicates failure., To get extended error information, call GetLastError.
)
如果进程创建成功, 则调用WaitForSingleObject等待进程的执行…进程执行完毕,调用CloseHandle函数将进程句柄关闭, 释放进程对象, 调用CloseHandle将主线程句柄关闭, 释放线程对象… 如果创建失败 则调用Messagebox显示出错信息…
调用RtlZeroMemory函数初始化stProcInfo参数.. 然后调用GetDlgItem函数和EnableWindow函数使”文件名”编辑框有效, “命令行”编辑框有效, “浏览”按钮有效.. 将
终止按钮的文本设置为”执行”,…


[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

收藏
免费 7
支持
分享
最新回复 (10)
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
非常感谢楼主的付出!
2009-11-26 12:07
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
看的我眼花啊……哈哈
2009-11-26 21:20
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
呵呵,谢谢分享
2009-11-26 21:37
0
雪    币: 173
活跃值: (132)
能力值: ( LV7,RANK:100 )
在线值:
发帖
回帖
粉丝
5
呵呵, 那我下次写的再清楚些
2009-11-26 22:07
0
雪    币: 210
活跃值: (20)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
没看明白啊
2009-11-26 22:31
0
雪    币: 202
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
我也没有看明白。。。。。。。。。汗
2009-11-27 11:03
0
雪    币: 150
活跃值: (16)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
粗略地看了一下,非常好,谢谢LZ。
还有其他章节的笔记吗?一并上传,共享一下啊
2009-11-27 11:15
0
雪    币: 173
活跃值: (132)
能力值: ( LV7,RANK:100 )
在线值:
发帖
回帖
粉丝
9
呵呵, 好的, 一定...
2009-11-27 11:46
0
雪    币: 173
活跃值: (132)
能力值: ( LV7,RANK:100 )
在线值:
发帖
回帖
粉丝
10
好吧, 那我下次再写详细下.. 嘿嘿
2009-11-27 11:57
0
雪    币: 72
活跃值: (10)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
11
加油,加油,不过笔记也稍微注意一下格式。呵呵。
2009-11-27 14:32
0
游客
登录 | 注册 方可回帖
返回
//