Buchempfehlung
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Umfassend, aber leicht verständlich führt dieses Buch in die Programmierung von ATMEL AVR Mikrocontrollern ein. [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!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

WinAPI - Complete source

Uploader:AdministratorSebastian
Datum/Zeit:23.06.2007 10:22:58

#include "windows.bi"

 TYPE ButtonType
   left    AS INTEGER
   top    AS INTEGER
   width  AS INTEGER
   height  AS INTEGER
   caption AS STRING
 END TYPE

 DECLARE FUNCTION WinMain (      szcmdline    AS STRING, _
                           BYVAL iChdShow    AS INTEGER ) AS INTEGER

 DECLARE FUNCTION WndProc ( BYVAL hWnd    AS HWND, _
                           BYVAL message  AS INTEGER, _
                           BYVAL wParam  AS INTEGER, _
                           BYVAL lParam  AS INTEGER ) AS INTEGER

 DIM SHARED hInstance  AS HMODULE

 DIM sHARED hWnd        AS INTEGER

 DIM SHARED ButtonCount AS INTEGER
 DIM SHARED hButtons()  AS HWND
 DIM SHARED DButtons()  AS ButtonType

 DIM SHARED klicks      AS INTEGER

 '=============================================================================='

 ButtonCount = 2

 REDIM hButtons(1 TO ButtonCount)
 REDIM DButtons(1 TO ButtonCount)

 WITH DButtons(1)
   .left    =  10
   .top    =  70
   .width  = 100
   .height  =  20
   .caption = "Add!"
 END WITH

 WITH DButtons(2)
   .left    = 150
   .top    =  70
   .width  = 100
   .height  =  20
   .caption = "quit"
 END WITH

 hInstance = GetModuleHandle( null )
 END WinMain( COMMAND, SW_NORMAL )

 '=============================================================================='

 FUNCTION WinMain (      szcmdline AS STRING, _
                   BYVAL iChdShow  AS INTEGER ) AS INTEGER

   DIM wMsg      AS MSG
   DIM wcls      AS WNDCLASS
   DIM szAppName AS STRING
   DIM hWnd      AS HWND
   DIM AppName   As ZString Ptr
   Dim BufferLen As Integer


   BufferLen = 255
   WinMain = 0
   szAppName = "MyButtonProgClass"

   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 = COLOR_WINDOW
       .lpszMenuName  = null
       .lpszClassName = STRPTR(szAppName)
   END WITH


   IF ( RegisterClass( @wcls ) = FALSE ) THEN
       MessageBox null, "This program requires Windows NT!", szAppName, MB_ICONERROR
       EXIT FUNCTION
   END IF

   AppName = Allocate(BufferLen)
   *AppName = "Application 12345"

   hWnd = CreateWindowEx( 0, _
                         AppName, _
                         AppName, _
                         DS_3DLOOK, _
                         CW_USEDEFAULT, _
                         CW_USEDEFAULT, _
                         300, _
                         150, _
                         null, _
                         null, _
                         hInstance, _
                         null )
   DeAllocate (AppName)

   ShowWindow  hWnd, iChdShow
   UpdateWindow hWnd

   WHILE ( GetMessage( @wMsg, null, 0, 0 ) <> false )
       TranslateMessage @wMsg
       DispatchMessage  @wMsg
   WEND

   WinMain = wMsg.wParam
 END FUNCTION

 FUNCTION WndProc (hWnd AS HWND, _
                   BYVAL message AS INTEGER, _
                   BYVAL wParam  AS INTEGER, _
                   BYVAL lParam  AS INTEGER) AS integer

   DIM rct AS RECT
   DIM pnt AS PAINTSTRUCT
   DIM hDC AS HDC

   WndProc = 0

   SELECT CASE message
   CASE WM_CREATE
       DIM i AS INTEGER
       FOR i = 1 TO ButtonCount
         WITH DButtons(i)
             hButtons(i) = CreateWindowEx (0, _
                                           "BUTTON", _
                                           .caption, _
                                           WS_CHILD or BS_PUSHBUTTON, _
                                           .left,    _
                                           .top,    _
                                           .width,  _
                                           .height,  _
                                           hWnd,    _
                                           null,    _
                                           hInstance,_
                                           null)
         END WITH
         ShowWindow hButtons(i), SW_NORMAL
       NEXT
       EXIT FUNCTION

   CASE WM_PAINT
       hDC = BeginPaint ( hWnd, @pnt )
       GetClientRect hwnd, @rct
       DrawText hDC, _
               "you pushed the button " + STR(klicks) + " times", _
               -1, _
               @rct, _
               DT_CENTER
       EndPaint hWnd, @pnt

       EXIT FUNCTION

   CASE WM_KEYDOWN
       IF lobyte(wParam) = 27 THEN PostQuitMessage 0

   CASE WM_COMMAND
       IF    lParam = hButtons(1) THEN
         klicks = klicks + 1
         GetClientRect hWnd, @rct
         InvalidateRect hWnd, @rct, TRUE

       ELSEIF lParam = hButtons(2) THEN
         PostQuitMessage 0
       END IF


   CASE WM_DESTROY
       PostQuitMessage 0
       EXIT FUNCTION

   END select

   WndProc = DefWindowProc( hWnd, message, wParam, lParam )

 END FUNCTION