Lutz Ifers WinAPI Tutorial

Windows specific questions.
Post Reply
RNBW
Posts: 267
Joined: Apr 11, 2015 11:06
Location: UK

Lutz Ifers WinAPI Tutorial

Post by RNBW »

I have been looking at Lutz Ifers WinAPI Tutorial on the German web site https://www.freebasic-portal.de/. If you are looking for useful tutorials there are many on this website. They are all in German but are easily translated using one of the online translators (Google translate, etc).

I have found all the examples to work with the exception of Chapter 2.5 Loading Bitmaps. I get the following warning and error messages:
FbTemp.bas(14) warning 4(2): Suspicious pointer assignment
FbTemp.bas(73) warning 2(2): Passing pointer to scalar, at parameter 4 of BITBLT()
FbTemp.bas(73) error 24: Invalid data types, at parameter 4 of BITBLT() in '@hbmiLutz->bmiHeader.biWidth, @hbmiLutz->bmiHeader.biHeight,_'
The code is:

Code: Select all

''' Lutz Ifers WinAPI-Tutorial
'''
''' Kapitel 2.5 - "Bitmaps laden"

#include "windows.bi"
const ProgrammName = "Bitmaps laden"

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

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

dim as HWND	hMeinFenster = CreateWindow(_
    ProgrammName, "Titelzeile", WS_OVERLAPPEDWINDOW,_
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,_
    NULL, NULL, GetModuleHandle(NULL), NULL)

ShowWindow   hMeinFenster, SW_NORMAL
UpdateWindow hMeinFenster

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

function Fenster(byval hWnd as HWND, byval message as UINTEGER,_
    byval wParam as WPARAM, byval lParam as LPARAM) as LRESULT
    
    static as HBITMAP           hbmpLutz
    static as BITMAPINFO POINTER hbmiLutz
    
    select case message
        case WM_DESTROY
            PostQuitMessage 0
            return 0
            
        case WM_CREATE
            open "lutz.bmp" for binary as #1
            dim as INTEGER  iFileLength = lof(1)
            dim as BYTE     bvBuffer(iFileLength)
            get #1,, bvBuffer() : close #1
            
            dim as BITMAPFILEHEADER PTR bmpFileHeader = _
                cptr(BITMAPFILEHEADER PTR, @bvBuffer(0))
            
            hbmiLutz = cptr(BITMAPINFO PTR, bmpFileHeader +1)
            hbmpLutz = CreateDIBitmap(_
                GetDC(hWnd), @hbmiLutz->bmiHeader, CBM_INIT, _
  				cptr(BYTE PTR, bmpFileHeader) + bmpFileHeader->bfOffBits,_
                hbmiLutz, DIB_RGB_COLORS)
            return 0
            
        case WM_PAINT
            dim as PAINTSTRUCT pnt
            dim as HDC hDC = BeginPaint(hWnd, @pnt)
                dim as HDC bmpDC = CreateCompatibleDC(hDC)
                dim hOldObject as HGDIOBJ = SelectObject(bmpDC, hbmpLutz)
                BitBlt(hDC, 0, 0,_
                    @hbmiLutz->bmiHeader.biWidth, @hbmiLutz->bmiHeader.biHeight,_
                    bmpDC, 0, 0, SRCCOPY)
                
                SelectObject bmpDC, hOldObject
                DeleteDC bmpDC 
            EndPaint(hWnd, @pnt)
            return 0
            
    end select
    return DefWindowProc(hWnd, message, wParam, lParam)
end function
Can anyone help?
UEZ
Posts: 972
Joined: May 05, 2017 19:59
Location: Germany

Re: Lutz Ifers WinAPI Tutorial

Post by UEZ »

Try this

Code: Select all

''' Lutz Ifers WinAPI-Tutorial
'''
''' Kapitel 2.5 - "Bitmaps laden"

#include "windows.bi"
const ProgrammName = "Bitmaps laden"

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

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

dim as HWND   hMeinFenster = CreateWindow(_
    ProgrammName, "Titelzeile", WS_OVERLAPPEDWINDOW,_
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,_
    NULL, NULL, GetModuleHandle(NULL), NULL)

ShowWindow   hMeinFenster, SW_NORMAL
UpdateWindow hMeinFenster

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

function Fenster(byval hWnd as HWND, byval message as UINTEGER,_
    byval wParam as WPARAM, byval lParam as LPARAM) as LRESULT
   
    static as HBITMAP           hbmpLutz
    static as BITMAPINFO POINTER hbmiLutz
	static as Integer w, h
   
    select case message
        case WM_DESTROY
            PostQuitMessage 0
            return 0
           
        case WM_CREATE
            open "lutz.bmp" for binary as #1
            dim as INTEGER  iFileLength = lof(1)
            dim as BYTE     bvBuffer(iFileLength)
            get #1,, bvBuffer() : close #1
           				
            dim as BITMAPFILEHEADER PTR bmpFileHeader = _
                cptr(BITMAPFILEHEADER PTR, @bvBuffer(0))
           
            hbmiLutz = cptr(BITMAPINFO PTR, bmpFileHeader +1)
            hbmpLutz = CreateDIBitmap(_
                GetDC(hWnd), @hbmiLutz->bmiHeader, CBM_INIT, _
				cptr(BYTE PTR, bmpFileHeader) + bmpFileHeader->bfOffBits,_
                hbmiLutz, DIB_RGB_COLORS)
			w = hbmiLutz->bmiHeader.biWidth : h = hbmiLutz->bmiHeader.biHeight
            return 0
           
        case WM_PAINT
            dim as PAINTSTRUCT pnt
            dim as HDC hDC = BeginPaint(hWnd, @pnt)
			dim as HDC bmpDC = CreateCompatibleDC(hDC)
			dim hOldObject as HGDIOBJ = SelectObject(bmpDC, hbmpLutz)

			BitBlt(hDC, 0, 0,_
					w, h,_
					bmpDC, 0, 0, SRCCOPY)
               
			SelectObject bmpDC, hOldObject
			DeleteDC bmpDC
            EndPaint(hWnd, @pnt)
            return 0
           
    end select
    return DefWindowProc(hWnd, message, wParam, lParam)
end function
instead.
Xusinboy Bekchanov
Posts: 783
Joined: Jul 26, 2018 18:28

Re: Lutz Ifers WinAPI Tutorial

Post by Xusinboy Bekchanov »

It should be like this:

Code: Select all

''' Lutz Ifers WinAPI-Tutorial
'''
''' Kapitel 2.5 - "Bitmaps laden"

#include "windows.bi"
Const ProgrammName = "Bitmaps laden"

Declare Function Fenster(ByVal hWnd As HWND, ByVal message As UINT, _
    ByVal wParam As WPARAM, ByVal lParam As LPARAM) As LRESULT

Dim As WNDCLASS   wcMeinFenster
With wcMeinFenster
    .style         =  CS_HREDRAW Or CS_VREDRAW
    .lpfnWndProc   =  ProcPtr(Fenster)
    .cbClsExtra    =  0
    .cbWndExtra    =  0
    .hInstance     =  GetModuleHandle(NULL)
    .hCursor       =  LoadCursor(NULL, IDC_ARROW)
    .hIcon         =  LoadIcon(NULL, IDI_APPLICATION)
    .hbrBackground =  GetStockObject(WHITE_BRUSH)
    .lpszClassName =  StrPtr(ProgrammName)
    .lpszMenuName  =  NULL
End With
RegisterClass @wcMeinFenster

Dim As HWND   hMeinFenster = CreateWindow(_
    ProgrammName, "Titelzeile", WS_OVERLAPPEDWINDOW,_
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,_
    NULL, NULL, GetModuleHandle(NULL), NULL)

ShowWindow   hMeinFenster, SW_NORMAL
UpdateWindow hMeinFenster

Dim As MSG msg
Do While getmessage(@msg, NULL, 0, 0) <> 0
    DispatchMessage  @msg
Loop
End msg.wParam

Function Fenster(ByVal hWnd As HWND, ByVal message As UInt, _
    ByVal wParam As WPARAM, ByVal lParam As LPARAM) As LRESULT
   
    Static As HBITMAP           hbmpLutz
    Static As BITMAPINFO Pointer hbmiLutz
   
    Select Case message
        Case WM_DESTROY
            PostQuitMessage 0
            Return 0
           
        Case WM_CREATE
            Open "lutz.bmp" For Binary As #1
            Dim As Integer  iFileLength = LOF(1)
            Dim As Byte     bvBuffer(iFileLength)
            Get #1,, bvBuffer() : Close #1
           
            Dim As BITMAPFILEHEADER Ptr bmpFileHeader = _
                CPtr(BITMAPFILEHEADER Ptr, @bvBuffer(0))
           
            hbmiLutz = CPtr(BITMAPINFO Ptr, bmpFileHeader +1)
            hbmpLutz = CreateDIBitmap(_
                GetDC(hWnd), @hbmiLutz->bmiHeader, CBM_INIT, _
              CPtr(Byte Ptr, bmpFileHeader) + bmpFileHeader->bfOffBits,_
                hbmiLutz, DIB_RGB_COLORS)
            Return 0
           
        Case WM_PAINT
            Dim As PAINTSTRUCT pnt
            Dim As HDC hDC = BeginPaint(hWnd, @pnt)
                Dim As HDC bmpDC = CreateCompatibleDC(hDC)
                Dim hOldObject As HGDIOBJ = SelectObject(bmpDC, hbmpLutz)
                BitBlt(hDC, 0, 0, _
                    hbmiLutz->bmiHeader.biWidth, hbmiLutz->bmiHeader.biHeight, _
                    bmpDC, 0, 0, SRCCOPY)
               
                SelectObject bmpDC, hOldObject
                DeleteDC bmpDC
            EndPaint(hWnd, @pnt)
            Return 0
           
    End Select
    Return DefWindowProc(hWnd, message, wParam, lParam)
end function
RNBW
Posts: 267
Joined: Apr 11, 2015 11:06
Location: UK

Re: Lutz Ifers WinAPI Tutorial

Post by RNBW »

Thank you very much UEZ and Xusinboy Bekchanov for your very rapid solutions. I'll have a look at them later today.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Lutz Ifers WinAPI Tutorial

Post by MrSwiss »

Windows internal data-types: wrote: UINT
An unsigned INT. The range is 0 through 4294967295 decimal.
This type is declared in WinDef.h as follows:
typedef unsigned int UINT;
Equivalents of UINT are:
(Windows) UINT32, DWORD (and, probably more ...)
(FreeBASIC) ULong, UInteger<32> (without size specifier it's simply wrong)
Lothar Schirm
Posts: 436
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Lutz Ifers WinAPI Tutorial

Post by Lothar Schirm »

There is an other tutorial "FreeBASIC and API" on https://users.freebasic-portal.de/freebasicru/api.html in russian language, but there is a button to "Google Translate" in nearly any language of the world, also english, of course. A lot of examples written in FreeBASIC and explained very well. This site was developed by Stanislav Budinov to support Russian-speaking users in using FreeBASIC and includes a lot of very interesting stuff, Windows API is a small part only.
Kwabbernoot
Posts: 79
Joined: Apr 19, 2010 18:23
Location: NL

Re: Lutz Ifers WinAPI Tutorial

Post by Kwabbernoot »

Lothar Schirm wrote:There is an other tutorial "FreeBASIC and API" on https://users.freebasic-portal.de/freebasicru/api.html in russian language, but there is a button to "Google Translate" in nearly any language of the world, also english, of course. A lot of examples written in FreeBASIC and explained very well. This site was developed by Stanislav Budinov to support Russian-speaking users in using FreeBASIC and includes a lot of very interesting stuff, Windows API is a small part only.
Interesting indeed with many examples. When translating from Russian, sometimes the FreeBASIC keywords are translated as well, such as: IF .. THEN .. ELSE in Dutch (my language), but I can live with that. Thanks.
RNBW
Posts: 267
Joined: Apr 11, 2015 11:06
Location: UK

Re: Lutz Ifers WinAPI Tutorial

Post by RNBW »

Lothar Schirm wrote:There is an other tutorial "FreeBASIC and API" on https://users.freebasic-portal.de/freebasicru/api.html in russian language, but there is a button to "Google Translate" in nearly any language of the world, also english, of course. A lot of examples written in FreeBASIC and explained very well. This site was developed by Stanislav Budinov to support Russian-speaking users in using FreeBASIC and includes a lot of very interesting stuff, Windows API is a small part only.
Unfortunately I was unable to access the page and received the following message
Secure Connection Failed

An error occurred during a connection to users.freebasic-portal.de. SSL received a record that exceeded the maximum permissible length.

Error code: SSL_ERROR_RX_RECORD_TOO_LONG

The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
Please contact the web site owners to inform them of this problem.
.
Also, MalwareBytes also blocked it because of a Trojan.
Lothar Schirm
Posts: 436
Joined: Sep 28, 2013 15:08
Location: Germany

Re: Lutz Ifers WinAPI Tutorial

Post by Lothar Schirm »

Hi Ray,

I do not use Malwarebytes. I use Firefox and Kaspersky Internet Security. When I go to that site, I see a small black warning triangel at the left side of the URL. This seems to mean that Kaspersky cannot verify the site (whatever that means - no certificate?). But when I enter "freebasic #32770" into Bing, the link is shown in the search list with a green Kaspersky signal (no warning). Perhaps Sebastian Steiner can help you (see Impressum of FreeBASIC Portal)?

Error code: SSL_ERROR_RX_RECORD_TOO_LONG:
I found something here https://kinsta.com/knowledgebase/ssl_er ... _too_long/ how to fix that problem if it is caused by Firefox - good luck! Looks a bit complicated.
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

Re: Lutz Ifers WinAPI Tutorial

Post by miilvyxg »

RNBW wrote:Also, MalwareBytes also blocked it because of a Trojan.
MBAM is too strict. If your browser doesn't said it's dangerous then most of the time it's just OK.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: Lutz Ifers WinAPI Tutorial

Post by aurelVZAB »

MalwareBytes

Is the worst BullSHeet av tend to throw on each compilation False positive
same is McAfee c_rap

DONT USE THIS AV !
Post Reply