|
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 |
Eternal_pain
Anmeldungsdatum: 08.08.2006 Beiträge: 1783 Wohnort: BW/KA
|
Verfasst am: 08.03.2014, 23:28 Titel: UpDown Control (SpinBox) |
|
|
Wollte eine einfache SpinBox erstellen und versucht mehrere Beispiele auf der MSDN seite umzusetzen.. aber keines davon funktioniert, habt ihr noch tipps und quellen zum erstellen einer spinbox?
Diese einfache aber wohl wohl veraltete Funktion geht leider nicht
http://msdn.microsoft.com/en-us/library/windows/desktop/bb759977%28v=vs.85%29.aspx
Hier ein größeres Beispiel von der MSDN Seite, viele Variabeln und Funktionen habe ich gar nicht:
Code: |
'http://msdn.microsoft.com/en-us/library/windows/desktop/hh298353%28v=vs.85%29.aspx
'' UpDown.cpp : Defines the entry point for the application.
#Define WIN_INCLUDEALL
#include "windows.bi"
#define MAX_LOADSTRING 100
Dim Shared as HINSTANCE g_hInst '' Global handle to the current instance.
Dim Shared as String*100 g_szTitle '' The title bar text.
Dim Shared as String*100 g_szWindowClass '' The main window class name.
'not in windows.bi
type INITCOMMONCONTROLSEX 'INITCOMMONCONTROLSEX, *LPINITCOMMONCONTROLSEX;
as DWORD dwSize
as DWORD dwICC
End Type
Dim Shared as INITCOMMONCONTROLSEX icex '' Structure for control initialization.
const as Integer valMin=0 '' The range of values for the Up-Down control.
const as Integer valMax=100
Dim Shared as RECT rcClient '' Client area of parent window (Dialog Box).
Dim Shared as UINT cyVScroll '' Height of scroll bar arrow.
Dim Shared as HWND hControl = NULL '' Handles to the controls.
Dim Shared as HWND hwndGroupBox = NULL
Dim Shared as HWND hwndLabel = NULL
Dim Shared as HWND hwndUpDnEdtBdy = NULL
Dim Shared as HWND hwndUpDnCtl = NULL
Dim Shared as HWND hwndProgBar = NULL
'' Handles to the create controls functions.
Declare Function CreateGroupBox(byref hwndParent as HWND) as HWND
Declare Function CreateLabel(byref hwndParent as HWND) as HWND
Declare Function CreateUpDnBuddy(byref hwndParent as HWND) as HWND
Declare Function CreateUpDnCtl(byref hwndParent as HWND) as HWND
Declare Function CreateProgBar(byref hwndParent as HWND) as HWND
Declare Function WndProc(byval hWnd as HWND, byval message as UINT,byval wParam as WPARAM, byval lParam as LPARAM) as LRESULT
Declare Function UpDownDialogProc(byval hDlg as HWND, byval message as UINT, byval wParam as WPARAM, byval lParam as LPARAM) as INT_PTR
Declare Function MyRegisterClass(byref hInstance as HINSTANCE) as integer
Declare Function InitInstance(byval hInstance as HINSTANCE, byval nCmdShow as integer) as integer
Function WinMain(byval hInstance as HINSTANCE, byval hPrevInstance as HINSTANCE, byval lpCmdLine as LPTSTR, byval nCmdShow as integer) as Integer
'UNREFERENCED_PARAMETER(hPrevInstance)
'UNREFERENCED_PARAMETER(lpCmdLine)
Dim as MSG msg
Dim as HACCEL hAccelTable
'LoadString(hInstance, IDS_APP_TITLE, g_szTitle, MAX_LOADSTRING)
'LoadString(hInstance, IDC_UPDOWN, g_szWindowClass, MAX_LOADSTRING)
MyRegisterClass(hInstance)
if (InitInstance(hInstance, nCmdShow)=0) Then return FALSE
'hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_UPDOWN))
while (GetMessage(@msg, NULL, 0, 0))
if (TranslateAccelerator(msg.hwnd, hAccelTable, @msg)=0) Then
TranslateMessage(@msg)
DispatchMessage(@msg)
End If
Wend
return msg.wParam
End Function
Function MyRegisterClass(byref hInstance as HINSTANCE) as integer
Dim as WNDCLASSEX wcex
wcex.cbSize = sizeof(WNDCLASSEX)
wcex.style = CS_HREDRAW OR CS_VREDRAW
wcex.lpfnWndProc = @WndProc
wcex.cbClsExtra = 0
wcex.cbWndExtra = 0
wcex.hInstance = hInstance
'wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_UpDown))
wcex.hCursor = LoadCursor(NULL, IDC_ARROW)
wcex.hbrBackground = cast(HBRUSH,COLOR_WINDOW+1)
'wcex.lpszMenuName = MAKEINTRESOURCE(IDM_MAIN)
wcex.lpszClassName = strptr(g_szWindowClass)
'wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_UpDown))
return RegisterClassEx(@wcex)
End Function
Function InitInstance(byval hInstance as HINSTANCE,byval nCmdShow as Integer) as Integer
Dim as HWND hWnd
g_hInst = hInstance '' Store instance handle in our global variable.
hWnd = CreateWindow(g_szWindowClass, _ '' Class.
g_szTitle, _ '' Window title.
WS_OVERLAPPEDWINDOW, _ '' Window style.
CW_USEDEFAULT, 0, _ '' Coordinates of top left corner.
CW_USEDEFAULT, 0, _ '' Width and height.
NULL, NULL, hInstance, NULL)
if (hWnd=0) Then return FALSE
ShowWindow(hWnd, nCmdShow)
UpdateWindow(hWnd)
return TRUE
End Function
Function WndProc(byval hWnd as HWND, byval message as UINT,byval wParam as WPARAM, byval lParam as LPARAM) as LRESULT
Dim as UINT wmId, wmEvent
Dim as PAINTSTRUCT ps
Dim as HDC hdc
icex.dwSize = sizeof(INITCOMMONCONTROLSEX)
Select case (message)
case WM_CREATE
return TRUE
case WM_COMMAND
wmId = LOWORD(wParam)
wmEvent = HIWORD(wParam)
Select Case (wmId)
' case IDM_RUN_UPDOWN
'DialogBox(g_hInst, MAKEINTRESOURCE(IDD_UPDOWN), hWnd, UpDownDialogProc)
' case IDM_EXIT
' DestroyWindow(hWnd)
case 0
' return DefWindowProc(hWnd, message, wParam, lParam)
End Select
case WM_PAINT
hdc = BeginPaint(hWnd, @ps)
EndPaint(hWnd, @ps)
case WM_DESTROY
PostQuitMessage(0)
End Select
return DefWindowProc(hWnd, message, wParam, lParam)
End Function
Function UpDownDialogProc(byval hDlg as HWND, byval message as UINT, byval wParam as WPARAM, byval lParam as LPARAM) as INT_PTR
Dim as UINT nCode
Dim as integer iPosIndicated
' Dim as LPNMUPDOWN lpnmud
Select Case (message)
case WM_INITDIALOG
GetClientRect(hDlg, @rcClient)
cyVScroll = GetSystemMetrics(SM_CYVSCROLL)
hwndGroupBox = CreateGroupBox(hDlg) '' Group the controls.
hwndLabel = CreateLabel(hDlg) '' Create a label for the Up-Down control.
hwndUpDnEdtBdy = CreateUpDnBuddy(hDlg) '' Create an buddy window (an Edit control).
hwndUpDnCtl = CreateUpDnCtl(hDlg) '' Create an Up-Down control.
hwndProgBar = CreateProgBar(hDlg) '' Create a Progress bar,
'' to reflect the state of the Up-down control.
return TRUE
case WM_NOTIFY
nCode = Cast(LPNMHDR,lParam)->code
' Select Case (nCode)
' case UDN_DELTAPOS
' lpnmud = cast(LPNMUPDOWN,lParam)
' iPosIndicated = SendMessage(hwndProgBar, PBM_GETPOS, NULL, NULL)
' SendMessage(hwndProgBar, _
' PBM_SETPOS, _
' (iPosIndicated + lpnmud->iDelta), '' iPosIndicated can have
' NULL) '' any signed integer value.
' End Select
case WM_COMMAND
if (LOWORD(wParam) = IDOK orelse LOWORD(wParam) = IDCANCEL) Then
EndDialog(hDlg, LOWORD(wParam))
return TRUE
End If
End Select
return FALSE
End Function
Function CreateUpDnBuddy(byref hwndParent as HWND) as HWND
' icex.dwICC = ICC_STANDARD_CLASSES '' Set the Initialization Flag value.
' InitCommonControlsEx(@icex) '' Initialize the Common Controls Library to use
'' Buttons, Edit Controls, Static Controls, Listboxes,
'' Comboboxes, and Scroll Bars.
hControl = CreateWindowEx(WS_EX_LEFT OR WS_EX_CLIENTEDGE OR WS_EX_CONTEXTHELP, _ ''Extended window styles.
WC_EDIT, _
NULL, _
WS_CHILDWINDOW OR WS_VISIBLE OR WS_BORDER _'' Window styles.
OR ES_NUMBER OR ES_LEFT, _ '' Edit control styles.
rcClient.left+160, rcClient.top+40, _
rcClient.left+52, rcClient.top+23, _
hwndParent, _
NULL, _
g_hInst, _
NULL)
return (hControl)
End Function
Function CreateUpDnCtl(byref hwndParent as HWND) as HWND
icex.dwICC = ICC_UPDOWN_CLASS '' Set the Initialization Flag value.
InitCommonControlsEx(@icex) '' Initialize the Common Controls Library.
hControl = CreateWindowEx(WS_EX_LEFT OR WS_EX_LTRREADING, _
UPDOWN_CLASS, _
NULL, _
WS_CHILDWINDOW OR WS_VISIBLE _
OR UDS_AUTOBUDDY OR UDS_SETBUDDYINT OR UDS_ALIGNRIGHT OR UDS_ARROWKEYS OR UDS_HOTTRACK, _
0, 0, _
0, 0, _ '' Set to zero to automatically size to fit the buddy window.
hwndParent, _
NULL, _
g_hInst, _
NULL)
SendMessage(hControl, UDM_SETRANGE, 0, MAKELPARAM(valMax, valMin)) '' Sets the controls direction
'' and range.
return (hControl)
End Function
Function CreateLabel(byref hwndParent as HWND) as HWND
hControl = CreateWindowEx(WS_EX_LEFT OR WS_EX_LTRREADING, _
WC_STATIC, _
"Adjust:", _
WS_CHILDWINDOW OR WS_VISIBLE OR SS_RIGHT, _
rcClient.left+100, rcClient.top+42, _
rcClient.left+45, rcClient.top+23, _
hwndParent, _
NULL, _
g_hInst, _
NULL)
return (hControl)
End Function
Function CreateGroupBox(byref hwndParent as HWND) as HWND
hControl = CreateWindowEx(WS_EX_LEFT OR WS_EX_CONTROLPARENT OR WS_EX_LTRREADING, _
WC_BUTTON, _
"Volume", _
WS_CHILDWINDOW OR WS_CLIPCHILDREN OR WS_VISIBLE OR WS_GROUP OR BS_GROUPBOX, _
rcClient.left+10, rcClient.top+10, _
rcClient.right-20, rcClient.bottom-2*cyVScroll-10, _
hwndParent, _
NULL, _
g_hInst, _
NULL)
return (hControl)
End Function
Function CreateProgBar(byref hwndParent as HWND) as HWND
icex.dwICC = ICC_PROGRESS_CLASS '' Set the Initialization Flag value.
InitCommonControlsEx(@icex) '' Initialize the Common Controls Library to use the Progress Bar control.
hControl = CreateWindowEx(WS_EX_STATICEDGE, _
PROGRESS_CLASS, _
"Current Volume", _
WS_CHILDWINDOW OR WS_VISIBLE OR PBS_SMOOTH, _
rcClient.left+10, rcClient.bottom - cyVScroll-10, _
rcClient.right-20, cyVScroll, _
hwndParent, _
NULL, _
g_hInst, _
NULL)
'' Set the range and increment of the progress bar.
SendMessage(hControl, PBM_SETRANGE, 0, MAKELPARAM(0, 100))
SendMessage(hControl, PBM_SETSTEP, (WPARAM) 1, 0)
return (hControl)
End Function
|
_________________
|
|
Nach oben |
|
|
Jojo alter Rang
Anmeldungsdatum: 12.02.2005 Beiträge: 9736 Wohnort: Neben der Festplatte
|
Verfasst am: 09.03.2014, 00:32 Titel: Re: UpDown Control (SpinBox) |
|
|
Natürlich gibt es die noch, die WinAPI ist wohl zu 99% abwärtskompatibel bis hin zurück zu den ersten Windows-Versionen. Ob die FreeBASIC-Header vollständig sind, ist eine andere Frage, aber notfalls kann man so eine Definition ja auch von Hand nachtragen - die Funktionssignatur der Funktion und dazugehörige DLL (comctl32) hast du ja in der WinAPI gegeben. Natürlich heißt das nicht, dass es sinnvoll wäre, eine solche obsolete Funktion zu verwenden. _________________ » Die Mathematik wurde geschaffen, um Probleme zu lösen, die es nicht gäbe, wenn die Mathematik nicht erschaffen worden wäre.
|
|
Nach oben |
|
|
Eternal_pain
Anmeldungsdatum: 08.08.2006 Beiträge: 1783 Wohnort: BW/KA
|
Verfasst am: 09.03.2014, 00:53 Titel: |
|
|
hab übersehen das ich noch... Code: | #include "win\commctrl.bi" |
...einbinden muss, dachte das gehört zu Windows dazu... jetzt funktioniert er.. da ich nichts anderes gefunden hatte wäre es besser als gar kein Control
Nach stundenlangen googlen bin ich auf diesen Thread gestoßen
http://www.freebasic.net/forum/viewtopic.php?f=6&t=19338
2 funktionierende Beispiele mit der veralteten und eine neue Methode
Edit:
Funktioniert bestens
_________________
|
|
Nach oben |
|
|
Eternal_pain
Anmeldungsdatum: 08.08.2006 Beiträge: 1783 Wohnort: BW/KA
|
Verfasst am: 10.03.2014, 14:26 Titel: |
|
|
Hab das ganze gestern nochmal fast neu geschrieben, da mein speichermanagment schlicht daneben war...
Jetzt werden per destructor alle Elemente aus den Speicher gelöscht, macht das ganze etwas einfacher....
Aus Gründen der reinen Übersicht wollte ich jedem Control eine eigene PROC zuweisen... nun aber das Problem, bei meinen Groupboxen... hab nun mehere Stunden damit verbracht nach Fehlern zu suchen und nach lösungen zu googlen...
Im eigenen Proc werden mir die GroupBoxen nicht gezeichnet bzw wenn ich beim Create noch SetWindowText drin habe wird immerhin das letzte gezeichnet (allerdings nicht aktualisiert)
Jetzt hab ich einfach die PROC weggelassen und läuft nun über die Standard WindowProc und da geht es nun fehlerfrei... woran kann das liegen? _________________
|
|
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.
|
|