Results 1 to 10 of 11

Thread: CreateWindowEx is resulting Zero.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    121
    Rep Power
    21

    CreateWindowEx is resulting Zero.

    Hi all,
    I am trying to create a window with win32 functions. But CreateWindowEx is returning 0 . This is my code. Please check this and guide me.
    Uses "Console"
     
    Type tWNDCLASSEX
      cbSize as DWord
      style As Long
      lpfnWndProc As Long
      cbClsExtra as Long
      cbWndExtra as Long
      hInstance As Long
      hIcon As Long
      hCursor As Long
      hbrBackground As Long
      lpszMenuName as Long
      lpszClassName as Long
      hIconSm As Long  
    End Type
    
    Type tPoint
    	x As dword
    	y as dword
    end type
    
    Type tMsg 
      hwnd as Long
      message as Long
      wParam as Long
      lParam as Long
      time as DWord
      pt as tPoint
      lPrivate as DWord
    end type
    
    Declare Function GetModuleHandle Lib "Kernel32.dll" Alias "GetModuleHandleW"(ByVal lpModuleName as Long) As Long
    Declare Function LoadIcon Lib "User32.dll" Alias "LoadIconW"(ByVal hInstance as Long, ByVal lpIconName As Long) As Long
    Declare Function LoadCursor Lib "User32.dll" Alias "LoadCursorW"( ByVal hInstance as Long, ByVal lpIconName As Long) As Long
    Declare Function RegisterClassEx Lib "User32.dll" Alias "RegisterClassExW" (pcWndClassEx As tWNDCLASSEX) As DWord
    Declare Function GetStockObject Lib "Gdi32.dll" Alias "GetStockObject" (ByVal nIndex As Long) As Long
    Declare Function CreateWindowEx Lib "User32.dll" Alias "CreateWindowExW" (ByVal dwExStyle As DWord, ByVal lpClassName As Long, ByVal lpWindowName As Long, ByVal dwStyle As DWord, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByVal lpParam As Long) As Long
    Declare Function ShowWindow Lib "User32.dll"(ByVal lhwnd As Long, ByVal nCmdShow As Long) As Long
    Declare Function UpdateWindow Lib "User32.dll" (ByVal lhwnd As Long) As Long
    Declare Function DefWindowProc Lib "User32.dll" Alias "DefWindowProcW" (ByVal lhwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    '// Declare Function GetMessage Lib "User32.dll" Alias "GetMessageW" (ByRef lpMsg As tMsg, ByVal lhwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
    Declare Function TranslateMessage Lib "User32.dll" Alias "TranslateMessageW" (ByRef lpMsg As tMsg) As Long
    Declare Function DispatchMessage Lib "User32.dll" Alias "DispatchMessageW" (ByRef lpMsg As tMsg) As Long
    
    
    Function MakeIntRs(i As Long) As Variant
      Dim temp As Long = i AND 0xffff
      Function = temp
    End Function
    
    
    
    Dim CSVREDRAW = 0x0001 
    Dim CSHREDRAW = 0x0002
    Dim CSDBLCLKS = 0x0008
    Dim IDC_ARROW = MakeIntRs(32512)	'// I am getting zero as value !
    Dim IDI_APPLICATION = MakeIntRs(32512)
    Dim My_OVERLAPPEDWINDOW As DWord = 0x00000000 OR 0x00C00000 OR 0x00080000 OR 0x00040000 OR 0x00020000 OR 0x00010000 
    Dim SWSHOW As Long = 5
    
    '// %'CS_OWNDC = 0x0020	'// These equates are not working !!!!
    
    Type Application
      ClassName As Asciiz
      hInstance as DWord 
      
      Function RegWindow() 
        Dim wndClsx As tWNDCLASSEX
        me.ClassName = "ThinBasic Window"
        me.hInstance = GetModuleHandle(0)
         with wndClsx
          .cbSize = SizeOf(wndClsx)
          .style = CSHREDRAW OR CSVREDRAW OR CSDBLCLKS
          .lpfnWndProc = Function_GetPtr(WndProc)	'// is this the correct way of getting a function pointer ?
          .cbClsExtra = 0
          .cbWndExtra = 0
          .hInstance = me.hInstance
          .hIcon = LoadIcon(0, IDI_APPLICATION) 
          .hCursor = LoadCursor(0, IDC_ARROW)
          .hbrBackground = GetStockObject(0)
          .lpszMenuName = 0
          .lpszClassName = StrPtr(me.ClassName)
          '// .hIconSm = 0
        End With
    	
        if RegisterClassEx(wndClsx) = 0 Then	'// Well, this is success.
          MsgBox("Window Registration Failed")
        EndIf
        
        PrintL PEEK$(ASCIIZ, wndClsx.lpszClassName)
      End Function   
    End Type
    
    Function WndProc(h As Long, msg As Long, wp As Long, lp As Long)
      Function = DefWindowProc(h, msg, wp, lp)
    End Function
    
    Dim ap as Application
    ap.RegWindow()
    
    dim wname As Asciiz = "My Thin Window"
    dim pWn As Long = StrPtr(wname)
    Dim hwn As Long = CreateWindowEx(0, ap.ClassName, wname, My_OVERLAPPEDWINDOW, 10, 10, 400, 400, 0, 0, ap.hInstance, NULL) '// Main problem lies on this function call.
    PrintL("Window Handle - ", hwn)	'// This will print a zero.
    PrintL(ap.hInstance)			'// But this will print a number.
    
    if hwn > 0 Then					
    	ShowWindow(hwn, 5)
    	UpdateWindow(hwn)
    
    	Dim uMsg As tMsg 
    	While Win_GetMessage(uMsg, hWnd, 0, 0) <> 0
    	    TranslateMessage(uMsg)
    	    DispatchMessage(uMsg)
        Wend
    
    Else
    	MsgBox("Window creation Failed..!")
    EndIf
    
    WaitKey
    
    Last edited by kcvinu; 03-04-2021 at 11:51.

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •