如何在进入程序时判断屏幕大小不是800X600的,如果是,自动把屏幕大小改成800X600,然后显示程序界面;在退出程序之前,再把屏幕大小由800X600改回到原来的设置。
(因为我做的界面是在800X600下做的,里面有许多文本控件什么的,不好用语句来调每个文本框的大小和位置。找到一个能实现这个功能的控件,但最多只支持8 个控件!没办法!)
请助!
(因为我做的界面是在800X600下做的,里面有许多文本控件什么的,不好用语句来调每个文本框的大小和位置。找到一个能实现这个功能的控件,但最多只支持8 个控件!没办法!)
请助!
解决方案 »
- 共享局域网内获取其他计算机里软件版本信息?
- 请问winsock的10061 connection is forcefully rejected错误是怎么产生的?
- 做好的OCX控件,为什么在Form里可以正常调用,在网页里却会报错?
- 急,谁有转换数字的源代码
- 下面这句里面的Command是做什么事情啊
- 简单问题:如何在VB中显示一个WORD文档的全部内容?
- true dbgrid 7 的问题
- VB中为什么总是出现过程声明与同名事件或过程的描述不匹配的问题?有用到数据库和ADODC
- 如何使用VB连接到网上的数据库上。
- 如何实现客户端与服务器相连?
- 在 VB 中如何使用Windows 脚本对象
- 窗体求教高手,谢谢!!!!
屏幕的分辨率改变时窗口跟着变好说,但是那些控件的大小要一起跟着调整比较麻烦哦。
你可以在搜索一下,有许多相关的资料的。
environment env
integer ii_ScreenWidth,ii_ScreenHeight
double WRadio,HRadio,Radio
integer ii_WinBolderWidth,ii_WinBolderHeight
getenvironment(env)
ii_WinBolderWidth=w_zzll.width - w_zzll.WorkSpaceWidth()//取得窗体的边框宽度
ii_WinBolderHeight=w_zzll.height - w_zzll.WorkSpaceHeight()
ii_ScreenWidth=env.screenwidth
ii_ScreenHeight=env.screenheight
//compute the radio that need be resizeWRadio=ii_ScreenWidth/1024 //标准认为屏幕分辨率为800*600
HRadio=ii_ScreenHeight/768//计算出屏幕相对800*600分辨率的变化量
Radio=Min(WRadio,HRadio)
if Radio=1.0 then //if the screen is default 800*600
move(pos_x,pos_y)
return 0
end if
this.hide()
this.width=(this.width - ii_WinBolderWidth)*Radio + ii_WinBolderWidth
this.height=(this.height - ii_WinBolderHeight)*Radio + ii_WinBolderHeight
integer i
dragobject temp//用于取各种控件for i=1 to upperbound(this.control)
temp=this.control[i]//调整大小,位置
temp.width=temp.width*Radio
temp.x=temp.x*Radio
temp.y=temp.y*Radio
temp.Height=temp.Height*Radio
choose case typeof(temp)
case tab!
tab mtab
mtab=temp
mtab.textsize = mtab.textsize*Radio//设置字体
case commandbutton!
commandbutton cb
cb = temp
cb.textsize = cb.textsize*Radio case singlelineedit!
singlelineedit sle
sle = temp
sle.textsize=sle.textsize*Radio
case editmask!
editmask em
em = temp
em.textsize = em.textsize*Radio
case statictext!
statictext st
st = temp
st.textsize = st.textsize*Radio case datawindow! // datawindows get zoomed
datawindow dw
dw = temp
dw.Object.DataWindow.zoom = string(int(Radio*100))//注意DATAWINDOW与其它控件的不同 case picturebutton!
picturebutton pb
pb = temp
pb.textsize = pb.textsize*Radio case checkbox!
checkbox cbx
cbx = temp
cbx.textsize = cbx.textsize*Radio case dropdownlistbox!
dropdownlistbox ddlb
ddlb = temp
ddlb.textsize = ddlb.textsize*Radio case groupbox!
groupbox gb
gb = temp
gb.textsize = gb.textsize*Radio case listbox!
listbox lb
lb = temp
lb.textsize = lb.textsize*Radio case multilineedit!
multilineedit mle
mle = temp
mle.textsize = mle.textsize*Radio case radiobutton!
radiobutton rb
rb = temp
rb.textsize = rb.textsize*Radioend choose
next
move(pos_x,pos_y)
this.show()
return 0
' * * * * * * * * * * 警告 * * * * * * * * * * * * *
' 对以下代码进行修改将有可能导致不可预料的后果,甚至能使您的VB崩溃!
' 在VB IDE环境中运行本程序之前请先保存您的修改
' 不要使用断点调试模式,这将导致VB崩溃!
' * * * * * * * * * * 注意 * * * * * * * * * * * * *
模块:
Option ExplicitPublic OldWindowProc As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
'从指定的窗口结构中取得信息
'参数/类型 说明
'hwnd(long): 欲为其获取信息的窗口的句柄
'nIndex(long): 欲取回的信息,可以是下述任何一个常数
'GWL_EXSTYLE:扩展窗口样式
'GWL_STYLE:窗口样式
'GWL_WNDPROC:该窗口的窗口函数的地址
'GWL_HINSTANCE:拥有窗口的实例的句柄
'GWL_HWNDPARENT:该窗口之父的句柄.不要用 SetWindowWord 来改变这个值
'GWL_ID:对话框中一个子窗口的标识符
'GWL_USERDATA:含义由应用程序规定
'对话框亦可指定下列常数
'DWL_DLGPROC:这个窗口的对话框函数地址
'DWL_MSGRESULT:在对话框函数中处理的一条消息返回的值
'DWL_USER:含义由应用程序规定
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
'在窗体结构中为指定的窗口设置信息
'参数/类型 说明
'hwnd(long) 欲为其获取信息的窗口的句柄
'nIndex(long) 参考GetWindowLong函数
'dwNewLong(long) 由nIndex指定的窗口信息的新值
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal ByteLen As Long)
'这就是在VisualBasic中处理指针的"短柄斧"--CopyMemory.你可能在API文档中找不到它,但它确实存在,并且功能异常强大
'参数/类型 说明
'pDest 你想写入字节到其中的任何变量的ByRef参数(地址)
'pSource 要从其中进行复制的ByRef变量
'ByteLen 要复制的字节数
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'把控制权传回给原来的窗口过程
Public Const WM_GETMINMAXINFO = &H24
Type POINTAPI
x As Long
y As Long
End Type
' This is the structure that is passed by reference(ByRef)(ie an address) to your message handler(消息侦听器)
' The key items in this structure are ptMinTrackSize and ptMaxTrackSize
Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type
Public Function SubClass1_WndMessage(ByVal hwnd As Long, ByVal Msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
' Watch for the pertinent message to come in
If Msg = WM_GETMINMAXINFO Then
Dim MinMax As MINMAXINFO
' This is necessary because the structure was passed by its address and there
' is currently no intrinsic way to use an address in Visual Basic
CopyMemory MinMax, ByVal lp, Len(MinMax)
' This is where you set the values of the MinX,MinY,MaxX, and MaxY
' The values placed in the structure must be in pixels. The values
' normally used in Visual Basic are in twips. The conversion is as follows:
' pixels = twips\twipsperpixel
MinMax.ptMinTrackSize.x = 3975 \ Screen.TwipsPerPixelX
MinMax.ptMinTrackSize.y = 1740 \ Screen.TwipsPerPixelY
MinMax.ptMaxTrackSize.x = Screen.Width \ Screen.TwipsPerPixelX \ 2
MinMax.ptMaxTrackSize.y = 3480 \ Screen.TwipsPerPixelY
' Here we copy the datastructure back up to the address passed in the parameters
' because Windows will look there for the information.
CopyMemory ByVal lp, MinMax, Len(MinMax)
' This message tells Windows that the message was handled successfully
SubClass1_WndMessage = 1
Exit Function
End If
' Here, we forward all irrelevant messages on to the default message handler.
SubClass1_WndMessage = CallWindowProc(OldWindowProc, hwnd, Msg, wp, lp)
End Function窗体代码:
Option ExplicitPrivate Const GWL_WNDPROC = (-4)
Private Sub Form_Load()
' First, we need to store the address of the existing Message Handler
OldWindowProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
' Now we can tell windows to forward all messages to out own Message Handler
Call SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf SubClass1_WndMessage)
End SubPrivate Sub Form_Unload(Cancel As Integer)
' We must return control of the messages back to windows before the program exits
Call SetWindowLong(Me.hwnd, GWL_WNDPROC, OldWindowProc)
End Sub