Can't Register Window Class

Windows specific questions.
Post Reply
myndgrrrrrl
Posts: 11
Joined: Feb 09, 2022 0:03

Can't Register Window Class

Post by myndgrrrrrl »

can someone show me where is the error?

Code: Select all

#define WIN32_LEAN_AND_MEAN
#include "windows.bi"
#define WIN_CLASS_NAME "MyClass"


Dim Shared hMainDC As HDC
Dim Shared g_hInstance As HINSTANCE
Dim Shared g_hWnd As HWND

Dim Shared nWidth As Integer = 640
Dim Shared nHeight As Integer = 480

Function WndProc ( ByVal hWnd As HWND, _
                   ByVal message As UINT, _
                   ByVal wParam As WPARAM, _
                   ByVal lParam As LPARAM ) As LRESULT
   
	Dim hdc As HDC
	Dim ps As PAINTSTRUCT
   
    Select Case( message )
        Case WM_CREATE  
			return 0
            Exit Function
       
        Case WM_PAINT
            hdc = BeginPaint(hWnd,@ps)
			EndPaint(hWnd,@ps)
			return 0
			Exit Function

        Case WM_DESTROY
            PostQuitMessage( 0 )
            Exit Function
			
        Case WM_SIZE
			nWidth = LOWORD(lparam)
			nHeight = HIWORD(lparam)
            Exit Function            
		Case WM_CLOSE
			Function = DefWindowProc(hWnd, message, wParam, lParam)
    End Select
   
    Function = DefWindowProc( hWnd, message, wParam, lParam )    
   
End Function

Function WinMain ( ByVal hInstance As HINSTANCE, _
                   ByVal hPrevInstance As HINSTANCE, _
                   szCmdLine As String, _
                   ByVal iCmdShow As Integer ) As Integer    
     
    Dim winclass As WNDCLASSEX
	Dim hwnd As HWND
	Dim wMsg As MSG 
	Dim As DWORD nStartTime
	 
    With winclass
		.cbSize =        sizeof(WNDCLASSEX)
        .style         = CS_OWNDC Or CS_HREDRAW Or CS_VREDRAW
        .lpfnWndProc   = @WndProc
        .cbClsExtra    = 0
        .cbWndExtra    = 0
        .hInstance     = hInstance
        .hIcon         = LoadIcon( NULL, IDI_APPLICATION )
        .hCursor       = LoadCursor( NULL, IDC_ARROW )
        .hbrBackground = GetStockObject(BLACK_BRUSH)
        .lpszMenuName  = NULL
        .lpszClassName = StrPtr( WIN_CLASS_NAME )
    End With
         
    If( RegisterClass( @winclass ) = FALSE ) Then
       MessageBox( null, "Failed to register wcls!", WIN_CLASS_NAME, MB_ICONERROR )
       Exit Function
    End If
   
    If((hWnd = CreateWindowEx( 0, _
                           WIN_CLASS_NAME, _
                           "The Hello Program", _
                           WS_OVERLAPPEDWINDOW OR WS_VISIBLE, _
                           CW_USEDEFAULT, _
                           CW_USEDEFAULT, _
                           nWidth, _
                           nHeight, _
                           NULL, _
                           NULL, _
                           hInstance, _
                           NULL )) = FALSE) Then
		Exit Function
	Endif
							
	g_hWnd = hWnd
	g_hInstance = hInstance
	hMainDC = GetDC(hWnd)

    ShowWindow( hWnd, iCmdShow )
    UpdateWindow( hWnd )
    
	do
		If(PeekMessage(@wMsg,NULL,0,0,PM_REMOVE)) Then
			TranslateMessage( @wMsg )
			DispatchMessage( @wMsg )
		Endif
		nStartTime = GetTickCount()
		
		while ((GetTickCount() - nStartTime) < 33)
		wEnd
	loop
	
	ReleaseDC(hWnd, hMainDC)
   
    Function = wMsg.wParam

End Function

WinMain( GetModuleHandle( null ), null, Command$, SW_NORMAL )
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Can't Register Window Class

Post by SARG »

With WNDCLASSEX you have to use RegisterClassEx instead RegisterClass
Post Reply