Hello,
I am attempting to make a new window with the CreateWindowEx call. After working on this for a few weeks I have created much spaghetti code ( ) and am stuck on the RegisterClassEx(wc) command.
Here is the code that has been put together. If anyone has a nicer example, then than would be good.
There is no returned value from RegisterClassEx and Xojo crashes before MyGetLastError is called.
[code] Declare Function GetModuleHandle Lib “kernel32” Alias “GetModuleHandleA” (ByVal lpModuleName As Integer) As Integer
Declare Function LoadIcon Lib “user32” Alias “LoadIconA” (ByVal hInstance As Integer, ByVal lpIconName As Integer) As Integer
Declare Function LoadCursor Lib “user32” Alias “LoadCursorA” (ByVal hInstance As Integer, ByVal lpCursorName As Integer) As Integer
Declare Function GetStockObject Lib “gdi32” (ByVal fnObject As Integer) As Integer
Declare Function RegisterClassEx Lib “user32” Alias “RegisterClassExA” (lpwcx As WNDCLASSEX) As Integer
Declare Function CreateWindowEx Lib “user32” Alias “CreateWindowExA” (ByVal dwExStyle As Integer, ByVal lpClassName As CString, ByVal lpWindowName As CString, ByVal dwStyle As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hWndParent As Integer, ByVal hMenu As Integer, ByVal hInstance As Integer, lpParam As WNDCLASSEX) As Integer
Declare Function ShowWindow Lib “user32” (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
Declare Function UpdateWindow Lib “user32” (ByVal lhwnd As Integer) As Integer
Declare Sub PostQuitMessage Lib “user32” (ByVal nExitCode As Integer)
Declare Function DefWindowProc Lib “user32” Alias “DefWindowProcA” (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Declare Function TextOut Lib “gdi32” Alias “TextOutA” (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer, ByVal lpString As CString, ByVal nCount As Integer) As Integer
Declare Function RegisterWindowMessage Lib “user32” Alias “RegisterWindowMessageA” (lpString As CString) As Integer
Declare Function RegisterClassExA Lib “user32” (ByRef pcWndClassEx As WNDCLASSEX) As Integer
Declare Function SendMessage Lib “user32” Alias “SendMessageA” (hwnd As Integer, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer
Declare Function GetLastError lib “kernel32” () as Integer
Declare Function DestroyWindow Lib “user32” (ByVal hwnd As Integer) As Integer
Const WS_CHILD = &H40000000
Const CW_USEDEFAULT = &H80000000
Const SW_NORMAL = 1
Const WS_EX_STATICEDGE = &H20000
Const WS_EX_TRANSPARENT = &H20
Const IDI_APPLICATION = 32512
Const IDC_ARROW = 32512
Const WS_SYSMENU = &H80000
Const WS_OVERLAPPED = &H0
Const WC_SYSTRAY As String = “Shell_TrayWnd”
Dim mWnd As Integer
Dim MyClassName as CString
MyClassName = “MyWindowsClass”
Dim MyWndProc as Ptr
Dim wc as WNDCLASSEX
wc.cbSize = 48
wc.style = 0
wc.lpfnWndProc = MyWndProc
wc.cbClsExtra = 0
wc.cbWndExtra = 0
wc.hInstance = InstanceHandle
wc.hIcon = LoadIcon(0, IDI_APPLICATION)
wc.hCursor = LoadCursor(0, IDC_ARROW)
wc.hbrBackground = 0
wc.lpszMenuName = “test”
wc.lpszClassName = WC_SYSTRAY
wc.hIconSm = LoadIcon(0, IDI_APPLICATION)
Dim AValue as integer
AValue = RegisterClassEx(wc)//Error occurs here
MsgBox "AValue = " + CStr(AValue)
Call MyGetLastError
Dim MyCString as CString
MyCString = “test”
'Create a new label
mWnd = CreateWindowEx(0 , MyCString, MyCString, WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, 240,120,0,0,InstanceHandle, wc)
[/code]
Here is the download link to the example project: New Window.xojo_binary_project
Thanks for your help.