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.