Add a horizontal line (separator) in form

Just starting out? Need help? Post your questions and find answers here.
neomember
User
User
Posts: 14
Joined: Tue Jul 27, 2004 12:17 am

Add a horizontal line (separator) in form

Post 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!!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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
Last edited by netmaestro on Thu May 25, 2006 7:39 pm, edited 1 time in total.
BERESHEIT
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post 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.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post 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
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Post 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
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

I know but on most controls it's very persistant, therefore i better be safe than sorry :)
neomember
User
User
Posts: 14
Joined: Tue Jul 27, 2004 12:17 am

Post 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!
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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:
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post 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.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

pretty neat xombie, but your code is very big, whilst my macro.. :wink:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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
BERESHEIT
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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.
Last edited by josku_x on Fri May 26, 2006 10:53 pm, edited 1 time in total.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply