Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function Keys to Call a Command of My Program

Status
Not open for further replies.

philsun

Programmer
Jul 13, 2001
2
SG
Hi,

Anyone knows how to use certain keyboard combinations to execute an exe command using Visual C++?

This is very urgent. Help will be really appreciated.
Thanks in advance.

 
You can execute an exe in many ways:
- with the WinExec function
- with the CreateProcess function
- with system(exe name) (#include <process.h>)

To capture a specific keyboard combination you have to capture the WM_CHAR and WM_SYSCHAR messages sent to your window, test for your chosen combination thenn call the exe.

Hope this helps,
s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 

#define _WIN32_WINNT 0x0500
#include<windows.h>
HHOOK x=0;
LRESULT CALLBACK KeyboardProc(int code,WPARAM wParam,LPARAM lParam information)
{
//do what do you want here
return CallNextHookEx( x,code,wParam,lParam);
//if you return -1 windows will call itsefl next hook proc
//if you return 1 windows will give you full control
//if you return 0 windows will process message after returning from function
//without giving it to next hook
//but is recommnended usuely you to return or call
CallNextHookEx
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR,int)
{
x=SetWindowsHookEx(WH_KEYBOARD_LL,KeyboardProc, hInstance,0);
MSG msg;
while(GetMessage(&msg,0,0,0))
DispatchMessage(&msg);//this assure what your program will finish when is called PostQuitMessage()
return 0;
}
John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top