2009年12月9日 星期三

無框視窗

 
使用 Dev C++ 的話,連結器欄需加入:-lgdi32
#include <windows.h>
#include <iostream>
using namespace std;
extern "C" WINBASEAPI HWND WINAPI GetConsoleWindow();

void set_size (int w, int h)     
{
    int cy = GetSystemMetrics (SM_CYCAPTION),
        bx = GetSystemMetrics (SM_CXBORDER),
        by = GetSystemMetrics (SM_CYBORDER),
        fx = GetSystemMetrics (SM_CXFIXEDFRAME),
        fy = GetSystemMetrics (SM_CYFIXEDFRAME);

    if (w > 640) w = 640;
    
    HANDLE     hOut = GetStdHandle (STD_OUTPUT_HANDLE);
    HWND       hwnd = GetConsoleWindow ();
    SMALL_RECT rc   = {0, 0, w/8 ,h/16};
    COORD      size = {w/8+1 ,h/16+1};    
    
    int dx = fx+bx;
    int dy = cy+fy+by;

    SetConsoleWindowInfo (hOut,1,&rc);          //變更視窗大小
    SetConsoleScreenBufferSize (hOut, size);
    SetWindowRgn (hwnd, CreateRectRgn (dx, dy, w-dx, h-dy), 1);
}

int main (/* 091210 */)   
{
    set_size (490, 690);
   
    cout << "frameless window";
    return getchar(); 
}

沒有留言:

張貼留言