Buchempfehlung
Windows System Programming
Windows System Programming
Das Kompendium liefert viele interessante Informationen zur Windows-Programmierung auf Englisch. [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 15 von 16

Kapitel 4.5: Buttons erstellen
Kap4.5

''' Lutz Ifers WinAPI-Tutorial
''' Lizenz: WTFPL
'''
''' Kapitel 4.5 - "Buttons erstellen"

#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
    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