Page 1 of 2

Add a horizontal line (separator) in form

Posted: Thu May 25, 2006 2:35 am
by neomember
I need a way to add horizontal lines to forms. I would like to do this with Win32 API calls, if possible.

Thanks in advance!!

Posted: Thu May 25, 2006 4:00 am
by netmaestro
It's not API, but of course you're working with PB, right?

Code: Select all

OpenWindow(0,0,0,640,480,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget) 
CreateGadgetList(WindowID(0)) 
CreateImage(0,1280,2)
StartDrawing(ImageOutput(0))
  Box(0,0,1280,1,$A0A0A0)
  Box(0,1,1280,1,#White)
StopDrawing()
ImageGadget(0,0,240,640,2,ImageID(0)) 
DisableGadget(0,1) 

Repeat 
  ev = WaitWindowEvent() 
  Select ev 
    Case #PB_Event_SizeWindow 
      ResizeGadget(0,0,WindowHeight(0)/2,WindowWidth(0),2) 
  EndSelect 
Until ev = #PB_Event_CloseWindow

Posted: Thu May 25, 2006 10:35 am
by josku_x
I think neomember wants to have a horizontal bar like <HR> in HTML pages, right? In this case, my code is better and maybe faster (Creating a image with 1280 width takes a lot memory)

Code: Select all

If OpenWindow(0, 0, 0, 640, 480, "Horizontal Bar", #PB_Window_SystemMenu|#PB_Window_SizeGadget|1) 
 If CreateGadgetList(WindowID(0))
  ContainerGadget(0, 0, 0, 0, 0, #PB_Container_Single)
  CloseGadgetList()
 EndIf
 Repeat 
  Event=WaitWindowEvent() 
  If Event=#PB_Event_SizeWindow 
   ResizeGadget(0, 0, WindowHeight(0)/2, WindowWidth(0), 2)
  EndIf
 Until Event=#PB_Event_CloseWindow
EndIf

Posted: Thu May 25, 2006 10:41 am
by Edwin Knoppert
Here is a control :)

CreateWindowEx_( 0, "Static", "Label1", #WS_CHILD | #WS_VISIBLE | #SS_NOTIFY | #SS_LEFT | #SS_REALSIZEIMAGE | #SS_ETCHEDHORZ, 56, 72, 169, 2, hWnd, 100, hInst, 0 )

I renamed a few constants, fix it for Purebasic.

Posted: Thu May 25, 2006 10:46 am
by josku_x
@Edwin: you don't need all those constants, I made a Macro, which should simplify things a bit:

Code: Select all

Macro HorizontalBarGadget(Window, x, y, Width)
 CreateWindowEx_(0, "Static", "", #WS_CHILD|#WS_VISIBLE|#SS_ETCHEDHORZ, x, y, Width, 2, WindowID(Window), 0, GetModuleHandle_(0), 0)
EndMacro

Posted: Thu May 25, 2006 12:09 pm
by Edwin Knoppert
Thanks, works fine.

PBDev users create module and dump the macro in that.
After lines: (In Main module)

; Obtain window id, we use it during the loop.
MainID = PBD_GetWindowId( hWndMain )

HorizontalBarGadget(MainID, 20, 100, 100)

Or better, forget the macro and use a custom control (toolsbox) and set:
Classname property to: STATIC
WindowStyle: SS_ETCHEDHORZ
Appearance to: none

Posted: Thu May 25, 2006 3:22 pm
by blueb
Edwin this works like a charm :)

Having the Appearance switch set to it's default doesn't
matter, the WindowStyle criteria seems to dominate.


--blueb

Posted: Thu May 25, 2006 3:41 pm
by Edwin Knoppert
I know but on most controls it's very persistant, therefore i better be safe than sorry :)

Posted: Thu May 25, 2006 10:40 pm
by neomember
All good solutions... thanks everybody!

I'm trying to learn programming through multiple languages. I like the API calls better because you can use it in almost every languages. It gives me a better understanding of how Windows works. I think that creating your own GUI using pure Win32 API in C/C++ is a good challenge for a beginner.

I'm pretty impressed by how easily you can create GUIs in Purebasic and without affecting the executable size also.

Do PB has it's own GUI library? Looks like an API wrapper to me.

I would like to write myself a wrapper for C/C++. It looks simple but it supposed to be a tedious task.

Maybe someday!!!

I'm using D-LIB also... i think it's pretty impressive!! Too bad the development stopped :?
It doesn't need much more.

BCX is good too... for learning!

Thanks again!

Posted: Fri May 26, 2006 6:51 am
by josku_x
Learning the Win32 API whilst you are a beginner isn't a very good idea. You should first learn the basics of programming like structures, interfaces, prototypes and so on. And to learn programming for multiple languages isn't also a very good idea. Perhaps an expert would do stuff like that, but you said yourself that you are a beginner.

About the PB GUI (Gadgets) library, It's not an API wrapper, Fred has made his custom gadgets too, and yes, for example an EditorGadget is RichEdit20A, but the PB commands are mostly cross-platform, so mostly the same GUI is compatible with Linux and MacOS X too; if you'd use API, you could use your GUI only in window$

And to create a wrapper for c/c++ is really a hard task.

And BTW: compare the executable sizes if you use API commands instead of the PB ones in creating a simple GUI. You'll see that the API one is more than 45% bigger in size. Also, most of the PB's functions are cross-platform, so don't forget that. :wink:

Posted: Fri May 26, 2006 10:32 pm
by Xombie
There's also my code here...

http://www.purebasic.fr/english/viewtopic.php?t=18332

...that'll give you some different options on drawing on a window.

Posted: Fri May 26, 2006 10:37 pm
by josku_x
pretty neat xombie, but your code is very big, whilst my macro.. :wink:

Posted: Fri May 26, 2006 10:49 pm
by netmaestro
but your code is very big, whilst my macro..
...isn't very useful as a macro in its present form. In order to make it a usable tool it needs to be a procedure that returns the handle of the created window, else you can't do anything with it. Here's a procedure version that allows for resizing the window, etc:

Code: Select all

Procedure HorizontalBarGadget(Window, x, y, Width) 
 hwnd = CreateWindowEx_(0, "Static", "", #WS_CHILD|#WS_VISIBLE|#SS_ETCHEDHORZ, x, y, Width, 2, WindowID(Window), 0, GetModuleHandle_(0), 0) 
 ProcedureReturn hwnd
EndProcedure

OpenWindow(0,0,0,640,480,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget) 

horizline = horizontalbargadget(0,0,240,640)

Repeat 
  ev = WaitWindowEvent() 
  Select ev 
    Case #PB_Event_SizeWindow 
      SetWindowPos_(horizline,0,0,WindowHeight(0)/2,WindowWidth(0)+1,2,#SWP_NOZORDER)
  EndSelect 
Until ev = #PB_Event_CloseWindow

Posted: Fri May 26, 2006 10:53 pm
by josku_x
netmaestro wrote:
but your code is very big, whilst my macro..
...isn't very useful as a macro in its present form. In order to make it a usable tool it needs to be a procedure that returns the handle of the created window, else you can't do anything with it. Here's a procedure version that allows for resizing the window, etc:

Code: Select all

Procedure HorizontalBarGadget(Window, x, y, Width) 
 hwnd = CreateWindowEx_(0, "Static", "", #WS_CHILD|#WS_VISIBLE|#SS_ETCHEDHORZ, x, y, Width, 2, WindowID(Window), 0, GetModuleHandle_(0), 0) 
 ProcedureReturn hwnd
EndProcedure

OpenWindow(0,0,0,640,480,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget) 

horizline = horizontalbargadget(0,0,240,640)

Repeat 
  ev = WaitWindowEvent() 
  Select ev 
    Case #PB_Event_SizeWindow 
      SetWindowPos_(horizline,0,0,WindowHeight(0)/2,WindowWidth(0)+1,2,#SWP_NOZORDER)
  EndSelect 
Until ev = #PB_Event_CloseWindow
My macro works as expected, as it's replaced with the CreateWindowEx_ line which returns the hWnd.

Posted: Fri May 26, 2006 10:53 pm
by ts-soft