1

I have question. I tried to send a signal to notepad for close ITS process by using code below

if pos('NOTEPAD',UpperCase(sName)) > 0 then
      postMessage(FindWindow(ClassName, TheText), WM_CLOSE, 0, 0);
  end

But if notepad is not blank it would need confirmation to close and it would not if notepad empty

so I wanna make if condition for it after WM_CLOSE signal has sended

I tried this code

if pos('NOTEPAD',UpperCase(sName)) > 0 then
begin
     postMessage(FindWindow(ClassName, TheText), WM_CLOSE, 0, 0);
Show message('signal to close has sended')

if not postMessage(FindWindow(ClassName, TheText), WM_CLOSE, 0, 0) then
Begin
Show message(' signal sended but process still exist it might need confirmation to close')
End;
      
End;

But code above was not working. Is there anyway to make the result of if condition after WM_CLOSE signal sended? Thanks

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
  • 4
    You should use UIAutomation. In any case this code contains multiple conceptual errors. If ditch it and start again. – David Heffernan Apr 13 '21 at 06:42
  • @DavidHeffernan alright, thank you for reply. – Mirana chan Apr 13 '21 at 06:47
  • Does this question exist because of [my answer](https://stackoverflow.com/a/67043418/4299358)? – AmigoJack Apr 13 '21 at 07:58
  • You can use one more enumwindows to find if the dialog asking to save is shown. If it is then you generate a click on the OK or Cancel button according to what you need. – fpiette Apr 13 '21 at 08:15
  • @AmigoJack it does not. by changed wm_close to wm_quit. it could avoid notepad close confirmation. i'm just like getting confused about the if condition just in case if a signal from WM_CLOSE it's fail – Mirana chan Apr 13 '21 at 08:47
  • @fpiette *noted – Mirana chan Apr 13 '21 at 08:50
  • i got another question. is there any syntax that could tell the program to execute the condition first? like i have line of code that i want program to execute it first and ignored other one – Mirana chan Apr 13 '21 at 08:52
  • 5
    Can you step back and tell us what you are trying to do, because sending messages to notepad doesn't sound like a good solution to any problem – David Heffernan Apr 13 '21 at 09:04
  • If you have another question, then open a new question on StackOverflow instead of asking in comment. This being said, I don't understand at all your new question. So when writing your new post, explain better what you want. – fpiette Apr 13 '21 at 09:11
  • @fpiette i'm sorry, nevermind. i'm new in english and it was not my native language i guess no matter how badly i explained it will never be clear to you guys. i am sorry if you offended by my word. i did not mean to. i do not know what is the right or the correct word or the good sentence to use in english. – Mirana chan Apr 13 '21 at 09:38
  • 2
    I don't think anyone would be offended by what you have said in your question or your comments, so there is no need to worry about that. Perhaps a new question with a diagram of what you are trying to achieve would reduce language difficulties? – MartynA Apr 13 '21 at 11:35
  • @Miranachan No problem, I don't feel offended at all. I'm just trying to help. English is not my native language so I know your problem: I sometimes feel misunderstood myself. – fpiette Apr 13 '21 at 15:23

0 Answers0