Buchempfehlung
MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

Tutorial

Lutz Ifers WinAPI Tutorial

von RedakteurMODSeite 16 von 16

Kapitel 4.6: Auf Buttons reagieren
Kap4.5

''' Lutz Ifers WinAPI-Tutorial
''' Lizenz: WTFPL
'''
''' Kapitel 4.6 - "Auf Buttons reagieren"

#include "windows.bi"
const ProgrammName = "Buttons"

declare function WndProc(byval hWnd as HWND, byval message as UINTEGER,_
    byval wParam as WPARAM, byval lParam as LPARAM) as LRESULT
declare function SubProc(byval hWnd as HWND, byval message as UINTEGER,_
    byval wParam as WPARAM, byval lParam as LPARAM) as LRESULT

dim as WNDCLASS wndcls
with wndcls
    .style         =  CS_HREDRAW or CS_VREDRAW
    .lpfnWndProc   =  ProcPtr(WndProc)
    .cbClsExtra    =  0
    .cbWndExtra    =  0
    .hInstance     =  GetModuleHandle(NULL)
    .hCursor       =  LoadCursor(NULL, IDC_ARROW)
    .hIcon         =  LoadIcon(NULL, IDI_APPLICATION)
    .hbrBackground =  GetSysColorBrush(COLOR_WINDOW)
    .lpszClassName =  StrPtr(ProgrammName)
    .lpszMenuName  =  NULL
end with
RegisterClass @wndcls

dim as HWND hWnd = CreateWindow(_
    ProgrammName, ProgrammName, WS_OVERLAPPED or WS_SYSMENU,_
    CW_USEDEFAULT, CW_USEDEFAULT, 180, 210,_
    NULL, NULL, GetModuleHandle(NULL), NULL)

ShowWindow   hWnd, SW_NORMAL
UpdateWindow hWnd

dim as MSG msg
do while getmessage(@msg, NULL, 0, 0) <> 0
    DispatchMessage  @msg
loop
end msg.wParam

function WndProc(byval hWnd as HWND, byval message as UINTEGER,_
    byval wParam as WPARAM, byval lParam as LPARAM) as LRESULT

    static  as HWND hBeenden, hLinks, hMitte, hRechts
    static  as HWND hfoo, hbar, hfrage
    static  as HWND hrot, hblau, hgruen

    select case message
        case WM_DESTROY
            PostQuitMessage 0
            return 0

        case WM_CREATE
            hBeenden = CreateWindow("button", "Beenden",_
                WS_CHILD or WS_VISIBLE,_
                5, 5, 160, 22, hWnd, NULL,_
                cast(LPCREATESTRUCT,lParam)->hInstance,NULL)
            hLinks = CreateWindow("button", "A",_
                WS_CHILD or WS_VISIBLE,_
                5, 30, 50, 22, hWnd, NULL,_
                cast(LPCREATESTRUCT,lParam)->hInstance,NULL)
            hMitte = CreateWindow("button", "B",_
                WS_CHILD or WS_VISIBLE,_
                60, 30, 50, 22, hWnd, NULL,_
                cast(LPCREATESTRUCT,lParam)->hInstance,NULL)
            hRechts = CreateWindow("button", "C",_
                WS_CHILD or WS_VISIBLE,_
                115, 30, 50, 22, hWnd, NULL,_
                cast(LPCREATESTRUCT,lParam)->hInstance,NULL)
            hfoo = CreateWindow("button", "foo",_
                BS_AUTOCHECKBOX or WS_VISIBLE or WS_CHILD or WS_CLIPSIBLINGS,_
                5, 60, 40,20, hWnd, NULL,_
                cast(LPCREATESTRUCT,lParam)->hInstance,NULL)
            hbar = CreateWindow("button", "bar",_
                BS_AUTOCHECKBOX or WS_VISIBLE or WS_CHILD or WS_CLIPSIBLINGS,_
                50, 60, 45,20, hWnd, NULL,_
                cast(LPCREATESTRUCT,lParam)->hInstance,NULL)
            hfrage = CreateWindow("button", "Sicher?",_
                BS_CHECKBOX or WS_VISIBLE or WS_CHILD or WS_CLIPSIBLINGS,_
                100, 60, 70,20, hWnd, NULL,_
                cast(LPCREATESTRUCT,lParam)->hInstance,NULL)
            CreateWindow("button", "Lieblingsfarbe?",_
                WS_CHILD or WS_VISIBLE or WS_GROUP or BS_GROUPBOX,_
                5,90,160, 90, hWnd, NULL,_
                cast(LPCREATESTRUCT,lParam)->hInstance,NULL)
            hrot = CreateWindow("button", "Rot",_
                BS_AUTORADIOBUTTON or WS_VISIBLE or WS_CHILD or WS_GROUP,_
                10, 110, 70,20, hWnd, NULL,_
                cast(LPCREATESTRUCT,lParam)->hInstance,NULL)
            hblau = CreateWindow("button", "Blau",_
                BS_AUTORADIOBUTTON or WS_VISIBLE or WS_CHILD,_
                10, 130, 70,20, hWnd, NULL,_
                cast(LPCREATESTRUCT,lParam)->hInstance,NULL)
            hgruen = CreateWindow("button", "Grün",_
                BS_AUTORADIOBUTTON or WS_VISIBLE or WS_CHILD,_
                10, 150, 70,20, hWnd, NULL,_
                cast(LPCREATESTRUCT,lParam)->hInstance,NULL)
            SendMessage hrot, BM_SETCHECK, BST_CHECKED, 0
            return 0


            ''' Auf Buttons
            ''' reagieren


        case WM_COMMAND
            if HIWORD(wParam) <> BN_CLICKED then return 0

            select case lParam
                case hLinks  : MessageBox  hWnd, "klick","Button A", 0
                case hMitte  : MessageBox  hWnd, "klick","Button B", 0
                case hRechts : MessageBox  hWnd, "klick","Button C", 0
                case hFrage
                    if SendMessage(hFrage, BM_GETCHECK, 0, 0) = BST_CHECKED then
                        SendMessage hFrage, BM_SETCHECK, BST_UNCHECKED, 0
                    elseif MessageBox(hWnd, "Wirklich auswählen?", "Frage",_
                            MB_YESNO or MB_ICONQUESTION) = IDYES then
                        SendMessage hFrage, BM_SETCHECK, BST_CHECKED, 0
                    end if
                case hBeenden
                    dim as string sText = "angeklickte Buttons:"+chr(13,10)
                    if SendMessage(hfoo,  BM_GETCHECK,0,0) = BST_CHECKED then _
                        sText += "foo "
                    if SendMessage(hbar,  BM_GETCHECK,0,0) = BST_CHECKED then _
                        sText += "bar "
                    if SendMessage(hfrage,BM_GETCHECK,0,0) = BST_CHECKED then _
                        sText += "sicher"

                    sText += chr(13, 10, 13, 10) + "Die Lieblingsfarbe ist "

                    if SendMessage(hrot,  BM_GETCHECK,0,0) = BST_CHECKED then _
                        sText += "rot"
                    if SendMessage(hblau, BM_GETCHECK,0,0) = BST_CHECKED then _
                        sText += "blau"
                    if SendMessage(hgruen,BM_GETCHECK,0,0) = BST_CHECKED then _
                        sText += "grün"

                    sText += chr(13, 10, 13, 10) + "Wirklich Beenden?"

                    if MessageBox(hWnd, sText, "Beenden",_
                            MB_YESNO or MB_ICONQUESTION) = IDYES then
                        SendMessage(hWnd, WM_CLOSE, 0, 0)
                    end if
            end select
            return 0
    end select
    return DefWindowProc( hWnd, message, wParam, lParam )
end function

Links:

In der MSDN: ,
In der FreeBasic-Referenz: BefehlsreferenzeintragEND, BefehlsreferenzeintragWITH, BefehlsreferenzeintragWHILE

 

Gehe zu Seite Gehe zu Seite  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  
Zusätzliche Informationen und Funktionen
  • Das Tutorial wurde am 17.09.2009 von RedakteurMOD angelegt.
  • Die aktuellste Version wurde am 17.07.2013 von AdministratorSebastian gespeichert.
  Bearbeiten Bearbeiten  

  Versionen Versionen