9 Years
Discussion Span
Last Post by nucleon

Tried searching but everything seems to be for VB C++. Is this even possible in dev c++ if so please tell me how to do it

Dev-C++ has no its own console window, it's Windows OS console window of your application started from the Dev-C++ IDE.
VB C++ - what is it?!


After a little testing I don't think its possible to prevent someone from closing the console window. I tried the code below with vc++ 2008 Express, but it doesn't work because SetWindowLong() returns 0 and the windows error message is "Access is denied". I assume its a permission thing.

#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
WNDPROC dwPrevWinProc = 0;
LRESULT CALLBACK WndProc (HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
    if( message == WM_CLOSE)
        return 0;
    return CallWindowProc(dwPrevWinProc, hwnd, message, wParam, lParam);

int main()
    HWND hWnd = GetConsoleWindow();
    dwPrevWinProc = (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC, (LONG)WndProc);
    if( dwPrevWinProc == 0)
        DWORD dwError = GetLastError();
        char buf[255];
        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, dwError, 0, buf, sizeof(buf), 0);
        cout << buf << "\n";
        string str;
        cout << "Enter something\n";
        cin >> str;
        SetWindowLong(hWnd, GWL_WNDPROC, (LONG)dwPrevWinProc);

This deactivates the close option. Remember that you'll have to catch ctrl-C too.

#define _WIN32_WINNT 0x0500
#include <windows.h>
int main() {
  HWND hwnd = GetConsoleWindow();
  HMENU hmenu = GetSystemMenu (hwnd, FALSE);
  HINSTANCE hinstance =
    (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE);
  while (DeleteMenu (hmenu, 0, MF_BYPOSITION))
  system ("pause");
Votes + Comments
Very Good :) :)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.