Dimonar Posted March 28, 2009 Share Posted March 28, 2009 Hi. I need to do a little separate program and part of this task is to "press" NextChannel button in DVBViewer. If I use real keyboard, I'd use a letter P to select next channel. So I need to simulate pressing P-button from my program. I use Delphi7 and I think, this code with winAPI can be used: procedure TForm1.Button1Click(Sender: TObject); var wnd: HWND; i: Integer; s: string; begin wnd := FindWindow('XXXX', nil); if wnd <> 0 then begin wnd := FindWindowEx(wnd, 0, 'XXXX', nil); s := 'p'; // key that controls channel in DVBViewer SendMessage(wnd, WM_CHAR, Word(s), 0); end; end; But I don't know what I should write instead of XXXX in FindWindow and FindWindowEx. I tried to find answers with Winspector, but there is a lot of names and I don't see right. Could you help me, please? Quote Link to comment
Griga Posted March 28, 2009 Share Posted March 28, 2009 Simply use the text in the title bar for lpWindowName (it's always the same): FindWindow(nil,'DVBViewer'); or more precisely FindWindow('TfrmMain','DVBViewer'); Quote Link to comment
Dimonar Posted March 28, 2009 Author Share Posted March 28, 2009 Griga, thank you for reply. Now I use code: begin wnd := FindWindow('TfrmMain', nil); if wnd <> 0 then begin label1.caption:='Yes1'; wnd := FindWindowEx(wnd, 0, 'TfrmControl', nil); If wnd <> 0 then label1.caption:='Yes2'; s := 'p'; SendMessage(wnd, WM_CHAR, Word(s[i]), 0); end else label1.caption:='No'; end; And it seems working, but channel does not changed... May be I use incorrect lpszclass in FindWindowEx ? But "TfrmMain" is not suitable, because when I use it, I get wnd=0. Where do I have a mistake? Thank you. Quote Link to comment
Dimonar Posted March 29, 2009 Author Share Posted March 29, 2009 (edited) Problem solved with wnd := FindWindow('TfrmMain', nil); if wnd <> 0 then begin PostMessage(wnd, WM_KEYDOWN, ord('P'),1); PostMessage(wnd, WM_KEYUP, ord('P'),1); label1.caption:='Yes1'; end I should read more... Edited March 29, 2009 by Dimonar Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.