Creating a custom control from scratch

Just starting out? Need help? Post your questions and find answers here.
r_hyde
Enthusiast
Enthusiast
Posts: 155
Joined: Wed Jul 05, 2006 12:40 am

Post by r_hyde »

DARKGirl
Try this out:

Code: Select all

Procedure MyWindowCallback(hWnd, message, wParam, lParam) 
  Select message 
    Case #WM_RBUTTONUP
      Debug "right button up!"
  EndSelect 
  
  Result = DefWindowProc_(hWnd, message, wParam, lParam)
  ProcedureReturn Result 
EndProcedure 

PV.WNDCLASSEX ;PV = PropertyViewer 
PVClass.s = "PViewer" 


PV\cbSize = SizeOf(PV) 
PV\style = #CS_HREDRAW | #CS_VREDRAW 
PV\lpfnWndProc = @MyWindowCallback() 
PV\cbClsExtra = 0 
PV\cbWndExtra = 0 
PV\hInstance = hInstance 
PV\hIcon = LoadIcon_(NULL, IDI_APPLICATION) 
PV\hCursor = LoadCursor_(NULL, IDC_ARROW) 
PV\hbrBackground = GetStockObject_( #WHITE_BRUSH) 
PV\lpszMenuName = 0 
PV\lpszClassName = @PVClass 
PV\hIconSm = 0 

RegisterClassEx_(@PV) 
hwnd = CreateWindowEx_(0, "PViewer", "sample", #WS_OVERLAPPEDWINDOW, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #Null, #Null, GetModuleHandle_(0), #Null) 
ShowWindow_(hwnd, 1) 
;UpdateWindow_(hwnd) 

ret.b = GetMessage_(@msg, hwnd, 0, 0 )
While msg <> 0
  If ret = -1
    Debug "error!"
  Else
    TranslateMessage_(@msg)
    DispatchMessage_(@msg)
  EndIf
  ret = GetMessage_(@msg, hwnd, 0, 0 )
Wend
(I switched to CreateWindowEx_() because I'm more used to it
DARKGirl
User
User
Posts: 61
Joined: Wed Nov 10, 2004 10:32 pm

Post by DARKGirl »

omg I fixed my own code!


r_hyde: huh, I didnt even know you posted a comment. I have managed to successfully register my very own class and create a window and attach it to a parent window. I gave it a general #WS_EX_Clientedge so I know theres something there
DARKGirl
User
User
Posts: 61
Joined: Wed Nov 10, 2004 10:32 pm

Post by DARKGirl »

here's what I have so far:

Code: Select all


Structure General
  hwnd.l
  GadgetID.l
  Positon.l
  PropertyName.s
  ToolTip.s
  state.b ;Is this field enabled or Disabled?
EndStructure

Structure TextField
  Common.General
  String.s
  type.l ;Theres Numerical, General, Password
EndStructure

Structure CheckBoxField
  Common.General
  CheckBoxState.b
EndStructure
  
Structure ColorPickerField
  Common.General
  Color.l ;This is the color value that is saved when the user chooses the color in the color picker.
 
EndStructure

Structure LinkedListStructure
  String.s
  Position.l
EndStructure

Global NewList PropertyGrid.LinkedListStructure()

Structure ComboBox
  Common.General
Propertygrid.l
EndStructure


TotalPropertyGrids.l
TotalPropertyFields.l

Procedure PropertyGridGadget(Gadget, x, y, Width, Height)
  
EndProcedure

Procedure AddBooleanField(PropertyName.s, Value.b, Position.b)
  
EndProcedure

Procedure AddColorPickerField(PropertyName.s, Value.b, Position.b)
  
EndProcedure
  
Procedure AddComboBoxField(PropertyName.s, Value.b, Position.b)
  
EndProcedure 

Procedure AddSpinField(PropertyName.s, MinValue.l, MaxValue.l, Position.b)
  
EndProcedure

Procedure AddTextField(PropertyName.s, Text.s, Position.b)
  
EndProcedure

Procedure AddCheckBoxFleild(PropertyName.s, state.b, Position.b)
  
EndProcedure

Procedure OpenPropertyGroup(GroupName.s)
  
EndProcedure

Procedure ClosePropertyGroup()
  
EndProcedure

Procedure GetPropertyFieldState(Position.b)
  
EndProcedure

Procedure SetPropertyFieldState(Position.b)
  
EndProcedure

Procedure GetPropertyFieldText(Position.b)
  
EndProcedure

Procedure SetPropertyFieldText(Position.b)
  
EndProcedure

Procedure OpenPropertyGroupFieldList(Gadget)
  
EndProcedure

Procedure ClosePropertyGroupFieldList(Gadget)
  
EndProcedure


Procedure PVCallback(hwnd, message, wParam, lParam)
  Select message
    
    Case #WM_NCCREATE
      
    Case #WM_NCDESTROY
      
    Case #WM_ERASEBKGND
      ProcedureReturn 1
      
    Case #WM_LBUTTONDOWN
      
    Case #WM_RBUTTONDOWN
      
    Case #WM_SETFONT
      
    Case #WM_PAINT 
      
      
  EndSelect
   
  Debug message 
  ProcedureReturn DefWindowProc_(hwnd, message, wParam, lParam)
EndProcedure
I sort of need some help setting up all the structures and whatnot because its all confusing to me. Any help is appreciated
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

DARKGirl, I'm currently working on a PropertyViewer just like the one you are requesting. It's almost done, but it lacks proper scrolling. It's not based on any existing controls, so completey written from scratch. "Unfortuneatly" I'm flying to spain tomorrow for 10 days and will not be able to finish it. But when I'm back I will post the whole source in the forum.

Laters! 8)
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
DARKGirl
User
User
Posts: 61
Joined: Wed Nov 10, 2004 10:32 pm

Post by DARKGirl »

Hey well thats cool. My goal is to have my control mimic the .Net control.
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

I'm looking forward... :wink:
Windows 7 & PureBasic 4.4
DARKGirl
User
User
Posts: 61
Joined: Wed Nov 10, 2004 10:32 pm

Post by DARKGirl »

ok, I have some good news, the more and more I work on this project, the more and more I understand it. I would like this control to work with many of the existing PB functions, as I have said before.

How do I get it to work with CreateGadgetList()? I assume this sets some sort of variable for the Parent hwnd of the CreateWindowEx function. If I cannot get it to work with CreateGadgetList, I will just have to require the user to pass the parent window hwnd to the function, so the gadget will appear on the correct window!

I also had a slight problem with dynamically creating linked lists, because they are a MUST because you should be able to use this function to create as many PropertyGrid Gadgets as you want! I don't think people will be too happy if they can only create one per application...

Thanks to the code I found here: http://www.purebasic.fr/english/viewtop ... sc&start=0, it looks like I just might be able to do this. I haven't created the window drawing code yet, I am still working on the multiple instance of the control part. Remember when I say 'instance' I don't mean some crazy OOP nonsense. I only mean 'the ability to create multiple controls within an application'.
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Post by hallodri »

You can get the current window with PB_Object_GetThreadMemory.

Example :

Code: Select all

Structure PB_GadgetGlobals
  CurrentWindow.l
  ;[...]
EndStructure 

Import "Gadget.lib"
  PB_Object_GetThreadMemory(Globals)
  PB_Gadget_Globals
EndImport

Procedure StaticGadget(x.l,y.l,w.l,h.l,flags.l=0)
  Protected hWnd 
  Protected *Globals.PB_GadgetGlobals
  
  *Globals   = PB_Object_GetThreadMemory(PB_Gadget_Globals) 
  hWnd       = CreateWindowEx_(#WS_EX_STATICEDGE,"static","",#WS_CHILD|#WS_VISIBLE|flags,x,y,w,h,*Globals\CurrentWindow,0,0,0)
  
  ProcedureReturn hWnd
EndProcedure
  
  
hWnd = OpenWindow(0,#PB_Ignore,#PB_Ignore,200,200,"leer",#WS_OVERLAPPEDWINDOW)


CreateGadgetList(hWnd)
StaticGadget(10,10,100,100)

Repeat
	event = WaitWindowEvent()

Until event = #PB_Event_CloseWindow  

For more info see in PB sdk directory.
DARKGirl
User
User
Posts: 61
Joined: Wed Nov 10, 2004 10:32 pm

Post by DARKGirl »

Blah, that is a bit too confusing for me, I think I will just keep it simple and require the user to pass the window they want it to be added to.

My second question, is that how do I throw a compiler exception when the user tries to create a gadget with an existing gadget ID? Sure I can scratch something together and make a messagebox popup, and end the application, but that would be no fun.

My Third Question, what would be the best way to draw to a window? I am ready to write the code for the #WM_Paint message, but not sure of the 'proper' way to do it.
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

Any news?
Windows 7 & PureBasic 4.4
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Hehe, I dropped the project because of other things I had to do. But it's almost done. I try to finish my version soon and post it here. Maybe over the weekend.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

Now you made me impatient :twisted:
No, I'm really looking forward...
Windows 7 & PureBasic 4.4
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Oh noooz! Pressure! :shock:

PS: Seriously, I finish this! :D :roll:
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Fluid Byte: Any luck with this yet?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Ok, enuff excuses... :roll:

I'll sit on my butt today! :!:
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Post Reply