我用FindWindow()和SetForegroundWindow()出问题了,哪位Help一下,,

nightfallrove 2003-09-10 03:27:20
一个主窗口,上有一按钮“查找”点击出现一个名为“查找”的窗口,
用户在查找的过程中可以在主窗口上进行操作,我是想如果已经打开了查找窗口就这样hForm=FindWindow(NULL,"查找");if(hForm)SetForegroundForm(hForm);如果没有找到就NEW一个,
可是现在问题是第一次点查找按钮,没问题,出现一个查找窗口,然后在主窗口上操作查找窗口移到后台,再点查找按钮,原先的查找窗口调到前台,可是一旦把查找窗口关掉再去点按钮就没反应了,既没有NEW一个也没有找到放到前面来,,怎么搞的?也就是说“查找”窗口关掉了可是还是可以用FindWindow()找到,按钮事件里的程序这样写的:
HANDLE hForm=FindWindow(NULL,"查找");
if(hForm){SetForegroundWindow(hForm);return;}
else{fmFind=new TFind(Application);fmFind->Show();}
...全文
122 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jishiping 2003-09-10
  • 打赏
  • 举报
回复
不过使用上面的方法后,查找窗口的属性Visible仍然为false。所以最好:
HANDLE hForm = FindWindow(NULL,"查找");
if (hForm) {
TWinControl* Form = FindControl(hForm);
if (Form!=NULL) Form->Visible = true;
SetForegroundWindow(hForm);
}
else {
fmFind = new TFind(Application);
fmFind->Show();
}
nightfallrove 2003-09-10
  • 打赏
  • 举报
回复
thank you...
ljianq 2003-09-10
  • 打赏
  • 举报
回复
如果要使关掉后,释放窗体,可以在窗体的OnClose事件中,将Action设为caFree;
jishiping 2003-09-10
  • 打赏
  • 举报
回复
BCB中,除了主窗口以及MDIChild窗口外,其它的窗口在关闭时只是隐藏。所以,
你的代码中,第二次按找到的窗口是隐藏的。
HANDLE hForm = FindWindow(NULL,"查找");
if (hForm) {
ShowWindow(hForm, SW_SHOW); //加上这一句
SetForegroundWindow(hForm);
}
else {
fmFind = new TFind(Application);
fmFind->Show();
}
jishiping 2003-09-10
  • 打赏
  • 举报
回复
BCB中,除了主窗口以及MDIChild窗口外,其它的窗口在关闭时只是隐藏。所以,
你的代码中,第二次按找到的窗口是隐藏的。
HANDLE hForm = FindWindow(NULL,"查找");
if (hForm) {
ShowWindow(hForm, SW_SHOW); //加上这一句
SetForegroundWindow(hForm);
}
else {
fmFind = new TFind(Application);
fmFind->Show();
}
Creating Windows CreateMDIWindow CreateWindow CreateWindowEx RegisterClass RegisterClassEx UnregisterClass Message Processing BroadcastSystemMessage CallNextHookEx CallWindowProc DefFrameProc DefMDIChildProc DefWindowProc DispatchMessage GetMessage GetMessageExtraInfo GetMessagePos GetMessageTime GetQueueStatus InSendMessage PeekMessage PostMessage PostQuitMessage PostThreadMessage RegisterWindowMessage ReplyMessage SendMessage SendMessageCallback SendMessageTimeout SendNotifyMessage SetMessageExtraInfo SetWindowsHookEx TranslateMessage UnhookWindowsHookEx WaitMessage Window Information AnyPopup ChildWindowFromPoint ChildWindowFromPointEx EnableWindow EnumChildWindows EnumPropsEx EnumThreadWindows EnumWindows FindWindow FindWindowEx GetClassInfoEx GetClassLong GetClassName GetClientRect GetDesktopWindow GetFocus GetForegroundWindow GetNextWindow GetParent GetProp GetTopWindow GetWindow GetWindowLong GetWindowRect GetWindowText GetWindowTextLength IsChild IsIconic IsWindow IsWindowEnabled IsWindowUnicode IsWindowVisible IsZoomed RemoveProp SetActiveWindow SetClassLong SetFocus SetForegroundWindow SetParent SetProp SetWindowLong SetWindowText WindowFromPoint Processes and Threads CreateEvent CreateMutex CreateProcess CreateSemaphore CreateThread DeleteCriticalSection DuplicateHandle EnterCriticalSection ExitProcess ExitThread GetCurrentProcess GetCurrentProcessId GetCurrentThread GetCurrentThreadId GetExitCodeProcess GetExitCodeThread GetPriorityClass GetThreadPriority GetWindowThreadProcessId InitializeCriticalSection InterlockedDecrement InterlockedExchange InterlockedIncrement LeaveCriticalSection OpenEvent OpenMutex OpenProcess OpenSemaphore PulseEvent ReleaseMutex ReleaseSemaphore ResetEvent ResumeThread SetEvent SetPr

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧