Archived

This topic is now archived and is closed to further replies.

ELS1

Custom Control Questions...

Recommended Posts

ever since ive started programming, ive been interested in GUI''s. ive created some custom buttons using the win32api, but each time i create a new program, i have to copy/paste all the code, which can get VERY tedious. i want to create a library or class of custom controls so i wont have to deal with this anymore. i could just define them something like this: HWND control1 = create_controlFLAT(hwnd_parent, color, size) , etc, and make them handle like regular buttons and process window msgs. the custom control will still call CreateWindow using the bs_owner flag. this is where my dilema is. instead of writing the code in the WM_MOUSEDOWN event which changes the appearance of the buttons (like when you press down on a button), how can it be handled seemlessly so you wont have to write the ''change appearance'' code in there? well, these are just some of my questions, as i am going to attempt to write some custom control libraries for myself... any help or point into the right direction is appreciated

Share this post


Link to post
Share on other sites
first, consider removing those special createstuff() functions at all. instead, only provide a register() function that will register all appropriate window classes, and let the clients create windows with createwindow() as they wish. the advantage of this method is that it fits nicely into existing code.

you probably want to provide a wndproc() for each of your classes that does enough to provide a sensible default look and feel, as well as handle all settings via windows messages, like the standard controls do. then, you can customize the appearance and behavior of controls by subclassing them, and calling the original wndproc when default handing is desired.

Share this post


Link to post
Share on other sites
Continuing with the current theme of custom controls WndProc(), do you have any suggestions on how to best include the callback function?

Making WndProc static and part of the class hampers flexiblity while placing the WndProc outside of the class means rewriting it every time.

(I have read other threads here dealing with this exact subject but I thought new ideas can never hurt)

Share this post


Link to post
Share on other sites
quote:
Original post by AceroSBU
Making WndProc static and part of the class hampers flexiblity while placing the WndProc outside of the class means rewriting it every time.


global wndprocs certainly don''t need to be rewritten for any reason at all. making them nonstatic class members makes your code cleaner and probably easier to reuse, but that is not a requirement for reusable code at all. For nonstatic wndprocs, see http://www.gamedev.net/community/forums/topic.asp?topic_id=106874; otherwise, please clarify your question.

Share this post


Link to post
Share on other sites