Hi all,
I need to open it and send it to background without notice on initialization. The form is needed to configure and etc... So, when you run it for the second time it shouldnt open another instance but open the old program showing the hidden form.
First my problem is send it to background. I know that the X button at the top do not close and send it to background as i desire, but i tried this next code for sending to background without success.
1) Form.hide - it send the program to background but it is not shown on task manager as a application but as a process. It was not possible to see the form again.
2) Form.WindowState := wsMinimized; - dont cause any effect. I dont know if minimize is the logical operation that i need.
3) there is a function function SetForegroundWindow(hWnd:HWND):WINBOOL; external KernelDLL name 'SetForegroundWindow'; but it does not have the SetBackgroundWindow. Otherwise i cannot find my window handler too. I'll explain it on two instances problem.
About the two instances i tried to use mutex. Tere still happening the next instances
Mutex := CreateMutex(nil, True, 'DynDNSInstance');
Error := GetLastError;
if Error = ERROR_ALREADY_EXISTS then begin
EnumWindows(@EnumWindowsProc, Longint(@W)); //enumwindowsproc must compare with self as in
CloseHandle(H);
Halt;
end;
else if (Mutex <> 0) and (Error = 0) then begin
Application.Initialize;
Application.Run;
if Mutex <> 0 then
CloseHandle(Mutex);
end;
And tried to find the window. Again without success, it aways run another instance.
Hwnd:= FindWindow('TApplication', 'RemorDynDNS');
if Hwnd = 0 then begin Application.Run
else begin
if not IsWindowVisible(Hwnd) then begin
ShowWindow(Hwnd, SW_SHOWNORMAL);
PostMessage(Hwnd, WM_USER, 0, 0);
end;
end;
maybe if i can find the window i can minimize it with hide command and return when running again the application, right?