السلام عليكم ورحمة الله
في البداية : أتقدم بالشكر لكل الأعضاء الذين ساهموا في نشر
علوم البرمجة والعلوم الأخرى
وأقول لهم ( أن جهدكم لن يضيع بسهولة )
وتحت هذا الشعار فإني أقدم لكم مجموعة من الأكواد والأفكار
كتبت في هذا المنتدى منذ زمن وبعضها من منتديات أخرى
مع ملاحظة أني لم أقم بكتابة أي كود ( وإنما نقلت الأكواد كما هي مع بعض التغييرات البسيطة )
لكي تعم الفائدة ( ولتقليل الأسألة المتكررة )
بسم الله نبدأ :
1 : فتح صفحة إنترنت من داخل برنامجك
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Private Sub Label1_Click() Dim lapi As Long a$ = App.Path & "index.html" lapi = ShellExecute(Me.hwnd, "open", a$, vbNull, vbNull, 5) End Sub
الطريقة الثانية
Shell ("explorer http://arabteam.nicmatic.com"), vbNormalNoFocus2 : تنفيذ الكود بعد فترة زمنية
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub cmd_Click() MsgBox Time Sleep 10000 MsgBox Time End Sub
3 : فتح وغلق السي دي
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub فتح_Click()
Call mciSendString("Set CDAudio Door Open", "", 0, 0)
End Sub
Private Sub غلق_Click()
Call mciSendString("Set CDAudio Door Closed", "", 0, 0)
End Sub4 : تغيير خلفية الجهاز
Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long Public Const SPI_SETDESKWALLPAPER = 20 Private Sub Command1_Click() Dim lngSuccess As Long Dim strBitmapImage As String strBitmapImage = "c:windowsstraw.bmp" lngSuccess = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, strBitmapImage, 0) End Sub
5 : تشغيل ملف صوتي
Private Declare Function sndPlaySound Lib "winmm.dll" Alias _ "sndPlaySoundA" (ByVal lpszSoundName As String, _ ByVal uFlags As Long) As Long Private Sub Command1_Click () sndPlaySond "c:\MySound.wav" , 1 End Sub
6 : تحريك الفورم بمفاتيح الأسهم في لوحة المفاتيح
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal v As Long) As Integer Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If GetAsyncKeyState(37) Then 'يسار Left = Left - 15 End If If GetAsyncKeyState(38) Then 'أعلى Top = Top - 15 End If If GetAsyncKeyState(39) Then 'يمين Left = Left + 15 End If If GetAsyncKeyState(40) Then 'أسفل Top = Top + 15 End If End Sub
7 : رسم مؤشر الماوس على الفورم
Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long Private Declare Function GetCursor Lib "user32" () As Long Private Sub Form_Paint() DrawIcon Me.hdc, 30, 30, GetCursor End Sub
8 : إضافة أيقونة البرنامج في شريط المهام
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" _ Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, _ lpData As NOTIFYICONDATA) As Longprivate Type NOTIFYICONDATA cbSize As Long hwnd As Long uID As Long uFlags As Long uCallbackMessage As Long hIcon As Long szTip As String * 64 End Type Private Const WM_RBUTTONDOWN = &H204 Private Const WM_RBUTTONUP = &H205 Private Const WM_RBUTTONDBLCLK = &H206 Private Const NIM_ADD = &H0 Private Const NIM_DELETE = &H2 Private Const NIM_MODIFY = &H1 Private Const NIF_ICON = &H2 Private Const NIF_MESSAGE = &H1 Private Const NIF_TIP = &H4 Private Ic As NOTIFYICONDATA 'هنا تعريف المتغير من نوع NotifyIcon '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Sub Load_Form() Ic.cbSize = Len(Ic) Ic.hwnd = Me.hwnd 'مقبض النافذة Ic.uID = 1& Ic.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE 'يحتوي على : ايقون + ملاحظات + رسائل الفأرة Ic.uCallbackMessage = WM_RBUTTONDOWN Or WM_RBUTTONUP Or WM_RBUTTONDBLCLK 'رسائل الفأرة النشطة Ic.hIcon = Picture 'ضع هنا الايقونه Ic.szTip = "My Program First" 'الملاجظات الخاصة للبرنامج او ما يسمىToolTipText Shell_NotifyIcon NIM_ADD, Ic 'الأمر اضافة للأيقونة End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Sub Form_Unload() Ic.cbSize = Len(Ic) Ic.hwnd = Me.hwnd Ic.uID = 1& Shell_NotifyIcon NIM_DELETE, Ic 'الأمر حذف للأيقونة End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Sub Timer1_Timer() Ic.szTip = "My Program Second" Shell_NotifyIcon NIM_MODIFY, Ic 'الأمر تعديل في الأيقونة وهنا كان التعديل فقط على الملاحظات End Sub
9 : تجميد برنامج وإعادة تنشيطة
Private Declare Function CreateProcessBynum Lib "kernel32" _
Alias "CreateProcessA" (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, ByVal lpProcessAttributes As _
Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles _
As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, _
ByVal lpCurrentDirectory As String, lpStartupInfo As _
STARTUPINFO, lpProcesstInfrmation As PROCESS_INFORMATION) As Long
Private Declare Function SuspendThread Lib "kernel32" _
(ByVal hThread As Long) As Long
Private Declare Function ResumeThread Lib "kernel32" _
(ByVal hThread As Long) As Long
'PROCESS_INFORMATION و STARTUPINFO البنيتين
' Process التي نحتاجها لانشاء الـ
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Const NORMAL_PRIORITY_CLASS = &H20
Dim Ret&, PrInf As PROCESS_INFORMATION
Dim stInf As STARTUPINFO
Private Sub Command1_Click()
'من الافضل ضبطها
With stInf
.cb = Len(stInf)
.lpReserved = vbNullString
.lpDesktop = vbNullString
.lpTitle = vbNullString
.dwFlags = 0
End With
'Process انشاء الـ
Ret = CreateProcessBynum("C:\Windows\calc.exe", vbNullString, 0, 0, _
True, NORMAL_PRIORITY_CLASS, ByVal 0&, vbNullString, stInf, PrInf)
End Sub
Private Sub Command2_Click()
'Thread تجميد الـ
SuspendThread PrInf.hThread
End Sub
Private Sub Command3_Click()
'Thread اعادة تنشيط الـ
ResumeThread PrInf.hThread
End Sub10 : جعل البرنامج يعمل مع بدء تشغيل وندوز
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _ (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias _ "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _ ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, _ ByVal cbData As Long) As Long Private Declare Function RegCloseKey Lib "advapi32.dll" _ (ByVal hKey As Long) As Long Private Const HKEY_LOCAL_MACHINE = &H80000002 Private Sub Form_Load() Dim lRegKey As Long Dim sApp As String sApp = App.Path + IIf(Right(App.Path, 1) <> "\", "\", "") + App.EXEName + ".exe" If RegOpenKey(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run\", lRegKey) = 0 Then If RegSetValueEx(lRegKey, "My Program", 0, 1, ByVal sApp, Len(sApp)) Then MsgBox "There was a Problem Adding This Program to the Registry", vbExclamation, "Error" End If Call RegCloseKey(lRegKey) End If End Sub
الطريقة الثانية
Set iii= CreateObject("wscript.shell")
'للكتابة
iii.regwrite " HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre
ntVersion\Run\code4arab", "c:\file name"
'اما للقراءه
iii.regread " HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre
ntVersion\Run\code4arab", "c:\file name"11 : كود لقلب الشاشة عموديا
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal _ x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _ ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop _ As Long) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x _ As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _ ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal _ nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long Private Sub Form_Initialize() Dim W, H W = Screen.Width / 15 H = Screen.Height / 15 StretchBlt hdc, 0, H, W, -H, GetDC(0&), 0, 0, W, H, vbSrcCopy End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, _ y As Single) End End Sub ملاحظة قلب الشاشة معناة إلتقاط صورة لسطح المكتب ثم قلب الصورة ولصقها في الفورم مع تكبير الفورم لحجم الشاشة
12 : فتح ملف نصي ووضعة في أداة نص
Open "c:\windows\desktop\books.txt" For Input As #1 Text1.Text = Input(LOF(1), 1) Close #1
13 : إخفاء وإظهار مؤشر الفأرة
Private Declare Function ShowCursor Lib "user32" _ (ByVal bShow As Long) As Long اخفاء المؤشر x = ShowCursor(False) إظهار المؤشر x = ShowCursor(True)
14 : إطفاء الشاشة وتشغيلها
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) _ As Long Const WM_SYSCOMMAND = &H112 Const SC_MONITORPOWER = &HF170 ' لإطفاء الشاشة SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, 2& 'لتشغيل الشاشة SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, -1&
15 : معرفة العنصر الذي تحت مؤشر الماوس في القائمة
Private Declare Function SendMessage Lib _ "user32" Alias "SendMessageA" (ByVal _ hWnd As Long, ByVal wMsg As Long, ByVal _ wParam As Long, lParam As Any) As Long Private Const LB_ITEMFROMPOINT = &H1A9 Private Sub List1_MouseMove(Button As Integer, _ Shift As Integer, X As Single, Y As Single) Dim P As Long Dim XPosition As Long, YPosition As Long XPosition = CLng(X / Screen.TwipsPerPixelX) YPosition = CLng(Y / Screen.TwipsPerPixelY) P = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0, ByVal _ ((YPosition * 65536) + XPosition)) If P < List1.ListCount Then List1.ToolTipText = List1.List(P) End If End Sub
-


