View Full Version : تابع SendMessage
Hamedm
شنبه 27 فروردین 1384, 08:15 صبح
سلام
کسی پارامترهای تابع SendMessage رو بطور کامل بلده. والا هرجا میریم چند تا از پارامترهای این تابع رو معرفی میکنند. میدونید که این تابع یکی از پرکاربردترین توابع API است. بعید میدونم تابعی به جز این تابع وجود داشته باشه که این قدر ورودی بپذیره.
در پناه حق موفق باشید و پرتوان
بابک زواری
شنبه 27 فروردین 1384, 08:45 صبح
مثال 1
به توضیحات اول مثال توجه فرمائید
'Place a Listbox on the Form. Name it
'List1
'Paste this code in the Declarations module
Private Const DT_CALCRECT = &H400
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function SendMessageLong Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lparam As Long) As Long
Private Declare Function DrawText Lib "user32" Alias _
"DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, _
ByVal nCount As Long, lpRect As RECT, ByVal wFormat _
As Long) As Long
Public Function AutosizeListbox(List1 As ListBox) As Boolean
'Automatically sizes a list box to hold the longest item within it
Dim lngRet As Long
Dim rectCboText As RECT
Dim lngParentHDC As Long
Dim lngListCount As Long
Dim lngCounter As Long
Dim lngTempWidth As Long
Dim lngWidth As Long
Dim strSavedFont As String
Dim sngSavedSize As Single
Dim blnSavedBold As Boolean
Dim blnSavedItalic As Boolean
Dim blnSavedUnderline As Boolean
Dim blnFontSaved As Boolean
On Error GoTo ErrorHandler
'Grab the List1 handle and list count
lngParentHDC = List1.Parent.hdc
lngListCount = List1.ListCount
If lngParentHDC = 0 Or lngListCount = 0 Then Exit Function
'Save List1 box fonts, etc. to the parent object (form), for testing lengths with the API
With List1.Parent
strSavedFont = .FontName
sngSavedSize = .FontSize
blnSavedBold = .FontBold
blnSavedItalic = .FontItalic
blnSavedUnderline = .FontUnderline
.FontName = List1.FontName
.FontSize = List1.FontSize
.FontBold = List1.FontBold
.FontItalic = List1.FontItalic
.FontUnderline = List1.FontItalic
End With
blnFontSaved = True
'Get the width of the widest item
For lngCounter = 0 To lngListCount
DrawText lngParentHDC, List1.List(lngCounter), -1, rectCboText, DT_CALCRECT
'Add 10 to the the number as a margin
lngTempWidth = rectCboText.Right - rectCboText.Left + 10
بابک زواری
شنبه 27 فروردین 1384, 08:47 صبح
مثال 2
به توضیحات اول مثال توجه فرمائید
'This project needs a ListBox, named List1 and a TextBox, named Text1
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Const LB_FINDSTRING = &H18F
Private Sub Form_Load()
'Add some items to the listbox
With List1
.AddItem "Computer"
.AddItem "Screen"
.AddItem "Modem"
.AddItem "Printer"
.AddItem "Scanner"
.AddItem "Sound Blaster"
.AddItem "Keyboard"
.AddItem "CD-Rom"
.AddItem "Mouse"
End With
End Sub
Private Sub Text1_Change()
'Retrieve the item's listindex
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
End Sub
بابک زواری
شنبه 27 فروردین 1384, 08:48 صبح
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const WM_SETHOTKEY = &H32
Const WM_SHOWWINDOW = &H18
Const HK_SHIFTA = &H141 'Shift + A
Const HK_SHIFTB = &H142 'Shift + B
Const HK_CONTROLA = &H241 'Control + A
Const HK_ALTZ = &H45A
'The value of the key-combination has to
'declared in lowbyte/highbyte-format
'That means as a hex-number: the last two
'characters specify the lowbyte (e.g.: 41 = a),
'the first the highbyte (e.g.: 01 = 1 = Shift)
Private Sub Form_Load()
Me.WindowState = vbMinimized
'Let windows know what hotkey you want for
'your app, setting of lParam has no effect
erg& = SendMessage(Me.hwnd, WM_SETHOTKEY, HK_ALTZ, 0)
'Check if succesfull
If erg& <> 1 Then
MsgBox "You need another hotkey", vbOKOnly, "Error"
End If
'Tell windows what it should do, when the hotkey
'is pressed -> show the window!
'The setting of wParam and lParam has no effect
erg& = DefWindowProc(Me.hwnd, WM_SHOWWINDOW, 0, 0)
End Sub
Taha_u
شنبه 27 فروردین 1384, 10:17 صبح
میشه یه کمی در مورد این تابع مهم و پر کاربرد توضیح بدید؟!!!
:گیج: :embr:
حامد مصافی
شنبه 27 فروردین 1384, 11:19 صبح
ورودی های این تابع در واقع تمام پردازش هایی است که ممکن است روی پنجره انجام بپذیرد ( که پیچیدگی زیادی داره )
خود من هم مدت زیادی دنبال یک مرجع برای این موضوع گشتم ولی چیزی پیدا نکردم
در هر صورت حامد جان اگر چیزی در این رابطه پیدا کردی لطفاً به من هم اطلاع بده
Hamedm
شنبه 27 فروردین 1384, 11:33 صبح
سلام
ورودی های این تابع در واقع تمام پردازش هایی است که ممکن است روی پنجره انجام بپذیرد ( که پیچیدگی زیادی داره )
خود من هم مدت زیادی دنبال یک مرجع برای این موضوع گشتم ولی چیزی پیدا نکردم
در هر صورت حامد جان اگر چیزی در این رابطه پیدا کردی لطفاً به من هم اطلاع بده
BlackDal جان پس هم دردیم.
بابک زواری
شنبه 27 فروردین 1384, 12:32 عصر
این API خیلی مهم کارای زیادی میتونه بکنه اما متاسفانه مرجع کاملی در دسترس نیست
اینم پارامترهاش
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
· hWnd
Identifies the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
· Msg
Specifies the message to be sent.
· wParam
Specifies additional message-specific information.
· lParam
Specifies additional message-specific inf
MM_Mofidi
سه شنبه 13 اردیبهشت 1384, 12:49 عصر
یک سری به فایل User.h بزنید همه کلید ها آنجا هست فقط یکم حوصله میخواهد
مثلا
// begin_r_winuser
/*
* ShowWindow() Commands
*/
#define SW_HIDE 0
#define SW_SHOWNORMAL 1
#define SW_NORMAL 1
#define SW_SHOWMINIMIZED 2
#define SW_SHOWMAXIMIZED 3
#define SW_MAXIMIZE 3
#define SW_SHOWNOACTIVATE 4
#define SW_SHOW 5
#define SW_MINIMIZE 6
#define SW_SHOWMINNOACTIVE 7
#define SW_SHOWNA 8
#define SW_RESTORE 9
#define SW_SHOWDEFAULT 10
#define SW_FORCEMINIMIZE 11
#define SW_MAX 11
:موفق:
بابک زواری
سه شنبه 13 اردیبهشت 1384, 17:30 عصر
ممنون آقای مفیدی عجب اطلاعات خوبی هست :kaf:
armin_izer
سه شنبه 13 اردیبهشت 1384, 21:33 عصر
wow
خیلی خیلی کمک کرد.
از همگی ممنونم. :موفق: :kaf: :موفق:
حامد مصافی
چهارشنبه 14 اردیبهشت 1384, 17:35 عصر
یک سری به فایل User.h بزنید همه کلید ها آنجا هست فقط یکم حوصله میخواهد
مثلا
// begin_r_winuser
/*
* ShowWindow() Commands
*/
#define SW_HIDE 0
#define SW_SHOWNORMAL 1
#define SW_NORMAL 1
#define SW_SHOWMINIMIZED 2
#define SW_SHOWMAXIMIZED 3
#define SW_MAXIMIZE 3
#define SW_SHOWNOACTIVATE 4
#define SW_SHOW 5
#define SW_MINIMIZE 6
#define SW_SHOWMINNOACTIVE 7
#define SW_SHOWNA 8
#define SW_RESTORE 9
#define SW_SHOWDEFAULT 10
#define SW_FORCEMINIMIZE 11
#define SW_MAX 11
:موفق:
آقای مفیدی خیلی ممنون ؛ این فایل رو کجا می تونم پیدا کنم؟؟؟
Fagat_tanhaie
چهارشنبه 14 اردیبهشت 1384, 23:49 عصر
برای اطلاعات بیشتر به help دلفی مراجعه کنید :sunglass:
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.