Thread: custom control from scratch

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    108

    custom control from scratch

    Well, I guess it's a bit harder than registering a window class with no styles and making a window procedure for it..

    I tried to make a plain, new window class, but I ultimately had to fill in the default message handling with DefWindowProc(), since if i leaveit out, it crashes. So, I tried to figure out what I need to cover from DefWindowProc, but to no avail..

    I was under a hunch that DefWindowProc is the thing that made the window draggable (has a title bar), etc. I was actually trying to make a control that is not draggable (think edit controls, richedits, buttons), but yeah, i think it's the DefWindowProc..

    or am I missing something so painstakingly obvious?
    (thanks in advance)

    edit: sorry I just found the answer, you just need to set the style to WS_CHILD, I cant believe I missed it :-)

    in which I come to the second question : how many windows (count them by the amount of HWND's) exist in applications like notepad, wordpad, msword, text editors like xemacs and vim etc? 0-10, 10-100, 100-1000, .. ? Im just curious of the performance overhead of hwnds..
    Last edited by underthesun; 01-17-2005 at 11:46 PM.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Use WinSpy++. Select a top level window and it will give you a list of child windows. Notepad has two child windows, an edit control and a status bar.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    108
    thanks, really appreciated

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>you just need to set the style to WS_CHILD

    ensure when you use the WS_CHILD you set the HMENU to an int ID number, (diff for each child of any given parent).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    108
    Oh, what is the need for the HMENU thing? I happen to be putting it to 0 all the time in my wrapper..

    also, I was thinking, is having too many windows (aka hwnd's) bad? say in the number of 100s or similar to that (of course not over 1000).

    I'm just a bit curious

  6. #6
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Oh, what is the need for the HMENU thing?
    For child windows the HMENU parameter is actually the child window ID, something that should be unique for each child window.

    also, I was thinking, is having too many windows (aka hwnd's) bad?
    What exactly are you getting at? In windows everything in all actuality is a window of some sort of window from the bigger control classes like the edit control right down to command buttons and icons. You should structure your program to use resources wisely so as to not overload the system but that is just basic programming guidance I am sure you know already.
    Last edited by andyhunter; 01-18-2005 at 07:21 PM.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    108
    Ah thanks. The thing is, currently I'm designing my wrapper library (so as not to have to register window class etc etc) and am trying to make them generic enough for general use.

    Now, in this wrapper, at the rate that it is going right now, hwnd's will be used a lot, and everything including menu elements will be made from hwnds. In short, an application like notepad (which im trying to make for testing) will contain so many hwnds (potentially reaching 30's), that it worries me. Especially that programs like windows explorer contains only something like 8 windows (including childs), after I checked using winspy++. But I could be wrong.

    At any rate, what is the real purpose of the ID thing? I seem to have been able to make 2 child windows using the same ID, NULL. You're talking about the 3rd last argument from CreateWindowEx right?

    edit: just got my answer from the win32 help file, its for parent notification i guess.
    Last edited by underthesun; 01-18-2005 at 08:30 PM.

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>its for parent notification i guess.

    Look at the data returned in a WM_COMMAND, WM_NOTIFY ect message.

    Easier to find window from ID (than HWND).

    This is because a window may be created and destroyed multiple times, each time getting a different HWND.

    >>hwnd's will be used a lot,

    because you don't use ID numbers?

    >>will contain so many hwnds (potentially reaching 30's), that it worries me.

    I think the limit is 32,000 odd (treeviews can contain a max of 32K items)
    I don't track HWNDs but many of my apps have 100+ controls spread over a dozen or so windows.
    Last edited by novacain; 01-19-2005 at 12:23 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    108
    >> I think the limit is 32,000 odd (treeviews can contain a max of 32K items)
    >> I don't track HWNDs but many of my apps have 100+ controls spread over a dozen or so windows.

    That's the answer I was looking for . Thanks a lot

    also, what I mean with "hwnd's will be used a lot", I mean that there will be lots of "hwnd" made, but after that there won't be much messing around with it.

    cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Superclassed edit control; custom notifications
    By Boksha in forum Windows Programming
    Replies: 2
    Last Post: 12-16-2006, 03:21 PM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. Custom Control
    By X PaYnE X in forum Windows Programming
    Replies: 24
    Last Post: 03-03-2005, 11:47 AM
  4. Custom control information
    By Mithoric in forum Windows Programming
    Replies: 6
    Last Post: 03-02-2004, 06:52 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM