-1
首先,我使用Createprocess()
來打開所有需要的窗口。 (未列出)SetWindowPos()有時不會調整子窗口的大小
成功打開流程後,我找到了FindWindow()
和FindWindowEx()
所有可用的窗口。 (列出)
有時功能SetWindowPos()
無法正常工作。幾個窗口被整理出一些沒有。但這種情況並不總是會發生!
爲了改進我總是有一個開放的耳朵!
//Some Variables comming from other code : numberOfWindows/numberOfStartedWindows
//Variables
bool trigger = true;
bool targetProcess = true;
HWND hwnd, hwndChilds = NULL;
int targetsFound = 0;
int targetsFoundMath = 0;
bool searchWindows = true;
//Start targetProcess
while (targetProcess) {
//If targetsFround == numberOfWindows then exit targetProcess.
if (targetsFound == numberOfWindows)
{
targetProcess = false;
}
//If all Windows are Started then start search loop
if (numberOfStartedWindows == numberOfWindows)
{
trigger = false;
}
//We starting search loop...
if (!trigger && targetProcess) {
//Find the Main Window.
hwnd = FindWindow(0, _T("World of Warcraft"));
if (hwnd)
{
targetsFound += 1;
//Set Window Foreground and call SetWindowPos to change Position
if (SetForegroundWindow(hwnd)) {
if (!SetWindowPos(hwnd, HWND_TOP, 0, 0, 1920, 800, SWP_SHOWWINDOW))
{
cout << "Error: HWND Failed with SETWINDOWPOS" << endl;
}
}
//Store HWND in StoreWindows
StoreWindows.emplace_back(hwnd);
//Now we search for child Windows
while (searchWindows)
{
//do it if targetsFound not numberOfWindows
if (targetsFound != numberOfWindows)
{
//Get Child Window
hwndChilds = FindWindowEx(NULL, hwnd, NULL, _T("World of Warcraft"));
if (hwndChilds != NULL)
{
//Little Math for Position
targetsFoundMath = (targetsFound - 1) * 384;
//if window in foreground SetWindowPos.
if(SetForegroundWindow(hwndChilds)){
if (!SetWindowPos(hwndChilds, HWND_TOP, targetsFoundMath, 800, 384, 280, SWP_SHOWWINDOW))
{
cout << "Error: HWNDChilds Failed with SETWINDOWPOS" << endl;
}
}
/*targetsFound += 1;
StoreWindows.emplace_back(hwndChilds);*/
//If all targetsFound then quit this loop after finish
if (targetsFound == numberOfWindows) {
searchWindows = false;
cout << "false" << targetsFound << endl;
}
//StoreChild Window and Add targetsfround +1
targetsFound += 1;
StoreWindows.emplace_back(hwndChilds);
}
else {
searchWindows = false;
cout << "no more child objects found!" << endl;
}
}
else
{
searchWindows = false;
}
}
}
}
}
cout << "Window Size: " << StoreWindows.size() << endl;
有趣,當我調試:
RECT debugRect;
for (int x = 0; x < StoreWindows.size(); x++)
{
GetClientRect(StoreWindows[x], &debugRect);
cout << debugRect.left << " " << debugRect.right<< " " << debugRect.bottom<< " " << debugRect.top << endl;
//debugRect.right = breite vom fenster // debugRect.bottom = Höhe
}
從該位置輸出看起來不錯,但在正確的地方窗口的心不是:/ 調試:
林的想法和希望你能幫我!如果你需要更多的解釋,不要猶豫,問。
有了它看起來是那麼的問題..
如果一切沒有問題,它看起來像這樣:
您是否重寫了子窗口的'WM_WINDOWPOSCHANGING'處理程序中的位置? –
即時通訊不知道^^(我認爲不是) – Lendoria
你是怎麼說的那麼好? SetWindowPos()做新的位置。或者我忘記了什麼? Sry im new in C++ – Lendoria