X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=main.cpp;h=1bc49fc60285905d642bba45f416486c20de3c34;hb=HEAD;hp=48372ea58e162e2943052051862ab68bb14e9f01;hpb=9498c97aeda8bf4b6b6ac3ac52d4ef4367921876;p=ckw%2Fckw.git diff --git a/main.cpp b/main.cpp index 48372ea..1bc49fc 100644 --- a/main.cpp +++ b/main.cpp @@ -358,8 +358,8 @@ static void __set_console_window_size(LONG cols, LONG rows) if(cols == CSI_WndCols(&csi) && rows == CSI_WndRows(&csi)) return; - SMALL_RECT tmp = { 0,0,0,0 }; - SetConsoleWindowInfo(gStdOut, TRUE, &tmp); + //SMALL_RECT tmp = { 0,0,0,0 }; + //SetConsoleWindowInfo(gStdOut, TRUE, &tmp); csi.dwSize.X = (SHORT)cols; csi.srWindow.Left = 0; @@ -587,6 +587,21 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) break; case WM_MOUSEMOVE: onMouseMove(hWnd, (short)LOWORD(lp),(short)HIWORD(lp)); + // scroll when mouse is outside (craftware) + { + short x = (short)LOWORD(lp); + short y = (short)HIWORD(lp); + + RECT rc; + GetClientRect(hWnd, &rc); + + if( y<0 ) { + PostMessage(gConWnd, WM_MOUSEWHEEL, WHEEL_DELTA<<16, y<<16|x ); + } + else if(y>=rc.bottom) { + PostMessage(gConWnd, WM_MOUSEWHEEL, -WHEEL_DELTA<<16, y<<16|x ); + } + } break; case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: @@ -702,7 +717,7 @@ static BOOL create_window(ckOpt& opt) }else{ title = new wchar_t[ strlen(conf_title)+1 ]; ZeroMemory(title, sizeof(wchar_t) * (strlen(conf_title)+1)); - MultiByteToWideChar(CP_ACP, 0, conf_title, strlen(conf_title), title, sizeof(wchar_t) * (strlen(conf_title)+1)); + MultiByteToWideChar(CP_ACP, 0, conf_title, (int)strlen(conf_title), title, (int)(sizeof(wchar_t) * (strlen(conf_title)+1)) ); } /* calc window size */ @@ -754,7 +769,7 @@ static BOOL create_window(ckOpt& opt) wc.hbrBackground = CreateSolidBrush(gColorTable[0]); wc.lpszMenuName = NULL; wc.lpszClassName = className; - wc.hIconSm = wc.hIcon; + wc.hIconSm = NULL; if(! RegisterClassEx(&wc)) return(FALSE); @@ -804,6 +819,10 @@ static BOOL create_child_process(const char* cmd, const char* curdir) si.hStdOutput = gStdOut; si.hStdError = gStdErr; + if (curdir) + if (char *p = strstr((char*)curdir, ":\"")) + *(p+1) = '\\'; + if(! CreateProcessA(NULL, buf, NULL, NULL, TRUE, 0, NULL, curdir, &si, &pi)) { delete [] buf; @@ -863,15 +882,47 @@ static BOOL create_font(const char* name, int height) return(TRUE); } +// for Windows SDK v7.0 ƒGƒ‰[‚ª”­¶‚·‚éê‡‚̓Rƒƒ“ƒgƒAƒEƒgB +#ifdef _MSC_VER +#include +#endif + /*----------*/ static void __hide_alloc_console() { + bool bResult = false; + /* * Open Console Window * hack StartupInfo.wShowWindow flag */ - DWORD* pflags = (DWORD*) 0x00020068; /* private memory */ - WORD* pshow = (WORD*) 0x0002006C; + +#ifdef _MSC_VER +#ifdef _WIN64 + INT_PTR peb = *(INT_PTR*)((INT_PTR)NtCurrentTeb() + 0x60); + INT_PTR param = *(INT_PTR*) (peb + 0x20); + DWORD* pflags = (DWORD*) (param + 0xa4); + WORD* pshow = (WORD*) (param + 0xa8); +#else +#ifndef _WINTERNL_ + INT_PTR peb = *(INT_PTR*)((INT_PTR)NtCurrentTeb() + 0x30); + INT_PTR param = *(INT_PTR*) (peb + 0x10); +#else + // for Windows SDK v7.0 + PPEB peb = *(PPEB*)((INT_PTR)NtCurrentTeb() + 0x30); + PRTL_USER_PROCESS_PARAMETERS param = peb->ProcessParameters; +#endif // _WINTERNL_ + + DWORD* pflags = (DWORD*)((INT_PTR)param + 0x68); + WORD* pshow = (WORD*)((INT_PTR)param + 0x6C); +#endif // _WIN64 +#else + // for gcc + INT_PTR peb = *(INT_PTR*)((INT_PTR)NtCurrentTeb() + 0x30); + PRTL_USER_PROCESS_PARAMETERS param = *(PRTL_USER_PROCESS_PARAMETERS*)(peb + 0x10); + DWORD* pflags = (DWORD*)&(param->dwFlags); + WORD* pshow = (WORD*)&(param->wShowWindow); +#endif // _MSC_VER DWORD backup_flags = *pflags; WORD backup_show = *pshow; @@ -881,8 +932,14 @@ static void __hide_alloc_console() /* check */ if(si.dwFlags == backup_flags && si.wShowWindow == backup_show) { + // Ú×‚Í•s–¾‚¾‚ªSTARTF_TITLEISLINKNAME‚ª—§‚Á‚Ä‚¢‚é‚ƁA + // Console‘‹‰B‚µ‚ÉŽ¸”s‚·‚é‚̂ŏœ‹Ž(Win7-64bit) + if (*pflags & STARTF_TITLEISLINKNAME) { + *pflags &= ~STARTF_TITLEISLINKNAME; + } *pflags |= STARTF_USESHOWWINDOW; *pshow = SW_HIDE; + bResult = true; } AllocConsole(); @@ -890,6 +947,20 @@ static void __hide_alloc_console() /* restore */ *pflags = backup_flags; *pshow = backup_show; + + while((gConWnd = GetConsoleWindow()) == NULL) { + Sleep(10); + } + + if (!bResult){ + while (!IsWindowVisible(gConWnd)) { + Sleep(10); + } + while(IsWindowVisible(gConWnd)) { + ShowWindow(gConWnd, SW_HIDE); + Sleep(10); + } + } } /*----------*/ @@ -905,24 +976,14 @@ static BOOL create_console(ckOpt& opt) conf_title = opt.getTitle(); if(!conf_title || !conf_title[0]){ - title = L"ckw"; - }else{ - title = new wchar_t[ strlen(conf_title)+1 ]; - ZeroMemory(title, sizeof(wchar_t) * (strlen(conf_title)+1)); - MultiByteToWideChar(CP_ACP, 0, conf_title, strlen(conf_title), title, sizeof(wchar_t) * (strlen(conf_title)+1)); - } - - __hide_alloc_console(); - - while((gConWnd = GetConsoleWindow()) == NULL) { - Sleep(10); - } - - while(!IsWindowVisible(gConWnd)) { - Sleep(10); + title = L"ckw"; + }else{ + title = new wchar_t[ strlen(conf_title)+1 ]; + ZeroMemory(title, sizeof(wchar_t) * (strlen(conf_title)+1)); + MultiByteToWideChar(CP_ACP, 0, conf_title, (int)strlen(conf_title), title, (int)(sizeof(wchar_t) * (strlen(conf_title)+1)) ); } - ShowWindow(gConWnd, SW_HIDE); + __hide_alloc_console(); SetConsoleTitle(title); @@ -968,7 +1029,7 @@ static BOOL create_console(ckOpt& opt) fonts = GetNumberOfConsoleFonts(); if (fonts > MAX_FONTS) fonts = MAX_FONTS; - + GetConsoleFontInfo(gStdOut, 0, fonts, font); CONSOLE_FONT minimalFont = { 0, {0, 0}}; for(DWORD i=0;i