Hello DaniWeb. I'm new to this site and will just have to say some words before asking my question. I'm Loyen and I am 14 years old and lives in Sweden. I've just started on an upper secondary school about IT and there I'm going one class that's called "programming" there we're learning the basics in Pascal.

Now, I'm really interested in this, and just wanted to know, how do I do a basic popup window that just gives you a message? Can I make one that has no buttons just a clean window without any "minimazers, closers" and all?

Write it here. :)

Thank you all for your time and hopefully somebody knows how to do a basic popup window.

//Loyen

Loyen,

Are you using Delphi for this class?

If so, there are several ways to go about doing this, although I would suggest having at least an "OK" button for closing the pop-up window.

One approach, in Delphi, would be to use a MessageDlg.

MessageDlg('Test with no buttons',mtInformation,[],0);

A question for you to consider is, if you create a pop-up window

that has no buttons just a clean window without any "minimazers, closers" and all

, how do you plan to close the window and exit the program?

I didn't plan to close it. ^^
through taskbar if I wanted some time though. :P

No, we don't use delphi. We are just using Pascal. :/

Which Pascal are you using?

Regrettably, it has been far too many years since I worked in base-level Pascal. Sorry.

Also, it really depends on the implimentation of Pascal (i.e. the compiler) with which you are working.

I work with the free Pascal version. (1.9.2)

OK, FP is very compatible with Delphi.

Add the Dialogs unit to your uses clause. The procedure that fits your requirement best is the first in this list:

procedure ShowMessage( const msg: string );
function MessageDlg( const msg: string; dlgType: tMsgDlgType; buttons: tMsgDlgButtons; helpctx: longint ): word;
function MessageDlgPos( ... x, y: integer ): word; //same args as MessageDlg
function InputBox( const aCaption, aPrompt, aDefault: string ): string;
function InputQuery( const aCaption, aPrompt: string; var value: string ): boolean;

The ShowMessage function just displays your message with a little OK button.
The MessageDlg displays a message with the desired icon and buttons.
The InputBox and InputQuery functions get a string from the user. The latter returns false if the user canceled.

type TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);

type TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mnNoToAll, mbYesToAll, mbHelp);

return values for MessageDlg:
mrNone mrAbort mrYes mrOk mrRetry mrNo mrCancel mrIgnore mrAll

If none of those work for you, create a new form that does what you want and set its border style to bsDialog. Display the form using the ShowModal function. Close the form and return a value by setting its ModalResult.

Good luck.

Now.. How do I make it work and where should I write the message? xD.. don't really know cause we have pretty much just worked with console programs..

If you use the
<code>
function MessageDlg( const msg: string; dlgType: tMsgDlgType; buttons: tMsgDlgButtons; helpctx: longint ): word;
</code>
approach and you do NOT want any buttons (which is still a most curious concept), you would write something like:
<code>
MessageDlg('your message goes here', mtInformation,[],0);
</code>
wherever you want it in your project and then, when that line is executed, it will pop up the message box.

Got this error?
J:\Pascal program\Message programs\Popup1\Popup.pas:5: parse error before `Begin'
J:\Pascal program\Message programs\Popup1\Popup.pas:7: module/unit `code' could not be compiled


Noticed that my program isn't free pascal.. it's called "Dev-Pascal" or something like that.. hmm..

You've made a syntax error somewhere. Please post your code.

program WindowsApp;
Uses
Messages, Windows

Begin

<code>
function MessageDlg( const msg: string; dlgType: tMsgDlgType; buttons: tMsgDlgButtons; helpctx: longint ): word;
</code>
approach and you do NOT want any buttons (which is still a most curious concept), you would write something like:
<code>
MessageDlg('your message goes here', mtInformation,[],0);
</code>
END.

You need to read up on how to use procedures and functions.
Here's a nice tutorial.

Also, to use the MessageDlg function, you will need to put the Dialogs unit in your uses clause.

Good luck.

Im not sure about FP but I know if they are compatible as Duaos mentioned... Then simply do something like:

Procedure TForm.FormCreate(Sender: TObject);
begin
label.caption := 'write what you want to here';
end;

Again, I dont know if that will work in FP. But if you can get that to work, then great! Then goto (if you have this) object inspector and remove anything you dont want there. click on the form itself first of course and then look for the minimize and close options in there.

I am probably way off base on what you need, but I am trying anyway. lol

That would work.

You would have to create a new form, and show it to display the message, and hide it to stop displaying the message. The trick is to let the user dismiss the form, which means responding to button presses or the [X] button or "Close" option of the window menu or if the user presses ENTER or ALT+F4. To do that stuff you'd have to display the form with showmodal, which I don't think you know enough to do easily.

If you are using Free Pascal and not the GNU Pascal (the Bloodshed Dev IDE works with both), then make sure you have the Dialogs unit in your uses clause: uses Windows, SysUtils, [B]Dialogs[/B], Messages; and to display a message use: showMessage( 'Hello world!' ); This displays a popup with the message and an OK button.

Or use: messageDlg( 'Hello world!', mtCustom, [], 0 ); to display the dialog without buttons. (I have never tried to show one without buttons. It may or may not work. Either way, you will still be able to click the [X] button or press ESC to terminate the dialog.)

Hope this helps. (And please read-up like I asked.)

The pascal version is "Bloodshed Dev-Pascal".

bump

Also, I'm an BIG amateur on this.. I know how to do simple procedures which takes integers or char/string from the main program, make function that tells you sums of an addition or something like that and iterations, selections, types.. not more.. so this is overclass for me, but I want to learn.. also Duoas, I've read that guide before, but still don't understand the "function" in the code.. .

Most older HLLs make a distinction between a function and a procedure. One returns a value, the other does not.

In C and C++, a procedure is declared by returning void (that is, it doesn't return anything): void my_proc() and, of course, a function: int my_func() In Pascal, they are: procedure my_proc; and function my_func: integer; Here's an example:

function intpow( base, exponent: integer ): integer;
  // Raises 'base' to the 'exponent' power
  // and returns the result.
  begin
  if exponent < 0
    then result := 0
    else begin
         result := 1;
         while exponent > 0 do
           begin
           result := result *base;
           dec( exponent )
           end
         end
  end;

Using this function, I can calculate any non-negative exponent that fits in an integer:
intpow( 2, 0 ) --> 1
intpow( 2, 1 ) --> 2
intpow( 2, 2 ) --> 4
intpow( 2, 3 ) --> 8
etc.

Did this help? Or did I misunderstand you?

I know that one of them returns a value (the function does that, right?) and the other does not..

*back to the topic cause I only want to do a simple popup, buttons or not I don't care.

but if you look at your examples:
should it look like this?

program popupwindow;

uses Windows, SysUtils, Dialogs, Messages;

begin showMessage( 'Hello world!' );

end.

Is that correct? Cause it doesn't work, and I tested the second "show message" you sended.. same thing[code=pascal]
program popupwindow;

uses Windows, SysUtils, Dialogs, Messages;

begin
showMessage( 'Hello world!' );

end.

Is that correct? Cause it doesn't work, and I tested the second "show message" you sended.. same thing

Hmm, I knew about that (but it got complicated at the program part but I know about functions and procedures (functions gives something back and procedures don't)

Back to the thing I wanted done, a popup windows with or without buttons

I've tried the things you wrote before but can't get it to work.. should it look like this:

program popupwindows;
uses Windows, SysUtils, Dialogs, Messages;

begin
showMessage( 'Hello world!' );

end.

is that it?

Cause it won't work :(

Question for you Loyen...

Are you using this program you are trying to write to fill a a user screen with whatever you want it to say?

As in a joke of some sort?

Far be it from me to insinuate your intentions, but from what I have read about your project, it seems to me that you don't want the user to be able to stop a continuous flow of windows popping up with no way to stop it minus killing the thread that it runs on.

If that is the case, google is your answer and you shouldn't be asking for help here.

If i am wrong about that, then simply explain why you would want such a program with any way to stop it.

My apologies if I have misread your intentions, but I am willing to bet that others have thought what I have written.

No, sorry if it sounded like that.. I wanted just a little popup to come up when you press the exe, saying something, but I tried some things and got it to work, with the little command window in the background.. the code is this:

PROGRAM popup;
USES Windows, Messages;
BEGIN
  MessageBox ( 0, 'You just got OWNED', '        OWNED', Mb_ok );
  PostQuitMessage ( 0 );
  Halt ( 1 );
END.

It has a ok button, and it stops by pressing ENTER.. It was just something I wanted to try out. I'll try to make something more.

The example you posted on the last page compiled and worked fine for me using Delphi, but FPC choked... I'm not sure why yet. I've recently upgraded FPC and I think I might have goofed something. I still need to play with it more...

Ok, I'm having fun with this thing. My teacher called me a hacker cause I'm going Porgramming A and popup windows will be introduced in Programming C course :P

Also this is the version of pascal I'm using:
http://www.bloodshed.net/devpascal.html


Now, I want to add a bitmap to my popup message and maybe try to change sounds.. I'm just goofing around to learn.. :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.