Author Topic: RegisterClass ?  (Read 5810 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
RegisterClass ?
« on: February 04, 2014, 02:55:01 AM »
Hi
Do you know that  RegisterClass  not work outside of Bind structure?

Quote
RegisterClass-Funktion

Diese Funktion registriert eine Klasse, die dann dazu benutzt werden kann, ein Fenster zu erstellen.

Betriebssystem:  Win95, Win98, WinNT 3.1, Win2000, WinME

so something like this not work on XP,Vista,7
Declare Function RegisterClass Lib "user32.dll" Alias "RegisterClassA" ( lpWndClass As WNDCLASS) As Long

I will try replace this with RegisterClassEx...
« Last Edit: February 04, 2014, 04:02:57 AM by Aurel »

Charles Pegge

  • Guest
Re: RegisterClass ?
« Reply #1 on: February 04, 2014, 03:15:51 AM »
Are you using a matching WNDCLASS structure?

Declare Function RegisterClass lib "user32" Alias "RegisterClassA" (Class As WNDCLASS) As Long

Declare Function RegisterClassEx lib "user32" Alias "RegisterClassExA" (pcWndClassEx As WNDCLASSEX) As Integer


Aurel

  • Guest
Re: RegisterClass ?
« Reply #2 on: February 04, 2014, 04:02:23 AM »
Hi Charles..
As i say this:
Quote
Declare Function RegisterClass Lib "user32.dll" Alias "RegisterClassA" ( lpWndClass As WNDCLASS) As Long
not work outside of Bind structrure:

Bind user32
(
  'LoadIcon         LoadIconA       
  'LoadCursor       LoadCursorA       
  RegisterClass    RegisterClassA
...
...
)
or in another words if u use RegisterClass from Bind user32 then program work properly.
So my question is why some api functions not work outside of bind scope?

Aurel

  • Guest
Re: RegisterClass ?
« Reply #3 on: February 04, 2014, 08:46:23 AM »
Unfortunatelly
sorry but NOT work...

If is inside Bind()  like:


Bind user32
(
  LoadIcon         LoadIconA       
  LoadCursor       LoadCursorA       
  RegisterClass    RegisterClassA
  RegisterClassEx  RegisterClassExA 
....
....
)

Then Work. ::)

But if is declared outside like this :

Declare Function RegisterClassEx Lib "user32.dll" Alias "RegisterClassExA" ( lpwcx As WNDCLASSEX) As Integer

then NOT work...

Charles...
Please , do you can remove this dependecies ?

Charles Pegge

  • Guest
Re: RegisterClass ?
« Reply #4 on: February 05, 2014, 11:10:27 AM »
How are you calling it, Aurel?

with the fully specified prototype:

RegisterClassEx wcx

Aurel

  • Guest
Re: RegisterClass ?
« Reply #5 on: February 05, 2014, 12:36:32 PM »
Yes Charles
Like you show

RegisterClassEx &wcx

Charles Pegge

  • Guest
Re: RegisterClass ?
« Reply #6 on: February 05, 2014, 04:38:55 PM »
With your prototype there should no '&' or '@', because it passes ByRef (implicitly when using basic-style prototypes).

Aurel

  • Guest
Re: RegisterClass ?
« Reply #7 on: February 05, 2014, 10:52:20 PM »
Quote
With your prototype there should no '&' or '@', because it passes ByRef (implicitly when using basic-style prototypes).

wait,,,Charles ..so you say that I use all the time wrong method  :o
so proper way would be
RegisterClassEx wcx   ....... right?

Charles Pegge

  • Guest
Re: RegisterClass ?
« Reply #8 on: February 06, 2014, 03:48:04 AM »
Hi Aurel, it depends on the prototype you use. If the prototype implies parameters 'BYREF' then   '&' is not used.

Aurel

  • Guest
Re: RegisterClass ?
« Reply #9 on: February 06, 2014, 10:52:12 AM »
Ok
I will try all possible options
and i will present here skeleton app with minimum of api functions.

Aurel

  • Guest
Re: RegisterClass ?
« Reply #10 on: February 08, 2014, 08:30:48 AM »
Hi Charles...
After i test all possible options it looks that RegisterClassEx and also RegisterClass
NOT work without Bind().
What might be problem i really cannot understand  ???

Code: [Select]
'skeleton VB way...
$ filename "skeleton.exe"
include "rtl32.inc"
'#lookahead
'structures
Type WNDCLASSEX
 cbSize        as long
 Style         as long
 lpfnwndproc   as sys
 cbClsextra    as long
 cbWndExtra    as long
 hInstance     as sys
 hIcon         as long
 hCursor       as long
 hbrBackground as long
 lpszMenuName  as string
 lpszClassName as string
 hIconSm       AS long
End Type

Type WNDCLASS
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 String
lpszClassName As String
End Type

Type POINTAPI
 x as sys
 y as sys
End Type

Type MSG
 hwnd    as sys
 message as sys
 wParam  as sys
 lParam  as sys
 time    as sys
 pt      as PointApi
End Type

'constants
% IDI_WINLOGO     = 32517
% IDI_APPLICATION = 32512
% IDC_ARROW       = 32512
% CS_OWNDC        = 32
% CS_DBLCLKS      =  &H8
% SW_NORMAL       = 1

% WM_CREATE      = 1
% WM_DESTROY     = 2
% WM_PAINT       = 15
% WM_QUIT        = 18
% WM_SIZE        = 5
% WM_MOVE        = 3
% WM_CHAR        = 258
% WM_KEYDOWN     = 256
% WM_KEYUP       = 257
% WM_MOUSEMOVE   = 512
% WM_MBUTTONDOWN = 519
% WM_LBUTTONDOWN = 513
% WM_RBUTTONDOWN = 516
% WM_LBUTTONUP   = 514
% WM_RBUTTONUP   = 517
% WM_MBUTTONUP   = 520

% WS_OVERLAPPEDWINDOW = 0x00CF0000
% WS_SYSMENU     = 0x80000
% WS_OVERLAPPED  = WS_SYSMENU     
% WS_POPUP       = 0x80000000
% WS_DLGFRAME    = 0x400000
% WS_VISIBLE     = 0x10000000
'defines...
Def WHITE_BRUSH   0
Def BLACK_BRUSH   4


'declarations...
Declare Function MessageBox Lib "kernel32.dll" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Declare Function LoadIcon Lib "user32.dll" Alias "LoadIconA" (ByVal hInstance As Long, ByVal lpIconName As Any) As Long
Declare Function LoadCursor Lib "user32.dll" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Any) As Long
Declare Function GetModuleHandle Lib "kernel32.dll" Alias "GetModuleHandleA" (sys lpModuleName) as Long
Declare Function RegisterClassEx Lib "user32.dll" Alias "RegisterClassExA" (wcx as WNDCLASSEX) as Long
Declare Function RegisterClass Lib "user32.dll" Alias "RegisterClassA" (byref lpwcx as WNDCLASS) as Long
Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (byval dwExStyle AS INT,byval lpClassName AS STRING,byval lpWindowName AS STRING,byval dwStyle AS INT,byval x AS INT,byval y AS INT,byval nWidth AS INT,byval nHeight AS INT,byval hWndParent AS INT,byval hMenu AS INT,byval hInstance AS INT,byval lpParam AS INT) as Long
Declare Function TranslateMessage Lib "user32.dll" Alias "TranslateMessageA" (byval lpMsg as Long) as Long
Declare Function DispatchMessage  Lib "user2.dll" Alias "DispatchMessageA" (byval lpMsg as Long) as Long
Declare Function GetMessage Lib "user32.dll" Alias "GetMessageA" (byval lpMsg As MSG, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Declare Function ShowWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function DefWindowProc Lib "user32.dll" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function PostQuitMessage Lib "user32.dll" (ByVal nExitCode As Long)

Dim wcx as WNDCLASSEX
Dim wm as MSG

'FILL WNDCLASSEX structure
inst = GetModuleHandle 0
wcx.cbSize       = sizeOf(WNDCLASSEX)
wcx.style         = CS_DBLCLKS Or CS_OWNDC
wcx.lpfnWndProc   = &WndProc
wcx.cbClsExtra    = 0
wcx.cbWndExtra    = 0
wcx.hInstance     = inst
wcx.hIcon         = LoadIcon 0,IDI_WINLOGO         
wcx.hCursor       = LoadCursor 0,IDC_ARROW 
wcx.hbrBackground = WHITE_BRUSH     
wcx.lpszMenuName  = ?0
wcx.lpszClassName = strptr"Oxygen"
wcx.hIconSm       = LoadIcon 0,IDI_APPLICATION

'register window class Ex
RegisterClassEx wcx

'create window -------------------------------
Dim hwnd,style, Wx, Wy, Ww, Wh, wparent as Long
Dim caption as String
'-------------------------------
caption = "MyWindow"
style   = WS_VISIBLE or WS_SYSMENU  'WS_OVERLAPPEDWINDOW
Wx=0 : Wy=0 : Ww=640 : Wh=480
wparent = 0 'HWND_DESKTOP
'-------------------------------
Hwnd = CreateWindowEx 0, wcx.lpszClassName, caption, style, Wx, Wy, Ww, Wh, wparent, 0, inst, byval 0
ShowWindow Hwnd,SW_NORMAL
'-------------------------------
'message loop
WHILE Getmessage(wm,0,0,0) <> 0
     TranslateMessage wm
     DispatchMessage  wm
WEND

'main callback procedure ---------------------------------------
Function WndProc (sys wMsg,Hwnd,wParam,lParam) as sys callback
Select wMsg
CASE WM_DESTROY
      PostQuitMessage 0
End Select
Return DefWindowProc(wMsg,Hwnd,wParam,lParam)

End Function
'----------------------------------------------------------------

.

Aurel

  • Guest
Re: RegisterClass ?
« Reply #11 on: February 08, 2014, 01:53:30 PM »
Here is another corection but still not work  ???

Code: [Select]
'skeleton VB way...
$ filename "skeleton.exe"
include "rtl32.inc"
#lookahead
'structures
Type WNDCLASSEX
 cbSize        as long
 Style         as long
 lpfnwndproc   as sys
 cbClsextra    as long
 cbWndExtra    as long
 hInstance     as sys
 hIcon         as long
 hCursor       as long
 hbrBackground as long
 lpszMenuName  as string
 lpszClassName as string
 hIconSm       AS long
End Type

Type POINTAPI
 x as sys
 y as sys
End Type

Type MSG
 hwnd    as sys
 message as sys
 wParam  as sys
 lParam  as sys
 time    as sys
 pt      as PointApi
End Type

'constants
% IDI_WINLOGO     = 32517
% IDI_APPLICATION = 32512
% IDC_ARROW       = 32512
% CS_OWNDC        = 32
% CS_DBLCLKS      =  &H8
% SW_NORMAL       = 1

% WM_CREATE      = 1
% WM_DESTROY     = 2
% WM_PAINT       = 15
% WM_QUIT        = 18
% WM_SIZE        = 5
% WM_MOVE        = 3
% WM_CHAR        = 258
% WM_KEYDOWN     = 256
% WM_KEYUP       = 257
% WM_MOUSEMOVE   = 512
% WM_MBUTTONDOWN = 519
% WM_LBUTTONDOWN = 513
% WM_RBUTTONDOWN = 516
% WM_LBUTTONUP   = 514
% WM_RBUTTONUP   = 517
% WM_MBUTTONUP   = 520

% WS_OVERLAPPEDWINDOW = 0x00CF0000
% WS_SYSMENU     = 0x80000
% WS_OVERLAPPED  = WS_SYSMENU     
% WS_POPUP       = 0x80000000
% WS_DLGFRAME    = 0x400000
% WS_VISIBLE     = 0x10000000
'defines...
Def WHITE_BRUSH   0
Def BLACK_BRUSH   4



'declarations...
Declare Function MessageBox Lib "kernel32.dll" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Declare Function LoadIcon Lib "user32.dll" Alias "LoadIconA" (ByVal hInstance As Long, ByVal lpIconName As Any) As Long
Declare Function LoadCursor Lib "user32.dll" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Any) As Long
Declare Function GetModuleHandle Lib "kernel32.dll" Alias "GetModuleHandleA" (sys lpModuleName) as Long
Declare Function RegisterClassEx Lib "user32.dll" Alias "RegisterClassExA" (WNDCLASSEX *lpwcx) as Long
'Declare Function RegisterClass Lib "user32.dll" Alias "RegisterClassA" (byref lpwcx as WNDCLASS) as Long
Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (byval dwExStyle AS INT,byval lpClassName AS STRING,byval lpWindowName AS STRING,byval dwStyle AS INT,byval x AS INT,byval y AS INT,byval nWidth AS INT,byval nHeight AS INT,byval hWndParent AS INT,byval hMenu AS INT,byval hInstance AS INT,byval lpParam AS INT) as Long
Declare Function TranslateMessage Lib "user32.dll" (byref lpMsg as Long) as Long
Declare Function DispatchMessage  Lib "user32.dll" Alias "DispatchMessageA" (byref lpMsg as Long) as Long
Declare Function GetMessage Lib "user32.dll" Alias "GetMessageA" (byval lpMsg As MSG, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Declare Function ShowWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function DefWindowProc Lib "user32.dll" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Sub PostQuitMessage Lib "user32.dll" (ByVal nExitCode As Long)

Dim wcx as WNDCLASSEX
Dim wm as MSG

'FILL WNDCLASSEX structure
inst = GetModuleHandle 0
wcx.cbSize       = sizeOf(WNDCLASSEX)
wcx.style         = CS_DBLCLKS Or CS_OWNDC
wcx.lpfnWndProc   = &WndProc
wcx.cbClsExtra    = 0
wcx.cbWndExtra    = 0
wcx.hInstance     = inst
wcx.hIcon         = LoadIcon 0,IDI_WINLOGO         
wcx.hCursor       = LoadCursor 0,IDC_ARROW 
wcx.hbrBackground = WHITE_BRUSH     
wcx.lpszMenuName  = ?0
wcx.lpszClassName = strptr"Oxygen"
wcx.hIconSm       = LoadIcon 0,IDI_APPLICATION

'register window class Ex
RegisterClassEx wcx

'create window -------------------------------
Dim hwnd,style, Wx, Wy, Ww, Wh, wparent as Long
Dim caption as String
'-------------------------------
caption = "MyWindow"
style   = WS_OVERLAPPEDWINDOW
Wx=0 : Wy=0 : Ww=640 : Wh=480
wparent = 0 'HWND_DESKTOP
'-------------------------------
Hwnd = CreateWindowEx 0, wcx.lpszClassName, caption, style, Wx, Wy, Ww, Wh, wparent, 0, inst, byval 0
ShowWindow Hwnd,SW_NORMAL
'-------------------------------
'message loop
WHILE GetMessage(wm,0,0,0) <> 0
     TranslateMessage wm
     DispatchMessage  wm
WEND

'main callback procedure ---------------------------------------
Function WndProc (sys hwnd,wMsg,wParam,lParam) as sys callback
Select wMsg
CASE WM_DESTROY
      PostQuitMessage 0
End Select
Return DefWindowProc(Hwnd,wMsg,wParam,lParam)

End Function
'------------------------------------------

Charles Pegge

  • Guest
Re: RegisterClass ?
« Reply #12 on: February 08, 2014, 03:08:36 PM »
I found one of the O2 examples specifically demos RegisterClassEx. It works with MinWin.inc

/examples/RegisterClassEx.o2bas
Code: [Select]

  $ filename "t.exe"
  '#include "..\..\inc\RTL32.inc"
  #include "../../inc/MinWin.inc"
  s=error()
  '
  if s then
    print s
    end
  end if



  % ID_Timer            3000
  % Interval            100



  '==================
  'GLOBAL DEFINITIONS
  '==================


  sys inst,hdc
  sys xmax,ymax,r,idx,idy,xball,yball

  r =15 : idx =5 : idy=5 : xball=200 : yball=100  





  dim as rect crect 'for WndProc

  '--------------------------------------------------------------------------------------------------------------------------
  function WndProc (  byval hWnd as long,  byval wMsg as long, byval wParam as long,  byval lparam as long ) as long callback
  '==========================================================================================================================

    static as sys count=0, refreshes=0, hdc, keycode, charcode
    static as String txt
    static as PaintStruct Paintst
 
    '==========
    select wMsg
    '==========
        
      '--------------
      case WM_CREATE
      '=============

      hTimer = SetTimer hWnd, ID_Timer, 50, 0
      GetClientRect  hWnd,@cRect

      '--------------
      case WM_TIMER
      '=============

      InvalidateRect hwnd,@crect,1

      '--------------  
      case WM_DESTROY
      '===============
          
      KillTimer(hWnd,ID_TIMER)
      PostQuitMessage 0
        
      '------------
      case WM_PAINT
      '============

      'TEXT
      'http://msdn.microsoft.com/en-us/library/dd144821(v=VS.85).aspx

      'DRAWING AND PAINTING
      'http://msdn.microsoft.com/en-us/library/dd162760(v=VS.85).aspx


      hDC=BeginPaint hWnd,@Paintst
      GetClientRect  hWnd,@cRect
      'style
      '0x20 DT_SINGLELINE
      '0x04 DT_VCENTER
      '0x01 DT_CENTER
      '0x25

       SetBkColor   hdc,white
       SetTextColor hdc,blue
       '
       txt="Key Code 0x" hex(keycode) "     Char Code 0x" hex(charcode)
       '
       DrawText hDC,*txt,-1,@cRect,0x25
       EndPaint hWnd,@Paintst
       ValidateRect hwnd,@crect
        
      '-----------  
      case WM_CHAR
      '===========

      charcode=wparam

      '--------------  
      case WM_KEYDOWN
      '==============

        keycode=wParam : charcode=0

if wParam=27 then SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE


      '--------        
      case else
      '========
          
        function=DefWindowProc hWnd,wMsg,wParam,lParam
        
    end select

  end function ' WndProc


  '----------------------------------------------------------------------
  Function WinMain(sys inst, prevInst,zstring* cmdline, sys show) as long
  '======================================================================

  WNDCLASSEX wc
  MSG        wm
  string     ClassName="Demo", MenuName="Menu"

  sys hwnd, wwd, wht, wtx, wty, tax
  '
  wc.cbSize=sizeof WNDCLASSEX
  wc.style = CS_HREDRAW or CS_VREDRAW
  wc.lpfnWndProc = @WndProc
  wc.cbClsExtra =0
  wc.cbWndExtra =0    
  wc.hInstance =inst
  wc.hIcon=LoadIcon 0, IDI_APPLICATION
  wc.hCursor=LoadCursor 0,IDC_ARROW
  wc.hbrBackground = GetStockObject WHITE_BRUSH
  wc.lpszMenuName  = strptr MenuName
  wc.lpszClassName = strptr ClassName
  wc.hIconSm=0
  '
  a=RegisterClassEx (@wc)
  '
  Wwd = 340 : Wht = 160
  Tax = GetSystemMetrics SM_CXSCREEN
  Wtx = (Tax - Wwd) /2
  Tax = GetSystemMetrics SM_CYSCREEN
  Wty = (Tax - Wht) /2
 
  hwnd = CreateWindowEx 0,wc.lpszClassName,"OXYGEN BASIC",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
  ShowWindow hwnd,SW_SHOW
  UpdateWindow hwnd
  '
  sys bRet
  '
  do while bRet := GetMessage (@wm, 0, 0, 0)
    if bRet = -1 then
      'show an error message
      exit while
    else
      TranslateMessage @wm
      DispatchMessage @wm
    end if
  wend

  End Function


  '=========
  'MAIN CODE
  '=========
  
  dim cmdline as asciiz ptr,inst as long
  @cmdline=GetCommandLine
  inst=GetModuleHandle 0
  '
  'WINDOWS
  '-------
  '
  WinMain inst,0,cmdline,SW_NORMAL
  end



Code: [Select]
 type WNDCLASSEX
  int cbSize
  int Style
  sys lpfnwndproc
  int cbClsextra
  int cbWndExtra
  sys hInstance
  sys hIcon
  sys hCursor
  sys hbrBackground
  sys lpszMenuName
  sys lpszClassName
  sys hIconSm
  end type

PS:
TranslateMessage does not have an A or W specifier, unlike DispatchMessage
« Last Edit: February 08, 2014, 03:18:56 PM by Charles Pegge »

Aurel

  • Guest
Re: RegisterClass ?
« Reply #13 on: February 08, 2014, 03:52:17 PM »
Yes Charles
i see and i remove this A but program still just stuck in memory.
Ok i will study this code  ;)
Yes i do all changes but still just stuck.
and this example don't use Bind() method but use
extern Lib "user32.dll"
« Last Edit: February 08, 2014, 04:09:01 PM by Aurel »

Charles Pegge

  • Guest
Re: RegisterClass ?
« Reply #14 on: February 08, 2014, 04:04:27 PM »

Assign strings using strptr with these two:

  sys lpszMenuName
  sys lpszClassName

lpszClassName = strptr "Demo"