I am making a c++ project for my High School. I am using Dev c++ with graphics. What I want is when BGI window opens it should start in maximized mode instead of normal window. following is my code but it doesn't works :(
#include<iostream>
#include<conio.h>
#include<graphics.h>
#include<windows.h>
using namespace std;
void loading() {
int x=170,i,gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
outtextxy(170,180,"LOADING,PLEASE WAIT");
for(i=0;i<300;++i)
{
delay(30);
line(x,200,x,220);
x++;
}
getch();
}
main() {
ShowWindow( GetConsoleWindow(), SW_HIDE );
loading();
ShowWindow(FindWindow(NULL,"Windows BGI"),SW_MAXIMIZE);
}
console window gets hide according to my need but BGI window don't get Maximized. I am newbie to c++ so i don't know how to handle windows with c++. Please help with some useful code or solution.
I don't have an immediate answer, but I can suggest a direction.
You need to break this down to see where it is failing (an approach that helps with many different kinds of bugs).
Are you getting to the second "ShowWindow" line of code? You can check with a breakpoint on that line.
What is FindWindow returning? My guess would be NULL, but you can confirm that (such as by pulling it out to its own line: HWND hwndBGI = FindWindow(NULL,"Windows BGI"); ShowWindow(hwndBGI,SW_MAXIMIZE);
Then you can check what FindWindow returns. If NULL, you know where to look for the problem; in the call to FindWindow.
FindWindow does not always succeed. Potential problems could be an inaccurate window name, issues finding a window in a different process, a window which is not a top-level window....
Wishing you success!