c++编程调用运行窗口(Win+R)

几年前以前写的代码了,备份到这边来.

//显示运行窗口
void	ShowRunDlg(
               HWND hParentWnd=NULL,		//父窗口句柄
               LPCWSTR lpszTitle=NULL,		//标题
               LPCWSTR lpszDes=NULL,		//说明文字
               HICON hIcon=NULL				//指定图标
            )
{
    //父窗口句柄,图标,一个未知路径,窗口标题,说明文字,未知(跟踪显示为0x14或0x4)
    typedef DWORD (WINAPI *LPRUNDLG)( HWND, HICON, LPCWSTR, LPCWSTR, LPCWSTR, DWORD); 
    LPRUNDLG RunDlg; 
    HMODULE hMod =::LoadLibrary("shell32.dll");
    if (hMod)
    {
        HWND hSBWnd=NULL;
        if (!hParentWnd)
        {
            //如果父窗口句柄为NULL,则先取得状态栏的句柄,防止运行窗口在左上角
            //hParentWnd=::FindWindowA("Shell_TrayWnd",NULL);
            //上面一招不太灵,显示运行窗口时,任务栏变成不可用了=,=
            
            //这里自己创建个窗口出来给他当父窗口-位置是左下角
            //跟踪发现explorer调用运行命令时 也是创建了一个类名为Static的隐藏窗口给他当父窗口用(XP下)
            hSBWnd = CreateWindowA("Static", NULL, NULL,-500,3000,1,1, NULL, NULL,(HINSTANCE)::GetModuleHandleA(NULL), NULL);
            hParentWnd=hSBWnd;
        }
        
        RunDlg = (LPRUNDLG)GetProcAddress( hMod, MAKEINTRESOURCE(61) ); 
        DWORD dwResult=RunDlg( hParentWnd, hIcon,NULL,lpszTitle, lpszDes, 4);
        FreeLibrary( hMod );
        
        if (hSBWnd) ::DestroyWindow(hSBWnd);
    }
}

BOOL CRunApp::InitInstance()
{
    CWinApp::InitInstance();

    HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    ShowRunDlg(NULL,L"运行",NULL,hIcon);
    ::DestroyIcon(hIcon);
    
    return FALSE;
}

 

BOSS

发表评论

PHP Code Snippets Powered By : XYZScripts.com