Thread: current window position

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    7

    current window position

    hi everyone, my name is Atique and i am new to the forum so my regards to all, i'm working in vc++ 6.0 and i need a function that gives the current console window position, and a function to set the position of the console,

    i have just covered oop form my uni and do not know much about windows programming, but someone suggested that it is concerned with windows programming,

    thanks for your precious time.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Code:
    #include <windows.h>
    
    #include <iostream>
    using namespace std;
    
    int main()
    {
        HWND conwin = GetConsoleWindow();
        RECT conrect;
        if (!conwin || !GetWindowRect(conwin, &conrect))
        {
            cerr << "Error" << endl;
            return 1;
        }//if
    
        cout << "(" << conrect.left << "," << conrect.top << ")-("
             << conrect.right << "," << conrect.bottom << ")" << endl;
        
        int width = conrect.right - conrect.left;
        int height = conrect.bottom - conrect.top;
        cout << "W=" << width << endl;
        cout << "H=" << height << endl;
        
        cout << "Moving to 0,0...." << endl;
        MoveWindow(conwin, 0, 0, width, height, TRUE);
        
        return 0;
    }//main
    Tutorial for other console manipulations in Win32: Win32 Console Applications 1

    gg

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    7
    thanks a lot man, it worked perfectly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get/Set current focused window
    By 4fingers in forum C++ Programming
    Replies: 0
    Last Post: 06-25-2010, 06:14 PM
  2. Get current position of pointer
    By Ducky in forum C Programming
    Replies: 13
    Last Post: 06-19-2010, 11:11 AM
  3. get current process name & ID on window
    By sgh in forum Windows Programming
    Replies: 13
    Last Post: 05-23-2008, 04:25 AM
  4. How to get current cursor position?
    By developersubham in forum C Programming
    Replies: 0
    Last Post: 01-14-2007, 01:12 AM
  5. changing pointers' destination relative to current position
    By doubleanti in forum C++ Programming
    Replies: 3
    Last Post: 04-12-2002, 04:34 PM

Tags for this Thread