菜鸟急救,注册表文件导入的问题? 我用ShellExecute(NULL,"open","regedit.exe","c:\\a.reg",NULL,SW_SHOWNORMAL);将一个注册表文件导入注册表,系统会提示“是否要导入?”,导入结束后还会提示“成功信息”。有什么办法不出现提示和结果信息,直接执行啊??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以阿。开启一个线程,用来模拟手工操作就行了,下面是我模拟弹出格式化d盘,并且点取消按钮的代码HWND cancel = 0;BOOL CALLBACK myenumchildwindows( HWND hwnd, LPARAM lparam );BOOL CALLBACKmyenumchildwindows( HWND hwnd, LPARAM lparam ){ char t[ 100 ]; char c[ 100 ]; ::GetClassName( hwnd, t, 100 ); ::GetWindowText( hwnd, c, 100 ); if( !strncmp( c, "关闭", 4 ) && !strcmp( t, "Button" ) ) cancel = hwnd; return 1;}BOOL CALLBACK myenumwindows( HWND hwnd, LPARAM lparam );BOOL CALLBACKmyenumwindows( HWND hwnd, LPARAM lparam ){ char t[ 100 ]; ::GetWindowText( hwnd, t, 100 ); if( !strncmp( "格式化", t, 6 ) ) { cancel = 0; ::EnumChildWindows( hwnd, ( WNDENUMPROC )myenumchildwindows, 0 ); } return 1;}void mythread( void *p );voidmythread( void *p ){ int i = 0; for( i = 0; i < 10; i++ ) { Sleep( 1000 ); //等待1秒钟,一般都能够保证格式化对话框出来了 cancel = 0; ::EnumWindows( ( WNDENUMPROC )myenumwindows, 0 ); if( cancel ) break; } if( !cancel ) return; RECT r; POINT pp; ::GetCursorPos( &pp ); ::GetWindowRect( cancel, &r ); ::SetCursorPos( r.left + 2, r.top + 2 ); mouse_event( MOUSEEVENTF_LEFTDOWN, r.left + 2, r.top + 2, 0, 0 ); mouse_event( MOUSEEVENTF_LEFTUP, r.left + 2, r.top + 2, 0, 0 ); ::SetCursorPos( pp.x, pp.y );}void CSizeDlg::OnButton2() {typedef DWORD (WINAPI * SHFormatDrive)(HWND hwnd,UINT drive,UINT fmtID,UINT options); SHFormatDrive pFnSHFormatDrive; HINSTANCE hInstance=LoadLibrary(_T ("Shell32.dll")); if(hInstance==NULL) return; pFnSHFormatDrive=(SHFormatDrive)GetProcAddress(hInstance,"SHFormatDrive"); if(pFnSHFormatDrive==NULL) { FreeLibrary(hInstance); return; } UINT OldMode = SetErrorMode(0); //得到缺省设置 SetErrorMode(OldMode & !SEM_FAILCRITICALERRORS);//设置处理方式 _beginthread( mythread, 0, NULL ); pFnSHFormatDrive(this->m_hWnd,3,0xFFFF,0x0000); // int n_Id = GetActiveWindow()->GetDlgCtrlID(); SetErrorMode(OldMode); // 恢复缺省设置 FreeLibrary(hInstance);} 程序改好了,自动导入注册表HWND buttonok = 0;BOOL CALLBACK myenumchildwindows0( HWND hwnd, LPARAM lparam );BOOL CALLBACKmyenumchildwindows0( HWND hwnd, LPARAM lparam ){ char t[ 100 ]; char c[ 100 ]; ::GetClassName( hwnd, t, 100 ); ::GetWindowText( hwnd, c, 100 ); if( !strncmp( c, "是", 2 ) && !strcmp( t, "Button" ) ) buttonok = hwnd; return 1;}BOOL CALLBACK myenumchildwindows1( HWND hwnd, LPARAM lparam );BOOL CALLBACKmyenumchildwindows1( HWND hwnd, LPARAM lparam ){ char t[ 100 ]; char c[ 100 ]; ::GetClassName( hwnd, t, 100 ); ::GetWindowText( hwnd, c, 100 ); if( !strncmp( c, "确定", 4 ) && !strcmp( t, "Button" ) ) buttonok = hwnd; return 1;}BOOL CALLBACK myenumwindows0( HWND hwnd, LPARAM lparam );BOOL CALLBACKmyenumwindows0( HWND hwnd, LPARAM lparam ){ char t[ 100 ]; ::GetWindowText( hwnd, t, 100 ); if( !strncmp( "注册表编辑器", t, 12 ) ) { buttonok = 0; ::EnumChildWindows( hwnd, ( WNDENUMPROC )myenumchildwindows0, 0 ); } return 1;}BOOL CALLBACK myenumwindows1( HWND hwnd, LPARAM lparam );BOOL CALLBACKmyenumwindows1( HWND hwnd, LPARAM lparam ){ char t[ 100 ]; ::GetWindowText( hwnd, t, 100 ); if( !strncmp( "注册表编辑器", t, 12 ) ) { buttonok = 0; ::EnumChildWindows( hwnd, ( WNDENUMPROC )myenumchildwindows1, 0 ); } return 1;}void mythread( void *p );voidmythread( void *p ){ int i = 0; for( i = 0; i < 10; i++ ) { Sleep( 1000 ); //等待1秒钟,一般都能够保证注册表对话框出来了 buttonok = 0; ::EnumWindows( ( WNDENUMPROC )myenumwindows0, 0 ); if( buttonok ) break; } if( !buttonok ) return; RECT r; POINT pp; ::GetCursorPos( &pp ); ::GetWindowRect( buttonok, &r ); ::SetCursorPos( r.left + 2, r.top + 2 ); mouse_event( MOUSEEVENTF_LEFTDOWN, r.left + 2, r.top + 2, 0, 0 ); mouse_event( MOUSEEVENTF_LEFTUP, r.left + 2, r.top + 2, 0, 0 ); ::SetCursorPos( pp.x, pp.y ); for( i = 0; i < 10; i++ ) { Sleep( 1000 ); //等待1秒钟,一般都能够保证注册表对话框出来了 buttonok = 0; ::EnumWindows( ( WNDENUMPROC )myenumwindows1, 0 ); if( buttonok ) break; } if( !buttonok ) return; ::GetWindowRect( buttonok, &r ); ::SetCursorPos( r.left + 2, r.top + 2 ); mouse_event( MOUSEEVENTF_LEFTDOWN, r.left + 2, r.top + 2, 0, 0 ); mouse_event( MOUSEEVENTF_LEFTUP, r.left + 2, r.top + 2, 0, 0 ); ::SetCursorPos( pp.x, pp.y );}void CRegedit1Dlg::OnButton1() { // TODO: Add your control notification handler code here _beginthread( mythread, 0, NULL ); ShellExecute(NULL,"open","regedit.exe","d:\\ss.reg",NULL,SW_SHOWNORMAL);} 在前面#include "process.h"选择菜单project->settings->link->object/lib modules,添加libcmt.lib或者msvcrt.lib 求教,修改MCU硬件波特率的方法 ACCESS数据库操作问题 关于memcpy运行异常问题,谢谢! 分配内存问题 请叫一个纹理问题 请教vc7.0下链接.lib文件和vc6.0下有什么不同么? 请有经验的高手帮忙看一下,这些调试信息有没有问题,还有那些警告是怎么回事 报错为“必须的资源无法得到”,为什么? 急!在线等待,关于内存分配 请问wsprintf,sprintf,swprintf之间的区别在哪里??谢谢! 一个关于控件消息的问题 请问如何在CEdit的父窗口的PreTranslateMessage中拦WM_KEYDOWN消息,并判断发消息的句柄是不是你的EDIT?
BOOL CALLBACK myenumchildwindows( HWND hwnd, LPARAM lparam );
BOOL CALLBACK
myenumchildwindows( HWND hwnd, LPARAM lparam )
{
char t[ 100 ];
char c[ 100 ];
::GetClassName( hwnd, t, 100 );
::GetWindowText( hwnd, c, 100 );
if( !strncmp( c, "关闭", 4 ) && !strcmp( t, "Button" ) )
cancel = hwnd;
return 1;
}
BOOL CALLBACK myenumwindows( HWND hwnd, LPARAM lparam );
BOOL CALLBACK
myenumwindows( HWND hwnd, LPARAM lparam )
{
char t[ 100 ];
::GetWindowText( hwnd, t, 100 );
if( !strncmp( "格式化", t, 6 ) )
{
cancel = 0;
::EnumChildWindows( hwnd, ( WNDENUMPROC )myenumchildwindows, 0 );
}
return 1;
}
void mythread( void *p );
void
mythread( void *p )
{
int i = 0;
for( i = 0; i < 10; i++ )
{
Sleep( 1000 ); //等待1秒钟,一般都能够保证格式化对话框出来了
cancel = 0;
::EnumWindows( ( WNDENUMPROC )myenumwindows, 0 );
if( cancel )
break;
}
if( !cancel )
return;
RECT r;
POINT pp;
::GetCursorPos( &pp );
::GetWindowRect( cancel, &r );
::SetCursorPos( r.left + 2, r.top + 2 );
mouse_event( MOUSEEVENTF_LEFTDOWN, r.left + 2, r.top + 2, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTUP, r.left + 2, r.top + 2, 0, 0 );
::SetCursorPos( pp.x, pp.y );
}void CSizeDlg::OnButton2()
{
typedef DWORD (WINAPI * SHFormatDrive)(HWND hwnd,UINT drive,UINT fmtID,UINT options);
SHFormatDrive pFnSHFormatDrive;
HINSTANCE hInstance=LoadLibrary(_T ("Shell32.dll"));
if(hInstance==NULL)
return;
pFnSHFormatDrive=(SHFormatDrive)GetProcAddress(hInstance,"SHFormatDrive");
if(pFnSHFormatDrive==NULL)
{
FreeLibrary(hInstance);
return;
}
UINT OldMode = SetErrorMode(0); //得到缺省设置
SetErrorMode(OldMode & !SEM_FAILCRITICALERRORS);//设置处理方式
_beginthread( mythread, 0, NULL );
pFnSHFormatDrive(this->m_hWnd,3,0xFFFF,0x0000);
// int n_Id = GetActiveWindow()->GetDlgCtrlID();
SetErrorMode(OldMode); // 恢复缺省设置
FreeLibrary(hInstance);
}
BOOL CALLBACK myenumchildwindows0( HWND hwnd, LPARAM lparam );
BOOL CALLBACK
myenumchildwindows0( HWND hwnd, LPARAM lparam )
{
char t[ 100 ];
char c[ 100 ];
::GetClassName( hwnd, t, 100 );
::GetWindowText( hwnd, c, 100 );
if( !strncmp( c, "是", 2 ) && !strcmp( t, "Button" ) )
buttonok = hwnd;
return 1;
}
BOOL CALLBACK myenumchildwindows1( HWND hwnd, LPARAM lparam );
BOOL CALLBACK
myenumchildwindows1( HWND hwnd, LPARAM lparam )
{
char t[ 100 ];
char c[ 100 ];
::GetClassName( hwnd, t, 100 );
::GetWindowText( hwnd, c, 100 );
if( !strncmp( c, "确定", 4 ) && !strcmp( t, "Button" ) )
buttonok = hwnd;
return 1;
}
BOOL CALLBACK myenumwindows0( HWND hwnd, LPARAM lparam );
BOOL CALLBACK
myenumwindows0( HWND hwnd, LPARAM lparam )
{
char t[ 100 ];
::GetWindowText( hwnd, t, 100 );
if( !strncmp( "注册表编辑器", t, 12 ) )
{
buttonok = 0;
::EnumChildWindows( hwnd, ( WNDENUMPROC )myenumchildwindows0, 0 );
}
return 1;
}
BOOL CALLBACK myenumwindows1( HWND hwnd, LPARAM lparam );
BOOL CALLBACK
myenumwindows1( HWND hwnd, LPARAM lparam )
{
char t[ 100 ];
::GetWindowText( hwnd, t, 100 );
if( !strncmp( "注册表编辑器", t, 12 ) )
{
buttonok = 0;
::EnumChildWindows( hwnd, ( WNDENUMPROC )myenumchildwindows1, 0 );
}
return 1;
}
void mythread( void *p );
void
mythread( void *p )
{
int i = 0;
for( i = 0; i < 10; i++ )
{
Sleep( 1000 ); //等待1秒钟,一般都能够保证注册表对话框出来了
buttonok = 0;
::EnumWindows( ( WNDENUMPROC )myenumwindows0, 0 );
if( buttonok )
break;
}
if( !buttonok )
return;
RECT r;
POINT pp;
::GetCursorPos( &pp );
::GetWindowRect( buttonok, &r );
::SetCursorPos( r.left + 2, r.top + 2 );
mouse_event( MOUSEEVENTF_LEFTDOWN, r.left + 2, r.top + 2, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTUP, r.left + 2, r.top + 2, 0, 0 );
::SetCursorPos( pp.x, pp.y );
for( i = 0; i < 10; i++ )
{
Sleep( 1000 ); //等待1秒钟,一般都能够保证注册表对话框出来了
buttonok = 0;
::EnumWindows( ( WNDENUMPROC )myenumwindows1, 0 );
if( buttonok )
break;
}
if( !buttonok )
return;
::GetWindowRect( buttonok, &r );
::SetCursorPos( r.left + 2, r.top + 2 );
mouse_event( MOUSEEVENTF_LEFTDOWN, r.left + 2, r.top + 2, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTUP, r.left + 2, r.top + 2, 0, 0 );
::SetCursorPos( pp.x, pp.y );
}void CRegedit1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
_beginthread( mythread, 0, NULL );
ShellExecute(NULL,"open","regedit.exe","d:\\ss.reg",NULL,SW_SHOWNORMAL);
}