void open_console() { char title[MAX_PATH]={0}; HWND hcon; FILE *hf; static BYTE consolecreated=FALSE; static int hcrt=0; if(consolecreated==TRUE) { GetConsoleTitle(title,sizeof(title)); if(title[0]!=0){ hcon=FindWindow(NULL,title); ShowWindow(hcon,SW_SHOW); } hcon=(HWND)GetStdHandle(STD_INPUT_HANDLE); FlushConsoleInputBuffer(hcon); return; } AllocConsole(); hcrt=_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT); fflush(stdin); hf=_fdopen(hcrt,"w"); *stdout=*hf; setvbuf(stdout,NULL,_IONBF,0); GetConsoleTitle(title,sizeof(title)); if(title[0]!=0){ hcon=FindWindow(NULL,title); ShowWindow(hcon,SW_SHOW); SetForegroundWindow(hcon); } consolecreated=TRUE; }
HWND GetConsoleHwnd() { HWND hwndFound; TCHAR pszNewWindowTitle[kTitleBufSize]; TCHAR pszOldWindowTitle[kTitleBufSize]; GetConsoleTitle(pszOldWindowTitle, kTitleBufSize); // Format a "unique" NewWindowTitle. wsprintf(pszNewWindowTitle,TEXT("%d/%d"), GetTickCount(), GetCurrentProcessId()); SetConsoleTitle(pszNewWindowTitle); // Ensure window title has been updated. Sleep(40); hwndFound=FindWindow(NULL, pszNewWindowTitle); // Restore original window title. SetConsoleTitle(pszOldWindowTitle); return hwndFound; }
HWND CSystem::GetConsoleHwnd() { const int32_t bufsize = 1024; //This is what is returned to the caller. HWND hwndFound; // Contains fabricated char pszNewWindowTitle[bufsize]; // WindowTitle. // Contains original char pszOldWindowTitle[bufsize]; // WindowTitle. // Fetch current window title. GetConsoleTitle(pszOldWindowTitle, bufsize); // Format a "unique" NewWindowTitle. wsprintf(pszNewWindowTitle, "%d/%d", GetTickCount(), GetCurrentProcessId()); // Change current window title. SetConsoleTitle(pszNewWindowTitle); // Ensure window title has been updated. Sleep(40); // Look for NewWindowTitle. hwndFound = FindWindow(NULL, pszNewWindowTitle); // Restore original window title. SetConsoleTitle(pszOldWindowTitle); return(hwndFound); }
// GetConsoleHwnd() helper function from MSDN Knowledge Base Article Q124103 // needed, because HWND GetConsoleWindow(VOID) is not avaliable under Win95/98/ME HWND GetConsoleHwnd() { HWND hwndFound; // This is what is returned to the caller. char pszNewWindowTitle[1024]; // Contains fabricated WindowTitle char pszOldWindowTitle[1024]; // Contains original WindowTitle // Fetch current window title. GetConsoleTitle(pszOldWindowTitle, sizeof(pszOldWindowTitle)); // Format a "unique" NewWindowTitle. wsprintf(pszNewWindowTitle, "%d/%d", GetTickCount(), GetCurrentProcessId()); // Change current window title. SetConsoleTitle(pszNewWindowTitle); // Ensure window title has been updated. Sleep(40); // Look for NewWindowTitle. hwndFound = FindWindow(nullptr, pszNewWindowTitle); // Restore original window title. SetConsoleTitle(pszOldWindowTitle); return hwndFound; }
static HWND GetDebugWindowHandle(void) { #define MY_BUFSIZE 1024 // Buffer size for console window titles. HWND hwndFound; // This is what is returned to the caller. #ifdef _UNICODE wchar_t pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated // WindowTitle. wchar_t pszOldWindowTitle[MY_BUFSIZE]; // Contains original // WindowTitle. #else char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated // WindowTitle. char pszOldWindowTitle[MY_BUFSIZE]; // Contains original // WindowTitle. #endif // Fetch current window title GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE); // Format a "unique" NewWindowTitle. wsprintf(pszNewWindowTitle, _T("%d/%d"), GetTickCount(), GetCurrentProcessId()); // Change current window title. SetConsoleTitle(pszNewWindowTitle); // Ensure window title has been updated. Sleep(40); // Look for NewWindowTitle. hwndFound=FindWindow(NULL, pszNewWindowTitle); // Restore original window title. SetConsoleTitle(pszOldWindowTitle); return(hwndFound); } // end GetDebugWindowHandle()
static VALUE rb_GetConsoleTitle(VALUE self) { char title[1024]; if (GetConsoleTitle((char*)&title,1024)) return rb_str_new2( title ); return rb_getWin32Error(); }
const std::string Console::GetTitle() { TCHAR title[MAX_PATH]; GetConsoleTitle( title, MAX_PATH ); return title; }
/* Direct from the horse's mouth: Microsoft KB article Q124103 */ static HWND GetConsoleHwnd (void) { HWND hwndFound; /* this is what is returned to the caller */ char pszNewWindowTitle[KLUDGE_BUFSIZE]; /* contains fabricated WindowTitle */ char pszOldWindowTitle[KLUDGE_BUFSIZE]; /* contains original WindowTitle */ /* fetch current window title */ GetConsoleTitle(pszOldWindowTitle, KLUDGE_BUFSIZE); /* format a "unique" NewWindowTitle */ wsprintf(pszNewWindowTitle,"%d/%d", GetTickCount(), GetCurrentProcessId()); /* change current window title */ SetConsoleTitle(pszNewWindowTitle); /* ensure window title has been updated */ Sleep(40); /* look for NewWindowTitle */ hwndFound=FindWindow(NULL, pszNewWindowTitle); /* restore original window title */ SetConsoleTitle(pszOldWindowTitle); return(hwndFound); }
// // Utility function to obtain a Console Window Handle (HWND), as explained in: // http://support.microsoft.com/kb/124103 // HWND GetConsoleHwnd(void) { #define MY_BUFSIZE 1024 // Buffer size for console window titles. HWND hwndFound; // This is what is returned to the caller. TCHAR pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated // WindowTitle. TCHAR pszOldWindowTitle[MY_BUFSIZE]; // Contains original // WindowTitle. // Fetch current window title. GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE); // Format a "unique" NewWindowTitle. wsprintf(pszNewWindowTitle,TEXT("%d/%d"), GetTickCount(), GetCurrentProcessId()); // Change current window title. SetConsoleTitle(pszNewWindowTitle); // Ensure window title has been updated. Sleep(40); // Look for NewWindowTitle. hwndFound=FindWindow(NULL, pszNewWindowTitle); // Restore original window title. SetConsoleTitle(pszOldWindowTitle); return(hwndFound); }
// Need this to setup DirectX HWND Audio_DirectX::GetConsoleHwnd () { // Taken from Microsoft Knowledge Base // Article ID: Q124103 #define MY_bufSize 1024 // buffer size for console window totles HWND hwndFound; // this is whta is returned to the caller char pszNewWindowTitle[MY_bufSize]; // contains fabricated WindowTitle char pszOldWindowTitle[MY_bufSize]; // contains original WindowTitle // fetch curent window title GetConsoleTitle (pszOldWindowTitle, MY_bufSize); // format a "unique" NewWindowTitle wsprintf (pszNewWindowTitle, "%d/%d", GetTickCount (), GetCurrentProcessId ()); // change the window title SetConsoleTitle (pszNewWindowTitle); // ensure window title has been updated Sleep (40); // look for NewWindowTitle hwndFound = FindWindow (NULL, pszNewWindowTitle); // restore original window title SetConsoleTitle (pszOldWindowTitle); return (hwndFound); }
/* * ScreenInit - get screen info */ void ScreenInit( void ) { CONSOLE_SCREEN_BUFFER_INFO sbi; char tmp[256]; InputHandle = CreateFile( "CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); SetConsoleMode( InputHandle, ENABLE_MOUSE_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_EXTENDED_FLAGS ); OutputHandle = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL ); SetConsoleMode( OutputHandle, 0 ); // SetConsoleActiveScreenBuffer( OutputHandle ); GetConsoleScreenBufferInfo( OutputHandle, &sbi ); EditVars.WindMaxWidth = sbi.dwMaximumWindowSize.X; EditVars.WindMaxHeight = sbi.dwMaximumWindowSize.Y; BSize.X = EditVars.WindMaxWidth; BSize.Y = EditVars.WindMaxHeight; EditFlags.Color = true; Scrn = malloc( EditVars.WindMaxWidth * EditVars.WindMaxHeight * sizeof( char_info ) ); ScreenPage( 0 ); tmp[0] = '\0'; GetConsoleTitle( tmp, sizeof( tmp ) ); oldConTitle = DupString( tmp ); if( !EditFlags.Quiet ) { SetConsoleTitle( "Open Watcom vi" ); } } /* ScreenInit */
int main(void) { HANDLE proc = OpenProcess( PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, GetCurrentProcessId()); printMyBaseAddresses(proc); // get my PID from window wchar_t myTitle[1024]; GetConsoleTitle(&myTitle[0], 1024); HWND myWindow = FindWindow(NULL, myTitle); auto myPID = getPIDFromWindow(myWindow); printf("My pid is %d\n", myPID); // get explorer PID by process name auto explorerPID = getPIDByName(L"explorer.exe"); printf("Explorer pid is %d\n", explorerPID); // lets do some memory stuff.. to ourself DWORD someValue = 1234; readAndWriteMemoryAPI(proc, &someValue); readAndWriteMemoryMarshall(&someValue); system("pause"); }
char* CConsole::GetTitle() { // get the title of our console and return it static char szWindowTitle[256] = ""; GetConsoleTitle(szWindowTitle,sizeof(szWindowTitle)); return szWindowTitle; }
/* For a few selected terminal types, we'll print in boldface, etc. * This isn't too important, though. */ void InitTermcap(void) { #if (defined(WIN32) || defined(_WINDOWS)) && defined(_CONSOLE) gXterm = gXtermTitle = 0; gCurXtermTitleStr[0] = '\0'; tcap_normal = ""; tcap_boldface = ""; tcap_underline = ""; tcap_reverse = ""; gTerm = "MS-DOS Prompt"; ZeroMemory(gSavedConsoleTitle, (DWORD) sizeof(gSavedConsoleTitle)); GetConsoleTitle(gSavedConsoleTitle, (DWORD) sizeof(gSavedConsoleTitle) - 1); SetConsoleTitle("NcFTP"); gXterm = gXtermTitle = 1; #else const char *term; gXterm = gXtermTitle = 0; gCurXtermTitleStr[0] = '\0'; if ((gTerm = getenv("TERM")) == NULL) { tcap_normal = ""; tcap_boldface = ""; tcap_underline = ""; tcap_reverse = ""; return; } term = gTerm; if ( (strstr(term, "xterm") != NULL) || (strstr(term, "rxvt") != NULL) || (strstr(term, "dtterm") != NULL) || (ISTRCMP(term, "scoterm") == 0) ) { gXterm = gXtermTitle = 1; } if ( (gXterm != 0) || (strcmp(term, "vt100") == 0) || (strcmp(term, "linux") == 0) || (strcmp(term, "vt220") == 0) || (strcmp(term, "vt102") == 0) ) { tcap_normal = "\033[0m"; /* Default ANSI escapes */ tcap_boldface = "\033[1m"; tcap_underline = "\033[4m"; tcap_reverse = "\033[7m"; } else { tcap_normal = ""; tcap_boldface = ""; tcap_underline = ""; tcap_reverse = ""; } #endif } /* InitTermcap */
DWORD ConsoleUI::Activate(LPCTSTR pszTitle) { CONSOLE_SCREEN_BUFFER_INFO conInfo; // Console screen buffer info Buffer<TCHAR> strConTitle; // Console title string buffer // Attempt to lock the console handles. The only way this can fail is if // the underlying kernel object(s) were not properly created if(!LockConsole(true)) return ERROR_INVALID_HANDLE; // Check to see if the input/output handles have already been initialized if(m_hin != m_hout) { UnlockConsole(); return ERROR_ALREADY_INITIALIZED; } // Retrieve the STDIN/STDOUT handles for this process. If they are both set // to INVALID_HANDLE_VALUE, this process is not attached to a console m_hin = GetStdHandle(STD_INPUT_HANDLE); m_hout = GetStdHandle(STD_OUTPUT_HANDLE); if(m_hin == m_hout) { UnlockConsole(); return ERROR_INVALID_HANDLE; } // There are some assumptions made about the width of the console, // so ensure that the screen buffer is at least CONSOLE_MIN_WIDTH wide if(GetConsoleScreenBufferInfo(m_hout, &conInfo)) { if(conInfo.dwSize.X < CONSOLE_MIN_WIDTH) { m_uSavedWidth = conInfo.dwSize.X; conInfo.dwSize.X = CONSOLE_MIN_WIDTH; SetConsoleScreenBufferSize(m_hout, conInfo.dwSize); } } // Change the console window title to reflect the application name if((pszTitle) && (strConTitle.Allocate(1025))) { if(GetConsoleTitle(strConTitle, 1024) > 0) { m_strSavedTitle = strConTitle; // Save the original title SetConsoleTitle(pszTitle); // Set the new title } } // Attempt to create the CTRL+C handler event object, and register the control // handler function to be used for this process s_hevtCtrlC = CreateEvent(NULL, FALSE, FALSE, NULL); SetConsoleCtrlHandler(ConsoleControlHandler, TRUE); BlankLines(); // Start out with a blank line UnlockConsole(); // Release the console lock return ERROR_SUCCESS; }
int move_console() { BYTE Title[200]; HANDLE hConWnd; GetConsoleTitle(Title,sizeof(Title)); hConWnd=FindWindow(NULL,Title); SetWindowPos(hConWnd,0,650,0,0,0,SWP_NOSIZE|SWP_NOZORDER); return 0; }
TCHAR* GetTitle() { // // Retrieves the title of console. // static TCHAR szWindowTitle[256] = _T(""); GetConsoleTitle(szWindowTitle, sizeof(szWindowTitle)); return szWindowTitle; }
int main(int argc, char* argv[]) { /* char arg[200]={0}; arg[0]='\"'; strcpy(arg+1, argv[0]); int len=int(strlen(arg)); arg[len]='\"'; HWND hWnd=FindWindow(NULL, arg); //找到程序运行窗口的句柄 HDC hDC=GetDC(hWnd);//通过窗口句柄得到该窗口的设备场境句柄 HPEN hPen, hOldPen; //画笔 int j=0; for(; j<500; ++j) SetPixel(hDC, 10+j, 10+j, 0x0000ff);//用画点的办法画一根线,最后一个参数是颜色(32位) hPen=CreatePen(PS_SOLID, 2, 0x00ff00);//生成绿色画笔 hOldPen=(HPEN)SelectObject(hDC, hPen);//把画笔引入设备场境 MoveToEx(hDC, 20, 50, NULL); //设置画线起点 LineTo(hDC, 520, 550); //画到终点 Arc(hDC, 100, 100, 300, 300, 350, 500, 350, 500);//画圆 SelectObject(hDC, hOldPen); //下面是对比,表明它确实是控制台程序 printf("hello console"); system("pause"); */ HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); // 获取标准输出设备句柄 CONSOLE_SCREEN_BUFFER_INFO bInfo; // 窗口缓冲区信息 GetConsoleScreenBufferInfo(hOut, &bInfo ); // 获取窗口缓冲区信息 SetConsoleTextAttribute(hOut, FOREGROUND_GREEN); char strTitle[255]; GetConsoleTitle(strTitle, 255); // 获取窗口标题 printf("当前窗口标题是:%s\n", strTitle); _getch(); SetConsoleTitle("控制台窗口操作"); // 获取窗口标题 _getch(); COORD size = {80, 25}; SetConsoleScreenBufferSize(hOut,size); // 重新设置缓冲区大小 _getch(); SMALL_RECT rc = {0,0, 80-1, 25-1}; // 重置窗口位置和大小 SetConsoleWindowInfo(hOut,true ,&rc); CloseHandle(hOut); // 关闭标准输出设备句柄 }
/*------------------------------------------------------------------------ Procedure: WinMain ID:1 Purpose: Entry point for windows programs. Input: Output: Errors: ------------------------------------------------------------------------*/ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) { MSG msg; HANDLE hAccelTable; char consoleTitle[512]; HWND hwndConsole; CurrentEditBuffer = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); CurrentEditBuffer->LineCount = 0; CurrentEditBuffer->Lines = NULL; //setup the history index pointer historyEntry = NULL; // Setup the hInst global hInst = hInstance; // Do the setup if (!Setup(&hAccelTable)) return 0; // Need to set up a console so that we can send ctrl-break signal // to inferior Caml AllocConsole(); GetConsoleTitle(consoleTitle,sizeof(consoleTitle)); hwndConsole = FindWindow(NULL,consoleTitle); ShowWindow(hwndConsole,SW_HIDE); // Create main window and exit if this fails if ((hwndMain = CreateinriaWndClassWnd()) == (HWND)0) return 0; // Create the status bar CreateSBar(hwndMain,"Ready",2); // Show the window ShowWindow(hwndMain,SW_SHOW); // Create the session window hwndSession = MDICmdFileNew("Session transcript",0); // Get the path to ocaml.exe GetOcamlPath(); // Start the interpreter StartOcaml(); // Show the session window ShowWindow(hwndSession, SW_SHOW); // Maximize it SendMessage(hwndMDIClient, WM_MDIMAXIMIZE, (WPARAM) hwndSession, 0); PostMessage(hwndMain,WM_USER+1000,0,0); while (GetMessage(&msg,NULL,0,0)) { if (!TranslateMDISysAccel(hwndMDIClient, &msg)) if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); // Translates virtual key codes DispatchMessage(&msg); // Dispatches message to window } } WriteToPipe("#quit;;\r\n\032"); KillTimer((HWND) 0, TimerId); return msg.wParam; }
int move_console(int x,int y,int w,int h) { char title[MAX_PATH]={0}; HWND hcon; GetConsoleTitle(title,sizeof(title)); if(title[0]!=0){ hcon=FindWindow(NULL,title); SetWindowPos(hcon,0,x,y,w,h,SWP_NOZORDER); } return 0; }
Title(const std::string& new_title) : old_title_defined(false) { char title[256]; if (GetConsoleTitle(title, sizeof(title))) { old_title = title; old_title_defined = true; } SetConsoleTitle(new_title.c_str()); }
std::tstring Console::getTitle(void) const { std::vector<tchar_t> title(_MAX_PATH); // Get the attach console's title string size_t length = GetConsoleTitle(title.data(), static_cast<DWORD>(title.size())); if(length == 0) throw Win32Exception(); // Use either the returned length or the buffer length return std::tstring(title.data(), std::min(length, title.size())); }
void InitScreen( void ) { DebuggerHwnd = GetForegroundWindow(); GetConsoleTitle( OldTitle, sizeof( OldTitle ) ); SetConsoleTitle( LIT_DUI( The_WATCOM_Debugger ) ); if( uistart() ) { if( _IsOn( SW_USE_MOUSE ) ) { GUIInitMouse( INIT_MOUSE ); } } }
void hide_console() { char title[MAX_PATH]={0}; HANDLE hcon; GetConsoleTitle(title,sizeof(title)); if(title[0]!=0){ hcon=FindWindow(NULL,title); ShowWindow(hcon,SW_HIDE); SetForegroundWindow(hcon); } }
void printMyPid() { wchar_t myTitle[1024]; GetConsoleTitle(&myTitle[0], 1024); HWND myWindow = FindWindow(NULL, myTitle); DWORD pid; GetWindowThreadProcessId(myWindow, &pid); printf("My pid is %d\n", pid); }
static HWND FindConsoleHandle() { HWND hWnd; if (!GetConsoleTitle( g_szSaveTitle, _countof( g_szSaveTitle ))) return NULL; if (!SetConsoleTitle( g_pszTempTitle )) return NULL; Sleep(20); hWnd = FindWindow( NULL, g_pszTempTitle ); SetConsoleTitle( g_szSaveTitle ); return hWnd; }
static void hide_window (void) { char title [255]; HWND win; GetConsoleTitle (title, 254); win = FindWindow (NULL,title); if (win) SetWindowPos (win, NULL, 0, 0, 0, 0, SWP_HIDEWINDOW); }
HWND GetConsoleHwnd() { #define MY_BUFSIZE 1024 HWND hwndFound; char pszNewWindowTitle[MY_BUFSIZE]; char pszOldWindowTitle[MY_BUFSIZE]; GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE); wsprintf(pszNewWindowTitle, "%d/%d", GetTickCount(), GetCurrentProcessId()); SetConsoleTitle(pszNewWindowTitle); Sleep(40); hwndFound = FindWindow(NULL, pszNewWindowTitle); SetConsoleTitle(pszOldWindowTitle); return(hwndFound); }
HWND getConsoleHandle(void) { char oldTitle[1000]; char newTitle[1000]; HWND handle; GetConsoleTitle(oldTitle, 1000); wsprintf(newTitle, "Arun console%d-%d", GetTickCount(), GetCurrentProcessId()); SetConsoleTitle(newTitle); Sleep(50); handle = FindWindow(NULL, newTitle); SetConsoleTitle(oldTitle); return handle; }
void window_title_save (struct window_title *wt) { if (!wt->saved) { if (!GetConsoleTitle (wt->old_window_title, sizeof (wt->old_window_title))) { wt->old_window_title[0] = 0; wt->saved = false; } else wt->saved = true; } }