May 04, 2024, 05:49:40 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Window handle

Started by Bruce Peaslee, December 16, 2005, 11:28:07 AM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

Bruce Peaslee

It may be because I'm still struggling a little with OOPÂÃ,  ;) , but I've having trouble passing the window handle to the MessageBox function. I want to give a message if the user clicks a menu item that is not yet implemented. It works fine if I put zero, but I want the box to stay in front until cleared by the user.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Zen

Ha ha i had that problem.

if you are calling you MessageBox from within your class. ie your OnDestroy() method. You can do the following MessageBox(this,"Goodbye","Destroy");

But if you are running the messagebox from within your main subroutine then use the name of your class variable.

mywindow win;
messagebox(win,"Hello","Test");

Hope this is what you are after.
Lewis

Bruce Peaslee

Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Zen

Your welcome. Iasked the same thing a few days ago. Ive never done OOP apart from in PHP which is a lot different apart from i understand how it is meant to work.

So i guess we are in the same boat here. :D Hey did anyone ever tell you, you look a lot like bruce willis? ::)

Lewis

Parker

PHP is interpreted, so they're free to do it however they want. I would use lists and descriptors of arguments to do that in an interpreted language, but it's done very differently in a compiler. Well, in the end the way its handled is different.

Bruce Peaslee

New question.

"This" worked when I used it in MessageBox, but now I want to use another method, WriteText, in myWindow::OnSize.


this.WriteText(10,10,"Whatever");


fails. So does


winMain.WriteText(10,10,"Whatever");
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Parker

"this" is a pointer. Messagebox probably expects a window pointer, so it works there. But you need to do this:

*this.something();

Hopefully Paul will add the -> operator, then we can do this->something();.

Zen

Because it is in a class method. Just call WriteText(...); without a prefix as it will automaticly do it for the class the method is within.

If it was not in a class then you would call classVar.WriteText(...);

Lewis

Parker

You can use either method. The way of calling with the this pointer is more explicit and shows more what you're trying to do, but either way works fine.

Zen

Yes i remember when i was doing Java at university we got told to use the this operator because it was good programming practise and it helps other developers to know what you are doing with your code.

Lewis

Bruce Peaslee

Thanks guys.

Here is the snippet of the code I am playing with. It recenters the string "Skeleton" when the window is resized.


myWindow::OnSize(int nType, int cx, int cy), int
{
def clientRect as rect;
def textSize as point;
def x,y as int;

SetWindowColor(GetSysColor(15)); // also clears screen
SetFont("Comic Sans MS",10,800);
FrontPen(RGB(0,0,0));
BackPen(GetSysColor(15));
textSize = GetTextSize("Skeleton");
clientRect = GetClientRect();
x = (clientRect.right - clientRect.left - textSize.x)/2; // to center text
y = 10;
WriteText(x,y,"Skeleton");
Return 0;
}


It gave me a little problem until I realized that OnSize was being called when the window first appears.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Parker

Just a sidenote, Lewis - look in profile settings, avatars, actors, Bruce Willis, you'll see the same picture as peaslee has, so I don't think it's a personal picture  ;)

Bruce Peaslee

Quote from: Parker on December 16, 2005, 02:43:10 PM
Just a sidenote, Lewis - look in profile settings, avatars, actors, Bruce Willis, you'll see the same picture as peaslee has, so I don't think it's a personal pictureÂÃ,  ;)

I think he gotcha, Parker.ÂÃ,  ;)
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Zen

Quote from: Parker on December 16, 2005, 02:43:10 PM
Just a sidenote, Lewis - look in profile settings, avatars, actors, Bruce Willis, you'll see the same picture as peaslee has, so I don't think it's a personal picture  ;)

He He. Just a joke.

Lewis

Parker

Oh, okay then :) I guess I didn't get it. Lewis, has anyone told you how much you look like a cube  ::)

Zen

He He. Im sorry if you didnt catch on. It must of been my british humor :D

Lewis