nk51
asked on
How to use the SendMessageTimeOut function ?
Hello !
In my code I make modifications in the registry.
After those modifications I have to notify all others applications of those changes by broadcasting the WM_WININICHANGE message.
Under win95 I have to use the SendMessageTimeOut function.
The SDK give this example :
SendMessageTimeOut(HWND_BR OADCAST,WM _WININICHA NGE,0,0L,( LPARAM)(LP CTSTR)"win dows",SMTO _NORMAL,10 00,NULL);
But it doesn't work !
Does anybody know how to use this function ?
If you have some examples, it will be great !
Thanks in advance.
In my code I make modifications in the registry.
After those modifications I have to notify all others applications of those changes by broadcasting the WM_WININICHANGE message.
Under win95 I have to use the SendMessageTimeOut function.
The SDK give this example :
SendMessageTimeOut(HWND_BR
But it doesn't work !
Does anybody know how to use this function ?
If you have some examples, it will be great !
Thanks in advance.
P.S: Try
(1) PostMessage(HWND_BROADCAST ,WM_SETTIN GCHANGE,0, lparam(poi nter('Wind ows')));
or
(2) PostMessage(HWND_BROADCAST ,WM_SETTIN GCHANGE,0, 0);
WM_WININICHANGE is obsolete.
(1) PostMessage(HWND_BROADCAST
or
(2) PostMessage(HWND_BROADCAST
WM_WININICHANGE is obsolete.
ASKER
if I use :
PostMessage(HWND_BROADCAST ,WM_SETTIN GCHANGE,0, lparam(poi nter('Wind ows')));
the compilation return the message :
"incorrect cast"
if I use :
PostMessage(HWND_BROADCAST ,WM_SETTIN GCHANGE,0, 0);
the compilation is OK but it doesn't work :
all others applications aren't notify about the changes I made in the registry.
Have you an explication about the compilation error ?
thanks.
PostMessage(HWND_BROADCAST
the compilation return the message :
"incorrect cast"
if I use :
PostMessage(HWND_BROADCAST
the compilation is OK but it doesn't work :
all others applications aren't notify about the changes I made in the registry.
Have you an explication about the compilation error ?
thanks.
nk51,
I looked again at the documentation. I'm sorry. The SDK is right. I was wrong... :-(
Now here comes the working solution:
procedure TForm1.Button1Click(Sender : TObject);
var s1 : string;
c1 : cardinal;
begin
s1:='windows';
SendMessageTimeout(HWND_BR OADCAST,WM _SETTINGCH ANGE,0,int eger(point er(s1)),SM TO_NORMAL, 1000,c1);
end;
Regards, Madshi.
P.S: This works with Delphi4. If you have Delphi3 or lower, perhaps you have to change "c1: cardinal" to "c1: integer".
I looked again at the documentation. I'm sorry. The SDK is right. I was wrong... :-(
Now here comes the working solution:
procedure TForm1.Button1Click(Sender
var s1 : string;
c1 : cardinal;
begin
s1:='windows';
SendMessageTimeout(HWND_BR
end;
Regards, Madshi.
P.S: This works with Delphi4. If you have Delphi3 or lower, perhaps you have to change "c1: cardinal" to "c1: integer".
ASKER
You're answer seems to be good but the SendMessageTimeout function erase the modification I made in the registry and restore the previous value.
Have you an idea about what's happening ?
My code :
procedure TForm1.Button3Click(Sender : TObject);
var s1 : string;
c1 : integer;
begin
//Modification de la registry
Imprimante := TStringList.Create;
RegImprimante := TRegistry.Create;
RegImprimante.RootKey := HKEY_LOCAL_MACHINE;
if RegImprimante.OpenKey('Con fig\0001\S ystem\Curr entControl Set\Contro l\Print\Pr inters',Fa lse)
then
begin
RegImprimante.WriteString( 'Default', 'Tertiaire ');
RegImprimante.LazyWrite := False;
RegImprimante.CloseKey;
end;
RegImprimante.free;
s1:='windows';
SendMessageTimeout(HWND_BR OADCAST,WM _WININICHA NGE,0,inte ger(pointe r(s1)),SMT O_NORMAL,1 000,c1);
end;
Have you an idea about what's happening ?
My code :
procedure TForm1.Button3Click(Sender
var s1 : string;
c1 : integer;
begin
//Modification de la registry
Imprimante := TStringList.Create;
RegImprimante := TRegistry.Create;
RegImprimante.RootKey := HKEY_LOCAL_MACHINE;
if RegImprimante.OpenKey('Con
then
begin
RegImprimante.WriteString(
RegImprimante.LazyWrite := False;
RegImprimante.CloseKey;
end;
RegImprimante.free;
s1:='windows';
SendMessageTimeout(HWND_BR
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Your answer is excellent.
But to use the WritePrivateProfileString function, I need to know the driver and the port of the printer I want to put as default.
So I use the GetPrivateProfileString function to retrieve those parameters. But I have a problem of Access violation because of the PChar I use. Have you an idea about this problem ?
Thanks.
My code :
function TForm1.PrinterParams : string;
var
buffer : pChar;
begin
GetPrivateProfileString('d evices','T ertiaire', '',buffer, sizeof(buf fer),'win. ini');
result := buffer;
end;
But to use the WritePrivateProfileString function, I need to know the driver and the port of the printer I want to put as default.
So I use the GetPrivateProfileString function to retrieve those parameters. But I have a problem of Access violation because of the PChar I use. Have you an idea about this problem ?
Thanks.
My code :
function TForm1.PrinterParams : string;
var
buffer : pChar;
begin
GetPrivateProfileString('d
result := buffer;
end;
Your "buffer" is only a pointer to a non-defined memory address. So what happens is: Windows writes 4 bytes (sizeOf(pointer)=4) to a non-defined memory address.
You can either allocate (and then of course free) a pchar using GetMem/FreeMem.
Or you can use "my" method:
begin
SetLength(result,MAX_PATH) ;
GetPrivateProfileString('d evices','T ertiaire', '',pchar(r esult),MAX _PATH,'win .ini');
result:=string(pchar(resul t)); // This line shortens the string by looking at the #0 char...
end;
Regards, Madshi.
You can either allocate (and then of course free) a pchar using GetMem/FreeMem.
Or you can use "my" method:
begin
SetLength(result,MAX_PATH)
GetPrivateProfileString('d
result:=string(pchar(resul
end;
Regards, Madshi.
ASKER
Thank, you're great Madshi !
No problem... :-)
Please try to use "PostMessage(HWND_BROADCAS
Regards, Madshi.