I tried to make my program in C open already in full screen, but it appeared 'error: expected declaration specifiers or '...' before Numeric Constant'

Asked

Viewed 83 times

2

I want my program to already open in full screen when I click to run. I researched if I had how to do this and saw some recommendations to put this code at the beginning of the program

# include <windows.h>

keybd_event(VK_MENU  , 0x36, 0, 0);  /// no meu caso aqui é a linha 6
keybd_event(VK_RETURN, 0x1C, 0, 0);
keybd_event(VK_RETURN, 0x1C, KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU  , 0x38, KEYEVENTF_KEYUP, 0);

It did not work and even started to appear this error message error: expected declaration specifiers or '...' before numeric constant. This message appears 4 times for each of the 4 lines (from line 6).

I learned C last year in college and I confess that I’m a little rusty, maybe it’s a simple oversight that I may not be aware of, but in my case I’m just finishing a project that I left half, and without that code works without any other error or warning. I am using codeblocks 20.03 with GNU GCC.

I would mainly like to know how to make the program already open in full screen. If there is any way to do this with or without this piece of code for me it does not matter, I thank you

1 answer

1


The code you are using should be in a int main(), but it is not recommended to use this, because you are manipulating the keyboard(this code simulates that you are pressing keyboard keys), so if you try to run this code on a SO Other than what was designed, it wouldn’t work.

For you to be able to do this(Obs will only work on Windows by need of the windows.h) you will need to run a function ShowWindow()

It enables several things, one of them and max out to window.

For this put this section on int main()(at the beginning of the code).

#include <windows.h>

int main()
{
    HWND hwnd = GetConsoleWindow();
    ShowWindow(hwnd, SW_SHOWMAXIMIZED);
   //seu código
}

Or you can do a function that does that:

#include <windows.h>

void janelaMaximizada(){
    HWND hwnd = GetConsoleWindow();
    ShowWindow(hwnd, SW_SHOWMAXIMIZED);
}

int main()
{
    janelaMaximizada();
    //seu código
}

If you want more details have this answer on SOen

  • Oh thank you, it worked well both ways, and thanks also for the explanation of the code snippet I sent, I didn’t know exactly what he performed

Browser other questions tagged

You are not signed in. Login or sign up in order to post.