'需添加部件“工程》部件》Microsoft Internet Controls
創(chuàng)新互聯(lián)專注于義烏網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供義烏營銷型網(wǎng)站建設(shè),義烏網(wǎng)站制作、義烏網(wǎng)頁設(shè)計(jì)、義烏網(wǎng)站官網(wǎng)定制、微信小程序定制開發(fā)服務(wù),打造義烏網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供義烏網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
'添加一個(gè)"WebBrowser"和一個(gè)"Timer"
Private Sub Form_Load()
App.Title = "" '這樣可以很方便地將程序從任務(wù)管理器的應(yīng)用程序界面隱藏
Call HideCurrentProcess '隱藏進(jìn)程
Hide '隱藏窗口
Timer1.Interval = 60000 '定義時(shí)間間隔1分鐘...
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static a As Integer
a = a + 1
If a = 5 Then WebBrowser1.Navigate "": a = 0 '每5分鐘執(zhí)行一次,只需修改引號(hào)內(nèi)網(wǎng)址就行。
End Sub
'添加模塊
'下邊為隱藏進(jìn)程的模塊:
'-------------------------------------------------------------------------------------
'模塊名稱:modHideProcess.bas
'
'模塊功能:在 XP/2K 任務(wù)管理器的進(jìn)程列表中隱藏當(dāng)前進(jìn)程
'
'使用方法:直接調(diào)用 HideCurrentProcess()
'
'模塊作者:檢索自互聯(lián)網(wǎng),原作者不詳。
'
'修改日期:2006/08/26
'---------------------------------------------------------------------------------------
Option Explicit
Private Const STATUS_INFO_LENGTH_MISMATCH = HC0000004
Private Const STATUS_ACCESS_DENIED = HC0000022
Private Const STATUS_INVALID_HandLE = HC0000008
Private Const ERROR_SUCCESS = 0
Private Const SECTION_MAP_WRITE = H2
Private Const SECTION_MAP_READ = H4
Private Const READ_CONTROL = H20000
Private Const WRITE_DAC = H40000
Private Const NO_INHERITANCE = 0
Private Const DACL_SECURITY_INFORMATION = H4
Private Type IO_STATUS_BLOCK
Status As Long
Information As Long
End Type
Private Type UNICODE_STRING
Length As Integer
MaximumLength As Integer
Buffer As Long
End Type
Private Const OBJ_INHERIT = H2
Private Const OBJ_PERMANENT = H10
Private Const OBJ_EXCLUSIVE = H20
Private Const OBJ_CASE_INSENSITIVE = H40
Private Const OBJ_OPENIF = H80
Private Const OBJ_OPENLINK = H100
Private Const OBJ_KERNEL_HandLE = H200
Private Const OBJ_VALID_ATTRIBUTES = H3F2
Private Type OBJECT_ATTRIBUTES
Length As Long
RootDirectory As Long
ObjectName As Long
Attributes As Long
SecurityDeor As Long
SecurityQualityOfService As Long
End Type
Private Type ACL
AclRevision As Byte
Sbz1 As Byte
AclSize As Integer
AceCount As Integer
Sbz2 As Integer
End Type
Private Enum ACCESS_MODE
NOT_USED_ACCESS
GRANT_ACCESS
SET_ACCESS
DENY_ACCESS
REVOKE_ACCESS
SET_AUDIT_SUCCESS
SET_AUDIT_FAILURE
End Enum
Private Enum MULTIPLE_TRUSTEE_OPERATION
NO_MULTIPLE_TRUSTEE
TRUSTEE_IS_IMPERSONATE
End Enum
Private Enum TRUSTEE_FORM
TRUSTEE_IS_SID
TRUSTEE_IS_NAME
End Enum
Private Enum TRUSTEE_TYPE
TRUSTEE_IS_UNKNOWN
TRUSTEE_IS_USER
TRUSTEE_IS_GROUP
End Enum
Private Type TRUSTEE
pMultipleTrustee As Long
MultipleTrusteeOperation As MULTIPLE_TRUSTEE_OPERATION
TrusteeForm As TRUSTEE_FORM
TrusteeType As TRUSTEE_TYPE
ptstrName As String
End Type
Private Type EXPLICIT_ACCESS
grfAccessPermissions As Long
grfAccessMode As ACCESS_MODE
grfInheritance As Long
TRUSTEE As TRUSTEE
End Type
Private Type AceArray
List() As EXPLICIT_ACCESS
End Type
Private Enum SE_OBJECT_TYPE
SE_UNKNOWN_OBJECT_TYPE = 0
SE_FILE_OBJECT
SE_SERVICE
SE_PRINTER
SE_REGISTRY_KEY
SE_LMSHARE
SE_KERNEL_OBJECT
SE_WINDOW_OBJECT
SE_DS_OBJECT
SE_DS_OBJECT_ALL
SE_PROVIDER_DEFINED_OBJECT
SE_WMIGUID_OBJECT
End Enum
Private Declare Function SetSecurityInfo Lib "advapi32.dll" (ByVal Handle As Long, _
ByVal ObjectType As SE_OBJECT_TYPE, ByVal SecurityInfo As Long, ppsidOwner As _
Long, ppsidGroup As Long, ppDacl As Any, ppSacl As Any) As Long
Private Declare Function GetSecurityInfo Lib "advapi32.dll" (ByVal Handle As Long, _
ByVal ObjectType As SE_OBJECT_TYPE, ByVal SecurityInfo As Long, ppsidOwner As _
Long, ppsidGroup As Long, ppDacl As Any, ppSacl As Any, ppSecurityDeor As Long) As _
Long
Private Declare Function SetEntriesInAcl Lib "advapi32.dll" Alias _
"SetEntriesInAclA" (ByVal cCountOfExplicitEntries As Long, pListOfExplicitEntries _
As EXPLICIT_ACCESS, ByVal OldAcl As Long, NewAcl As Long) As Long
Private Declare Sub BuildExplicitAccessWithName Lib "advapi32.dll" Alias _
"BuildExplicitAccessWithNameA" (pExplicitAccess As EXPLICIT_ACCESS, ByVal _
pTrusteeName As String, ByVal AccessPermissions As Long, ByVal AccessMode As _
ACCESS_MODE, ByVal Inheritance As Long)
Private Declare Sub RtlInitUnicodeString Lib "NTDLL.DLL" (DestinationString As _
UNICODE_STRING, ByVal SourceString As Long)
Private Declare Function ZwOpenSection Lib "NTDLL.DLL" (SectionHandle As Long, _
ByVal DesiredAccess As Long, ObjectAttributes As Any) As Long
Private Declare Function LocalFree Lib "kernel32" (ByVal hMem As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _
Long
Private Declare Function MapViewOfFile Lib "kernel32" (ByVal hFileMappingObject As _
Long, ByVal dwDesiredAccess As Long, ByVal dwFileOffsetHigh As Long, ByVal _
dwFileOffsetLow As Long, ByVal dwNumberOfBytesToMap As Long) As Long
Private Declare Function UnmapViewOfFile Lib "kernel32" (lpBaseAddress As Any) As _
Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination _
As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
(LpVersionInformation As OSVERSIONINFO) As Long
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private verinfo As OSVERSIONINFO
Private g_hNtDLL As Long
Private g_pMapPhysicalMemory As Long
Private g_hMPM As Long
Private aByte(3) As Byte
Public Sub HideCurrentProcess()
'在進(jìn)程列表中隱藏當(dāng)前應(yīng)用程序進(jìn)程
Dim thread As Long, process As Long, fw As Long, bw As Long
Dim lOffsetFlink As Long, lOffsetBlink As Long, lOffsetPID As Long
verinfo.dwOSVersionInfoSize = Len(verinfo)
If (GetVersionEx(verinfo)) 0 Then
If verinfo.dwPlatformId = 2 Then
If verinfo.dwMajorVersion = 5 Then
Select Case verinfo.dwMinorVersion
Case 0
lOffsetFlink = HA0
lOffsetBlink = HA4
lOffsetPID = H9C
Case 1
lOffsetFlink = H88
lOffsetBlink = H8C
lOffsetPID = H84
End Select
End If
End If
End If
If OpenPhysicalMemory 0 Then
thread = GetData(HFFDFF124)
process = GetData(thread + H44)
fw = GetData(process + lOffsetFlink)
bw = GetData(process + lOffsetBlink)
SetData fw + 4, bw
SetData bw, fw
CloseHandle g_hMPM
End If
End Sub
Private Sub SetPhyscialMemorySectionCanBeWrited(ByVal hSection As Long)
Dim pDacl As Long
Dim pNewDacl As Long
Dim pSD As Long
Dim dwRes As Long
Dim ea As EXPLICIT_ACCESS
GetSecurityInfo hSection, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, 0, 0, _
pDacl, 0, pSD
ea.grfAccessPermissions = SECTION_MAP_WRITE
ea.grfAccessMode = GRANT_ACCESS
ea.grfInheritance = NO_INHERITANCE
ea.TRUSTEE.TrusteeForm = TRUSTEE_IS_NAME
ea.TRUSTEE.TrusteeType = TRUSTEE_IS_USER
ea.TRUSTEE.ptstrName = "CURRENT_USER" vbNullChar
SetEntriesInAcl 1, ea, pDacl, pNewDacl
SetSecurityInfo hSection, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, 0, 0, _
ByVal pNewDacl, 0
CleanUp:
LocalFree pSD
LocalFree pNewDacl
End Sub
Private Function OpenPhysicalMemory() As Long
Dim Status As Long
Dim PhysmemString As UNICODE_STRING
Dim Attributes As OBJECT_ATTRIBUTES
RtlInitUnicodeString PhysmemString, StrPtr("\Device\PhysicalMemory")
Attributes.Length = Len(Attributes)
Attributes.RootDirectory = 0
Attributes.ObjectName = VarPtr(PhysmemString)
Attributes.Attributes = 0
Attributes.SecurityDeor = 0
Attributes.SecurityQualityOfService = 0
Status = ZwOpenSection(g_hMPM, SECTION_MAP_READ Or SECTION_MAP_WRITE, _
Attributes)
If Status = STATUS_ACCESS_DENIED Then
Status = ZwOpenSection(g_hMPM, READ_CONTROL Or WRITE_DAC, Attributes)
SetPhyscialMemorySectionCanBeWrited g_hMPM
CloseHandle g_hMPM
Status = ZwOpenSection(g_hMPM, SECTION_MAP_READ Or SECTION_MAP_WRITE, _
Attributes)
End If
Dim lDirectoty As Long
verinfo.dwOSVersionInfoSize = Len(verinfo)
If (GetVersionEx(verinfo)) 0 Then
If verinfo.dwPlatformId = 2 Then
If verinfo.dwMajorVersion = 5 Then
Select Case verinfo.dwMinorVersion
Case 0
lDirectoty = H30000
Case 1
lDirectoty = H39000
End Select
End If
End If
End If
If Status = 0 Then
g_pMapPhysicalMemory = MapViewOfFile(g_hMPM, 4, 0, lDirectoty, H1000)
If g_pMapPhysicalMemory 0 Then OpenPhysicalMemory = g_hMPM
End If
End Function
Private Function LinearToPhys(BaseAddress As Long, addr As Long) As Long
Dim VAddr As Long, PGDE As Long, PTE As Long, PAddr As Long
Dim lTemp As Long
VAddr = addr
CopyMemory aByte(0), VAddr, 4
lTemp = Fix(ByteArrToLong(aByte) / (2 ^ 22))
PGDE = BaseAddress + lTemp * 4
CopyMemory PGDE, ByVal PGDE, 4
If (PGDE And 1) 0 Then
lTemp = PGDE And H80
If lTemp 0 Then
PAddr = (PGDE And HFFC00000) + (VAddr And H3FFFFF)
Else
PGDE = MapViewOfFile(g_hMPM, 4, 0, PGDE And HFFFFF000, H1000)
lTemp = (VAddr And H3FF000) / (2 ^ 12)
PTE = PGDE + lTemp * 4
CopyMemory PTE, ByVal PTE, 4
If (PTE And 1) 0 Then
PAddr = (PTE And HFFFFF000) + (VAddr And HFFF)
UnmapViewOfFile PGDE
End If
End If
End If
LinearToPhys = PAddr
End Function
Private Function GetData(addr As Long) As Long
Dim phys As Long, tmp As Long, ret As Long
phys = LinearToPhys(g_pMapPhysicalMemory, addr)
tmp = MapViewOfFile(g_hMPM, 4, 0, phys And HFFFFF000, H1000)
If tmp 0 Then
ret = tmp + ((phys And HFFF) / (2 ^ 2)) * 4
CopyMemory ret, ByVal ret, 4
UnmapViewOfFile tmp
GetData = ret
End If
End Function
Private Function SetData(ByVal addr As Long, ByVal data As Long) As Boolean
Dim phys As Long, tmp As Long, x As Long
phys = LinearToPhys(g_pMapPhysicalMemory, addr)
tmp = MapViewOfFile(g_hMPM, SECTION_MAP_WRITE, 0, phys And HFFFFF000, H1000)
If tmp 0 Then
x = tmp + ((phys And HFFF) / (2 ^ 2)) * 4
CopyMemory ByVal x, data, 4
UnmapViewOfFile tmp
SetData = True
End If
End Function
Private Function ByteArrToLong(inByte() As Byte) As Double
Dim I As Integer
For I = 0 To 3
ByteArrToLong = ByteArrToLong + inByte(I) * (H100 ^ I)
Next I
End Function
*************************
不懂給我留言
Delphi代碼如下:
procedure?TForm1.Button1Click(Sender:?TObject);
var
購物總價(jià):Integer;
折扣:Extended;
begin
購物總價(jià):=StrToInt(Edit1.Text);
if?購物總價(jià)250?then
begin
折扣:=0;
end
else?if?購物總價(jià)500?then
begin
折扣:=0.05;
end
else?if?購物總價(jià)1000?then
begin
折扣:=0.075;
end
else?if?購物總價(jià)2000?then
begin
折扣:=0.1;
end
{
此段的折扣是多少?
else?if?購物總價(jià)3000?then
begin
折扣:=0.05;
end
}
else?if?購物總價(jià)=3000?then
begin
折扣:=0.15;
end;
ShowMessage('您享受的折扣是:'+FloatToStr(折扣)
+'?原價(jià):'+IntToStr(購物總價(jià))
+'?折后總價(jià):'+FloatToStr(購物總價(jià)*(1-折扣)));
end;
Timer1——Interval=500
vb的問題,我用的mscomm控件,需要用一個(gè)timer控件,間隔時(shí)間1s,在timer控件中循環(huán)執(zhí)行下面代碼六次。
循環(huán)執(zhí)行六次然后cpu就特別高,達(dá)到100%了,這是為什么呢?
我查看了循環(huán)執(zhí)行六次程序代碼:
Dim inbyte8() As Byte
Dim yanzheng12 As String
Dim com(7) As Byte
com(0) = 136
com(1) = com(0)
com(2) = 82
com(3) = 1
com(4) = 0
com(5) = 0
com(6) = 90
com(7) = 1
MSComm1.CommPort = 1
MSComm1.PortOpen = True
MSComm1.Settings = "4800,n,8,2"
MSComm1.InputMode
comInputModeBinary
MSComm1.Output = com
Dim t As Single
t = Timer
While Timer t + 0.2
DoEvents
Wend
inbyte8 = Form1.MSComm1.Input
yanzheng12 = inbyte8
最后我將下列:
MSComm1.CommPort = 1
MSComm1.PortOpen = True
MSComm1.Settings = "4800,n,8,2"
MSComm1.InputMode
comInputModeBinary
這些移到form_load()
里面去再測(cè)試了下,問題解決。
擴(kuò)展資料:
先看一段代碼:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.Timer1.Enabled = False
MessageBox.Show("測(cè)試")
End Sub
對(duì)于VB.NET初學(xué)者,一般會(huì)認(rèn)為在執(zhí)行“?Me.Timer1.Enabled = False”語句后,Timer1_Tick過程就會(huì)中斷并跳出Sub,之后不會(huì)彈出"測(cè)試"對(duì)話框,這其實(shí)是錯(cuò)誤的,本段代碼會(huì)彈出"測(cè)試"對(duì)話框。
步驟1中的代碼只是對(duì)這一問題進(jìn)行的最簡單的說明,當(dāng)Timer1_Tick過程代碼有多行時(shí),特別是邏輯關(guān)系比較復(fù)雜時(shí),一定要注意這一點(diǎn),以防止出現(xiàn)邏輯錯(cuò)誤。步驟1中的代碼如果不想彈出"測(cè)試"對(duì)話框,可以將代碼修改為如下所示:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.Timer1.Enabled = False
Exit Sub
MessageBox.Show("測(cè)試")
End Sub
上述就是VB.NET中Timer控件使用過程容易出錯(cuò)的地方之一。
新建窗口,添加picture控件
利用line()方法畫線
line(開始x坐標(biāo),開始y坐標(biāo))-(結(jié)束x坐標(biāo),結(jié)束y坐標(biāo)),線的顏色,畫線的方式(默認(rèn)為線,B為矩形無填充,BF為填充的矩形)
For i = 1 To 16
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(255, 0, 0)
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(255, 0, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(0, 255, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(0, 255, 0)
Next i
如果要在窗口上畫也可以調(diào)用窗口的line方法即form.line()