예제 #1
0
void TitanPoker::close_login_ads() {

  //try to get root window
  std::vector<HWND> buf_vec = ScreenScraper::get_windows_by_type(WindowType::TitanRoot);
  if (buf_vec.size() != 1) { std::cout << "error, couldn't get titan root window" << std::endl; exit(0); }
  titan_root_window = buf_vec[0];

  //first popup
  HWND buf = GetLastActivePopup(titan_root_window);
  RECT rect = {0};
  GetWindowRect(buf, &rect);
  //press escape as long as we dont recognize titan-root-window through width and height
  while (rect.right - rect.left != 1016 && rect.bottom - rect.top != 738) {

    PostMessage(buf, WM_KEYDOWN, VK_ESCAPE, 0);
    PostMessage(buf, WM_KEYUP, VK_ESCAPE, 0);

    // needs to be in foreground in order to be an active popup
    SetForegroundWindow(titan_root_window);

    //if buf != titan-root-window, its an add
    buf = GetLastActivePopup(titan_root_window);
    GetWindowRect(buf, &rect);
    Sleep(200);
  }

  //imshow("test", ScreenScraper::window_to_mat(titan_root_window));
	//waitKey(0);

  //GetLastActivePopup(ScreenScraper::get_windows_by_type(WindowType::TitanRoot)[0]))
}
예제 #2
0
void CInstanceChecker::QuitPreviousInstance(int nExitCode)
{
  //Try to open the previous instances MMF
  HANDLE hPrevInstance = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, GetMMFFilename());
	if (hPrevInstance)
	{
		// Open up the MMF
		int nMMFSize = sizeof(CWindowInstance);
		CWindowInstance* pInstanceData = static_cast<CWindowInstance*>(MapViewOfFile(hPrevInstance, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, nMMFSize));
		if (pInstanceData != NULL) //Opening the MMF should work
		{
		  // Lock the data prior to reading from it
		  CSingleLock dataLock(&m_instanceDataMutex, TRUE);

		  //activate the old window
		  ASSERT(pInstanceData->hMainWnd); //Something gone wrong with the MMF?
		  HWND hWnd = pInstanceData->hMainWnd;

      //Ask it to exit
      HWND hChildWnd = GetLastActivePopup(hWnd);
  	  PostMessage(hChildWnd, WM_QUIT, nExitCode, 0);
	  }

    //Close the file handle now that we 
    CloseHandle(hPrevInstance);
  }
}
예제 #3
0
// https://blogs.msdn.microsoft.com/oldnewthing/20071008-00/?p=24863/
static bool is_alttab_window(HWND const Window)
{
	if (!IsWindowVisible(Window))
		return false;

	auto Try = GetAncestor(Window, GA_ROOTOWNER);
	HWND Walk = nullptr;
	while (Try != Walk)
	{
		Walk = Try;
		Try = GetLastActivePopup(Walk);
		if (IsWindowVisible(Try))
			break;
	}
	if (Walk != Window)
		return false;

	// Tool windows should not be displayed either, these do not appear in the task bar
	if (GetWindowLongPtr(Window, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)
		return false;

	if (IsWindows8OrGreater())
	{
		int Cloaked = 0;
		if (SUCCEEDED(imports.DwmGetWindowAttribute(Window, DWMWA_CLOAKED, &Cloaked, sizeof(Cloaked))) && Cloaked)
			return false;
	}

	return true;
}
예제 #4
0
TS_OldSieveProcedure(HWND hwnd, TSTaskList* tasklist)
{
	HWND parent;

	parent = GetParent(hwnd);

	if (parent == NULL) {
		DWORD hwnd_style;
		HWND lapopup;
		DWORD lapopup_style;
		int i;

		hwnd_style = GetWindowLongPtr(hwnd, GWL_STYLE);

		lapopup = GetLastActivePopup(hwnd);
		lapopup_style = GetWindowLongPtr(lapopup, GWL_STYLE);

		if ( (!IS_PROPER_WINDOW(lapopup, lapopup_style))
		     && (!IS_PROPER_WINDOW(hwnd, hwnd_style)) )
		{
			return TRUE;
		}

		for (i = 0; i < tasklist->count; i++) {
			if (lapopup == tasklist->list[i]->window)
				return TRUE;
		}

		return TSTaskList_Append(tasklist, lapopup, NULL, 0);
	}

	return TRUE;
}
예제 #5
0
파일: window.c 프로젝트: emonkak/cereja
static int
ui_window_raise(lua_State* L)
{
	HWND hwnd = NULL;
	HWND rootowner;
	HWND lap;
	Crj_ParseArgs(L, "| u", &hwnd);
	hwnd = GetTargetWindow(hwnd);

	rootowner = GetAncestor(hwnd, GA_ROOTOWNER);
	if (rootowner != NULL)
		hwnd = rootowner;
	lap = GetLastActivePopup(hwnd);
	if (lap != NULL)
		hwnd = lap;

	if (hwnd != GetForegroundWindow()) {
		SetForegroundWindow(hwnd);
	} else {
		SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0,
		             (SWP_ASYNCWINDOWPOS
		              | SWP_NOACTIVATE
		              | SWP_NOMOVE
		              | SWP_NOOWNERZORDER
		              | SWP_NOSIZE));
	}
	return 0;
}
예제 #6
0
bool CTask::OnThreadDone()
{
	// Когда поток послал сообщение что он завершил работу
	// мы ждём когда его хендл просигнализирует
	WaitForSingleObject(m_pThread->GetHandle(), INFINITE);

	// и удалим класс, отвечающий за работу с потоком (CThread)
	delete m_pThread;
	m_pThread = NULL;

	// Установим состояние задачи в "бездействие"
	m_bState = TASK_STATE_NONE;

	// Скажем главному окну что задача завершена
	SendMessage(MainWindow, RegisterWindowMessage(TaskDoneMessage), (WPARAM) this, NULL);

	// Запишем в лог что задача завершена
	if (m_bAborted)
		Log->WriteLogLine(TEXT("[%s] Выполнение задачи прервано"), TEXT("i"), m_TaskInfo.sName);
	else
		Log->WriteLogLine(TEXT("[%s] Выполнение задачи завершено"), TEXT("i"), m_TaskInfo.sName);

	// Покажем окно с информацией о прогрессе
	if (Settings->bShowProgress)
	{
		m_hProgressWnd->Show();
		SetForegroundWindow(GetLastActivePopup(MainWindow));
	}

	return true;
}
예제 #7
0
BOOL IsAltTabWindow(HWND hwnd)
{
    long wndStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
    if(GetWindowTextLength(hwnd) == 0)
        return false;

    // Ignore desktop window.
    if (hwnd == GetShellWindow())
        return(false);

    if(wndStyle & WS_EX_TOOLWINDOW)
        return(false);

    // Start at the root owner
    HWND hwndWalk = GetAncestor(hwnd, GA_ROOTOWNER);

    // See if we are the last active visible popup
    HWND hwndTry;
    while ((hwndTry = GetLastActivePopup(hwndWalk)) != hwndTry)
    {
        if (IsWindowVisible(hwndTry))
            break;
        hwndWalk = hwndTry;
    }
    return hwndWalk == hwnd;
}
예제 #8
0
void CWorkspaceDialog::OnClose()
{
	// Is a modal dialog box is up (like the about box), don't destroy the window
	CWnd* pPopup = GetLastActivePopup();
	if (pPopup && (pPopup->m_hWnd != m_hWnd))
		return;

	CDHtmlDialog::OnClose();
	DestroyWindow();
}
예제 #9
0
HWND GetLastVisibleActivePopUpOfWindow(HWND window)
{
    HWND lastPopUp = GetLastActivePopup( window );
    if( IsWindowVisible( lastPopUp ) )
        return lastPopUp;
    else if( lastPopUp == window)
        return NULL;
    else
        return GetLastVisibleActivePopUpOfWindow( lastPopUp );
}
예제 #10
0
HWND GetRunningWindow()
{
    // Check if exists an application with the same class name as this application
    HWND hWnd = FindWindow(szClassName, NULL);
    if (IsWindow(hWnd))
    {
        HWND hWndPopup = GetLastActivePopup(hWnd);
        if (IsWindow(hWndPopup))
            hWnd = hWndPopup; // Previous instance exists
    }
    else hWnd = NULL; // Previous instance doesnt exist
    return hWnd;
}
예제 #11
0
파일: main.cpp 프로젝트: stream009/launchy
void SetForegroundWindowEx(HWND hWnd)
{
        // Attach foreground window thread to our thread
	const DWORD foreGroundID = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
	const DWORD currentID = GetCurrentThreadId();

	AttachThreadInput(foreGroundID, currentID, TRUE);
	// Do our stuff here 
	HWND lastActivePopupWnd = GetLastActivePopup(hWnd);
	SetForegroundWindow(lastActivePopupWnd);

	// Detach the attached thread
	AttachThreadInput(foreGroundID, currentID, FALSE);
}
예제 #12
0
BOOL IsAltTabWindow(HWND hwnd)
{
    // Start at the root owner
    HWND hwndWalk = GetAncestor(hwnd, GA_ROOTOWNER);

    // See if we are the last active visible popup
    HWND hwndTry;
    while( (hwndTry = GetLastActivePopup( hwndWalk )) != hwndTry )
    {
        if( IsWindowVisible( hwndTry ) )
            break;
        hwndWalk = hwndTry;
    }
    return hwndWalk == hwnd;
}
예제 #13
0
static HWND
get_last_active_window(void)
{
	HWND last_active_window;
	HWND t;

	last_active_window = GetForegroundWindow();

	while ((t = GetParent(last_active_window)) != NULL)
		last_active_window = t;

	while ((t = GetWindow(last_active_window, GW_OWNER)) != NULL)
		last_active_window = t;

	return GetLastActivePopup(last_active_window);
}
예제 #14
0
WINBOOL SetForegroundWindowEx(HWND hWnd)
{
    //Attach foreground window thread to our thread
    const DWORD ForeGroundID = GetWindowThreadProcessId(::GetForegroundWindow(), NULL);
    const DWORD CurrentID   = GetCurrentThreadId();
    WINBOOL retval;

    AttachThreadInput(ForeGroundID, CurrentID, TRUE);
    //Do our stuff here
    HWND hLastActivePopupWnd = GetLastActivePopup(hWnd);
    retval = SetForegroundWindow(hLastActivePopupWnd);

    //Detach the attached thread
    AttachThreadInput(ForeGroundID, CurrentID, FALSE);
    return retval;
}// End SetForegroundWindowEx
예제 #15
0
void AlreadyRun(void)
{
	HWND	FirsthWnd, FirstChildhWnd;

	if((FirsthWnd = FindWindowEx(NULL, NULL, szWindowClass, NULL )) != NULL)
	{
		FirstChildhWnd = GetLastActivePopup(FirsthWnd);
		SetForegroundWindow(FirsthWnd);
	
		if(FirsthWnd != FirstChildhWnd)
		{
			SetForegroundWindow(FirstChildhWnd);
		}
		
		ShowWindow(FirsthWnd, SW_SHOWNORMAL);
	}
}
예제 #16
0
HWND getLastVisibleActivePopUpOfWindow(HWND window)
{
    HWND currentWindow = window;

    for (int i = 0; i < 50; ++i) {
        HWND lastPopUp = GetLastActivePopup(currentWindow);

        if (IsWindowVisible(lastPopUp))
            return lastPopUp;

        if (lastPopUp == currentWindow)
            return NULL;

        currentWindow = lastPopUp;
    }

    return NULL;
}
예제 #17
0
BOOL AssertFailedLine(LPCSTR lpszFileName, int nLine)
{
	TCHAR szMessage[_MAX_PATH*2];

	InterlockedDecrement(&AssertReallyBusy);

	// format message into buffer
	wsprintf(szMessage, _T("File %hs, Line %d"),
		lpszFileName, nLine);

	TCHAR szT[_MAX_PATH*2 + 20];
	wsprintf(szT, _T("Assertion Failed: %s\n"), szMessage);
	OutputDebugString(szT);

	if (InterlockedIncrement(&AssertBusy) > 0)
	{
		InterlockedDecrement(&AssertBusy);

		// assert within assert (examine call stack to determine first one)
		DebugBreak();
		return FALSE;
	}

	// active popup window for the current thread
	HWND hWndParent = GetActiveWindow();
	if (hWndParent != NULL)
		hWndParent = GetLastActivePopup(hWndParent);

	// display the assert
	int nCode = ::MessageBox(hWndParent, szMessage, _T("Assertion Failed!"),
		MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);

	// cleanup
	InterlockedDecrement(&AssertBusy);

	if (nCode == IDIGNORE)
		return FALSE;   // ignore

	if (nCode == IDRETRY)
		return TRUE;    // will cause DebugBreak

	AfxAbort();     // should not return (but otherwise DebugBreak)
	return TRUE;
}
예제 #18
0
void I_SwitchToWindow(HWND hwnd)
{
  typedef BOOL (WINAPI *TSwitchToThisWindow) (HWND wnd, BOOL restore);
  static TSwitchToThisWindow SwitchToThisWindow = NULL;

  if (!SwitchToThisWindow)
    SwitchToThisWindow = (TSwitchToThisWindow)GetProcAddress(GetModuleHandle("user32.dll"), "SwitchToThisWindow");
  
  if (SwitchToThisWindow)
  {
    HWND hwndLastActive = GetLastActivePopup(hwnd);

    if (IsWindowVisible(hwndLastActive))
      hwnd = hwndLastActive;

    SetForegroundWindow(hwnd);
    Sleep(100);
    SwitchToThisWindow(hwnd, TRUE);
  }
}
예제 #19
0
파일: diagnose.c 프로젝트: futre1529/core
sal_Int32 SAL_CALL osl_reportError(sal_uInt32 nType, const sal_Char* pszMessage)
{
    UINT nFlags;
    int nDisposition;

    // active popup window for the current thread
    HWND hWndParent = GetActiveWindow();
    if (hWndParent != NULL)
        hWndParent = GetLastActivePopup(hWndParent);

    /* set message box flags */
    nFlags = MB_TASKMODAL | MB_ICONERROR | MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_SETFOREGROUND;
    if (hWndParent == NULL)
        nFlags |= MB_SERVICE_NOTIFICATION;

    // display the assert
    nDisposition = MessageBox(hWndParent, pszMessage, "Exception!", nFlags);
    (void)nType; //unused, but part of public API/ABI
    return nDisposition;
}
예제 #20
0
파일: wowexec.c 프로젝트: chunhualiu/OpenNT
WORD ActivatePrevInstance(LPSTR lpszPath)
{
    HWND hwnd;
    HINSTANCE ret = IDS_MULTIPLEDSMSG;

    if (hwnd = FindPopupFromExe(lpszPath)) {
        if (IsIconic(hwnd)) {
            ShowWindow(hwnd,SW_SHOWNORMAL);
        }
        else {
            HWND hwndT = GetLastActivePopup(hwnd);
            BringWindowToTop(hwnd);
            if (hwndT && hwnd != hwndT)
                BringWindowToTop(hwndT);
        }
        ret = 0;
    }

    return (ret);
}
예제 #21
0
DWORD CALLBACK EXPORT KeyboardHookProc(
/***********************************************************************/
/*  Process the F1 key and ask for context sensitive help on the last id to receive a hint */
int 	nCode,
WPARAM 	wParam,
LPARAM 	lParam)
{
HWND hWnd;
int id;
#define STATE_MASK 0xC0000000L
#define UP_GOING_DOWN 0x00000000L
#define DOWN_GOING_UP 0xC0000000L

if ( nCode < 0 ||
     bHelpDisabled ||
     wParam != VK_F1 ||
     (lParam & STATE_MASK) != UP_GOING_DOWN )
	return( CallNextHookEx( hKBHook, nCode, wParam, lParam ) );

if ( LBUTTON )
	PostMessage ( hWndAstral, WM_KEYDOWN, VK_ESCAPE, 0L );

if ( idItemHelp <= 0 )
	{ // No help topic 
	if ( hWnd = GetLastActivePopup( hWndAstral ) )
		{ // Found a modal dialog up
		if ( !(id = GET_WINDOW_ID( hWnd )) )
			if ( !(id = AstralDlgGetID( hWnd )) );
				id = AstralDlgGetID( NULL );
		idItemHelp = MessageStatus( id, (LPSTR)"", (LPSTR)"" );
		}
	}

if ( idItemHelp > 0 )
		Help( HELP_CONTEXT, (long)idItemHelp );
else	Help( HELP_CONTEXT, (long)Tool.id );

return( TRUE );
}
예제 #22
0
static BOOL TaskEnumFunc(const struct tasklist *p, LPARAM lParam)
{
    HWND hwnd = p->hwnd;
    Desk *f = (Desk*)lParam;
    int n;
    for (n = 0;;)
    {
        winStruct ws;
        memset(&ws, 0, sizeof ws);

        if (false == GetTaskLocation(hwnd, &ws.info))
            break;

        if (GetMonitorRect(hwnd, NULL, GETMON_FROM_WINDOW) != f->mon)
            break;

        ws.hwnd = hwnd;
        ws.iconic = FALSE != IsIconic(hwnd);
        ws.active = p->active;
        ws.index = 0;

        if (0 == ws.info.width && 0 == ws.info.height && !ws.iconic)
        {
            if (2 == ++n)
                break;
            hwnd = GetLastActivePopup(hwnd);
            continue;
        }

        winStruct *p = new winStruct(ws);
        p->next = f->winList;
        f->winList = p;

        ++f->winCount;
        break;
    }
    return TRUE;
}
예제 #23
0
HWND __fastcall diablo_find_window(LPCSTR lpClassName)
{
	HWND result; // eax
	HWND v2; // esi
	HWND v3; // eax
	HWND v4; // edi

	result = FindWindowA(lpClassName, 0);
	v2 = result;
	if ( result )
	{
		v3 = GetLastActivePopup(result);
		if ( v3 )
			v2 = v3;
		v4 = GetTopWindow(v2);
		if ( !v4 )
			v4 = v2;
		SetForegroundWindow(v2);
		SetFocus(v4);
		result = (HWND)1;
	}
	return result;
}
예제 #24
0
TS_DefaultSieveProcedure(HWND hwnd, TSTaskList* tasklist)
{
	HWND root_owner;
	DWORD style;
	DWORD exstyle;
	int i;
	ULONG_PTR extra[1];

	hwnd = GetLastActivePopup(hwnd);

	style = GetWindowLongPtr(hwnd, GWL_STYLE);
	if (!(style & WS_VISIBLE) || (style & WS_DISABLED))
		return TRUE;

	exstyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
	if (!( (!(exstyle & WS_EX_TOOLWINDOW))
	       || (exstyle & WS_EX_APPWINDOW) ))
	{
		return TRUE;
	}

	root_owner = get_root_owner(hwnd);

	for (i = 0; i < tasklist->count; i++) {
		if (root_owner == (HWND)(tasklist->list[i]->extra[0])) {
			tasklist->list[i]->window = hwnd;
			GetWindowText( hwnd,
			               tasklist->list[i]->title,
			               NUMBER_OF(tasklist->list[i]->title) );
			tasklist->list[i]->extra[0] = (ULONG_PTR)root_owner;
			return TRUE;
		}
	}

	extra[0] = (ULONG_PTR)root_owner;
	return TSTaskList_Append(tasklist, hwnd, extra, 1);
}
예제 #25
0
파일: hook.cpp 프로젝트: Eun/MoveToDesktop
// Taken from http://www.dfcd.net/projects/switcher/switcher.c
BOOL IsAltTabWindow(HWND hwnd)
{
	TITLEBARINFO ti;
	HWND hwndTry, hwndWalk = NULL;

	if (!IsWindowVisible(hwnd))
		return FALSE;

	hwndTry = GetAncestor(hwnd, GA_ROOTOWNER);
	while (hwndTry != hwndWalk)
	{
		hwndWalk = hwndTry;
		hwndTry = GetLastActivePopup(hwndWalk);
		if (IsWindowVisible(hwndTry))
			break;
	}
	if (hwndWalk != hwnd)
		return FALSE;

	// the following removes some task tray programs and "Program Manager"
	ti.cbSize = sizeof(ti);
	GetTitleBarInfo(hwnd, &ti);
	if (ti.rgstate[0] & STATE_SYSTEM_INVISIBLE)
		return FALSE;

	// Tool windows should not be displayed either, these do not appear in the
	// task bar.
	if (GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)
		return FALSE;

	// Also remove all windows without a title
	if (GetWindowTextLength(hwnd) == 0)
		return FALSE;


	return TRUE;
}
예제 #26
0
BOOL AFXAPI AfxAssertFailedLine(LPCSTR lpszFileName, int nLine)
{
	TCHAR szMessage[_MAX_PATH*2];

	// handle the (hopefully rare) case of AfxGetAllocState ASSERT
	if (InterlockedIncrement(&afxAssertReallyBusy) > 0)
	{
		// assume the debugger or auxiliary port
		wsprintf(szMessage, _T("Assertion Failed: File %hs, Line %d\n"),
			lpszFileName, nLine);
		OutputDebugString(szMessage);
		InterlockedDecrement(&afxAssertReallyBusy);

		// assert w/in assert (examine call stack to determine first one)
		AfxDebugBreak();
		return FALSE;
	}

	// check for special hook function (for testing diagnostics)
	AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
	AFX_ALLOC_STATE* pAllocState = AfxGetAllocState();
	InterlockedDecrement(&afxAssertReallyBusy);
	if (pAllocState->m_lpfnAssertFailedLine != NULL)
		return pAllocState->m_lpfnAssertFailedLine(lpszFileName, nLine);

	// get app name or NULL if unknown (don't call assert)
	LPCTSTR lpszAppName = afxCurrentAppName;
	if (lpszAppName == NULL)
		lpszAppName = _T("<unknown application>");

	// format message into buffer
	wsprintf(szMessage, _T("%s: File %hs, Line %d"),
		lpszAppName, lpszFileName, nLine);

	if (afxTraceEnabled)
	{
		// assume the debugger or auxiliary port
		// output into MacsBug looks better if it's done in one string,
		// since MacsBug always breaks the line after each output
		TCHAR szT[_MAX_PATH*2 + 20];
		wsprintf(szT, _T("Assertion Failed: %s\n"), szMessage);
		OutputDebugString(szT);
	}
	if (InterlockedIncrement(&afxAssertBusy) > 0)
	{
		InterlockedDecrement(&afxAssertBusy);

		// assert within assert (examine call stack to determine first one)
		AfxDebugBreak();
		return FALSE;
	}

	// active popup window for the current thread
	HWND hWndParent = GetActiveWindow();
	if (hWndParent != NULL)
		hWndParent = GetLastActivePopup(hWndParent);

	// display the assert
	int nCode = ::MessageBox(hWndParent, szMessage, _T("Assertion Failed!"),
		MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);

	// cleanup
	InterlockedDecrement(&afxAssertBusy);

	if (nCode == IDIGNORE)
		return FALSE;   // ignore

	if (nCode == IDRETRY)
		return TRUE;    // will cause AfxDebugBreak

	UNUSED nLine;   // unused in release build
	UNUSED lpszFileName;

	AfxAbort();     // should not return (but otherwise AfxDebugBreak)
	return TRUE;
}
예제 #27
0
int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
                    LPSTR lpszCmdLine,  int nCmdShow )
{
    MSG         msg;
#ifndef __NT__
#if 0
    HWND        win;
    HWND        child;
#endif
#endif

    /* touch unused vars to get rid of warning */
    _wde_touch( lpszCmdLine );
    _wde_touch( nCmdShow );
#ifdef __NT__
    _wde_touch( hinstPrevious );
#endif
#if defined( __NT__ ) && !defined( __WATCOMC__ )
    _argc = __argc;
    _argv = __argv;
#endif

    WRInit();
    WdeInitDisplayError( hinstCurrent );

    /* store the handle to this instance of Wde in a static variable */
    hInstWde = hinstCurrent;

    //check we are running in DDE mode
    IsDDE = WdeIsDDEArgs( _argv, _argc );

    WdeFirstInst = (hinstPrevious == NULL);

    WdeInitEditClass();

    /* is this the first instance of the application? */
#ifndef __NT__
    if( WdeFirstInst ) {
#endif
        /* if so call the routine to initialize the application */
        if( !WdeInit( hinstCurrent ) ) {
            if( IsDDE ) {
                WdeDDEDumpConversation( hinstCurrent );
            }
            return( FALSE );
        }
#ifndef __NT__
    }
#if 0
    else if( IsDDE ) {
        WdeDisplayErrorMsg( WDE_NOMULTIPLEINSTANCES );
        WdeDDEDumpConversation( hinstCurrent );
        return( FALSE );
    } else {
        win = FindWindow( WdeMainClass, NULL );
        if( win != NULL ) {
            child = GetLastActivePopup( win );
            PostMessage( win, WM_USER, 0, 0 );
            BringWindowToTop( win );
            if( child != (HWND)NULL && child != win ) {
                BringWindowToTop( child );
            }
        } else {
            WdeDisplayErrorMsg( WDE_NOMULTIPLEINSTANCES );
        }
        return( FALSE );
    }
#endif
#endif

    if( !WdeInitInst( hinstCurrent ) ) {
        WdeDisplayErrorMsg( WDE_INITFAILED );
        if( IsDDE ) {
            WdeDDEDumpConversation( hinstCurrent );
        }
        return( FALSE );
    }

    if( IsDDE ) {
        if( WdeDDEStart( hinstCurrent ) ) {
            if( !WdeDDEStartConversation() ) {
                WdeDisplayErrorMsg( WDE_DDEINITFAILED );
                PostMessage( hWinWdeMain, WDE_FATAL_EXIT, 0, 0 );
            }
        } else {
            WdeDisplayErrorMsg( WDE_DDEINITFAILED );
            PostMessage( hWinWdeMain, WDE_FATAL_EXIT, 0, 0 );
        }
    }

    WdeEnableMenuInput( TRUE );

    if( setjmp( WdeEnv ) ) {
        PostMessage( hWinWdeMain, WDE_FATAL_EXIT, 0, 0 );
        if( setjmp( WdeEnv ) ) {
            WdeDisplayErrorMsg( WDE_EXCEPTIONDURINGABNORMALEXIT );
            exit( -1 );
        }
        WdePushEnv( &WdeEnv );
    } else {
        WdePushEnv( &WdeEnv );
        WdeProcessArgs( _argv, _argc );
    }

    if( !WdeGetNumRes() ) {
        WdeCreateNewResource( NULL );
    }

    /* create the message loop */
    while( GetMessage( &msg, (HWND)NULL, 0, 0 ) ) {
        if( !WdeIsTestMessage( &msg ) && !WdeIsInfoMessage( &msg ) &&
            !WRIsWRDialogMsg( &msg ) ) {
            if( !WdeWasAcceleratorHandled( &msg ) ) {
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }
        }
    }

    if( IsDDE ) {
        WdeDDEEndConversation();
    }

    WdePopEnv( &WdeEnv );

    if( IsDDE ) {
        WdeDDEEnd();
    }

    WRFini();

    return( msg.wParam );
}
예제 #28
0
파일: wasap.c 프로젝트: Erikhht/TCPMP
static LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam,
                                    LPARAM lParam)
{
	UINT idc;
	POINT pt;
	PCOPYDATASTRUCT pcds;
	switch (msg) {
	case WM_COMMAND:
		if (opening)
			break;
		idc = LOWORD(wParam);
		switch (idc) {
		case IDM_OPEN:
			SelectAndLoadFile(hWnd);
			break;
		case IDM_STOP:
			WaveOut_Stop();
			Tray_Modify(hWnd, hStopIcon);
			break;
		case IDM_ABOUT:
			MessageBox(hWnd,
				ASAP_CREDITS
				"WASAP icons (C) 2005 Lukasz Sychowicz\n\n"
				ASAP_COPYRIGHT,
				APP_TITLE " " ASAP_VERSION,
				MB_OK | MB_ICONINFORMATION);
			break;
		case IDM_EXIT:
			PostQuitMessage(0);
			break;
		default:
			if (idc >= IDM_SONG1 && idc < IDM_SONG1 + songs) {
				WaveOut_Stop();
				PlaySong(hWnd, idc - IDM_SONG1);
			}
			else if (idc >= IDM_QUALITY_RF && idc <= IDM_QUALITY_MB3)
				SetQuality(hWnd, use_16bit, idc - IDM_QUALITY_RF);
			else if (idc >= IDM_8BIT && idc <= IDM_16BIT)
				SetQuality(hWnd, idc - IDM_8BIT, quality);
			break;
		}
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case MYWM_NOTIFYICON:
		if (opening) {
			SetForegroundWindow(GetLastActivePopup(hWnd));
			break;
		}
		switch (lParam) {
		case WM_LBUTTONDOWN:
			SelectAndLoadFile(hWnd);
			break;
		case WM_RBUTTONDOWN:
			GetCursorPos(&pt);
			SetForegroundWindow(hWnd);
			TrackPopupMenu(hTrayMenu,
				TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON,
				pt.x, pt.y, 0, hWnd, NULL);
			PostMessage(hWnd, WM_NULL, 0, 0);
			break;
		default:
			break;
		}
		break;
	case WM_COPYDATA:
		pcds = (PCOPYDATASTRUCT) lParam;
		if (pcds->dwData == 'O' && pcds->cbData <= sizeof(strFile)) {
			memcpy(strFile, pcds->lpData, pcds->cbData);
			LoadFile(hWnd);
		}
		break;
	default:
		return DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}
예제 #29
0
파일: wasap.c 프로젝트: Erikhht/TCPMP
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{
	char *pb;
	char *pe;
	WNDCLASS wc;
	HWND hWnd;
	HMENU hMainMenu;
	MSG msg;

	for (pb = lpCmdLine; *pb == ' ' || *pb == '\t'; pb++);
	for (pe = pb; *pe != '\0'; pe++);
	while (--pe > pb && (*pe == ' ' || *pe == '\t'));
	/* Now pb and pe point at respectively the first and last
	   non-blank character in lpCmdLine. If pb > pe then the command line
	   is blank. */
	if (*pb == '"' && *pe == '"')
		pb++;
	else
		pe++;
	*pe = '\0';
	/* Now pb contains the filename, if any, specified on the command line. */

	hWnd = FindWindow(WND_CLASS_NAME, NULL);
	if (hWnd != NULL) {
		/* as instance of WASAP is already running */
		if (*pb != '\0') {
			/* pass the filename */
			COPYDATASTRUCT cds = { 'O', (DWORD) (pe + 1 - pb), pb };
			SendMessage(hWnd, WM_COPYDATA, (WPARAM) NULL, (LPARAM) &cds);
		}
		else {
			/* bring the open dialog to top */
			HWND hChild = GetLastActivePopup(hWnd);
			if (hChild != hWnd)
				SetForegroundWindow(hChild);
		}
		return 0;
	}

	wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
	wc.lpfnWndProc = MainWndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP));
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = WND_CLASS_NAME;
	RegisterClass(&wc);

	hWnd = CreateWindow(WND_CLASS_NAME,
		APP_TITLE,
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		NULL,
		NULL,
		hInstance,
		NULL
	);

	hStopIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_STOP));
	hPlayIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PLAY));
	hMainMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
	hTrayMenu = GetSubMenu(hMainMenu, 0);
	hSongMenu = CreatePopupMenu();
	InsertMenu(hTrayMenu, 1, MF_BYPOSITION | MF_ENABLED | MF_STRING | MF_POPUP,
	           (UINT_PTR) hSongMenu, "So&ng");
	hQualityMenu = GetSubMenu(hTrayMenu, 3);
	SetMenuDefaultItem(hTrayMenu, 0, TRUE);
	Tray_Add(hWnd, hStopIcon);
	SetQuality(hWnd, use_16bit, quality);
	if (*pb != '\0') {
		memcpy(strFile, pb, pe + 1 - pb);
		LoadFile(hWnd);
	}
	else
		SelectAndLoadFile(hWnd);
	while (GetMessage(&msg, NULL, 0, 0)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	WaveOut_Close();
	Tray_Delete(hWnd);
	DestroyMenu(hMainMenu);
	return 0;
}
예제 #30
0
static void
investigate(HWND hwnd)
{
	LONG_PTR exstyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
	LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE);
	TCHAR buf[80];

	GetWindowText(hwnd, buf, NUMBER_OF(buf));
	DEBUG_PRINTF(( T("inv: %p <- %p (%p) '%s'"),
	               hwnd, GetParent(hwnd), GetLastActivePopup(hwnd), buf ));

	buf[0] = T('\0');
	_tcscat(buf, (exstyle&WS_EX_ACCEPTFILES ? T("Af") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_APPWINDOW ? T("Aw") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_CLIENTEDGE ? T("Ce") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_COMPOSITED ? T("Cm") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_CONTEXTHELP ? T("Ch") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_CONTROLPARENT ? T("Cp") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_DLGMODALFRAME ? T("Dm") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_LAYERED ? T("Ly") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_LAYOUTRTL ? T("Lr") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_LEFT ? T("Le") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_LEFTSCROLLBAR ? T("Ls") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_LTRREADING ? T("Lr") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_MDICHILD ? T("Md") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_NOACTIVATE ? T("Na") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_NOINHERITLAYOUT ? T("Ni"):T(".,")));
	_tcscat(buf, (exstyle&WS_EX_NOPARENTNOTIFY ? T("Np") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_OVERLAPPEDWINDOW ? T("Ol"):T(".,")));
	_tcscat(buf, (exstyle&WS_EX_PALETTEWINDOW ? T("Pw") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_RIGHT ? T("Ri") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_RIGHTSCROLLBAR ? T("Rs") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_RTLREADING ? T("Rr") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_STATICEDGE ? T("Se") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_TOOLWINDOW ? T("Tw") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_TOPMOST ? T("Tm") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_TRANSPARENT ? T("Tp") : T(".,")));
	_tcscat(buf, (exstyle&WS_EX_WINDOWEDGE ? T("We") : T(".,")));
	DEBUG_PRINTF((T("inv: ex '%s'"), buf));

	buf[0] = T('\0');
	_tcscat(buf, (style&WS_BORDER ? T("Br") : T(".,")));
	_tcscat(buf, (style&WS_CAPTION ? T("Cp") : T(".,")));
	_tcscat(buf, (style&WS_CHILD ? T("Ch") : T(".,")));
	_tcscat(buf, (style&WS_CHILDWINDOW ? T("Cw") : T(".,")));
	_tcscat(buf, (style&WS_CLIPCHILDREN ? T("Cc") : T(".,")));
	_tcscat(buf, (style&WS_CLIPSIBLINGS ? T("Cs") : T(".,")));
	_tcscat(buf, (style&WS_DISABLED ? T("Di") : T(".,")));
	_tcscat(buf, (style&WS_DLGFRAME ? T("Df") : T(".,")));
	_tcscat(buf, (style&WS_GROUP ? T("Gr") : T(".,")));
	_tcscat(buf, (style&WS_HSCROLL ? T("Hs") : T(".,")));
	_tcscat(buf, (style&WS_ICONIC ? T("Ic") : T(".,")));
	_tcscat(buf, (style&WS_MAXIMIZE ? T("Mx") : T(".,")));
	_tcscat(buf, (style&WS_MAXIMIZEBOX ? T("Mb") : T(".,")));
	_tcscat(buf, (style&WS_MINIMIZE ? T("Mn") : T(".,")));
	_tcscat(buf, (style&WS_MINIMIZEBOX ? T("Mb") : T(".,")));
	_tcscat(buf, (style&WS_OVERLAPPED ? T("Ol") : T(".,")));
	_tcscat(buf, (style&WS_OVERLAPPEDWINDOW ? T("Ow") : T(".,")));
	_tcscat(buf, (style&WS_POPUP ? T("Po") : T(".,")));
	_tcscat(buf, (style&WS_POPUPWINDOW ? T("Pw") : T(".,")));
	_tcscat(buf, (style&WS_SIZEBOX ? T("Sb") : T(".,")));
	_tcscat(buf, (style&WS_SYSMENU ? T("Sm") : T(".,")));
	_tcscat(buf, (style&WS_TABSTOP ? T("Ts") : T(".,")));
	_tcscat(buf, (style&WS_THICKFRAME ? T("Tf") : T(".,")));
	_tcscat(buf, (style&WS_TILED ? T("Ti") : T(".,")));
	_tcscat(buf, (style&WS_TILEDWINDOW ? T("Tw") : T(".,")));
	_tcscat(buf, (style&WS_VISIBLE ? T("Vi") : T(".,")));
	_tcscat(buf, (style&WS_VSCROLL ? T("Vs") : T(".,")));
	_tcscat(buf, (style&WS_ACTIVECAPTION ? T("Ac") : T(".,")));
	DEBUG_PRINTF((T("inv: st '%s'"), buf));
}