Click here to Skip to main content
15,919,500 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralOnSetFont Pin
Vancouver8-Nov-03 19:55
Vancouver8-Nov-03 19:55 
GeneralSharing MFC objects among threads... Pin
Suhail Yousaf2-Nov-03 19:16
Suhail Yousaf2-Nov-03 19:16 
GeneralFiles and folders Pin
Selevercin2-Nov-03 17:26
Selevercin2-Nov-03 17:26 
GeneralRe: Files and folders Pin
Michael Dunn2-Nov-03 20:04
sitebuilderMichael Dunn2-Nov-03 20:04 
Generaladding a cbutton to a custom control Pin
mindows2-Nov-03 17:11
mindows2-Nov-03 17:11 
GeneralRe: adding a cbutton to a custom control Pin
Antti Keskinen2-Nov-03 23:03
Antti Keskinen2-Nov-03 23:03 
GeneralRe: adding a cbutton to a custom control Pin
mindows3-Nov-03 11:54
mindows3-Nov-03 11:54 
GeneralRe: adding a cbutton to a custom control Pin
Antti Keskinen5-Nov-03 1:44
Antti Keskinen5-Nov-03 1:44 
Well, I made a small miscalculation in my first reply. To explain it a bit, let's dive into the way stuff is handled in Windows.

You might already know (and if you didn't, now you do) that everything in Windows are windows. Sounds like an idiodome, but it is the fact. For example, our notorious button control is a WINDOW placed OVER a portion of parent view's area (custom control's client area).

So, you need to remake the original Create call to actually include the WS_VISIBLE style for the button. Now, after you have created the button, issue a SetWindowPos, placing the button window AFTER the control's view (first parameter to 'this'), and flagging it to SWP_HIDEWINDOW. You can ignore the size and position parameters by putting the necessary flags in the call (SWP_NOSIZE | SWP_NOMOVE, I think).

Now, when you need to show the button on your control, call it's ShowWindow with SW_SHOW flag. Note, that this call should only be made in a function which is not repeatedly called.

To clarify, consider the hiearchy we have created now. There is the custom control. It has a view. You can draw into this view (device context), displaying lines, texts, rectangles, everything you need to make it look cool. Then, you place new small window objects to represent different types of controls (Edit control, button control, hell, even a static control is a window).

This hiearchy understanding is especially relevant if you use custom-skinned windows (Common trait in custom control creation). Those could have a background image, with black rectangular holes where the controls will be. Then, they might have custom-drawn controls like bitmapped buttons, to fill those holes and fit seamlessly into the control's view.

For the code part you posted: remove the m_button1.SetWindowPos call from the WM_PAINT handler. Instead, hide it in the creation phase, and move this creation to the OnCreate-handler INSTEAD of OnCreateClient, if it is currently there.
The OnCreate-handler is called when the window representing your custom control is created. That is correct, we want to create and hide the button control when the window is being created. The OnCreateClient -handler (which is called to create the VIEW inside the window) can then display the control, if you want it to be visible as soon as the control window is shown. Remember to call the display function as the last thing in OnCreateClient, after everything else is drawn.

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
QuestionHow to manage objects unknown at run-time Pin
Steve Messer2-Nov-03 16:42
Steve Messer2-Nov-03 16:42 
AnswerRe: How to manage objects unknown at run-time Pin
Christian Graus2-Nov-03 17:08
protectorChristian Graus2-Nov-03 17:08 
GeneralRe: How to manage objects unknown at run-time Pin
Steve Messer2-Nov-03 21:26
Steve Messer2-Nov-03 21:26 
GeneralRe: How to manage objects unknown at run-time Pin
Christian Graus3-Nov-03 9:07
protectorChristian Graus3-Nov-03 9:07 
GeneralRe: How to manage objects unknown at run-time Pin
Steve Messer3-Nov-03 10:23
Steve Messer3-Nov-03 10:23 
GeneralRe: How to manage objects unknown at run-time Pin
Steve S3-Nov-03 23:02
Steve S3-Nov-03 23:02 
GeneralFloat window in MDI application Pin
novachen2-Nov-03 16:35
novachen2-Nov-03 16:35 
QuestionHow can I put my window under any other application window? Pin
golden06062-Nov-03 16:24
golden06062-Nov-03 16:24 
GeneralText in the taskbar vs. title bar Pin
Vancouver2-Nov-03 15:21
Vancouver2-Nov-03 15:21 
GeneralFoundation Problem, #include Problem Pin
Mehran Ziadloo2-Nov-03 15:12
Mehran Ziadloo2-Nov-03 15:12 
GeneralRe: Foundation Problem, #include Problem Pin
ZoogieZork2-Nov-03 15:21
ZoogieZork2-Nov-03 15:21 
GeneralRe: Foundation Problem, #include Problem Pin
Christian Graus2-Nov-03 15:22
protectorChristian Graus2-Nov-03 15:22 
GeneralProblem with CAsyncSocket Pin
Daniel13242-Nov-03 14:30
Daniel13242-Nov-03 14:30 
GeneralHelp with file management... Pin
Snyp2-Nov-03 14:18
Snyp2-Nov-03 14:18 
GeneralRe: Help with file management... Pin
Ravi Bhavnani2-Nov-03 15:03
professionalRavi Bhavnani2-Nov-03 15:03 
GeneralRe: Help with file management... Pin
Christian Graus2-Nov-03 15:21
protectorChristian Graus2-Nov-03 15:21 
GeneralPlease help me Pin
golden06062-Nov-03 14:03
golden06062-Nov-03 14:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.