大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> VB调用API函数建立控制台窗口

VB调用API函数建立控制台窗口

时间: 2021-07-31 作者:daque

    跟着软硬件的界面安排的兴盛,人机交互的办法同往日也有了很大的各别,图形用户 界面,鼠标操纵以至语音等早仍旧率见不先了。然而在有少许步调中,仍旧要运用到 象往日那种旧式的长机——结尾那么的字符型遏制台窗口格局的界面。而本质上,在 windows中也保持了如许的一系列遏制台因变量,底下的典型演练了怎样创造遏制台窗口以及让用户在个中输出字符同计划机举行交互对话。     开始在选vb菜单中的 project | module 项向工程文献中介入一个模块,而后在 这个module中介入以次代码: option explicit private declare function allocconsole lib "kernel32" () as long private declare function freeconsole lib "kernel32" () as long private declare function getstdhandle lib "kernel32" _ (byval nstdhandle as long) as long private declare function readconsole lib "kernel32" alias _ "readconsolea" (byval hconsoleinput as long, _ byval lpbuffer as string, byval nnumberofcharstoread as long, _ lpnumberofcharsread as long, lpreserved as any) as long private declare function setconsolemode lib "kernel32" (byval _ hconsoleoutput as long, dwmode as long) as long private declare function setconsoletextattribute lib _ "kernel32" (byval hconsoleoutput as long, byval _ wattributes as long) as long private declare function setconsoletitle lib "kernel32" alias _ "setconsoletitlea" (byval lpconsoletitle as string) as long private declare function writeconsole lib "kernel32" alias _ "writeconsolea" (byval hconsoleoutput as long, _ byval lpbuffer as any, byval nnumberofcharstowrite as long, _ lpnumberofcharswritten as long, lpreserved as any) as long private const std_input_handle = -10& private const std_output_handle = -11& private const std_error_handle = -12& private const foreground_blue = &h1 private const foreground_green = &h2 private const foreground_red = &h4 private const foreground_intensity = &h8 private const background_blue = &h10 private const background_green = &h20 private const background_red = &h40 private const background_intensity = &h80 'for setconsolemode (input) private const enable_line_input = &h2 private const enable_echo_input = &h4 private const enable_mouse_input = &h10 private const enable_processed_input = &h1 private const enable_window_input = &h8 'for setconsolemode (output) private const enable_processed_output = &h1 private const enable_wrap_at_eol_output = &h2 '''''g l o b a l s''''''''''''''''''''''''''''''''''' private hconsolein as long ' the console's input handle private hconsoleout as long ' the console's output handle private hconsoleerr as long ' the console's error handle '''''m a i n''''''''''''''''''''''''''''''''''''''''' private sub main()     dim szuserinput as string     allocconsole    '创造一个遏制台窗口     setconsoletitle "vb console example" '树立窗口题目     '赢得遏制窗口的句柄     hconsolein = getstdhandle(std_input_handle)     hconsoleout = getstdhandle(std_output_handle)     hconsoleerr = getstdhandle(std_error_handle)     setconsoletextattribute hconsoleout, _     foreground_red or foreground_green _     or foreground_blue or foreground_intensity _     or background_blue     consoleprint "vb console example" & vbcrlf          setconsoletextattribute hconsoleout, _     foreground_red or foreground_green _     or foreground_blue          consoleprint "please enter your name here--> "     '赢得用户名     szuserinput = consoleread()     if not szuserinput = vbnullstring then         consoleprint "hello, " & szuserinput & "!" & vbcrlf     else         consoleprint "hello,but who are you?" & vbcrlf     end if     consoleprint "press enter to close the console"     call consoleread     freeconsole ' destroy the console end sub private sub consoleprint(szout as string)     writeconsole hconsoleout, szout, len(szout), vbnull, vbnull end sub private function consoleread() as string     dim suserinput as string * 256          call readconsole(hconsolein, suserinput, len(suserinput), vbnull, vbnull)     'trim off the null charactors and the crlf.     consoleread = left$(suserinput, instr(suserinput, chr$(0)) - 3) end function     选vb菜单中的 project | project1 properties项,将startup object变换为sub main,而后 运路途序,步调就会弹出一个遏制台窗口,用户不妨按照遏制台窗口中的提醒消息与步调举行交互 对话。     上头的步调在win98、vb6下运转经过。

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.