Page 1 of 1

API Window and GDI question

Posted: Tue May 10, 2005 11:43 pm
by va!n
i taked a look to some api sources and i try to create a window using API only! Atm i have following source...

Code: Select all


Procedure WindowCallback(Window, Message, wParam, lParam) 
  Select Message 
      Case #WM_CLOSE 
        DestroyWindow_(Window) 
        Result  = 0 
      Case #WM_DESTROY 
        PostQuitMessage_(0) 
        Result  = 0 
      Default 
        Result  = DefWindowProc_(Window, Message, wParam, lParam) 
  EndSelect 
  ProcedureReturn Result 
EndProcedure 

#Style  =   #WS_EX_TOPMOST|#PB_Window_BorderLess
#StyleEx  = #WS_EX_TOOLWINDOW   

;--------------


WindowClass.s  = "Test" 
wc.WNDCLASSEX 
wc\cbSize  = SizeOf(WNDCLASSEX) 
wc\lpfnWndProc  = @WindowCallback() 
wc\hCursor  = LoadCursor_(0, #IDC_CROSS) 
wc\hbrBackground  = CreateSolidBrush_($0) 
wc\lpszClassName  = @WindowClass 
RegisterClassEx_(@wc) 

;--------------

lWindowWidth  = 400
lWindowHeight = 300

hWnd  = CreateWindowEx_(#StyleEx, WindowClass, "", #Style, 0, 0, lWindowWidth, lWindowHeight, 0, 0, 0, 0) 

UpdateWindow_(hWnd) 
ShowWindow_(hWnd,#SW_SHOWNORMAL) 
SetForegroundWindow_(hWnd)  

While GetMessage_(msg.MSG, 0, 0, 0 ) 
  TranslateMessage_(msg) 
  DispatchMessage_(msg) 
Wend
Hope there is no problem!? Whats the real Win32 API name of #PB_Window_BorderLess ? How can i draw a box and text with GDI (again API only) on this window?

Posted: Wed May 11, 2005 12:39 am
by El_Choni
Hi, try this:

Code: Select all

Global rc.RECT, hBrush, text$
rc\left = 40
rc\right = 400-40
rc\top = 40
rc\bottom = 300-40

hBrush = CreateSolidBrush_($ff0000)
text$ = "Hi, va!n ;)"

Procedure WindowCallback(Window, Message, wParam, lParam)
  Select Message
      Case #WM_CLOSE
        DestroyWindow_(Window)
      Case #WM_DESTROY
        PostQuitMessage_(0)
      Case #WM_PAINT
        BeginPaint_(Window, @ps.PAINTSTRUCT)
        FillRect_(ps\hdc, @rc, hBrush)
        SetTextColor_(ps\hdc, $ffffff)
        SetBkMode_(ps\hdc, #TRANSPARENT)
        DrawText_(ps\hdc, text$, Len(text$), @rc, #DT_CENTER|#DT_VCENTER|#DT_SINGLELINE)
        EndPaint_(Window, @ps)
      Default
        Result  = DefWindowProc_(Window, Message, wParam, lParam)
  EndSelect
  ProcedureReturn Result
EndProcedure

#Style  =   #WS_EX_TOPMOST|#PB_Window_BorderLess
#StyleEx  = #WS_EX_TOOLWINDOW   

;--------------


WindowClass.s  = "Test"
wc.WNDCLASSEX
wc\cbSize  = SizeOf(WNDCLASSEX)
wc\lpfnWndProc  = @WindowCallback()
wc\hCursor  = LoadCursor_(0, #IDC_CROSS)
wc\hbrBackground  = CreateSolidBrush_($0)
wc\lpszClassName  = @WindowClass
RegisterClassEx_(@wc)

;--------------

lWindowWidth  = 400
lWindowHeight = 300

hWnd  = CreateWindowEx_(#StyleEx, WindowClass, "", #Style, 0, 0, lWindowWidth, lWindowHeight, 0, 0, 0, 0)

UpdateWindow_(hWnd)
ShowWindow_(hWnd,#SW_SHOWNORMAL)
SetForegroundWindow_(hWnd) 

While GetMessage_(msg.MSG, 0, 0, 0 )
  TranslateMessage_(msg)
  DispatchMessage_(msg)
Wend 

Posted: Wed May 11, 2005 7:34 pm
by va!n
ah cool, thanks el_choni ;)
how can i set the x,y position of a text like locate? ;)