🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8286

PostMessage() does not close the Form

#8286
From: Umut Ozden
Date: Wed, 10 Nov 2004 06:22
48 lines
2568 bytes
I've posted this question to borland.public.cppbuilder.students but
the answer I got is insufficient. I think
borland.public.cppbuilder.nativeapi
is the right place to ask.

I have an application with 2 forms. (Form1 and Form2)
Form1 consists of 3 ListViews all in vsReport mode.
The OwnerData properties are set to true for all of them.

If I click a button on Form1, Form2 is displayed and executes
a function automatically. After execution of this function Form2 should be
automatically closed.
The minimal code is below:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    Form2->ShowModal();
}

void f()
{
    ...
}

void __fastcall TForm2::FormActivate(TObject *Sender)
{
    f();
    Caption = "Post message is executing";
    PostMessage((HWND)(Handle),WM_CLOSE,0,0);
    Caption = "Post message executed";
}

I was told to use PostMessage() instead of Close() in a FormActivate()
function a long time ago.
Another program(very similar in implementation) of mine works well with this
PostMessage() function
but this program doesn't. I don't know why.
The problem is, PostMessage() function doesn't close the Form2 sometimes
.(aprox. 5%)
f() function is executed, then (sometimes) Form2 remains forever unless I
move the mouse (even 1 pixel),
click the mouse button or press a key.Changing mouse cursor position with
Mouse->CursorPos = TPoint(Mouse->CursorPos.x, Mouse->CursorPos.y - 10);
also closes Form2.

If Form2 remains forever, I can see the "Post message executed" string as
caption, and this implies that PostMessage is executed..
So, how can I close Form2?. What are the suggestions?
Technical Details
Message-ID: <4191b34d@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!demon!194.74.65.66.MISMATCH!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,eddba34e31a6f877,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Umut Ozden" <umut_ozden@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: PostMessage() does not close the Form
Date: Wed, 10 Nov 2004 08:22:05 +0200
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4807.1700
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
NNTP-Posting-Host: 212.174.88.7
Message-ID: <4191b34d@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1100067661 212.174.88.7 (9 Nov 2004 22:21:01 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!demon!194.74.65.66.MISMATCH!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail