Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get m_hWnd in CDialog

259 views
Skip to first unread message

mircowhat

unread,
Oct 27, 2009, 4:03:01 PM10/27/09
to
I need to access to the CDialog main class window handle in the OnInit
function.

I've tried just accessing m_hWnd. Doesnt work.

Also tried, HWND myHwnd=AfxGetMainWnd()->GetSafeHwnd();

Reason is i need a CWnd *; so i can call
SetWindowPos(&pWnd->wndTopMost,x,....); to change the Z-order of a
CbitmapButton.

Any help or ideas is appreciated.

Stephen Myers

unread,
Oct 27, 2009, 4:47:44 PM10/27/09
to
If by OnInit you mean OnInitDialog I suspect that you are trying to
access m_hWnd before calling CDialog::OnInitDialog().

Calling the base class is critical and creates the needed windows objects.

HTH
Steve

mircowhat

unread,
Oct 27, 2009, 6:13:01 PM10/27/09
to

> .
>

Yes im trying to do this in,

BOOL MyDiagClassDlg::OnInitDialog(){
CDialog::OnInitDialog();

//other initializations

CBitmapButton mybtn;
mybtn.create(...........);
//heres where i want to call
mybtn.SetWindowPos(.....);

}

I'm not sure if your last sentence was a statement or instructions.
I've tried just about every combination i can think of to get m_hWnd of the
dialog window. Could you please elaborate?

Thanks.

David Lowndes

unread,
Oct 27, 2009, 7:00:20 PM10/27/09
to
>> > I've tried just accessing m_hWnd. Doesnt work.

Steve,

What exactly does "doesn't work" mean? It doesn't compile, or doesn't
give your desired result?
What precisely is the code you've tried?

>I'm not sure if your last sentence was a statement or instructions.
>I've tried just about every combination i can think of to get m_hWnd of the
>dialog window.

From inside a method of your dialog, you can just use m_hWnd to get
the dialog's window handle - but if you're using SetWindowPos to alter
the Z-order of controls you don't want the dialog's window handle
anyway.

Dave

Tom Serface

unread,
Oct 27, 2009, 7:09:53 PM10/27/09
to
Why do you need m_hWnd of the dialog to call SetWindowPos()? That should
all be built in.

Another method would be just to always create the button on the dialog and
just show or hide it as you decide you need it. I found that to be a lot
easier than dynamically creating controls.

Also, remember to return FALSE from OnInitDialog() if you change the focus
of the controls.

Tom

"mircowhat" <mirc...@discussions.microsoft.com> wrote in message
news:B6BA959D-8235-4F1C...@microsoft.com...

David Lowndes

unread,
Oct 27, 2009, 7:34:38 PM10/27/09
to
>Steve,

Sorry, I meant it to the original poster, not Steve :)

Dave

Ajay Kalra

unread,
Oct 27, 2009, 7:50:52 PM10/27/09
to
On Oct 27, 6:13 pm, mircowhat <mircow...@discussions.microsoft.com>
wrote:

> Yes im trying to do this in,
>
> BOOL MyDiagClassDlg::OnInitDialog(){
>         CDialog::OnInitDialog();
>
>        //other initializations
>
>        CBitmapButton mybtn;
>        mybtn.create(...........);
>        //heres where i want to call
>       mybtn.SetWindowPos(.....);
>
> }
>
> I'm not sure if your last sentence was a statement or instructions.
> I've tried just about every combination i can think of to get m_hWnd of the
> dialog window.  

You dont need m_hWnd to call SetWindowPos on your button.
CWnd::SetWindowPos doesnt need the handle. ::SetWindowPos needs it.
Also note that your CBitmapButton is local to your method and is
destroyed as soon it exits the method.

--
Ajay

Tom Serface

unread,
Oct 27, 2009, 11:03:59 PM10/27/09
to
I almost did that too :o)

Tom

"David Lowndes" <Dav...@example.invalid> wrote in message
news:7r0fe59a7j61patk3...@4ax.com...

Tom Serface

unread,
Oct 27, 2009, 11:05:12 PM10/27/09
to
This is a really good point. OP's code isn't going to work even if they get
it to do what they want in that routine. OP should move the CBitmapButton
into the dialog class .h file as a member so it can live the life of the
dialog.

Nice catch.

Tom

"Ajay Kalra" <ajay...@yahoo.com> wrote in message
news:d8b422b0-b707-45bf...@k19g2000yqc.googlegroups.com...

Stephen Myers

unread,
Oct 28, 2009, 9:29:41 AM10/28/09
to

Dave,

I had that figured out. No problem.

Besides, I needed a "Huh?" this morning.

Steve

mircowhat

unread,
Oct 28, 2009, 10:58:01 AM10/28/09
to

"Tom Serface" wrote:

///////////////////

I need the m_hWnd so i cant use this,
CWnd *pWnd = CWnd::FromHandle(m_hWnd);

So i can call

bitmabpbutton.SetWindowPos(&pWnd->wndTopMost,x,y,20,20,0);

Reason i need to do this is because the z-order is off.

On my dialog i have
BitmapBackground(z-order=1)->BitmapButton(z-order=2)->Bitmabutton(z-order=3)
(Everything is stacked on top of each other). The last button is the top
button and is movable via mouse while everything else is static. When i
launch the dialog, if the last button(Coords x,y) is over the background and
you try dragging it over the second button it works fine and always draws on
top of the second button and you are able to release(unclick) and click it
again while over the second button without any issues. If i move the last
button via movewindow to the second buttons client area , the last button
draws underneath the second and once you release it the only way you are able
to click it again is by click a area of the last button the is exposed from
underneath the second button. The whole point of this, is a dual
bitmapbutton slider control with a bitmap slider bar. This is my last issue.
I have to be able to move the last button over the second with movewindow so
i can place the indicators at a value of the bar.

Does changing the actual z-Order set the focus? Didn't think i did.

////////////////////////////////////


"David Lowndes" wrote:

> >> > I've tried just accessing m_hWnd. Doesnt work.
>

> Steve,
>
> What exactly does "doesn't work" mean? It doesn't compile, or doesn't
> give your desired result?
> What precisely is the code you've tried?
>

> >I'm not sure if your last sentence was a statement or instructions.
> >I've tried just about every combination i can think of to get m_hWnd of the
> >dialog window.
>

> From inside a method of your dialog, you can just use m_hWnd to get
> the dialog's window handle - but if you're using SetWindowPos to alter
> the Z-order of controls you don't want the dialog's window handle
> anyway.
>
> Dave

> .
>

///////////
m_hWnd=NULL; when i step through.

See above explanation in reply to Tom.
////////////////////////////


"Ajay Kalra" wrote:

> On Oct 27, 6:13 pm, mircowhat <mircow...@discussions.microsoft.com>
> wrote:
>

> > Yes im trying to do this in,
> >
> > BOOL MyDiagClassDlg::OnInitDialog(){
> > CDialog::OnInitDialog();
> >
> > //other initializations
> >
> > CBitmapButton mybtn;
> > mybtn.create(...........);
> > //heres where i want to call
> > mybtn.SetWindowPos(.....);
> >
> > }
> >
> > I'm not sure if your last sentence was a statement or instructions.
> > I've tried just about every combination i can think of to get m_hWnd of the
> > dialog window.
>

> You dont need m_hWnd to call SetWindowPos on your button.
> CWnd::SetWindowPos doesnt need the handle. ::SetWindowPos needs it.
> Also note that your CBitmapButton is local to your method and is
> destroyed as soon it exits the method.
>
> --
> Ajay

> .
>


/////////
See above explanation in reply to Tom.

Sorry, CBitmapButton is declared in the dialog classes header file.

//////////////////////////////


So once again, how do i get the m_hWnd in,

BOOL MyDiagClassDlg::OnInitDialog(){
> > CDialog::OnInitDialog();

///HERE

}

Thanks.

mircowhat

unread,
Oct 28, 2009, 11:01:01 AM10/28/09
to
See top first reply to Toms post for the new post. Hate how this thing
orders post. Should have replied to the last.

Scott McPhillips [MVP]

unread,
Oct 28, 2009, 11:36:29 AM10/28/09
to
"mircowhat" <mirc...@discussions.microsoft.com> wrote in message
news:A468BF48-3296-4931...@microsoft.com...

>
> I need the m_hWnd so i cant use this,
> CWnd *pWnd = CWnd::FromHandle(m_hWnd);
>
> So i can call
>
> bitmabpbutton.SetWindowPos(&pWnd->wndTopMost,x,y,20,20,0);
>
> Reason i need to do this is because the z-order is off.


This is all wrong.

The first statement does nothing except retrieve the 'this' pointer, which
you alreay have. (And don't need!)

The second statement should be bitmabpbutton.SetWindowPos(&wndTopMost, ....
and it probably needs some flags in the last parameter.

--
Scott McPhillips [VC++ MVP]

Tom Serface

unread,
Oct 28, 2009, 4:51:50 PM10/28/09
to
You could just "this" for the dialog window, but I don't think you need even
though to do what you're trying to do.

Tom

"mircowhat" <mirc...@discussions.microsoft.com> wrote in message

news:A468BF48-3296-4931...@microsoft.com...

microwhat

unread,
Oct 28, 2009, 6:16:12 PM10/28/09
to

"Scott McPhillips [MVP]" wrote:

> .
>

Thanks Scott,
That worked. Although SetWindowPos doesn't seem to do what i need it to.
Searched around and seems like other people have had the same problem with it
not working very well.


Tom, For what i'm doing, that doesn't work.


Thanks for the help.


Tom Serface

unread,
Oct 28, 2009, 6:30:16 PM10/28/09
to
What about the idea of just creating the button on the dialog by default and
showing or hiding it as needed. You can easily set it to top using the
ctrl+D functionality.

You can create a regular button control then change it to a CBitmapButton
after it is created in the .h file.

Would that simplify it some?

Tom

"microwhat" <micr...@discussions.microsoft.com> wrote in message
news:9CF57186-60AB-43C2...@microsoft.com...

Joseph M. Newcomer

unread,
Oct 28, 2009, 7:07:45 PM10/28/09
to
See below...

****
...and when you leave the scope of OnInitDialog, you will find that the button is
destroyed.

(a) why are you creating this button dynamically? Why not create it at design time?
(b) the button variable must be a member variable of the class
(c) what does SetWindowPos have to do with the m_hWnd; it is a child control and
it would make no sense to make a child control have a different Z-order relative
to the parent window. And I have no idea why you would have used
hwndTopMost, since you would never want a child control to be the topmost
window in the system.

You have not explained what you want to do; you have shown code that makes no sense, used
terms that make no sense, done something (dynamic button creation) of questionable sense,
and at no point have you said what you are trying to accomplish!
joe

****


>
>}
>
>I'm not sure if your last sentence was a statement or instructions.
>I've tried just about every combination i can think of to get m_hWnd of the
>dialog window. Could you please elaborate?
>
>Thanks.

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer

unread,
Oct 28, 2009, 7:12:05 PM10/28/09
to
This makes no sense. See below...

*****
You could have written
CWnd * pWnd = this;
but I cannot imagine why you would think either of these statements could possibly make
sense.
****


>
>So i can call
>
>bitmabpbutton.SetWindowPos(&pWnd->wndTopMost,x,y,20,20,0);

****
So why do you choose random numbers for your button size? How did you choose x and y
(another random number generator?)

wndTopMost is a static class member and the above code is nonsensical. And you would not
make a child control "topmost" in the Z-order
****

>
>Reason i need to do this is because the z-order is off.

****
Whatever is wrong with it, this will not fix it, nor is it vaguely close to fixing it!
****


>
>On my dialog i have
>BitmapBackground(z-order=1)->BitmapButton(z-order=2)->Bitmabutton(z-order=3)
>(Everything is stacked on top of each other). The last button is the top
>button and is movable via mouse while everything else is static. When i
>launch the dialog, if the last button(Coords x,y) is over the background and
>you try dragging it over the second button it works fine and always draws on
>top of the second button and you are able to release(unclick) and click it
>again while over the second button without any issues. If i move the last
>button via movewindow to the second buttons client area , the last button
>draws underneath the second and once you release it the only way you are able
>to click it again is by click a area of the last button the is exposed from
>underneath the second button. The whole point of this, is a dual
>bitmapbutton slider control with a bitmap slider bar. This is my last issue.
> I have to be able to move the last button over the second with movewindow so
>i can place the indicators at a value of the bar.

****
It is usually safe to assume that moving controls on top of each other is a mistake. But
assuming you do, the button you move to the top of the Z-order needs to be set to the top
of the Z-order, and the above code is not even close to accomplishing that.
****

Joseph M. Newcomer

unread,
Oct 29, 2009, 9:38:02 AM10/29/09
to
See below...

***
Actually, SetWindowPos works perfectly. I've done all kinds of things using it, and
never, ever had a problem. On the other hand, I have probably used it in accordance with
its documentation. If it doesn't work "very well", it is being used incorrectly. The
easiest fix for this is to use it correctly,
joe
****


>
>
>Tom, For what i'm doing, that doesn't work.
>
>
>Thanks for the help.
>

microwhat

unread,
Oct 29, 2009, 9:39:01 AM10/29/09
to

"Tom Serface" wrote:

> What about the idea of just creating the button on the dialog by default and
> showing or hiding it as needed. You can easily set it to top using the
> ctrl+D functionality.

//////////////////
The buttons are already added as a control from resource manager. The Tab
order is set correctly. Their is no hiding or showing, i need these controls
on the screen at the same time.
////////////////////////////


>
> You can create a regular button control then change it to a CBitmapButton
> after it is created in the .h file.
>

///////
Already doing this.
I'll be going of more things in my reply to Joseph.
//////////////////

microwhat

unread,
Oct 29, 2009, 10:56:11 AM10/29/09
to

"Joseph M. Newcomer" wrote:

> This makes no sense. See below...
> On Wed, 28 Oct 2009 07:58:01 -0700, mircowhat <mirc...@discussions.microsoft.com> wrote:

> >///////////////////
> >
> >I need the m_hWnd so i cant use this,
> >CWnd *pWnd = CWnd::FromHandle(m_hWnd);
> *****
> You could have written
> CWnd * pWnd = this;
> but I cannot imagine why you would think either of these statements could possibly make
> sense.
> ****

///////////////////
Still learning, many examples i found said to do it this way.

///////////////////////////////


> >
> >So i can call
> >
> >bitmabpbutton.SetWindowPos(&pWnd->wndTopMost,x,y,20,20,0);
> ****
> So why do you choose random numbers for your button size? How did you choose x and y
> (another random number generator?)

///////
They are specific variables in my app. Didn't think post 800,500 vs 200,400
made a difference with the issue i'm having. And the fact that they are
variables and i don't have them right in front of me makes that kinda
irrelevant. The buttons are all within my applications dialog. I changed the
dimension to the exact pixels yesterday while trying to further debug it.
The reason it's 20,20 is a lot of buttons call SizeToContent(). I didn't
start this project, but it helps sometimes as this applications load 1000's
of different images.
/////////////////


>
> wndTopMost is a static class member and the above code is nonsensical. And you would not
> make a child control "topmost" in the Z-order
> ****

////
It seemed to work partially. On initial start up the button would be
visibly under the one it should be on top of, but when you tried clicking it,
it would activate it and the it would appear visibly on top and it would not
fall visibly under the other control anymore after that. But outside that,
it wasn't working.
///////////////

//////

All of the buttons i'm working with are created in the dialog through
resource manager.

In, OnInitDialog() I call,

ButtonBase.Create(_T("btnbase"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,CRect(varx,vary,20,20),this, IDC_BBASE);
ButtonBase.LoadBitmapFF(String here);
ButtonBase.SizeToContent();

Button1.Create(_T("btn1"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,CRect(var1x,var1y,59,62),this, IDC_SETL);
Button1.LoadBitmapFF(String here);

Button2.Create(_T("btn2"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,CRect(var2x,var2y,59,62),this, IDC_SETH);
Button2.LoadBitmapFF(String here);


This is basically what i have, Their is 30 of the base buttons(ButtonBase)
making a solid bar about 800 pixels long. Button1&2 are the position
indicators.

Event though i have the Tab order set in the dialog through the resource
manager, calling create in a different order seems to change the z-order.
Loading them in the order show above should give me the correct z-order. The
position indicators are set to stop 100 pixels from each other so them
overlapping will never be a issue(Not the actual reason for the limit though).


Currently if i set the x,y's of both Button1&2 outside of the
ButtonBase's(BB) RECT area on startup, and i click one of the position
buttons(PB) and drag it over the BB, it stays on top visibly and the z-order
stays on top(IE. I can click anywhere in the PB rect and control it
properly). If i start up with the PB x,y's over the BB, the PB draws behind
the BB and you can only gain control of the PB by click a small portion of
the PB the stick out from underneath the BB(PB is Slightly taller than BB).
If i call,
Buttton1.SetWindowPos(&wndTopMost,var1x,var1y,59,62,0);
right after Button1.Create(). The PB will still draw underneath the BB, but
if i click anywhere in the PB RECT it draw on top of BB and i can control
it(I dont have to click on the small area exposed from underneath BB). And
when i unclick PB it stays on top of BB. So using SetWindowPos works
partially. I would just need it to be draw on top with out any interaction
from the user. I've tried countless different combination of
redraw/invalidate functions to do this with no luck.

Going back now to assuming i'm not calling SetWindowPos. If i try calling
MoveWindow(into the BB rect) in OnInitDialog right after all the buttons are
created and loaded(At x,y's outside of the BB rect). The PB draws underneath
the BB. And you have to click the small exposed part of PB to bring it to the
front. Once you do that it works fine. I'm looking at alternative way to
call MoveWindow once the application start up. But nothing seem promising.


It their some voodoo function for changing the z-order? The only functions i
could find that where suggested to be capable where SetWindowPos &
SetWindowPlacement. Obviously neither worked.

Thanks.

/////////////////////////////

> Joseph M. Newcomer [MVP]
> email: newc...@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm

> .
>

Scott McPhillips [MVP]

unread,
Oct 29, 2009, 11:58:02 AM10/29/09
to
"microwhat" <micr...@discussions.microsoft.com> wrote in message
news:E0F99DBF-62F2-4F4B...@microsoft.com...

> All of the buttons i'm working with are created in the dialog through
> resource manager.
>
> In, OnInitDialog() I call,
>
> ButtonBase.Create(_T("btnbase"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,CRect(varx,vary,20,20),this,
> IDC_BBASE);
> ButtonBase.LoadBitmapFF(String here);
> ButtonBase.SizeToContent();
>
> Button1.Create(_T("btn1"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,CRect(var1x,var1y,59,62),this,
> IDC_SETL);
> Button1.LoadBitmapFF(String here);
>
> Button2.Create(_T("btn2"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,CRect(var2x,var2y,59,62),this,
> IDC_SETH);
> Button2.LoadBitmapFF(String here);
>
>
> This is basically what i have, Their is 30 of the base buttons(ButtonBase)
> making a solid bar about 800 pixels long. Button1&2 are the position
> indicators.
>
> Event though i have the Tab order set in the dialog through the resource
> manager, calling create in a different order seems to change the z-order.


You seem to have a big misunderstanding here. If the buttons are created
through the resource editor then they will appear when the dialog is
displayed, with no code needed. By calling Create you are creating
additional buttons. The z-order that you set in the resource editor is
irrelevant for these redundant buttons.

microwhat

unread,
Oct 29, 2009, 12:58:06 PM10/29/09
to

"Scott McPhillips [MVP]" wrote:

> .
>

The buttons created in the resource editor have their "Visible" state set to
false. The Create() function is using the resource ID as a way of binding
the two together, so the button presses are handled by the original function
for the button created in the resource editor. I don't know why it was do
this way as i didn't start this project. All i know is it has been working
perfectly fine. I think the saying, "Don't fix it if it's not broke",
applies. My purpose is not go go around changing little discrepancies . If
that was my task. I would have to just start from scratch and it would take
months to have something even close to what has been created.

Joseph M. Newcomer

unread,
Oct 29, 2009, 9:15:13 PM10/29/09
to
See below...

On Thu, 29 Oct 2009 07:56:11 -0700, microwhat <micr...@discussions.microsoft.com> wrote:

>
>
>"Joseph M. Newcomer" wrote:
>
>> This makes no sense. See below...
>> On Wed, 28 Oct 2009 07:58:01 -0700, mircowhat <mirc...@discussions.microsoft.com> wrote:
>
>> >///////////////////
>> >
>> >I need the m_hWnd so i cant use this,
>> >CWnd *pWnd = CWnd::FromHandle(m_hWnd);
>> *****
>> You could have written
>> CWnd * pWnd = this;
>> but I cannot imagine why you would think either of these statements could possibly make
>> sense.
>> ****
>///////////////////
>Still learning, many examples i found said to do it this way.

****
I would suggest that the site that shows this as a meaningful example is completely wrong
and should be ignored
****


>
>///////////////////////////////
>> >
>> >So i can call
>> >
>> >bitmabpbutton.SetWindowPos(&pWnd->wndTopMost,x,y,20,20,0);
>> ****
>> So why do you choose random numbers for your button size? How did you choose x and y
>> (another random number generator?)
>
>///////
>They are specific variables in my app. Didn't think post 800,500 vs 200,400
>made a difference with the issue i'm having. And the fact that they are
>variables and i don't have them right in front of me makes that kinda
>irrelevant. The buttons are all within my applications dialog. I changed the
>dimension to the exact pixels yesterday while trying to further debug it.
>The reason it's 20,20 is a lot of buttons call SizeToContent(). I didn't
>start this project, but it helps sometimes as this applications load 1000's
>of different images.

****
Key here is that if you show code, we have to assume that the code we see is the code you
are using. You can say
20, 20 // example values; actually computed in pixels
// based on actual button sizes

Note that buttons can have different sizes based on the screen resolution, etc., and even
SizeToContent does not guarantee that 20, 20 would ever be a meaningful value. Absolute
values in coordinates are always deeply suspect.
****


>/////////////////
>>
>> wndTopMost is a static class member and the above code is nonsensical. And you would not
>> make a child control "topmost" in the Z-order
>> ****
>////
>It seemed to work partially. On initial start up the button would be
>visibly under the one it should be on top of, but when you tried clicking it,
>it would activate it and the it would appear visibly on top and it would not
>fall visibly under the other control anymore after that. But outside that,
>it wasn't working.

****
"Work partially" seems to be equivalent to "doesn't work". Note that it is always an
error to have two active controls laying one on top of the other; the controls below must
always be disabled, and it is even better if you make them totally invisible. There are
consequences to failing to adhere to this rule, which are usually manifested by questions
that start "The following does not appear to work correctly..."
****

****
So why do you need to create one?
****


>
>In, OnInitDialog() I call,
>
>ButtonBase.Create(_T("btnbase"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,CRect(varx,vary,20,20),this, IDC_BBASE);

****
This contradicts the staement that "All of the buttons I'm working with are created in the
dialog through resource manager"

If they are created in the resource manager, you do not need to do a Create in
OnInitDialog. If you are doing a Create in OnInitDialog, then you can't make the staement
that the buttons are created in the resource editor.

So which statement is true?
****


>ButtonBase.LoadBitmapFF(String here);
>ButtonBase.SizeToContent();
>
>Button1.Create(_T("btn1"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,CRect(var1x,var1y,59,62),this, IDC_SETL);
>Button1.LoadBitmapFF(String here);

****
If the button is ownerdraw, is there any value to giving it a text caption? Why not NULL
for the text?
****


>
>Button2.Create(_T("btn2"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,CRect(var2x,var2y,59,62),this, IDC_SETH);
>Button2.LoadBitmapFF(String here);
>
>
>This is basically what i have, Their is 30 of the base buttons(ButtonBase)
>making a solid bar about 800 pixels long. Button1&2 are the position
>indicators.
>
>Event though i have the Tab order set in the dialog through the resource
>manager, calling create in a different order seems to change the z-order.
>Loading them in the order show above should give me the correct z-order. The
>position indicators are set to stop 100 pixels from each other so them
>overlapping will never be a issue(Not the actual reason for the limit though).

****
But you shouldn't be doing a Create! The buttons, by your own description, already exist.
So they are already created. You are creating duplicates!

What version of VS are you using? Note that VS6 had a problem with Z-order in that it was
inverted from the actual tab order.
****


>
>
>Currently if i set the x,y's of both Button1&2 outside of the
>ButtonBase's(BB) RECT area on startup, and i click one of the position
>buttons(PB) and drag it over the BB, it stays on top visibly and the z-order
>stays on top(IE. I can click anywhere in the PB rect and control it
>properly). If i start up with the PB x,y's over the BB, the PB draws behind
>the BB and you can only gain control of the PB by click a small portion of
>the PB the stick out from underneath the BB(PB is Slightly taller than BB).

****
See previous comment about which version of VS you are using.
****
>If i call,
>Buttton1.SetWindowPos(&wndTopMost,var1x,var1y,59,62,0);
****
Not clear how you arrived at the meaningless random numbers 59,62. They are going to be
resolution-dependent positions. No matter where you find them on your machine, you have
to assume that any other machine in the known universe will potentially have them at some
other location.
****


>right after Button1.Create(). The PB will still draw underneath the BB, but
>if i click anywhere in the PB RECT it draw on top of BB and i can control
>it(I dont have to click on the small area exposed from underneath BB). And
>when i unclick PB it stays on top of BB. So using SetWindowPos works
>partially. I would just need it to be draw on top with out any interaction
>from the user. I've tried countless different combination of
>redraw/invalidate functions to do this with no luck.

****
It is generally considered that it is always a mistake to have two overlapping controls,
particularly if the lower-Z-order are still active and/or visible.
****


>
>Going back now to assuming i'm not calling SetWindowPos. If i try calling
>MoveWindow(into the BB rect) in OnInitDialog right after all the buttons are
>created and loaded(At x,y's outside of the BB rect). The PB draws underneath
>the BB. And you have to click the small exposed part of PB to bring it to the
>front. Once you do that it works fine. I'm looking at alternative way to
>call MoveWindow once the application start up. But nothing seem promising.

****
MoveWindow will not change Z-order; MoveWindow only controls position on the screen. And
you should assume that it is always a mistake to have overlapping controls.
****


>
>
>It their some voodoo function for changing the z-order? The only functions i
>could find that where suggested to be capable where SetWindowPos &
>SetWindowPlacement. Obviously neither worked.

****
SetWindowPos works, but only if you use it correctly. hwndTop is almost certainly the
wrong value to use. Therefore, you are using it incorrectly.

I do not understand why you are moving buttons you create on top of buttons that already
exist. If you have a button, you have a button; you don't need to create a new one. Then
the Z-order is going to be based on the order you lay it out with, except for the fact
that VS6 gets it backwards (as did all versions of VS prior to VS.NET)
joe
****

Joseph M. Newcomer

unread,
Oct 29, 2009, 9:26:37 PM10/29/09
to
See below...

****
This is wrong.
****


>The Create() function is using the resource ID as a way of binding
>the two together, so the button presses are handled by the original function
>for the button created in the resource editor.

****
This simply doesn't make sense! You have a button! Why do you need to do this weird
re-creation? Get rid of this whole idea!
****


>I don't know why it was do
>this way as i didn't start this project.

****
I would then suggest it was done this way because the original programmer is what is
technically referred to as "totally clueless". The code is wrong. Rip it out and ignore
it.
****


>All i know is it has been working
>perfectly fine.

****
Obviously, it hasn't been working "perfectly fine", except possibly by accident.
****


>I think the saying, "Don't fix it if it's not broke",
>applies. My purpose is not go go around changing little discrepancies .

****
(a) it is broke. Or you wouldn't be asking these questions
(b) it is not a "little discrepancy". Not to put too fine a point on it, it is a
completely ridiculous design, which primarily seems to illustrate a total cluelessness of
the original programmer.
****


>If
>that was my task. I would have to just start from scratch and it would take
>months to have something even close to what has been created.

****
Eliminating meaningless Create operations and unnecessary SetWindowPos calls constitutes
"starting from scratch"? I fail to see what needs to be done "from scratch" here. You
use the DDX_Control mechanism ("Add variable") to bind the *visible* buttons to the
variables, and then you can load the bitmaps and resize content to your heart's content.
So what you would be doing here is eliminating dysfunctional code. That's pretty far from
starting "from scratch".

Values like 20,20 and 59,62 are random numbers which are essentially meaningless and
completely unreliable. So that code is definitely "broke" also, you just haven't noticed
it yet.

You are arguing that a piece of code that demonstrably does not work is "not broke" and
that the cost of eliminating erroneous code is so high that it will take months to repair.
It probably would take less time to fix than the amount of time invested in this thread
discussion.

Use ClassWizard to bind the buttons to their variables (probably the most significant
piece of cluelessness going on here).

It appears that the correct code would be

ButtonBase.LoadBitmapFF(String here);
ButtonBase.SizeToContent();

Button1.LoadBitmapFF(String here);
Button2.LoadBitmapFF(String here);
joe
****

0 new messages