کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی
کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی

ScrollBar



At the picture below you can see what I've already done. Left scrollbar is a system scrollbar, right one - custom scrollbar.




FVertBar: Boolean; FPressedBtn1, FPressedBtn2, FSelectedBtn1, FSelectedBtn2: Boolean; FBarBmp, FBtn1Bmp, FBtn2Bmp: TBitmap; MainDC: hDC; 


FBarBmp.Free; FBtn1Bmp.Free; FBtn2Bmp.Free;


Case WM_ENABLE ' WM_SHOWWINDOW
Width=100
Height=80

FSelectedBtn1=false
FSelectedBtn2=false
FPressedBtn1=false
FPressedBtn2=false

(FBarBmp=LoadImageA(0,"D:\...bmp",0,16,16,&H10
=FBtn1Bmp
=FBtn2Bmp

Case WM_DESTROY

DeleteObject FBarBmp
DeleteObject FBtn1Bmp
DeleteObject FBtn2Bmp


Case WM_NCCALCIZE

decrease width to create non-client area'
(Dec(Message.CalcSize_Params.rgrc(0).Right,17
FVertBar= true


Case WM_NCPAINT

(MainDC=GetWindowDC(Hwnd

(if FVertBar then PaintScrollBarVert(MainDC

if FVertBar then 
PaintButtonVert1 MainDC
PaintButtonVert2 MainDC
End if 
Enf if 
ReleaseDC Handle, MainDC


Case WM_NCMOUSEMOVE

GetCursorPos pt
ScreenToClient hwnd,pt

Top Vert Button'
(Rect(Width - 17 - 2, ClientRect.Top, Width - 2, 17
if PtInRect(Crect,pt) then
FSelectedBtn1= true
else
FSelectedBtn1=false
End If 
bottom vert button '
Rect(Width - 17 - 2, ClientRect.Bottom - 17, Width - 2,
(ClientRect.Bottom + 17,
if PtInRect(Crect,pt)   then
FSelectedBtn2=true
else
FSelectedBtn2=false
End if 
SendMessageA hwnd,WM_NCPAINT,1, 0



Cas WM_NCLBUTTONDOWN

GetCursorPos pt 
ScreenToClient hwnd,pt
'Top Vert Button
Rect(Width - 17 - 2, ClientRect.Top, Width - 2, 17)
if PtInRect(Crect,pt) then
FPressedBtn1=true
End If 
'bottom vert button 
Rect(Width - 17 - 2, ClientRect.Bottom - 17, Width - 2, ClientRect.Bottom + 17)
if PtInRect(Crect,pt)   then
FPressedBtn2=true
End if 
SendMessageA hwnd,WM_NCPAINT,1, 0


Case WM_NCLBUTTONUP
FPressedBtn1=false
FPressedBtn2 =false 
SendMessageA hwnd,WM_NCPAINT,1, 0


(PaintScrollBarVert(hDC

FBarBmp.Width= 17
FBarBmp.Height=ClientRect.Bottom
FBarBmp.Canvas.Brush.Color=clLime FBarBmp.Canvas.FillRect(FBarBmp.Canvas.ClipRect)
BitBlt(MainDC,Width-17-2,ClientRect.Top + 2,FBarBmp.Width,FBarBmp.Height, FBarBmp.Canvas.Handle,0, 0,SRCCOPY) 


(PaintButtonVert1(hDC


FBtn1Bmp.Width=17
FBtn1Bmp.Height=17

if not FSelectedBtn1 then FBtn1Bmp.Canvas.Brush.Color=clRed
End if 

if FSelectedBtn1 then FBtn1Bmp.Canvas.Brush.Color =clBlue
End if 

if FSelectedBtn1 and FPressedBtn1 then FBtn1Bmp.Canvas.Brush.Color=clPurple
FBtn1Bmp.Canvas.FillRect(FBtn1Bmp.Canvas.ClipRect)
BitBlt(DC, Width - 17 - 2, ClientRect.Top + 2, FBtn1Bmp.Width, FBtn1Bmp.Height, FBtn1Bmp.Canvas.Handle, 0, 0, SRCCOPY)
End if 



(PaintButtonVert2(hDC


FBtn2Bmp.Width=17
FBtn2Bmp.Height=17

if not FSelectedBtn2 then FBtn1Bmp.Canvas.Brush.Color=clRed
End if 

if FSelectedBtn2 then FBtn1Bmp.Canvas.Brush.Color=clBlue
End if 

if FSelectedBtn2 and FPressedBtn2 then FBtn1Bmp.Canvas.Brush.Color=clPurple
FBtn1Bmp.Canvas.FillRect(FBtn1Bmp.Canvas.ClipRect)
BitBlt(DC, Width - 17 - 2, ClientRect.Bottom - 17 + 2, FBtn1Bmp.Width,FBtn1Bmp.Height, FBtn1Bmp.Canvas.Handle, 0, 0, SRCCOPY)
End if 





مربوط به مثال بالا نیست 






ساختار WINDOWPLACEMENT




WINDOWPLACEMENT structure

Contains information about the placement of a window on the screen.

Type WINDOWPLACEMENT
length As Long
flags As Long
showCmd As Integer
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
rcDevice As RECT
End Type





Of course you should measure/obtain the correct border size from your window style by using methods like GetSystemMetrics or GetThemeMetric, its a very simple task. I just wanted to demonstrate how you can change the border size of your frame when switching between the window states.

The size and positions of the caption buttons are now correct, as you can see here









GetWindowPlacement function

Retrieves the show state and the restored, minimized, and maximized positions of the specified window.

Parameters

hWnd

Type: HWND

A handle to the window.

lpwndpl

Type: WINDOWPLACEMENT*

A pointer to the WINDOWPLACEMENTstructure that receives the show state and position information. Before calling GetWindowPlacement, set the lengthmember to sizeof(WINDOWPLACEMENT). GetWindowPlacement fails if lpwndpl-> length is not set correctly.

Return Value

Type: Type: BOOL

If the function succeeds, the return value is nonzero.


Remarks

The flags member of WINDOWPLACEMENTretrieved by this function is always zero. If the window identified by the hWnd parameter is maximized, the showCmd member is SW_SHOWMAXIMIZED. If the window is minimized, showCmd is SW_SHOWMINIMIZED. Otherwise, it is SW_SHOWNORMAL.

The length member of WINDOWPLACEMENTmust be set to sizeof(WINDOWPLACEMENT). If this member is not set correctly, the function returns FALSE. For additional remarks on the proper use of window placement coordinates, see WINDOWPLACEMENT.








VSCROLL.HSCROLL ایجاد دو باتن در ناحیه ی NonClient لیست باکس



https://www.codeproject.com/Articles/1293/Control-Subclassing



هنوز تست نشده  ولی نحوه ی کار به این شکل است که اندازه ی ناحیه Client  رو عوض میکنند تا دو مستطیل با حالت باتن در پائین و بالای آن بکشند ، بعنوان Scroll Up/Down و NCHITTEST هم  زمانی که ماوس روی آن قسمت ها قرار می گیرد یا موقعیت عوض میشود عدد ثابتی رو بر میگردونه و طبق همون و NCLBUTTONDOWN تابعی رو صدا میزنن که حالت PUSH بگیره وقتی فشرده شه یا  به حالت اولش برگرده .


در NCCALCSIZE و WPARAM=1 اندازه ی دوباره داده میشود البته SWP_FRAMECHANGED نباید فراموش شود بعد از ساب کلاس کردن فرضا 


Private listboxProc As LongPtr

listboxProc=0

HookWindow


در HOOKPROC زمانیکه پیام  HCBT_CREATEWND دریافت میشود  برای هنگ نکردن یا عدم Crash باید اگر listbox=0 و wparam  برابر با کلاس پنجره  با تابع GetClassName و نام پنجره ( منظور کپشن آن ) همان نام پنجره  (قلاب شده) شد منظور  با GETWINDOWTEXT  به تابع WndProc ریفر داده شود جهت تسخیر پیام های ارسالی 


WndProc

Select Case Msg 

 Case WM_ENABLE  ' WM_SHOWWINDOW

listboxproc=SetWindowLongPtrA(hlist,GWL_WNDPROC,AddressOf 

(fnlist

SetWindowpos 0,0,0,0,0,0,SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOZORDER Or SWP_FRAMECHANGED

WM_DESTROY

SetWindowLongPtrA hwnd,GWL_WNDOROC,listboxProc

End Function 


تابعی برای Capture کردن یا تسخیر پیام های دریافتی  ( لیست باکس )


Function fnlist(ByVal hwnd As LongPtr,ByVal Msg As Long,ByVal wParam As LongPtr,ByVal lParam As LongPtr) As LongPtr 

Dim nccsp As NCCALCSIZE_PARAMS

Select Case Msg

Case WM_NCCALCSIZE

CallWindProcA listboxProc,hwnd,Msg,wParam,lParam

Use CopyMemory'


Case WM_NCPAINT


End Select

(fnlist=CallWindProcA(listboxProc,hwnd,Msg,wParam,lParam

End Function 


در NCPAINT کشیدن Scroll انجام میشود 


SetBkColor(COLORREF crBkColor,COLORREF 

(crSelectedColor

{
Deletes previous brush. Must do in order to create a'

new one '

DeleteObject m_BkBrush

Sets the brush the specified background color' 

m_BkBrush=CreateSolidBrush(crBkColor)

Invalidate  'Forces Redraw



()Function DrawBorders

GetClientRect hlist,Crect

InflateRect Crect,GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)

'Since we'll be using m_bOver, let's 'initialize it. Add m_bOver = 'FALSE; on PreSubclassWindow.
if (m_bOver) Then 
DrawEdge hdc,Crect,EDGE_BUMP,BF_RECT
Else
DrawEdge hdc,Crect,EDGE_SUNKEN,BF_RECT
End If 
ReleaseDC hdc

End Function 

WM_MOUSLEAVE
m_bOver=FALSE
()DrawBorders
if (!m_bOver)
m_bOver=TRUE 'Now the mouse is over DrawBorders() 'Self explanatory //Add TRACKMOUSEEVENT track 'Declares structure

(track.cbSize=sizeof(track

track.dwFlags=TME_LEAVE 'Notify us when the mouse leaves

 track.hwndTrack=m_hWnd 'Assigns this window's hwnd 

TrackMouseEvent &track



MouseMove


'If m_bOver==FALSE,and this function is 'called, it means that the mouse entered. 

if (!m_bOver) Then 
m_bOver=TRUE 'Now the mouse is over

DrawBorders() ' Self explanatory 




We then set them to an initial value under PreSubclassWindow:

m_bOver = FALSE;
m_ItemHeight=18; m_crTextHlt=GetSysColor(COLOR_HIGHLIGHTTEXT);
m_crTextClr=GetSysColor(COLOR_WINDOWTEXT);
m_HBkColor=GetSysColor(COLOR_HIGHLIGHT);
m_BmpWidth=16;
m_BmpHeight=16;

 : MeasureItem
lpMeasureItemStruct->itemHeight=m_ItemHeight;




4. Scrollbars

For simplicity purposes. the scrollbars that we are going to make are going to be static, always shown regardless of whether they are needed. I don't think we are using the correct term since they don't have bars but who cares. As we all know, we must draw them. However, the problem is how to do it so that it is within the listbox rect and does not cover any item. There's a simple solution, we can resize the client area. This can be done by receiving the message WM_NCCALCSIZE. Add a function for it, and we get:


lpncsp->rgrc[0].top += 16; //Top
lpncsp->rgrc[0].bottom -= 16; //Bottom



WM_NCPAINT

static BOOL before=FALSE
if (!before) Then
SetWindowPos(NULL,0,0,0,0,SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE before=TRUE
()DrawBorders


(DrawScrolls(UINT WhichOne, UINT State
()pDC=GetDC
CRect rect
GetClientRect hwnd,Crect
 
if (IsWindowEnabled())State=SC_DISABLED; //Expands the so that it does not draw over the borders

Crect.left=Crect.left-GetSystemMetrics(SM_CYEDGE) Crect.right= Crect.right+GetSystemMetrics(SM_CXEDGE)

(if (WhichOne==SC_UP
 
rect.bottom=rect.top-GetSystemMetrics(SM_CXEDGE) rect.top=rect.top-16-GetSystemMetrics(SM_CXEDGE)

Draws the scroll up '

DrawFrameControl pDC,Crect,DFC_SCROLL,State Or DFCS_SCROLLUP)
else
Needs to draw down
rect.top=rect.bottom+GetSystemMetrics(SM_CXEDGE) rect.bottom=rect.bottom+16+GetSystemMetrics(SM_CXEDGE); DrawFrameControl pDC,Crect,DFC_SCROLL,State Or DFCS_SCROLLDOWN
ReleaseDC pDC


pubic const SC_UP=2
public const SC_DOWN=3



WM_Enable 
'SC_NORMAL will be changed to 'SC_DISABLED if the window is disabled DrawScrolls(SC_UP,SC_NORMAL) DrawScrolls(SC_DOWN,SC_NORMAL);




(OnNcLButtonDown(UINT nHitTest, CPoint point


if (nHitTest=HTVSCROLL) 'Up scroll Pressed DrawScrolls(SC_UP,SC_PRESSED) 'Scroll up 1 line SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0)
SetTimer(1,100,NULL)'Sets the timer ID 1
else if (nHitTest==HTHSCROLL)'Down scroll Pressed DrawScrolls(SC_DOWN,SC_PRESSED) ' Scroll down 1 line SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0) SetTimer(2,100,NULL) 'Sets the timer ID 2
 

(OnTimer(UINT nIDEvent

(result=GetKeyState(VK_LBUTTON

if (nIDEvent==1) ' Up timer If it returns negative then it is pressed

(if (result<0
SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0)
else ' No longer pressed
(KillTimer(1
( DrawScrolls(SC_UP,SC_NORMAL
else 'Down timer 
'If it returns negative then it is pressed

(if (result<0
SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0)
else
(KillTimer(2
(DrawScrolls(SC_DOWN,SC_NORMAL


(OnNcHitTest(CPoint point


CRect rect,top,bottom


GetWindowRect hwnd,Crect
ScreenToClient hwnd,Crect


top=bottom=rect
top.bottom=rect.top+16
bottom.top=rect.bottom-16
Obtains where the mouse is '

UINT 
(where=CListBox::OnNcHitTest(point

Converts the point so its relative to the client area'

ScreenToClient hwnd,&point

if (where == HTNOWHERE) 'If mouse is not in a place it recognizes 

if (PtInRect(top,point)) 'Check to see if the mouse is on the top 

where=HTVSCROLL

else if (PtInRect(bottom,point)) 'Check to see if its on the bottom 

where=HTHSCROLL
return where ' Returns where it is 



WM_NCLBUTTONDOWN 0x00A1

Parameters

wParam

The hit-test value returned by the DefWindowProc function as a result of processing the WM_NCHITTEST message. For a list of hit-test values, see WM_NCHITTEST.

lParam

A POINTS structure that contains the x- and y-coordinates of the cursor. The coordinates are relative to the upper-left corner of the screen.


















case WM_NCCALCSIZE

ncParams=(LPNCCALCSIZE_PARAMS) lParam

ncParams.rgrc(0).top=ncParams.rgrc(0).top4
ncParams.rgrc(0).left=ncParams.rgrc(0).left+4
ncParams.rgrc(0).bottom=ncParams.rgrc(0).bottom-4
ncParams.rgrc(0).right=ncParams.rgrc(0).right-4
Function=0


case WM_NCPAINT

Crect As RECT

GetWindowRect hWnd, Crect
(hdc=GetDC(hwnd
((hpen=CreatePen(PS_INSIDEFRAME,4, RGB(255, 0, 0

(holdobj=SelectObject(dc,hpen

width=Crect.right-Crect.left
height=Crect.bottom-Crect.top
Rectangle hdc,0,0,width,height SelectObject hdc,holdobj
ReleaseDC hWnd, dc
DeleteObject hpen
Function=0

case WM_NCACTIVATE

RedrawWindow hWnd,0,0, RDW_UPDATENOW???
Function=0







lpncsp->rgrc[0].right -= 100








VSCROLL.HSCROLL



void CListBoxEx::SetBkColor(COLORREF crBkColor,COLORREF crSelectedColor)
{
//Deletes previous brush. Must do in order to create a new one m_BkBrush.DeleteObject();
//Sets the brush the specified background color m_BkBrush.CreateSolidBrush(crBkColor); Invalidate();
//Forces Redraw
}

Function DrawBorders()

GetClientRect hlist,Crect

InflateRect Crect,GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)

'Since we'll be using m_bOver, let's 'initialize it. Add m_bOver = 'FALSE; on PreSubclassWindow.
if (m_bOver) Then
DrawEdge hdc,Crect,EDGE_BUMP,BF_RECT
Else
DrawEdge hdc,Crect,EDGE_SUNKEN,BF_RECT
End If
ReleaseDC hdc

End Function

WM_MOUSEAVE
m_bOver=FALSE
DrawBorders()

We then set them to an initial value under PreSubclassWindow:

m_bOver = FALSE;
m_ItemHeight=18; m_crTextHlt=GetSysColor(COLOR_HIGHLIGHTTEXT);
m_crTextClr=GetSysColor(COLOR_WINDOWTEXT);
m_HBkColor=GetSysColor(COLOR_HIGHLIGHT);
m_BmpWidth=16;
m_BmpHeight=16;

MeasureItem:
lpMeasureItemStruct->itemHeight=m_ItemHeight;





we can resize the client area. This can be done by receiving the message WM_NCCALCSIZE

lpncsp->rgrc[0].top += 16; //Top
lpncsp->rgrc[0].bottom -= 16; //Bottom



OnNcPaint()

static BOOL before=FALSE
if (!before) Then
SetWindowPos(NULL,0,0,0,0,SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE before=TRUE
DrawBorders()


DrawScrolls(UINT WhichOne, UINT State)
pDC=GetDC()
CRect rect
GetClientRect hwnd,Crect)
 
if (IsWindowEnabled())State=SC_DISABLED; //Expands the so that it does not draw over the borders

Crect.left=Crect.left-GetSystemMetrics(SM_CYEDGE) Crect.right= Crect.right+GetSystemMetrics(SM_CXEDGE)

if (WhichOne==SC_UP)
 
rect.bottom=rect.top-GetSystemMetrics(SM_CXEDGE) rect.top=rect.top-16-GetSystemMetrics(SM_CXEDGE)

'Draws the scroll up

DrawFrameControl pDC,Crect,DFC_SCROLL,State Or DFCS_SCROLLUP)
else
'Needs to draw down rect.top=rect.bottom+GetSystemMetrics(SM_CXEDGE) rect.bottom=rect.bottom+16+GetSystemMetrics(SM_CXEDGE); DrawFrameControl pDC,Crect,DFC_SCROLL,State Or DFCS_SCROLLDOWN
ReleaseDC pDC


pubic const SC_UP=2
public const SC_DOWN=3


OnEnable
'SC_NORMAL will be changed to 'SC_DISABLED if the window is disabled DrawScrolls(SC_UP,SC_NORMAL) DrawScrolls(SC_DOWN,SC_NORMAL);



OnNcLButtonDown(UINT nHitTest, CPoint point)


if (nHitTest=HTVSCROLL) 'Up scroll Pressed DrawScrolls(SC_UP,SC_PRESSED) 'Scroll up 1 line SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0)
SetTimer(1,100,NULL)'Sets the timer ID 1
else if (nHitTest==HTHSCROLL)'Down scroll Pressed DrawScrolls(SC_DOWN,SC_PRESSED) ' Scroll down 1 line SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0) SetTimer(2,100,NULL) 'Sets the timer ID 2
 

OnTimer(UINT nIDEvent)

result=GetKeyState(VK_LBUTTON)

if (nIDEvent==1) ' Up timer If it returns negative then it is pressed

if (result<0)
SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0)
else ' No longer pressed
KillTimer(1) DrawScrolls(SC_UP,SC_NORMAL)
else 'Down timer
'If it returns negative then it is pressed

if (result<0)
SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0)
else
KillTimer(2)
DrawScrolls(SC_DOWN,SC_NORMAL)


OnNcHitTest(CPoint point)


CRect rect,top,bottom


GetWindowRect hwnd,Crect
ScreenToClient hwnd,Crect)


top=bottom=rect
top.bottom=rect.top+16 bottom.top=rect.bottom-16
'Obtains where the mouse is

UINT
where=CListBox::OnNcHitTest(point)

'Converts the point so its relative to the client area

ScreenToClient hwnd,&point)

if (where == HTNOWHERE) 'If mouse is not in a place it recognizes

if (PtInRect(top,point)) 'Check to see if the mouse is on the top

where=HTVSCROLL

else if (PtInRect(bottom,point)) 'Check to see if its on the bottom

where=HTHSCROLL
return where ' Returns where it is



WM_NCLBUTTONDOWN 0x00A1

Parameters

wParam

The hit-test value returned by the DefWindowProc function as a result of processing the WM_NCHITTEST message. For a list of hit-test values, see WM_NCHITTEST.

lParam

A POINTS structure that contains the x- and y-coordinates of the cursor. The coordinates are relative to the upper-left corner of the screen.

DRAWITEM ... LISTBOX



Type NCCALCSIZEPARAM

rgrc(3) As RECT

lpos As WINDOWPOS

End Type



lParam

If wParam is TRUElParam points to an NCCALCSIZE_PARAMS structure that contains information an application can use to calculate the new size and position of the client rectangle.

If wParam is FALSElParam points to a RECTstructure. On entry, the structure contains the proposed window rectangle for the window. On exit, the structure should contain the screen coordinates of the corresponding window client area


Function fnListSubClass(ByVal hwnd As LongPtr,ByVal msg As Long,ByVal wParam As LongPtr,ByVal lParam As LongPtr)

Select Case msg

case WM_NCCALCSIZE

CallWindowProc listboxProc,hwnd,msg, wParam, lParam
'what is doing???
RECT* pRect = (RECT*)lParam
pRect->left+=4;
pRect->top+=23;
pRect->bottom+=23;
return 0;

case WM_NCPAINT

hdc=GetDC(hwnd) GetClientRect hwnd,rect
SetRect rect,0,0,4, rect.bottom brush=LoadBitmap(GetModuleHandle(0), MAKEINTRESOURCE(IDB_BORDER))
newBrush=CreatePatternBrush(brush)
oldBrush=SelectObject(hdc, newBrush) FillRect hdc,rect,newBrush SelectObject hdc, oldBrush
DeleteObject newBrush
DeleteObject oldBrush
DeleteObject brush
UpdateWindow hwnd
ReleaseDC hwnd, hdc
Exit Function



fnListSubClass=CallWindowProc(listboxProc, hwnd

(msg, wParam, lParam,


End Function 


Function WinProc(ByVal hwnd As LongPtr,ByVal msg As Long,ByVal wParam As LongPtr,ByVal lParam As 
(LongPtr

CASE WM_SHOWWINDOW,WM_CREATE 

listboxProc=SetWindowLongPtrA(listbox, GWL_WNDPROC,AddressOf fnListSubClass)

SendMessage listbox,WM_SETFONT, CreateFont=tahoma16, true

Case WM_DRAWITEM

Dim pdis AS DRAWITEMSTRUCT
CopyMemory pdis,ByVal lParam,40

if pdis.itemID=-1 Then Exit Function

Dim txt As String*40

SendMessage pdis.hwndItem,LB_GETTEXT,pdis.itemID, text
(itemLength=Len(text



if(pdis.itemAction=ODA_FOCUS Or pdis.itemState And ODS_FOCUS) Then 

(SetTextColor pdis.hDC,RGB(255,255,255

(SetBkColor pdis.hDC,RGB(51,94,168

FillRect pdis.hDC,pdis.rcItem

((CreateSolidBrush(RGB(51,94,168,

  
Else

(SetTextColor pdis.hDC,RGB(0,0,0

(SetBkColor pdis.hDC,RGB(255,255,255

FillRect pdis.hDC,pdis.rcItem

((CreateSolidBrush(RGB(255,255,255,


End if 


DrawTextExW pdis.hDC,text,itemLength, pdis.rcItem,DT_CENTER Or DT_END_ELLIPSIS,0



if(pdis.itemState=ODS_FOCUS) Then DrawFocusRect pdis.hDC,pdis.rcItem
End if 

CopyMemory ByVal lParam,pdis,40

Case WM_DESTROY
SetWindowLongPtrA hwnd,GWL_WNDPROC,listboxProc





WM_NCCREATE

We handle WM_NCCREATE because we want to associate so data with the LISTBOX and make a minor modification to the LISTBOX style. Creating our data is a simple and store in the window properties.

We modify the style by adding the WS_HSCROLL if the LISTBOX doesn't already have it. Without this style the horizontal scrollbar won't show no matter what we do.

WM_NCDESTROY

Here we simply destroy our data structure and remove it from the window properties. Nothing exciting.



مثالی دیگر از مطالب به اشتراک گذاشته در سایت خارجی 



Code:
Private Sub Form_Load()
 Dim I As Integer
    
 For I = 15 To 0 Step -1
   'Load a List of 0 to 15 with the Item Data
   'Set to the QBColors 0 - 15
   List1.AddItem "Color " & I
   List1.itemData(List1.NewIndex) = QBColor(I)
 Next
    
 For I = 0 To 15
   'Load a List of 0 to 15 with the Item Data
   'Set to the QBColors 0 - 15
   List2.AddItem "Color " & I
   List2.itemData(List2.NewIndex) = QBColor(I)
 Next
    
 'Subclass the "Form", to Capture the Listbox Notification Messages
 lPrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubClassedList)
End Sub

Private Sub Form_Unload(Cancel As Integer)
 'Release the SubClassing, Very Import to Prevent Crashing!
 Call SetWindowLong(hwnd, GWL_WNDPROC, lPrevWndProc)
End Sub
.BAS Code

Code:
Option Explicit

Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Public Type DRAWITEMSTRUCT
        CtlType As Long
        CtlID As Long
        itemID As Long
        itemAction As Long
        itemState As Long
        hwndItem As Long
        hdc As Long
        rcItem As RECT
        itemData As Long
End Type

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public 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 Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Public Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Public Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Public Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Public Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
Public Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long

Public Const COLOR_HIGHLIGHT = 13
Public Const COLOR_HIGHLIGHTTEXT = 14
Public Const COLOR_WINDOW = 5
Public Const COLOR_WINDOWTEXT = 8
Public Const LB_GETTEXT = &H189
Public Const WM_DRAWITEM = &H2B
Public Const GWL_WNDPROC = (-4)
Public Const ODS_FOCUS = &H10
Public Const ODT_LISTBOX = 2

Public lPrevWndProc As Long

Public Function SubClassedList(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
 Dim tItem As DRAWITEMSTRUCT
 Dim sBuff As String * 255
 Dim sItem As String
 Dim lBack As Long
    
 If Msg = WM_DRAWITEM Then
   'Redraw the listbox
   'This function only passes the Address of the DrawItem Structure, so we need to
   'use the CopyMemory API to Get a Copy into the Variable we setup:
   Call CopyMemory(tItem, ByVal lParam, Len(tItem))
        
   'Make sure we're dealing with a Listbox
   If tItem.CtlType = ODT_LISTBOX Then
     'Get the Item Text
     Call SendMessage(tItem.hwndItem, LB_GETTEXT, tItem.itemID, ByVal sBuff)
            
     sItem = Left(sBuff, InStr(sBuff, Chr(0)) - 1)
            
     If (tItem.itemState And ODS_FOCUS) Then
       'Item has Focus, Highlight it, I'm using the Default Focus
       'Colors for this example.
       lBack = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT))
                
       Call FillRect(tItem.hdc, tItem.rcItem, lBack)
       Call SetBkColor(tItem.hdc, GetSysColor(COLOR_HIGHLIGHT))
       Call SetTextColor(tItem.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT))
       TextOut tItem.hdc, tItem.rcItem.Left, tItem.rcItem.Top, ByVal sItem, Len(sItem)
       DrawFocusRect tItem.hdc, tItem.rcItem
     Else
       'Item Doesn't Have Focus, Draw it's Colored Background
       'Create a Brush using the Color we stored in ItemData
       lBack = CreateSolidBrush(tItem.itemData)
       'Paint the Item Area
       Call FillRect(tItem.hdc, tItem.rcItem, lBack)
                
       'Set the Text Colors
       Call SetBkColor(tItem.hdc, tItem.itemData)
       Call SetTextColor(tItem.hdc, IIf(tItem.itemData = vbBlack, vbWhite, vbBlack))
       
       'Display the Item Text
       TextOut tItem.hdc, tItem.rcItem.Left, tItem.rcItem.Top, ByVal sItem, Len(sItem)
     End If
            
     Call DeleteObject(lBack)
     
     'Don't Need to Pass a Value on as we've just handled the Message ourselves
     SubClassedList = 0
     Exit Function
   End If
 End If
    
 SubClassedList = CallWindowProc(lPrevWndProc, hwnd, Msg, wParam, lParam)
End Function


فقط در CopyMemory سایز ۴۰ را به آرگومان سومش تخصیص دهید و از ByVal lParam استفاده کنید.


در مورد LB_GETTEXT  : 


Return value

The return value is the length of the string, in TCHARs, excluding the terminating null character. If wParam does not specify a valid index, the return value is LB_ERR.

     Remarks

If the list box has an owner-drawn style but not the LBS_HASSTRINGS style, the buffer pointed to by the lParam parameter receives the value associated with the item (the item 

(data


ListBox در InputBox




Vb Uses Unicode For Text String hence delcare SendMessageW instead Of SendMessageA****



: Important Notes

Use -----> LBS_OWNERDRAWFIXED Or LBS_HASSTRINGS 

use -----> SendMessageW,   /   TextoutW

 To Add Item it is important to Use SendMessageA And Byval  "Item" you want to add like 

"SendMessageA hlist, &H180, 0, ByVal "FFF




case WM_DRAWITEM

Dim Buff As String * 255 ' important

GetClientRect pdis.hwndItem, pdis.rcItem

    r = pdis.rcItem

    l = SendMessageW(pdis.hwndItem, LB_GETTEXT, pdis.itemID, ByVal Buff

    SendMessageA pdis.hwndItem, LB_GETITEMRECT, pdis.itemID, r

    TextOutW pdis.hdc, r.Left, r.Top, ByVal Buff, l



"SendMessageA hlist, &H180, 0, ByVal "FFF

       "SendMessageA hlist, &H180, 0, ByVal "HHT

       "SendMessageA hlist, &H180, 0, ByVal "123E

       "سلام" SendMessageA hlist, &H180, 0, ByVal 

        "حاجی"SendMessageA hlist, &H180, 0, ByVal









if pdis.itemid mod 2=. then SetTextColor Else SetTextColor


If pdis.itemAction = ODA_SELECT Then

    ( l = SendMessageW(pdis.hwndItem, LB_GETTEXT, pdis.itemID, ByVal Buff

     SetWindowTextW hwnd, ByVal Buff

     End If










Static OldRect

If pdis.itemAction = ODA_SELECT Then

         ( l = SendMessageW(pdis.hwndItem, LB_GETTEXT, pdis.itemID, ByVal Buff

          SetWindowTextW hwnd, ByVal Buff

          r.Left = r.Left + 15

          (FillRect pdis.hdc, r, GetSysColorBrush(0

          InvalidateRect pdis.hwndItem, OldRect, 1

          OldRect = r

    End If







%WS_CHILD Or %LBS_OWNERDRAWFIXED Or %LBS_MULTICOLUMN Or %LBS_NOTIFY Or %WS_TABSTOP Or %WS_HSCROLL, %WS_EX_CLIENTEDGE
    


ListBox در InputBox




vb Uses Unicode for text string so use SendMessageW instead Of SendMessageA Function 



The list box has the LBS_OWNERDRAWFIXED and LBS_HASSTRINGS styles, in addition to the standard list box styles.


LBS_HASSTRINGS


Specifies that a list box contains items consisting of strings. The list box maintains the memory and addresses for the strings so that the application can use the LB_GETTEXT message to retrieve the text for a particular item. By default, all list boxes except owner-drawn list boxes have this style. You can create an owner-drawn list box either with or without this style.


کاملا به دو نکته ی زیر توجه شود : 

To obtain the exact length of the text, use the WM_GETTEXTLB_GETTEXT, or CB_GETLBTEXT messages, or the GetWindowText function



LB_GETTEXT


The return value is the length of the string, in TCHARs, excluding the terminating  

(null character  ( hence buff+1


If the list box has an owner-drawn style but not the LBS_HASSTRINGS style, the buffer pointed to by the lParam parameter receives the value associated  with the item the item data

Means Use Byval


If the list box has WS_HSCROLL style and you insert a string wider than the list box, send an LB_SETHORIZONTALEXTENT message to ensure the horizontal scroll bar appears.




Case WM_MEASUREITEM



Case WM_DRAWITEM

   

 

    Dim pdis As DRAWITEMSTRUCT

    Dim tm As TEXTMETRIC

    Dim hDCMem As LongPtr


 CopyMemory pdis, ByVal lParam, 40

Select Case pdis.itemAction

          Case ODA_SELECT, ODA_DRAWENTIRE



Dim p As RECT

         GetClientRect pdis.hwndItem, pdis.rcitem


BitBlt pdis.hdc


SetBkMode pdis.hdc, 0

                        SetTextColor pdis.hdc, vbRed

                        TextOutA pdis.hdc, pdis.rcitem.Left,pdis.rcitem.Top, buffer$, 5


CopyMemory lParam, pdis,40

End Select 






گرفتن  تعداد آیتم ها در لیست باکس 



LB_GETCOUNT message

Gets the number of items in a list box


wParam,lParam

Not used; must be zero


Dim index As Integer
Dim textBuff As String
(textBuff = Space(255
(NumItems=SendMessage(hWndList,LB_GETCOUNT,0,0


index use GETCURSEL'

Gets the index of the currently selected item)'

(if any, in a single-selection list box'


SendMessageW hWndList, LB_GETTEXT,index, textBuff
MsgBox textBuff 




docs.microsoft.com/enmeasureitemstruct


مثالی از کشیدن نقطه چین دور آیتم سلکت شده به زبان دیگر 



if  lpdis->itemState & ODS_SELECTED


* Set RECT coordinates to surround only the'

* bitmap.


rcBitmap.left=lpdis->rcItem.left

rcBitmap.top=lpdis->rcItem.top

rcBitmap.right=lpdis->rcItem.left+XBITMAP

rcBitmap.bottom=lpdis->rcItem.top + YBITMAP


* Draw a rectangle around bitmap to indicate'

* the selection.


DrawFocusRect lpdis->hDC, &rcBitmap




استفاده در مثال شکل بالا  به زبان دیگر 


 Display the text associated with the item'

SendMessage lpdis->hwndItem

LB_GETTEXT,lpdis->itemID, (LPARAM) tchBuffer,

GetTextMetrics lpdis->hDC, &tm

GetClientRect lpdis.hwnditem,lpdis.rcItem'


-y=(lpdis->rcItem.bottom+lpdis->rcItem.top

tm.tmHeight) / 2


6+TextOutA lpdis->hDC,XBITMAP

(y,tchBuffer,len(tchBuffer,


SelectObject hdcMem, hbmpOld

DeleteDC hdcMem






The GetTextMetrics function fills the specified buffer with the metrics for the currently selected font

BOOL GetTextMetrics( HDC hdc, LPTEXTMETRIC lptm );

Parameters

hdc

A handle to the device context

lptm

A pointer to the TEXTMETRIC structure that receives the text metrics.


Type TEXTMETRICA
tmHeight As Long
tmWeight As Long
tmItalic As Long
tmMaxCharWidth As Long
tmUnderlined As Long
tmCharSet As Long
End Type




 : case WM_MEASUREITEM
;lpmis = (LPMEASUREITEMSTRUCT) lParam
;lpmis->itemHeight=20
;return TRUE

(DrawEntire(LPDRAWITEMSTRUCT lpDStruct

;(CRect rect(lpDStruct->rcItem
;HDC dc =lpDStruct->hDC
;MYLISTITEM *a = (MYLISTITEM*)lpDStruct->itemData

TextOut(dc,rect.left+20,rect.top+2,a->title,strlen(a-

;((title<

(if (lpDStruct->itemState & ODS_FOCUS
}

;(DrawFocusRect(dc,rect

{

clean up //

;(SelectObject(dc,hOldFont

;(SelectObject(dc,oldpen

;(SelectObject(dc,oldbrush



;logFont.lfHeight = 16
;logFont.lfWeight = FW_BOLD

;("strcpy(logFont.lfFaceName,"courier

;(hFont = CreateFontIndirect(&logFont

(hOldFont = (HFONT)SelectObject(dc,hFont








CHARFORMAT صرفا جهت فرمت کاراکتر




EM_SETCHARFORMAT message

wParam : SCF_ALL

lParam

Pointer to a CHARFORMAT structure specifying the character formatting to use. Only the formatting attributes specified by the dwMask member are changed.



Type LOGFONTA 
lfHeight As Long
lfWidth As Long
lfItalic As Long 
lfCharSet As Long 
lfFaceName As String
End Type

The character set. The following values are predefined

ANSI_CHARSET=&H0
BALTIC_CHARSET=&BA
CHINESEBIG5_CHARSET
DEFAULT_CHARSET=&H1
EASTEUROPE_CHARSET=&HEE
GB2312_CHARSET=&H86
GREEK_CHARSET=&A1
HANGUL_CHARSET=&H81
MAC_CHARSET=&H4D
OEM_CHARSET=&HFF
RUSSIAN_CHARSET=&HCC
SHIFTJIS_CHARSET=&H80
SYMBOL_CHARSET=&H2
TURKISH_CHARSET=&HA2
VIETNAMESE_CHARSET=&HA3
JOHAB_CHARSET=&H82
ARABIC_CHARSET=&HB2
HEBREW_CHARSET=&HB1
THAI_CHARSET=&HDE

Type CHARFORMATA
 cbSize
dwMask  : CFM_ALL
dwEffects : CFE_BOLD
yHeight
yOffset
crTextColor
(bCharSet  : See LOGFONT Structure (lfCharSet
bPitchAndFamily : See LOGFONT Structure 
(lfPitchAndFamily)
szFaceName
End Type 




SCF_DEFAULT=&H0
SCF_SELECTION=&H1
SCF_ALL=&H4
'Char Format Effect
CFE_BOLD=&H0
CFE_ITALIC=&H1
CFE_UNDERLINE=&H4
CFE_LINK=&H20
'Char Format Mask
CFM_BOLD=&H0
CFM_ITALIC=&H2
CFM_UNDERLINE=&H4
CFM_COLOR=&H40000000
CFM_CHARSET=&H8000000






InitCommonControls

Case WM_Command       wm-command

if lparam=hRichEdit Then
 SendMessage(hRichEdit,EM_setBkgndColor,False,Green)


Dim P As CharRange
P.cpmin = 0 : P.cpmax = -1 

SendMessage(hRichEdit,EM_EXSetSel, 0, VarPtr(p))
'0,-1 selects all 'make selection red Local

Dim cf As CHARFORMAT
cf.cbSize=Len(cf)
cf.dwMask=CFM_COLOR
cf.crTextColor=vbRed

SendMessage(hRichEdit,EM_SETCHARFORMAT,SCF_SELECTION,VarPtr(cf))

P.cpmin = 0:P.cpmax = 0

SendMessage(hRichEdit,EM_EXSetSel,0, VarPtr(p))

End If


Type CHARRANGE
cpMin As Long
cpMax As Long
End Type

CHARRANGE structure


Specifies a range of characters in a rich edit control.

If the cpMin and cpMax members are equal, the range is empty. The range includes everything if cpMin is 0 and cpMax is –1


برای تغییر Font ارسال پیام WM_SETFONT که wparam همان hfont است و lparam هم NonZero

Dim lf As LOGFONT
lf.lfUnderline = 1
lf.lfCharSet = &HB1
(x = CreateFontIndirect(lf
SendMessageA Et, WM_SETFONT, x, 1


TabOrder .... KeyBoard Focus در InputBox


KEYBOARD FOCUS


تماما طبق داکیومنت آفیس و فروم خارجی انجام شده ماجیک نیست و بنده هم خالقش نیستم تجربه ای بود که شما را هم سهیم کردم هر چند خود شما استاد بنده هستید.


در پیام ShowWindow در WndProc 


تب اوردر یا ترتیب فوکس کنترل ها در Inputbox اول Edit است و بعد Ok و نهایتا Cancel 

درhbtn که JK است در EXSTYLE آن از CLIENTEDGE و STATICEDGE استفاده شده 


در تابع زیر فوکس بعد از ٍ Edit به باتن JK داده شده طبق تصویر و بعد به باتن Cancel طبق تصویر پایین ترش 


Et: Edit Control Handle

اگر NOSIZE را بکار نبریم سایز باتن صفر میشود پس حتما بگذارید مگر اینکه بخواهید سایز طبق آرگومانها تغییرکند همچنین جابجایی اش .

SetWindowPos hbtn, Et, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE






SetWindowPos GetDlgItem(hwnd, 2), hbtn, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE











DateTime




msctls_progress32     ProgressBar

SysDateTimePick32   Custom

PostMessage(hWnd, WM_CHAR, '3', 0); (where '3' is the actual key typed in) –


Private Const DTS_SHORTDATEFORMAT As Long = &H0
Private Const DTS_SHOWNONE As Long = &H2
Private Const DATETIMEPICK_CLASS As String = SysDateTimePick32



Dim hDT As Long 
WS_EX_CLIENTEDGE Or WS_EX_LEFT Or WS_EX_LTRREADING Or WS_EX_RIGHTSCROLLBAR

WS_CHILD Or WS_OVERLAPPED Or WS_VISIBLE Or DTS_SHORTDATEFORMAT Or DTS_SHOWNONE

,


Type SYSTEMTIME
wYear                    ' 1601 To 30827
wMonth                ' 1 To 12 
wDayOfWeek       ' 0 To 6
wDay                    ' 1 To 31
wHour                  ' 0 To 23
wMinute              ' 0 To 59
wSecond             ' 0 To 59
wMilliseconds    ' 0 To 999
End Type 


DTS_TIMEFORMAT 
"The display will look like: "5:31:42 PM


DTM_SETFORMAT message

Sets the display of a date and time picker (DTP) control based on a given format string


wParam

Must be zero

lParam

A pointer to a zero-terminated format stringthat defines the desired display. Setting this parameter to NULL will reset the control to the default format string for the current style

For example, the format string "'Today is: 'hh':'m':'s ddddMMMdd', 'yyy" would produce output like "Today is: 04:22:31 Tuesday Mar 23, 1996".


DTS_UPDOWN

Places an up-down control to the right of the DTP control to modify date-time values. This style can be used in place of the drop-down month calendar, which is the default style.





Public Const DTM_SETFORMATA = &H1005

   '"SendMessageA hdtp, DTM_SETFORMATA, 0, ByVal "yyyy/M/d












ProgressBar نوار پیشرفت




PBM_SETRANGE=&H401
PBM_SETPOS=&H402
PBM_DELTAPOS=&H403
PBM_SETSTEP=&H404
PBM_STEPIT=&H405
PBM_SETRANGE32=&H406
PBM_GETRANGE=&H407
PBM_GETPOS=&H408
PBM_SETBARCOLOR=&H409
PBM_SETMARQUEE=&H40A


PBS_SMOOTH=&H1
PBS_VERTICAL=&H4
PBS_MARQUEE=&H8
PBS_SMOOTHREVERSE=&H10

PBST_NORMAL=&H1
PBST_ERROR=&H2
PBST_PAUSED=&H3


PBM_GETPOS message

Retrieves the current position of the progress bar


Parameters

wParam

Must be zero

lParam

Must be zero




PBM_SETPOS message

Sets the current position for a progress bar and redraws the bar to reflect the new position

Parameters

wParam

Signed integer that becomes the new position

lParam

Must be zero


PBM_SETSTEP message


Specifies the step increment for a progress bar. The step increment is the amount by which the progress bar increases its current position whenever it receives a PBM_STEPITmessage. By default, the step increment is set to 10

Parameters

wParam

New step increment

lParam

Must be zero



case UDN_DELTAPOS

lpnmud = (LPNMUPDOWN)lParam

iPosIndicated =SendMessage(hwndProgBar
(PBM_GETPOS,(WPARAM)0, (LPARAM)0,

SendMessage(hwndProgBar, PBM_SETPOS,(WPARAM)(iPosIndicated + lpnmud->iDelta,0


lParam

Pointer to an NMUPDOWN structure that contains information about the position change. The iPos member of this structure contains the current position of the control. The iDelta member of the structure is a signed integer that contains the proposed change in position


If the user has clicked the up button, this is a positive value

If the user has clicked the down button, this  is a negative value







زمان ساختن  کنترل نوار پیشرفت 

SendMessage(hControl,
((PBM_SETRANGE,0,MAKELPARAM(0, 100,

SendMessage(hControl, PBM_SETSTEP, (WPARAM) 1,
(0,

Parameters

wParam

State of the progress bar that is being set. One of the following values.

ValueMeaning
PBST_NORMAL
In progress.
PBST_ERROR
Error.
PBST_PAUSED
Paused.

lParam

Must be zero.





Case WM_COMMAND
    Dim iPosIndicated As LongPtr
     If lParam = hbtn Then 
    " SetWindowTextA hbtn, "JK
     SendMessageA hprog, PBM_SETSTEP, 1, 0

     Do While pp < 102
     'SetWindowTextA hwnd, nmp.iPos
            SendMessageA hprog, PBM_SETPOS,  pp, 0
       pp = pp + 1
       Loop
     End If









SetWindowLongPtr hprog, GWL_STYLE, GetWindowLongPtrA(hprog, GWL_STYLE) Or PBS_VERTICAL









UPDOWN CONTROL در InputBox




Dim nmh As NMHDR

Dim nmp As NMUPDOWN

1400UpDownControlId


 Case WM_NOTIFY

چون کنترل ساخته شده پیامی را دریافت نمی کند از طریق parent  خود در نتیجه 

     

   If wParam = 1400 Then nmh.code = (-722) ' UDN_DELTAPOS

      

   

    SetWindowTextA Et, nmh.hwndFrom & " ID: " & nmh.idFrom & "/  code ...." & nmh.code & "... Wparam: " & wParam

    

    

    If nmh.code = (-722) Then

     

 ( CopyMemory nmp, ByVal lParam, Len(nmp

      nmp.hdr = nmh     ' No Need'

      SetWindowTextA hwnd, "Delta : " & nmp.iDelta & "  Pos : " & nmp.iPos

     End If

   (CopyMemory lParam, nmp, Len(nmp



iPos

Type: int

Signed integer value that represents the up-down control's current position.

iDelta

Type: int

Signed integer value that represents the proposed change in the up-down control's position.





Static ddd

If nmp.iDelta = 1 Then ddd = ddd - 1 Else ddd = ddd + 1

      nmp.iPos = ddd

      SetWindowTextA hwnd, "Delta : " & nmp.iDelta & "  Pos : " & nmp.iPos

     End If

in case wm_destroy nmp.ipos=0:ddd=0'






UDM_SETRANGE message


Sets the minimum and maximum positions (range) for an up-down control


Parameters

wParam

Must be zero

lParam

The LOWORD is a short that specifies the maximum position for the up-down control, and the HIWORD is a short that specifies the minimum position





case WM_VSCROLL

delta=LOWORD(SendDlgItemMessage(dlg, IDC_SPIN1,UDM_GETPOS,0,0))

SetDlgItemText(dlg,IDC_DTRANS,mystring 




WM_VSCROLL

wparam

The HIWORD specifies the current position of the scroll box

The LOWORD specifies a scroll bar value that indicates the user's scrolling request.
SB_BOTTOM
SB_TOP


lParam

If the message is sent by a scroll bar control, this parameter is the handle to the scroll bar control. If the message is sent by a standard scroll bar, this parameter is NULL.




با WS_TABSTOP  فوکس میگیرد ( کیبورد)  ولی برای اجرای دستور توسط پیام  WM_COMMAND باید از lparam  آن استفاده کرد که هندل پنجره  ایجاد شده است .

 


 Case WM_COMMAND    '   wm-command

     "!!!..." & ( If lParam = hbtn Then MsgBox "Clicked " & GetWindowText(hbtn

        Select Case wParam

          Case 2

            

        End Select




با توجه باینکه WS_TABSTOP تنظیم شده لذا باتن JK توسط کلید TAB کیبورد فوکس خواهد گرفت و در شکل زیر نقطه چین هایی که در مستطیل آن باتن مشخص است نشاندهنده ی فوکس گرفتن است .









TTM_POPUP پیامی برای ToolTip



باعث میشود که Tooltip در مختصات  پیام آخرین ماوس ارسالی نمایش داده شود.

Causes the tooltip to display at the coordinates of the last mouse message

Parameters

wParam

Must be zero

lParam

Must be zero

Return value

The return value is not used



SetCursorPos 300, 300

SendMessageA hWndtoolTip,TTM_POPUP, 0,0



Private Const WM_SETCURSOR=&H20

Parameters

wParam

با GetDlgItem
A handle to the window that contains the cursor

lParam

The low-order word of lParam specifies the hit-test code

The high-order word of lParam specifies the identifier of the mouse message

Return value

If an application processes this message, it should return TRUE to halt further processing or FALSE to continue.



?last=0

case WM_MOUSEMOVE

if (?lParam<>0) Then
SetTimer hwnd, 1,   GetDoubleClickTime   , 0
last = lParam
End if
Exit Function


case WM_TIMER

if (wParam<>1) The Exit Function

KillTimer hwnd, 1
(makeTooltip(hwnd
SendMessage tooltip, TTM_POPUP, 0, 0


TTM_SETDELAYTIME = &H403
TTM_ADDTOOLA = &H404
TTM_RELAYEVENT = &H407
TTM_SETTOOLINFOA = &H409
TTM_HITTESTA = &H40A
TTM_UPDATETIPTEXTA = &H40C
TTM_WINDOWFROMPOINT := 0x410
TTM_TRACKACTIVATE = &H411
TTM_TRACKPOSITION = &H412
TTM_SETTIPBKCOLOR = &H413
TTM_SETTIPTEXTCOLOR = &H414
TTM_SETMAXTIPWIDTH = &H418
TTM_GETMAXTIPWIDTH = &H419

TTM_SETMARGIN = &H41A

TTM_POP = &H41C
TTM_UPDATE = &H41D
TTM_ADJUSTRECT = &H41F
TTM_SETTITLEA = &H420
TTM_SETTITLEW = &H421
TTM_POPUP = &H422
TTM_ADDTOOLW = &H432
 TTM_SETTOOLINFOW = &H436

 TTM_HITTESTW = &H437

TTM_GETTEXTW = &H438

 TTM_UPDATETIPTEXTW = &H439



ChildWindowFromPoint hWndParent,Point


MapWindowPoints hWndFrom,hWndTo, lpPoints(Rect),cPoints(number of points

(POINT pt(2

MapWindowPoints hWnd1,hWnd2,pt(0), 1

MapWindowPoints(hWnd1,hWnd2,pt(1), 1




تغییر سایز Edit در پنجره 


(hEdit=GetDlgItem(hDlg,IDC_EDIT
Dim rct As RECT
GetClientRect hEdit,rct

MapWindowPoints hEdit,hDlg,rct,1

MoveWindow hEdit,rct.left,rct.top, rct.right-40,rct.bottom





 : OnCreate 

(ti.cbSize = Len(ti
ti.uFlags =TTF_TRACK Or TTF_ABSOLUTE
ti.hwnd = hwndOwner
ti.uId = '(UINT)FIT_NLSF_EDIT_FUNC
ti.hinst =0
("ti.lpszText =TEXT("hello
ti.rect.left = 0
ti.rect.right = 0
ti.rect.bottom =0
ti.rect.top =0
SetRectEmpty ti.rect'

SendMessageA hwndTT,TTM_ADDTOOL, 0,ti

SendMessageA hwndTT,TTM_SETMAXTIPWIDTH,0,80

SendMessageA hwndTT,TTM_SETTIPBKCOLOR, RGB(247, 252, 203),0

SendMessageA hwndTT,TTM_SETTIPTEXTCOLOR, RGB(0, 0, 0),0

RetVal = SendMessage(hwndTT, TTM_UPDATETIPTEXTA, 0, ti)

SendMessageA hwndTT,TTM_TRACKACTIVATE,TRUE, ti





GetCursorPos pt 'get the cursor position

if  WM_SETCURSOR Then

get the button rect'
GetWindowRect(GetDlgItem(hDlg, FIT_NLSF_SELECT_FUNC),rc1

if PtInRect(rc1, pt) Then

SendMessage hwndTT,TTM_TRACKPOSITION, 0,(LPARAM)MAKELPARAM(pt.x,pt.y)

TTM_POPUP message'
'Causes the tooltip to display at the coordinates of the' last mouse message.
SendMessage hwndTT,TTM_POPUP,0,0
Else

TTM_POP message'
Removes a displayed tooltip window from view'
SendMessage hwndTT,TTM_POP,0,0

End If


Re: TOOLTIP in win32

Tacking means that the tooltip will move with the mouse( it just explicitly send the TTM_TRACKPOSITION message to the tooltip window).
as for the handle of tooltip control window, I use the global static type. the parent window is not deconstructed.
ps,I think if I use the TTF_IDISHWND flag, then uId should be the handle to that control .
Thanks
tony



اگر درست باشد البته 

Public Function MAKELPARAM(ByVal wLow As Long, ByVal wHigh As Long) As Long

(&MAKELPARAM=(wlow And &H7FFF
(&Or (&H10000 * (wHigh And &H7FFF 

End Function

ListBox



Const LBN_SELCHANGE = 1
Const LBN_DBLCLK = 2
Const LBN_SELCANCEL = 3
Const LBN_SETFOCUS = 4
Const LBN_KILLFOCUS = 5

Const LB_ADDSTRING = &H180
Const LB_SETSEL = &H185
Const LB_SETCURSEL = &H186 Const LB_GETSEL = &H187
Const LB_GETCURSEL = &H188
Const LB_GETTEXT = &H189
Const LB_GETTEXTLEN = &H18A
Const LB_GETCOUNT = &H18B
Const LB_SELECTSTRING = &H18C
Const LB_GETITEMRECT = &H198
Const LB_GETITEMDATA = &H199
Const LB_SETITEMDATA = &H19A
Const LB_SELITEMRANGE = &H19B
Const LB_SETITEMHEIGHT = &H1A0
Const LB_GETITEMHEIGHT = &H1A1

private Const WM_NOTIFY=&H4E
public Const WM_COMMAND=&H111
Const WM_DRAWITEM =&H2B

Const ODA_FOCUS = &H4
Const ODS_FOCUS = &H10
Const ODS_SELECTED = &H1




?private lpListBox as ListBox
?set lpListBox = lpLB
?m_LBHwnd = lpListBox.hwnd

private Function LBSubcls_WndProc_V3(byval hwnd as Long, byval Msg as Long, byval wParam as Long, byval lParam as Long) as Long

Dim lCurind as Long


Select Case Msg 

Case WM_COMMAND

If lParam = m_LBHwnd then
LongInt2Int wParam, iHw, iLW
(Select Case (iHw

Case LBN_SELCHANGE

lCurind=SendMessage(lParam, LB_GETCURSEL,0,byval 0&)

If (lCurind Mod 3) = 0 then

lCurind = SendMessage(lParam, LB_SETCURSEL, lCurind + 1, byval 0&)

End If 

Debug.print " sendmessage returned:" & Hex$(lCurind)

Case LBN_SELCANCEL

lCurind=SendMessage(lParam, LB_GETCURSEL,0,byval 0&) 

Debug.print " lbnselcancel for:"; Hex$(lCurind)

End Select 
End If


Case WM_DRAWITEM

If LB_Drawitem(lParam) = 0 then 

LBSubcls_WndProc_V3 = 0 
Exit Function 

End If
Case else 
End Select

LBSubcls_WndProc_V3=CallWindowProc(oldWndProc,hwnd,Msg, wParam, lParam)

End Function





private Function LB_Drawitem(byval lParam as Long) as Integer

Dim drawstruct as DRAWITEMSTRUCT 
Dim szBuf(256) as Byte

CopyMemory drawstruct,byval lParam, len(drawstruct)

Dim i as Integer
Dim hbrGray as Long,hbrback as Long,szListStr as string ' * 256
Dim crback as Long,crtext as Long,lbuflen as Long


Select Case (drawstruct.CtlType)
   Case ODT_LISTBOX

lbuflen=SendMessagedrawstruct.hwndItem,LB_GETTEXTLENdrawstruct.itemID,byval 0&)


Redim szBuf(lbuflen+2)

lbuflen=SendMessage(drawstruct.hwndItem,LB_GETTEXT,drawstruct.itemID,szBuf(0))


i = drawstruct.itemID

If i Mod 3=0 then
hbrGray = CreateSolidBrush(GetSysColor(COLOR_GRAYTEXT))

 

GrayString drawstruct.hdc, hbrGray,byval 0&,szListStr, len(szListStr),drawstruct.rcItem.Left,drawstruct.rcItem.Top, 0,0

DeleteObject hbrGray 

crback=RGB(180, 180, 180) crtext=RGB(60, 60, 60) 

else

If (drawstruct.itemState And ODS_SELECTED)=ODS_SELECTED then 

crback=GetSysColor(COLOR_HIGHLIGHT)
crtext=GetSysColor(COLOR_HIGHLIGHTTEXT)


ElseIf (drawstruct.itemState And ODS_FOCUS)=ODS_FOCUS then

crback=GetSysColor(COLOR_WINDOW)
crtext=vbRed

else

End if 


If (drawstruct.itemState And ODS_FOCUS)= 
ODS_FOCUS then
crtext=vbRed
End If
End If


hbrback=CreateSolidBrush(crback)

FillRect drawstruct.hdc, drawstruct.rcItem,hbrback 

DeleteObject hbrback

SetBkColor drawstruct.hdc, crback

SetTextColor drawstruct.hdc, crtext 


TextOut drawstruct.hdcdrawstruct.rcItem.Left,drawstruct.rcItem.Top, szListStr,len(szListStr) 

TextOutBStr drawstruct.hdc, drawstruct.rcItem.Left,drawstruct.rcItem.Top,szBuf(0),lbuflen


If (drawstruct.itemState And ODS_FOCUS) then

DrawFocusRect drawstruct.hdc, drawstruct.rcItem

End If

LB_Drawitem = 1

End Select

End Function



private Function LBSubcls_WndProc_V4(byval hwnd as Long,byval Msg as Long, byval wParam as Long,byval lParam as Long) as Long

Dim iHw as Integer,iLW as Integer
Dim lCurind as Long

Select Case Msg 

Case WM_LBUTTONDOWN, WM_LBUTTONDBLCLK

LongInt2Int lParam, iHw, iLW

Debug.print " Mouse down at(" & iHw & "," & iLW &  ")"

lCurind=SendMessage(hwnd, LB_ITEMFROMPOINT,byval 0, byval lParam)

Debug.print "Index of btn down:" & Hex$(lCurind)


If (lCurind Mod 3) = 0 then 
LBSubcls_WndProc_V4 = 1
Exit Function
End If

,Case WM_KEYDOWN

LongInt2Int wParam, iHw, iLW 

Select Case (iLW)

Case vbKeyDown

lCurind=SendMessage(hwnd, LB_GETCARETINDEX,0,byval 0&) 

Debug.print " Keydown With Itemid :" & Hex$(lCurind) 

If ((lCurind + 1) Mod 3) = 0 then 

lCurind=SendMessage(hwnd, LB_SETCARETINDEX,lCurind + 1, byval 0&)

End If 

lCurind = SendMessage(hwnd, LB_GETCURSEL, 0, byval 0&) 

Debug.print " Keydown With Itemid :" & Hex$(lCurind)

If ((lCurind + 1) Mod 3) = 0 then

lCurind = SendMessage(hwnd, LB_SETCURSEL, lCurind + 1, byval 0&)

End If 

Case vbKeyUp 

lCurind = SendMessage(hwnd, LB_GETCARETINDEX,0,byval 0&) 

Debug.print " KeyUp With Itemid :" & Hex$(lCurind)

If ((lCurind - 1) Mod 3) = 0 then

lCurind = SendMessage(hwnd, LB_SETCARETINDEX,lCurind - 1, byval 0&)

End If 

lCurind = SendMessage(hwnd, LB_GETCURSEL,0,byval 0&) 

Debug.print " KeyUp With Itemid :" & Hex$(lCurind)

If ((lCurind - 1) Mod 3) = 0 then

lCurind = SendMessage(hwnd, LB_SETCURSEL, lCurind - 1, byval 0&)

End If 

End Select 

Case else 

End Select

LBSubcls_WndProc_V4 = CallWindowProc(LBProc1, hwnd, Msg, wParam, lParam)

End Function 



public Function LongInt2Int(byval lLongInt as Long,byref iHiWord as Integer, byref iLowWord as Integer) as Boolean 

Dim tmpHW as Integer,tmpLW as Integer

CopyMemory tmpLW,lLongInt, len(tmpLW)

tmpHW =(lLongInt / TwoPower16) 

iHiWord = tmpHW 
iLowWord = tmpLW 

End Function 








TwoPower16=2^16 : 65536

public Function MakeLParam(byval iHiWord as Integer, byval iLowWord as Integer) as Long 
MakeLParam=(iHiWord * TwoPower16) + iLowWord
End Function








WS_BORDRR,WS_EX_CLIENDEDGE

"SendMessageA hlist, &H180, 0, ByVal "D
       "SendMessageA hlist, &H180, 0, ByVal "E
       "SendMessageA hlist, &H180, 0, ByVal "FFF
      " SendMessageA hlist, &H180, 0, ByVal "HHT
       "SendMessageA hlist, &H180, 0, ByVal "123E
    "سلام  " SendMessageA hlist, &H180, 0, ByVal
"حاجی " SendMessageA hlist, &H180, 0, ByVal 
در Subclassing
Case WM_KEYDOWN
    Select Case wParam
      Case &H11, &H1
      Dim c, ll
      Dim buf As String
      Dim Idx
     ( Idx = SendMessageA(hwnd, LB_GETCURSEL, 0, 0
     ( c = SendMessageA(hwnd, LB_GETCOUNT, 0, 0
      (textcount = SendMessageA(hwnd, LB_GETTEXTLEN, i, 0
buffer$ = Space$(textcount + 255)
      $SendMessageA hwnd, LB_GETTEXT, Idx, ByVal buffer
  $ SetWindowTextA GetParent(hwnd), c & "... Idx : " & Idx & "...." & l & buffer
     End Select








ListBox



Private Const WM_REFLECTNOTIFY As Int32 = & H204E
Private Const NM_FIRST As Int32 = 0 
Private Const NM_DBLCLK As Int32 = (NM_FIRST - 3) 

Dim lNMHDR As NMHDR 
Select Case uMsg 
Case WM_REFLECTNOTIFY
CopyMemory (lNMHDR,LParam, Marshal.SizeOf (lNMHDR)) 

If lNMHDR.code=NM_DBLCLK Then 
' Do Something 
return 
End If 
End Select 


List Box Types and Styles

There are two types of list boxes: single-selection (the default) and multiple-selection. In a single-selection list box, the user can select only one item at a time. In a multiple-selection list box, the user can select more than one item at a time. To create a multiple-selection list box, specify the LBS_MULTIPLESEL or the LBS_EXTENDEDSEL style.

LBS_EXTENDEDSEL
LBS_MULTIPLESEL
LBS_NOTIFY( Causes the list box to send a notification code to the parent window whenever the user clicks a list box item (LBN_SELCHANGE), double-clicks an item (LBN_DBLCLK), or cancels the selection (LBN_SELCANCEL)

LBS_SORT


LB_SETCURSEL message

wParam

Specifies the zero-based index of the string that is selected. If this parameter is -1, the list box is set to have no selection.

lParam

This parameter is not used.


LB_ADDSTRING message

Adds a string to a list box. If the list box does not have the LBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list and the list is sorted.

Parameters

wParam

This parameter is not used.

lParam

A pointer to the null-terminated string that is to be added.

If the list box has an owner-drawn style but not the LBS_HASSTRINGS style, this parameter is stored as item data instead of a string. You can send the LB_GETITEMDATAand LB_SETITEMDATA messages to retrieve or modify the item data


LBN_SELCHANGE notification code

Parameters

wParam

The LOWORD contains the identifier of the list box. The HIWORD specifies the notification code.

lParam

Handle to the list box.

Remarks

This notification code is sent only by a list box that has the LBS_NOTIFY style.

This notification code is not sent if the LB_SETSEL, LB_SETCURSEL, LB_SELECTSTRING, LB_SELITEMRANGE or LB_SELITEMRANGEEX message changes the selection.

For a multiple-selection list box, the LBN_SELCHANGE notification code is sent whenever the user presses an arrow key, even if the selection does not change.



LBN_SETFOCUS notification code

Notifies the application that the list box has received the keyboard focus. The parent window of the list box receives this notification code through the WM_COMMAND message.

Parameters

wParam

The LOWORD contains the identifier of the list box. The HIWORD specifies the notification code.

lParam

Handle to the list box.


LB_GETCURSEL message

Gets the index of the currently selected item, if any, in a single-selection list box.

Parameters

wParam

Not used; must be zero.

lParam

Not used; must be zero.


Return value

In a single-selection list box, the return value is the zero-based index of the currently selected item. If there is no selection, the return value is LB_ERR.

Remarks

To retrieve the indexes of the selected items in a multiple-selection list box, use the LB_GETSELITEMS message. To determine whether the item that has the focus rectangle in a multiple selection list box is selected, use the LB_GETSEL message.

If sent to a multiple-selection list box, LB_GETCURSEL returns the index of the item that has the focus rectangle. If no items are selected, it returns zero.


LB_GETSELITEMS message

Fills a buffer with an array of integers that specify the item numbers of selected items in a multiple-selection list box.

Parameters

wParam

The maximum number of selected items whose item numbers are to be placed in the buffer.

This means list boxes cannot contain more than 32,767 items

lParam

A pointer to a buffer large enough for the number of integers specified by the wParamparameter.


Return value

The return value is the number of items placed in the buffer. If the list box is a single-selection list box, the return value is LB_ERR.


LB_GETSEL message

Gets the selection state of an item.

wParam

The zero-based index of the item.

This means list boxes cannot contain more than 32,767 items

lParam

This parameter is not used.


Return value

If an item is selected, the return value is greater than zero; otherwise, it is zero. If an error occurs, the return value is LB_ERR.


LB_SETITEMHEIGHT message

Sets the height, in pixels, of items in a list box. If the list box has the LBS_OWNERDRAWVARIABLE style, this message sets the height of the item specified by the wParam parameter. Otherwise, this message sets the height of all items in the list box

Parameters

wParam

Specifies the zero-based index of the item in the list box. Use this parameter only if the list box has the LBS_OWNERDRAWVARIABLEstyle; otherwise, set it to zero.


This means list boxes cannot contain more than 32,767 items.
lParam

Specifies the height, in pixels, of the item. The maximum height is 255 pixels.


UpDown Control


up-down message'

(UDM_SETRANGE=(&H400+101

(UDM_SETPOS=(&H400+103
(UDM_SETBUDDY=(&H400+105
up-down notification  use in wm_notify'
(UDN_FIRST=(-721
(UDN_LAST=(-740
(UDN_DELTAPOS=(UDN_FIRST-1
up-down styles'
UDS_ALIGNRIGHT=&H4
UDS_ALIGNLEFT=&H8
UDS_AUTOBUDDY=&H10
UDS_ARROWKEYS=&H20
UDS_HORZ=&H40
UDS_NOTHOUSANDS=&H80
UDS_HOTTRACK=&H100



msctls_trackbar32Slider
msctls_updown32Spinner
msctls_statusbar32StatusBar



(CreateControls(HWND hwnd
آپ داون جز کامان کنترل هست و باید فراخوان شود .
Dim INITCOMMONCONTROLSEX As icex icex.dwSize= sizeof(INITCOMMONCONTROLSEX) 
icex.dwICC=ICC_UPDOWN_CLASS
 InitCommonControlsEx &icex

hUpDown= CreateWindowW(UPDOWN_CLASSW, NULL, WS_CHILD | WS_VISIBLE | UDS_SETBUDDYINT | UDS_ALIGNRIGHT, 0, 0, 0, 0, hwnd, (HMENU) ID_UPDOWN, NULL, NULL)

'if create Edit
SendMessageW(hUpDown, UDM_SETBUDDY, (WPARAM)hEdit, 0) SendMessageW(hUpDown, UDM_SETRANGE, 0, MAKELPARAM(UD_MAX_POS, UD_MIN_POS)); SendMessageW(hUpDown, UDM_SETPOS32, 0, 0)

#define UD_MAX_POS 30 
#define UD_MIN_POS 0


LPNMUPDOWN lpnmud

case WM_NOTIFY

code=((LPNMHDR) lParam)->code

if (code == UDN_DELTAPOS)

lpnmud = (NMUPDOWN *) lParam

int value = lpnmud->iPos + lpnmud->iDelta

if (value < UD_MIN_POS)

value = UD_MIN_POS

if (value > UD_MAX_POS)
value = UD_MAX_POS

const int asize = 4
wchar_t buf[asize]
size_t cbDest = asize * sizeof(wchar_t) StringCbPrintfW(buf, cbDest, L"%d", value)
(SetWindowTextW(hStatic, buf
break


UDM_SETBUDDY

Sets the buddy window for an up-down control.

Parameters

wParam

Handle to the new buddy window.

lParam

Must be zero.

Return value

The return value is the handle to the previous buddy window.


NM_UPDOWN

Type      LPNMUPDOWN
hdr As NMHDR
iPos As Long
iDelta As Long
End Type


iPos

Type: int

Signed integer value that represents the up-down control's current position.

iDelta

Type: int

Signed integer value that represents the proposed change in the up-down control's position.


Type NMHDR 'Contains information about a notification message
hwndFrom As Long
idFrom As Long
code As Long
End Type


idFrom

Type: UINT_PTR

An identifier of the control sending the message.

code

Type: UINT

A notification code. This member can be one of the common notification codes (see Notifications under General Control Reference), or it can be a control-specific notification code.





تغییر ترتیب تب Change Tab Order



HWNDTOP


()OnInitDialog

: Original tab order is'
( 1) IDOK'
( 2) IDCANCEL'
( 3) IDC_MY_EDIT'


Get pointers to the controls '

(pOK=GetDlgItem(IDOK
(pCancel=GetDlgItem(IDCANCEL
(pEdit=GetDlgItem(IDC_MY_EDIT

Set the new tab order'

setwindowpos pEdit,&wndTop,0,0,0,0, SWP_NOMOVE Or SWP_NOSIZE

SetWindowPos pCancel,pEdit,0,0,0,0, SWP_NOMOVE Or SWP_NOSIZE

SetWindowPos pOk,pCancel,0,0,0,0, SWP_NOMOVE Or SWP_NOSIZE

: The new tab order is
( 1) IDC_MY_EDIT'
( 2) IDCANCEL'
( 3) IDOK'


BOOL SetWindowPos( HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags )


hWndInsertAfter

Type: HWND

A handle to the window to precede the positioned window in the Z order. This parameter must be a window handle or one of the following values.

HWND_BOTTOM(HWND)1
HWND_NOTOPMOST(HWND)-2
HWND_TOP(HWND)0
HWND_TOPMOST(HWND)-1







OwnerDrawnList Box


تمام مطالب ذکر شده برگرفته از اینترنت و داکیومنت آفیس است و تنها یک سوم آنها تست شده



Const XBITMAP=48
Cpnst YBITMAP=48 

Const BUFFER MAX_PATH

HBITMAP hbmpPencil, hbmpCrayon, hbmpMarker,hbmpPen,hbmpFork

HBITMAP hbmpPicture, hbmpOld


Sub AddItem(hwnd,pstr,hbmp)

Dim lbItem As Integer 

lbItem=SendMessage(hwnd, LB_ADDSTRING,0,(LPARAM)pstr) 

SendMessage(hwnd,LB_SETITEMDATA, (WPARAM)lbItem,(LPARAM)hbmp)

End Sub



DlgDrawProc : 

Dim hListBox As Long 
Dim pmis As PMEASUREITEMSTRUCT Dim pdis As PDRAWITEMSTRUCT 
TCHAR achBuffer[BUFFER]
size_t cch
Dim yPos As Integer 
Dim lbItem As Integer
Dim tm As TEXTMETRIC
Dim rcBitmap As RECT
Dim hbmp As Long 


case WM_INITDIALOG

hbmpPencil=LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_PENCIL))

hListBox=GetDlgItem(hDlg, IDC_LIST_STUFF)

AddItem hListBox,L"pencil",hbmpPencil AddItem hListBox, L"crayon",hbmpCrayon

SetFocus hListBox
SendMessage hListBox,LB_SETCURSEL, 0, 0
return TRUE


case WM_MEASUREITEM
pmis = (PMEASUREITEMSTRUCT) lParam
'Set the height of the list box items. 
pmis.itemHeight=YBITMAP
return TRUE

case WM_DRAWITEM
pdis = (PDRAWITEMSTRUCT) lParam

Select Case pdis.itemAction

case ODA_SELECT,ODA_DRAWENTIRE

hbmpPicture=SendMessage(pdis.hwndItem,LB_GETITEMDATA,pdis.itemID,0)

hdcMem=CreateCompatibleDC(pdis.hDC)

hbmpOld=SelectObject(hdcMem, hbmpPicture)

BitBlt(pdis.hDC,pdis.rcItem.left,pdis.rcItem.top,pdis.rcItem.right-pdis.rcItem.left

SendMessage pdis.hwndItem,LB_GETTEXT, pdis.itemID,(LPARAM)achBuffer

GetTextMetrics pdis.hDC, &tm

yPos=(pdis.rcItem.bottom+ 
pdis.rcItem.top-tm.tmHeight)/2


hr=StringCchLength(achBuffer,BUFFER, &cch)

TextOut pdis.hDC,XBITMAP+6,yPos, achBuffer,cch

SelectObject hdcMem,hbmpOld
DeleteDC hdcMem

if (pdis.itemState & ODS_SELECTED) Then 
rcBitmap.left=pdis.rcItem.left rcBitmap.top=pdis.rcItem.top rcBitmap.right=pdis.rcItem.left+XBITMAP
rcBitmap.bottom=pdis.rcItem.top+YBITMAP
DrawFocusRect pdis.hDC,&rcBitmap
End If 

Exit Function 

case WM_COMMAND

  Select Case (LOWORD(wParam)) 
     case IDOK

lbItem=SendMessage(GetDlgItem(hDlg, IDC_LIST_STUFF),LB_GETCURSEL, 0, 0)


if (hbmp<>hbmpFork) Then  

MessageBox hDlg,L"Try again!",L"Oops", MB_OK)
return FALSE
else
MessageBox hDlg,L"You're right!", L"Congratulations.",MB_OK)
End if 



case WM_DESTROY
'Free the bitmap resources.

DeleteObject hbmpPencil
DeleteObject hbmpCrayon
DeleteObject hbmpMarker
DeleteObject hbmpPen
DeleteObject hbmpFork
return TRUE

















ToolTip



Private g_hwndTT As Long 
Private g_ti As TOOLINFOA

(OnCreate(hwnd
g_hwndTT=CreateWindow(TOOLTIPS_CLASS, nullptr,WS_POPUP Or TTS_ALWAYSTIP Or 
(TTS_BALLOON,0,0,0, 0,hwnd,0,0,0

g_ti.uFlags=TTF_TRACK
g_ti.hwnd = hwnd
("g_ti.lpszText=TEXT("Hi there

SendMessage(g_hwndTT, TTM_ADDTOOL,0,
(LPARAM)&g_ti,
return TRUE

  : On Char  

Dim pt As POINTAPI

Select Case wparam 

 if  GetCursorPos (pt) Then

SendMessage(g_hwndTT,TTM_TRACKPOSITION,0,MAKELPARAM(pt.x,
((pt.y,

SendMessage(g_hwndTT,TTM_TRACKACTIVATE,TRUE
((LPARAM)&g_ti,
Exit Function 

case 27  ' ESCAPE

SendMessage(g_hwndTT,TTM_TRACKACTIVATE
(FALSE,0,
Exit Function 



.At startup, we add the tool but do not show the balloon tooltip yet

When the user presses the space bar
we get the current cursor position and tell the tracking tooltip
.to appear at exactly that location
.then we activate tracking mode
  :The result
The balloon tip appears, and the tip of the balloon points directly
.at the mouse cursor

.When the user presses the ESC key
we deactivate tracking mode, which removes the tooltip from the
.screen





TTM_ACTIVEPOSITION

Parameters

wParam

.Must be zero

lParam

The LOWORD specifies the x-coordinate of the point at which the tracking tooltip will be displayed, in screen coordinates. The HIWORD specifies the y-coordinate of the point at which the tracking tooltip will be  displayed, in screen coordinates

To have tooltip windows displayed at specific coordinates, include the TTF_ABSOLUTE flag in the uFlagsmember of the TOOLINFO structure when 
.adding the tool



TTF_ABSOLUTE
Positions the tooltip window at the same coordinates provided by TTM_TRACKPOSITION. This flag must be used with the TTF_TRACK flag.

TTF_CENTERTIP
Centers the tooltip window below the tool specified bythe uId member.

TTF_IDISHWND
Indicates that the uIdmember is the window handle to the tool. If this flag is not set, uId is the tool's identifier.



(Sub CreateToolTipForRect(HWND hwndParent

'Create a tooltip. HWND

hwndTT=CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndParent, NULL, g_hInst,NULL)

SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE)

'Set up "tool" information. In this case, the "tool" is the entire parent window.

TOOLINFO ti = { 0 }
ti.cbSize = sizeof(TOOLINFO)
ti.uFlags = TTF_SUBCLASS
ti.hwnd = hwndParent
ti.hinst = g_hInst
ti.lpszText = TEXT("This is your tooltip string.")

GetClientRect (hwndParent, &ti.rect)

' Associate the tooltip with the "tool" window.

SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti)

End Sub 








We need to show the tooltip form without activating it, so we can use the API method, 'ShowWindow' with the SW_SHOWNA parameter, which will show the form and bring it to the front without stealing focus from other windows.


ShowWindow function

Sets the specified window's show state

SW_SHOW=5
Activates the window and displays it in its current size and position.

SW_SHOWNA=8
Displays the window in its current size and position. This value is similar to SW_SHOW, except that the window is not activated.



ToolTip










g_toolItem is a global TOOLINFO

(HWND CreateTrackingToolTip(toolID, hDlg,pText
Create a tooltip'

hwndTT=CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,WS_POPUP Or TTS_NOPREFIX Or TTS_ALWAYSTIP, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,hDlg, NULL,

(g_hInst,NULL,


g_toolItem.cbSize = sizeof(TOOLINFO) g_toolItem.uFlags=TTF_IDISHWND Or TTF_TRACK Or TTF_ABSOLUTE g_toolItem.hwnd=hDlg
g_toolItem.hinst=g_hInst g_toolItem.lpszText=pText
g_toolItem.uId=hDlg

GetClientRect  hDlg, &g_toolItem.rect) 'Associate the tooltip with the tool window.

SendMessage hwndTT,TTM_ADDTOOL,0, (LPARAM) (LPTOOLINFO) &g_toolItem
CreateTrackingToolTip=hwndTT


g_hwndTrackingTT is a global HWND variable'



case WM_INITDIALOG

()InitCommonControls
g_hwndTrackingTT=CreateTrackingToolTip(IDC_BUTTON1, 

(hDlg,""

        return TRUE

case WM_MOUSELEAVE
'The mouse pointer has left our window. Deactivate' 

the tooltip.


SendMessage g_hwndTrackingTT, TTM_TRACKACTIVATE,(WPARAM)FALSE,

(LPARAM)&g_toolItem),



g_TrackingMouse = FALSE
 return FALSE

:case WM_MOUSEMOVE

static oldX, oldY
Dim newX, newY

    if (!g_TrackingMouse) Then 'The mouse has just entered the window.
Request notification when the mouse leaves.
    
Dim tme As TRACKMOUSEEVENT 

(tme =sizeof(TRACKMOUSEEVENT
tme.hwndTrack=hDlg
tme.dwFlags=TME_LEAVE
        
TrackMouseEvent &tme

Activate the tooltip.'

SendMessage g_hwndTrackingTT, TTM_TRACKACTIVATE, (WPARAM)TRUE, (LPARAM)&g_toolItem

g_TrackingMouse = TRUE

(newX = GET_X_LPARAM(lParam
(newY = GET_Y_LPARAM(lParam

Make sure the mouse has actually moved. The '

presence of the tooltip causes Windows to send the message continuously

    
((if ((newX <> oldX) Or  (newY<> oldY

        oldX = newX
        oldY = newY

Update the text.'
        

g_toolItem.lpszText=newX & newY

SendMessage g_hwndTrackingTT, TTM_SETTOOLINFO, 0,(LPARAM)&g_toolItem

Position the tooltip. The coordinates are adjusted so '

that the tooltip does not overlap the mouse pointer

        

{POINT pt = { newX, newY 
ClientToScreen hDlg, &pt
SendMessage 

,g_hwndTrackingTT,TTM_TRACKPOSITION,0

((LPARAM)MAKELONG(pt.x+10,pt.y-20


 return FALSE




sub CreateToolTip(ByVal hwnd as HWND,ByVal txt As 
(String,ByVal tthwnd as HWND

dim iccex As INITCOMMONCONTROLSEX
   
dim ti As  TOOLINFOA

iccex.dwICC=ICC_WIN95_CLASSES
(iccex.dwSize =sizeof(INITCOMMONCONTROLSEX

InitCommonControlsEx iccex

hwndTT=CreateWindowEx(0, TOOLTIPS_CLASS,VbNullStrinh,WS_POPUP or TTS_NOPREFIX or TTS_ALWAYSTIP,CW_USEDEFAULT, 
,CW_USEDEFAULT,CW_USEDEFAULT, 
(CW_USEDEFAULT,tthwnd,0,0, 0

SetWindowPos hwndTT,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE


(ti.cbSize = 40 'sizeof(TOOLINFOW
ti.uFlags = TTF_SUBCLASS
ti.hwnd = hwnd
ti.hinst =0
(ti.lpszText=strptr(text
GetClientRect hwnd,ti.rect

SendMessage hwndTT,TTM_ADDTOOL, 0 , ti

End sub




HideCaret/ShowCaret



Case WM_CHAR










)Function UserInfoProc 

(hUserInfoWnd,uMsg,wParam,lParam,uIdSubclass,dwRefData


,lRes=DefSubclassProc(hUserInfoWnd

(uMsg,wParam,lParam

if uMsg =WM_SETFOCUS) '?maybe

HideCaret hUserInfoWnd

End if 
UserInfoProc=lRes









TEXTMETRICA



The TEXTMETRIC structure contains basic information about a physical font. All sizes are specified in logical units; that is, they depend on the current mapping mode of the display context


typedef struct tagTEXTMETRICA {
LONG tmHeight;
LONG tmAscent;
LONG tmDescent;
LONG tmInternalLeading;
LONG tmAveCharWidth;
LONG tmExternalLeading;
LONG tmMaxCharWidth;
LONG tmDigitizedAspectX;
LONG tmWeight;
LONG tmOverhang;
LONG tmDigitizedAspectY;
BYTE tmBreakChar;
BYTE tmFirstChar;
BYTE tmLastChar;
BYTE tmDefaultChar;
BYTE tmItalic;
BYTE tmCharSet;
BYTE tmUnderlined;
BYTE tmStruckOut;
BYTE tmPitchAndFamily;

} TEXTMETRICA, *PTEXTMETRICA, *NPTEXTMETRICA, *LPTEXTMETRICA;

DrawBackground



HDC hdc = GetDC(m_hWnd)
m_hMemDC=CreateCompatibleDC(hdc) SelectObject m_hMemDC,m_hBKbitmap
m_hStretchedBitmap=CreateCompatibleBitmap(hdc,WndClintRect.right-WndClintRect.left,WndClintRect.bottom- WndClintRect.top)
m_hStretchedMem=CreateCompatibleDC(hdc)
SelectObject m_hStretchedMem,m_hStretchedBitmapReleaseDC m_hWnd, hdc


This is how you handle the sizing message WM_SIZE:

SelectObject m_hStretchedMem,m_hStretchedBitmapOld
DeleteObject m_hStretchedBitmap
HDC hdc = GetDC(m_hWnd) m_hStretchedBitmap=CreateCompatibleBitmap(hdc,WndClintRect.right- WndClintRect.left,WndClintRect.bottom- WndClintRect.top)
InvalidateRect m_hWnd,NULL,false
SelectObject m_hStretchedMem, m_hStretchedBitmap
ReleaseDC m_hWnd, hdc


before we draw the background we will pass the bitmap to the rich edit control so it would draw its background on the given bitmap. We will handle this in the background erasing of the main dialog


int SemiRichEditDlg::OnEraseBkgnd(WPARAM wParam, LPARAM lParam)

HDC hdc = (HDC)wParam
StretchBlt m_hStretchedMem, 0, 0, WndClintRect.right, WndClintRect.bottom, m_hMemDC, 0, 0, m_iBitmapWidth, m_iBitmapHight, SRCCOPY
 m_semiricheditctrl.DrawBackGround(hdc, m_hStretchedMem); BitBlt(hdc, 0, 0, WndClintRect.right - WndClintRect.left, WndClintRect.bottom - WndClintRect.top, m_hStretchedMem, 0, 0, SRCCOPY) return 1


How Does the Rich Edit draw its Background (Rich Edit to Bitmap)?


Now that we are almost done all we need to draw the background of the rich edit control to a bitmap and then copy it to the main window background(the main bitmap). So we need to create a bitmap the size of the rich edit background



' Creating A DC 
HDC hdcTransparent=CreateCompatibleDC(hdc)
'Creating a bitmap 
hTransparentBitmap=CreateCompatibleBitmap(hdc,m_RichEditRect.right-m_RichEditRect.left,m_RichEditRect.bottom-m_RichEditRect.top)
'Selecting the bitmap in to the created DC SelectObject hdcTransparent, hTransparentBitmap

'Fill the bitmap with white colour FloodFill hdcTransparent,0,0,RGB(255,255,255)


AlphaBlend hStretchedMem, m_RichEditRect.left + 1, m_RichEditRect.top + 1, m_RichEditRect.right - m_RichEditRect.left, m_RichEditRect.bottom - m_RichEditRect.top, hdcTransparent, 0, 0, m_RichEditRect.right - m_RichEditRect.left, m_RichEditRect.bottom - m_RichEditRect.top, blend

'Finding the size in twips 
nLogPixelsX =GetDeviceCaps(hdcTransparent, LOGPIXELSX)

nLogPixelsY =GetDeviceCaps(hdcTransparent, LOGPIXELSY)

rc.left=MulDiv(rc.left,1440, nLogPixelsX)
rc.top=MulDiv(rc.top,1440, nLogPixelsY)
rc.right=MulDiv(rc.right, 1440,nLogPixelsX)
rc.bottom=MulDiv(rc.bottom,1440, nLogPixelsY)
fr.hdc=hdcTransparent
fr.hdcTarget=hdcTransparent
fr.rc=rc
fr.rcPage=rc
fr.chrg.cpMin=SendMessage(m_hWnd, EM_CHARFROMPOS,(WPARAM) FALSE, <BR> (LPARAM) &point)
fr.chrg.cpMax=-1
'Requesting to draw on the DC 
lResult=SendMessage(m_hWnd, EM_FORMATRANGE,(WPARAM) TRUE, <BR> (LPARAM) &fr)
lResult=SendMessage(m_hWnd, EM_FORMATRANGE,(WPARAM) FALSE, <BR> (LPARAM) NULL)

BitBlt  hStretchedMem, m_RichEditRect.left + 1, m_RichEditRect.top + 1,<BR> m_RichEditRect.right - m_RichEditRect.left, <BR> m_RichEditRect.bottom - m_RichEditRect.top, hdcTransparent, 0, 0,SRCAND


EM_FORMATRANGE message

wParam

Specifies whether to render the text. If this parameter is not zero, the text is rendered. Otherwise, the text is just measured.

lParam

A FORMATRANGE structure containing information about the output device, or NULLto free information cached by the control.



Type FORMATRANGE
hdcTarget As Long
hdc As Long
rc As RECT
rcPage As RECT
chrg As CHARRANGE
End Type 


Type CHARRANGE 
cpMin As Long
cpMax As Long 
End Type





Private Const EM_DISPLAYBAND=&H451
Private Const EM_EXLINEFROMCHAR=&H454
Private Const EM_FORMATRANGE=&H457
Private Const EM_SETBKGNDCOLOR=&H467
Private Const EM_SETZOOM=&H625
 




EM_DISPLAYBAND message


Displays a portion of the contents of a rich edit control, as previously formatted for a device using the EM_FORMATRANGE message


Parameters

wParam

This parameter is not used; it must be zero.

lParam

A RECT structure specifying the display area of the device.