 |
Das deutsche QBasic- und FreeBASIC-Forum Für euch erreichbar unter qb-forum.de, fb-forum.de und freebasic-forum.de!
|
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
eisschwimmer
Anmeldungsdatum: 12.02.2017 Beiträge: 3
|
Verfasst am: 12.02.2017, 17:45 Titel: Trackbar mit Zusätzlichen Funktionen |
|
|
Bin neu hier und weiss nicht, ob dies hier richtig ist.
Ich denke, so eine Trackbar lässt sich aus 3 dynamischen Buttons entwickeln.
Finde jedoch nichts, wie ich zur Laufzeit Position und Grösse verändern kann.
Als Code HTML, dort funzt es. (Als html file speichern und im Browser aufrufen)
Code: |
<style type="text/css">
#box{
width: 99px;
height: 80px;
position: absolute;
left: 520px;
top: 20px;
border:1px solid ;
}
#slider{
width: 1000px;
height: 20px;
position: absolute;
left: 10px;
top: 99px;
border:1px solid ;
background: #cccccc;
}
#lg{
width: 20px;
height: 20px;
position: absolute;
left: 500px;
top: 100px;
}
#po{
width: 100px;
height: 20px;
position: absolute;
left: 520px;
top: 100px;
}
#rg{
width: 20px;
height: 20px;
position: absolute;
left: 620px;
top: 100px;
}
#infx{
position: absolute;
left: 20px;
top: 200px;
}
#infy{
position: absolute;
left: 20px;
top: 220px;
}
</style>
<script type="text/javascript">
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
document.onmousedown = mouseDown;
document.onmouseup = mouseUp;
var tempX = 0
var tempY = 0
var aend = 0
var dif = 0
var p_lg = 500
var p_rg = 620
var p_rg1 = 640
var p_po = 520
var w_po = 100
function getMouseXY(e) {
if (IE) {
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
}
else
{
tempX = e.pageX
tempY = e.pageY
}
if (aend==1) {
p_lg = tempX - dif;
p_po = p_lg + 20;
w_po = p_rg - p_lg -20;
document.getElementById("lg").style.left = p_lg;
document.getElementById("box").style.left = p_lg + 19 ;
document.getElementById("po").style.left = p_po ;
document.getElementById("po").style.width = w_po ;
document.getElementById("box").style.width = w_po ;
}
if (aend==2) {
p_lg = tempX - 20 - dif;
p_po = tempX - dif;
p_rg = p_po + w_po;
p_rg1 = p_rg + 20;
document.getElementById("lg").style.left = p_lg;
document.getElementById("box").style.left = p_lg + 19 ;
document.getElementById("po").style.left = p_po;
document.getElementById("rg").style.left = p_rg;
}
if (aend==3) {
p_rg = tempX - dif;
p_rg1 = p_rg + 20;
w_po = p_rg - p_lg -20;
document.getElementById("rg").style.left = p_rg;
document.getElementById("po").style.width = w_po ;
document.getElementById("box").style.width = w_po-1 ;
}
document.Show.MouseX.value = p_lg + 19
document.Show.MouseY.value = p_rg
return true
}
function mouseUp() {
aend = 0;
}
function mouseDown() {
if (aend==0){
if (tempX > p_lg){
if (p_po > tempX){
aend = 1;
dif = tempX-p_lg;
} else {
if (p_rg > tempX){
aend = 2;
dif = tempX-p_po;
}else{
if (p_rg1 > tempX){
aend = 3;
dif = tempX-p_rg;
}
}
}
}
}
}
</script>
</head>
<form name="Show">
Eigene Trackbar/Scrollbar<br>
L und R Grenzen mittels Drag and Drop veränderbar<br>
Button mittels Drag and Drop auch verschiebbar<br>
<input type="text" id="infx" name="MouseX" value="0" size="4">
<input type="text" id="infy" name="MouseY" value="0" size="4">
</form>
<body>
<div id="box">
</div>
<div id="slider">
</div>
<input type="button" value="L" id="lg">
<input type="button" value="Button" id="po">
<input type="button" value="R" id="rg">
</body>
|
Danke für Infos und Tips |
|
Nach oben |
|
 |
Sebastian Administrator

Anmeldungsdatum: 10.09.2004 Beiträge: 5969 Wohnort: Deutschland
|
|
Nach oben |
|
 |
nemored

Anmeldungsdatum: 22.02.2007 Beiträge: 4686 Wohnort: ~/
|
Verfasst am: 12.02.2017, 22:17 Titel: |
|
|
Wobei ich nicht sicher bin, ob das JS nicht nur dazu dienen sollte zu verdeutlichen, wie das Ganze ungefähr aussehen sollte. Dann wäre aber interessant zu wissen, womit es am Ende umgesetzt werden soll - mit WinAPI (wegen das ursprünglichen Topic-Ortes)? Oder generell mit irgend einer GUI? _________________ Deine Chance beträgt 1:1000. Also musst du folgendes tun: Vergiss die 1000 und konzentriere dich auf die 1. |
|
Nach oben |
|
 |
eisschwimmer
Anmeldungsdatum: 12.02.2017 Beiträge: 3
|
|
Nach oben |
|
 |
Jojo alter Rang

Anmeldungsdatum: 12.02.2005 Beiträge: 9736 Wohnort: Neben der Festplatte
|
Verfasst am: 17.02.2017, 14:15 Titel: |
|
|
Die normalen Windows-Trackbars bieten diese Funktionalität nicht, aber vielleicht könntest du ein [url=https://msdn.microsoft.com/en-us/library/windows/desktop/bb760149(v=vs.85).aspx]Selection Range[/url] verwenden, um die Funktionalität zu emulieren?
Ansonsten ist es natürlich möglich, dass du deine eigenen Controls mit Buttons (evtl Spin Buttons) und Trackbars zusammenbaust, aber das ist etwas Aufwand - aber nicht unmöglich. _________________ » Die Mathematik wurde geschaffen, um Probleme zu lösen, die es nicht gäbe, wenn die Mathematik nicht erschaffen worden wäre.
 |
|
Nach oben |
|
 |
grindstone
Anmeldungsdatum: 03.10.2010 Beiträge: 1274 Wohnort: Ruhrpott
|
Verfasst am: 18.02.2017, 16:33 Titel: |
|
|
Weder komplett noch perfekt, und die WinAPI hat sich nach Kräften gewehrt, aber das Ziehen der Buttons klappt schon mal. Code: | ' slider demo, basierend auf "TrackBar Demo , code by Volta"
#Include Once "windows.bi"
#Include Once "win/commctrl.bi"
Declare Function WndProc ( ByVal hWnd As HWND, ByVal uMsg As UINT, _
ByVal wParam As WPARAM, ByVal lParam As LPARAM ) As Integer
Dim Shared hInstance As HINSTANCE
hInstance = GetModuleHandle( NULL )
'Program Main
Dim wMsg As MSG
Dim wcls As WNDCLASS
Dim hWnd As HWND
'object handle
Dim Shared As HWND hMidButton, hLeftButton, hRightButton
Dim Shared As Integer vpos, lEnde, rEnde, loffs, roffs, btn, lneu, rneu, pwidth, lwidth, rwidth
Dim Shared As Point cur
Dim Shared As RECT lwpos, mwpos, rwpos, pwpos
Dim appName As String
appName = "SliderDemo"
Enum
mbtn = 1
lbtn
rbtn
End Enum
lEnde = 50
rEnde = 350
vpos = 200
With wcls
.style = CS_HREDRAW Or CS_VREDRAW
.lpfnWndProc = @WndProc
.cbClsExtra = 0
.cbWndExtra = 0
.hInstance = hInstance
.hIcon = LoadIcon( NULL, IDI_APPLICATION )
.hCursor = LoadCursor( NULL, IDC_ARROW )
.hbrBackground = CPtr( HGDIOBJ, COLOR_BACKGROUND )
.lpszMenuName = NULL
.lpszClassName = StrPtr( appName )
End With
If ( RegisterClass( @wcls ) = FALSE ) Then
MessageBox( NULL, "Fehler bei der Registrierung der WindowClass!", _
appName, MB_ICONERROR )
End 1
End If
hWnd = CreateWindowEx( 0, appName, "Slider Demo", _
WS_OVERLAPPEDWINDOW Or WS_VISIBLE, _
CW_USEDEFAULT, CW_USEDEFAULT, 1000, 300, _
NULL, NULL, hInstance, NULL )
Do Until( GetMessage( @wMsg, NULL, 0, 0 ) = FALSE ) 'messages loop
TranslateMessage( @wMsg )
DispatchMessage ( @wMsg )
Loop
End 0
' Window Procedure Handler
Function WndProc ( ByVal hWnd As HWND, ByVal uMsg As UINT, _
ByVal wParam As WPARAM, ByVal lParam As LPARAM ) As Integer
GetWindowRect(hWnd, @pwpos) 'position des elternfensters (client)
pwidth = pwpos.right - pwpos.left
GetWindowRect(hLeftButton, @lwpos) 'position des linken buttons
ScreenToClient(hWnd, Cast(POINT Ptr, @lwpos)) 'umrechnen auf position relativ zum elternfenster
ScreenToClient(hWnd, Cast(POINT Ptr, @lwpos) + 1)
lwidth = lwpos.right - lwpos.left
GetWindowRect(hMidButton, @mwpos) 'position des rechten buttons
ScreenToClient(hWnd, Cast(Point Ptr, @mwpos)) 'umrechnen auf position relativ zum elternfenster
ScreenToClient(hWnd, Cast(Point Ptr, @mwpos) + 1)
GetWindowRect(hRightButton, @rwpos) 'position des rechten buttons
ScreenToClient(hWnd, Cast(Point Ptr, @rwpos)) 'umrechnen auf position relativ zum elternfenster
ScreenToClient(hWnd, Cast(Point Ptr, @rwpos) + 1)
rwidth = rwpos.right - rwpos.left
MoveWindow(hMidButton, _
lwpos.right, _
vpos, _
rwpos.left - lwpos.right, _
lwpos.bottom - lwpos.top, _
TRUE) 'breite des mittleren buttons anpassen
GetCursorPos(@cur)
ScreenToClient(hWnd, @cur) 'cursorposition relativ zum elternfenster
If (GetAsyncKeyState(VK_LBUTTON) And 1) Then 'linke maustaste neu gedrückt
loffs = cur.x - lwpos.left 'abstand zwischen cursor und linkem button
roffs = rwpos.left - cur.x 'abstand zwischen cursor und rechtem button
If PtInRect(@mwpos, cur) Then 'cursor befindet sich über mittlerem button
btn = mbtn
ElseIf PtInRect(@lwpos, cur) Then 'dto. linker button
btn = lbtn
ElseIf PtInRect(@rwpos, cur) Then 'dto. rechter button
btn = rbtn
EndIf
ElseIf GetAsyncKeyState(VK_LBUTTON) = 0 Then 'taste losgelassen
btn = 0
EndIf
lneu = cur.x - loffs 'neue position des linken buttons
rneu = cur.x + roffs 'neue position des rechten buttons
Select Case btn
Case mbtn
If (lneu > 0) And (rneu + rwidth < pwidth) Then
MoveWindow(hLeftButton, lneu, vpos, 20, 20, TRUE)
MoveWindow(hRightButton, rneu, vpos, 20, 20, TRUE)
EndIf
Case lbtn
If (lneu > 0) And (lneu + lwidth < rwpos.left) Then
MoveWindow(hLeftButton, lneu, vpos, 20, 20, TRUE)
EndIf
Case rbtn
If (rneu > lwpos.right) And (rneu + rwidth < pwidth) Then
MoveWindow(hRightButton, rneu, vpos, 20, 20, TRUE)
EndIf
End Select
Select Case ( uMsg )
Case WM_CREATE
InitCommonControls 'initialisiere common controls
'buttons erstellen
hMidButton = CreateWindowEx(0, WC_BUTTON, "Button", _
WS_CHILD Or WS_VISIBLE Or BS_CENTER , _
lEnde, vpos, 300, 20, hWnd, NULL, hInstance, NULL )
hLeftButton = CreateWindowEx(0, WC_BUTTON, "L", _
WS_CHILD Or WS_VISIBLE Or BS_CENTER , _
lEnde - 20, vpos, 20, 20, hWnd, NULL, hInstance, NULL )
hRightButton = CreateWindowEx(0, WC_BUTTON, "R", _
WS_CHILD Or WS_VISIBLE Or BS_CENTER , _
rEnde, vpos, 20, 20, hWnd, NULL, hInstance, NULL )
Return 0
Case WM_DESTROY
DestroyWindow hMidButton 'mittleren button zerstören
DestroyWindow hLeftButton 'linken " "
DestroyWindow hRightButton 'rechten " "
PostQuitMessage( 0 ) 'programm beenden
Exit Function
End Select
Function = DefWindowProc( hWnd, uMsg, wParam, lParam )
End Function |
Gruß
grindstone _________________ For ein halbes Jahr wuste ich nich mahl wie man Proggramira schreibt. Jetzt bin ich einen! |
|
Nach oben |
|
 |
eisschwimmer
Anmeldungsdatum: 12.02.2017 Beiträge: 3
|
Verfasst am: 20.02.2017, 11:24 Titel: |
|
|
Danke an grindstone, fantastische Arbeit.
Gehört nun eigentlich wieder in Fragen zu WinAPI
Mit dieser Trackbar könnten z.B. Panorama - Bilder wie mit einer Auschnittslupe behandelt werden. |
|
Nach oben |
|
 |
grindstone
Anmeldungsdatum: 03.10.2010 Beiträge: 1274 Wohnort: Ruhrpott
|
Verfasst am: 20.02.2017, 12:13 Titel: |
|
|
eisschwimmer hat Folgendes geschrieben: | Danke an grindstone, fantastische Arbeit. | Moment, ist doch noch gar nicht fertig!
Der endgültige Slider könnte ungefähr so aussehen: Code: | ' slider demo, basierend auf "TrackBar Demo , code by Volta"
#Include Once "windows.bi"
#Include Once "win/commctrl.bi"
Declare Function WndProc ( ByVal hWnd As HWND, ByVal uMsg As UINT, _
ByVal wParam As WPARAM, ByVal lParam As LPARAM ) As Integer
Dim Shared hInstance As HINSTANCE
hInstance = GetModuleHandle( NULL )
'Program Main
Dim wMsg As MSG
Dim wcls As WNDCLASS
Dim hWnd As HWND
'object handle
Dim Shared As HWND hMidButton, hLeftButton, hRightButton, hBefore, hBrush, hBehind, hFrame
Dim Shared As Integer vpos, lEnde, rEnde, loffs, roffs, btn, lneu, rneu, pwidth, lwidth, rwidth
Dim Shared As Point cur
Dim Shared As RECT lwpos, mwpos, rwpos, pwpos
Dim appName As String
appName = "SliderDemo"
hBrush = Cast(HWND, CreateSolidBrush(RGBA(255,255,255,0)))
Enum
mbtn = 1
lbtn
rbtn
End Enum
lEnde = 50
rEnde = 350
vpos = 200
With wcls
.style = CS_HREDRAW Or CS_VREDRAW
.lpfnWndProc = @WndProc
.cbClsExtra = 0
.cbWndExtra = 0
.hInstance = hInstance
.hIcon = LoadIcon( NULL, IDI_APPLICATION )
.hCursor = LoadCursor( NULL, IDC_ARROW )
.hbrBackground = CPtr( HGDIOBJ, COLOR_BACKGROUND )
.lpszMenuName = NULL
.lpszClassName = StrPtr( appName )
End With
If ( RegisterClass( @wcls ) = FALSE ) Then
MessageBox( NULL, "Fehler bei der Registrierung der WindowClass!", _
appName, MB_ICONERROR )
End 1
End If
hWnd = CreateWindowEx( 0, appName, "Slider Demo", _
WS_OVERLAPPEDWINDOW Or WS_VISIBLE, _
CW_USEDEFAULT, CW_USEDEFAULT, 1000, 300, _
NULL, NULL, hInstance, NULL )
Do Until( GetMessage( @wMsg, NULL, 0, 0 ) = FALSE ) 'messages loop
TranslateMessage( @wMsg )
DispatchMessage ( @wMsg )
Loop
End 0
' Window Procedure Handler
Function WndProc ( ByVal hWnd As HWND, ByVal uMsg As UINT, _
ByVal wParam As WPARAM, ByVal lParam As LPARAM ) As Integer
GetWindowRect(hWnd, @pwpos) 'position des elternfensters (client)
pwidth = pwpos.right - pwpos.left
GetWindowRect(hLeftButton, @lwpos) 'position des linken buttons
ScreenToClient(hWnd, Cast(POINT Ptr, @lwpos)) 'umrechnen auf position relativ zum elternfenster
ScreenToClient(hWnd, Cast(POINT Ptr, @lwpos) + 1)
lwidth = lwpos.right - lwpos.left
GetWindowRect(hMidButton, @mwpos) 'position des rechten buttons
ScreenToClient(hWnd, Cast(Point Ptr, @mwpos)) 'umrechnen auf position relativ zum elternfenster
ScreenToClient(hWnd, Cast(Point Ptr, @mwpos) + 1)
GetWindowRect(hRightButton, @rwpos) 'position des rechten buttons
ScreenToClient(hWnd, Cast(Point Ptr, @rwpos)) 'umrechnen auf position relativ zum elternfenster
ScreenToClient(hWnd, Cast(Point Ptr, @rwpos) + 1)
rwidth = rwpos.right - rwpos.left
MoveWindow(hBefore, _
0, _
vpos, _
lwpos.left, _
lwpos.bottom - lwpos.top, _
TRUE) 'breite des linken freiraums anpassen
MoveWindow(hMidButton, _
lwpos.right, _
vpos, _
rwpos.left - lwpos.right, _
lwpos.bottom - lwpos.top, _
TRUE) 'breite des mittleren buttons anpassen
MoveWindow(hBehind, _
rwpos.right, _
vpos, _
pwpos.right - rwpos.right, _
lwpos.bottom - lwpos.top, _
TRUE) 'breite des rechten freiraums anpassen
MoveWindow(hFrame, _
mwpos.left, _
20, _
mwpos.right - mwpos.left, _
vpos - 20, _
TRUE) 'breite des fensters anpassen
GetCursorPos(@cur)
ScreenToClient(hWnd, @cur) 'cursorposition relativ zum elternfenster
If (GetAsyncKeyState(VK_LBUTTON) And 1) Then 'linke maustaste neu gedrückt
loffs = cur.x - lwpos.left 'abstand zwischen cursor und linkem button
roffs = rwpos.left - cur.x 'abstand zwischen cursor und rechtem button
If PtInRect(@mwpos, cur) Then 'cursor befindet sich über mittlerem button
btn = mbtn
ElseIf PtInRect(@lwpos, cur) Then 'dto. linker button
btn = lbtn
ElseIf PtInRect(@rwpos, cur) Then 'dto. rechter button
btn = rbtn
EndIf
ElseIf GetAsyncKeyState(VK_LBUTTON) = 0 Then 'taste losgelassen
btn = 0
EndIf
lneu = cur.x - loffs 'neue position des linken buttons
rneu = cur.x + roffs 'neue position des rechten buttons
Select Case btn
Case mbtn
If (lneu > 0) And (rneu + rwidth < pwidth) Then
MoveWindow(hLeftButton, lneu, vpos, 20, 20, TRUE)
MoveWindow(hRightButton, rneu, vpos, 20, 20, TRUE)
EndIf
Case lbtn
If (lneu > 0) And (lneu + lwidth < rwpos.left) Then
MoveWindow(hLeftButton, lneu, vpos, 20, 20, TRUE)
EndIf
Case rbtn
If (rneu > lwpos.right) And (rneu + rwidth < pwidth) Then
MoveWindow(hRightButton, rneu, vpos, 20, 20, TRUE)
EndIf
End Select
Select Case ( uMsg )
Case WM_CREATE
InitCommonControls 'initialisiere common controls
'buttons erstellen
hMidButton = CreateWindowEx(0, WC_BUTTON, "Button", _
WS_CHILD Or WS_VISIBLE Or BS_CENTER Or BS_PUSHBUTTON, _
lEnde, vpos, 300, 20, hWnd, NULL, hInstance, NULL )
hLeftButton = CreateWindowEx(0, WC_BUTTON, "L", _
WS_CHILD Or WS_VISIBLE Or BS_CENTER , _
lEnde - 20, vpos, 20, 20, hWnd, NULL, hInstance, NULL )
hRightButton = CreateWindowEx(0, WC_BUTTON, "R", _
WS_CHILD Or WS_VISIBLE Or BS_CENTER , _
rEnde, vpos, 20, 20, hWnd, NULL, hInstance, NULL )
hBefore = CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, WC_STATIC, "", _
WS_CHILD Or WS_VISIBLE, _
lEnde, vpos - 50, 200, 20, _
hWnd, NULL, hInstance, NULL )
hBehind = CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, WC_STATIC, "", _
WS_CHILD Or WS_VISIBLE , _
rEnde, vpos - 50, 200, 20, _
hWnd, NULL, hInstance, NULL )
hFrame = CreateWindowEx( 0, WC_STATIC, "", _
WS_CHILD Or WS_VISIBLE Or WS_BORDER, _
rEnde, vpos - 50, 200, 20, _
hWnd, NULL, hInstance, NULL )
Return 0
Case WM_CTLCOLORSTATIC
Select Case lParam 'fensterhandle
Case hBefore
Return CreateSolidBrush(RGBa(250,250,255,0)) 'hintergrundfarbe weiss
Case hBehind
Return CreateSolidBrush(RGBa(250,250,255,0))
Case hFrame
Return CreateSolidBrush(RGBa(250,250,255,0))
End Select
Return 0
Case WM_DESTROY
DestroyWindow hMidButton 'mittleren button zerstören
DestroyWindow hLeftButton 'linken " "
DestroyWindow hRightButton 'rechten " "
PostQuitMessage( 0 ) 'programm beenden
Exit Function
End Select
Function = DefWindowProc( hWnd, uMsg, wParam, lParam )
End Function |
Wie man den passenden (Bild-)Inhalt in den Rahmen bekommt, ist dann noch einmal ein Kapitel für sich.
eisschwimmer hat Folgendes geschrieben: | Gehört nun eigentlich wieder in Fragen zu WinAPI | Ja, das würde ich auch sagen.
Gruß
grindstone _________________ For ein halbes Jahr wuste ich nich mahl wie man Proggramira schreibt. Jetzt bin ich einen! |
|
Nach oben |
|
 |
|
|
Du kannst keine Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum nicht antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen.
|
|