OSDN Git Service

Change icon.ico. And fix icon bug, write ChangeLog.txt.
[ckw/ckw.git] / main.cpp
index 61badbf..1bc49fc 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -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);
 
@@ -867,15 +882,47 @@ static BOOL create_font(const char* name, int height)
        return(TRUE);
 }
 
+// for Windows SDK v7.0 \83G\83\89\81[\82ª\94­\90\82·\82é\8fê\8d\87\82Í\83R\83\81\83\93\83g\83A\83E\83g\81B
+#ifdef _MSC_VER
+#include <winternl.h>
+#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;
@@ -885,8 +932,14 @@ static void __hide_alloc_console()
 
        /* check */
        if(si.dwFlags == backup_flags && si.wShowWindow == backup_show) {
+               // \8fÚ\8d×\82Í\95s\96¾\82¾\82ªSTARTF_TITLEISLINKNAME\82ª\97§\82Á\82Ä\82¢\82é\82Æ\81A
+               // Console\91\8b\89B\82µ\82É\8e¸\94s\82·\82é\82Ì\82Å\8f\9c\8b\8e(Win7-64bit)
+               if (*pflags & STARTF_TITLEISLINKNAME) {
+                       *pflags &= ~STARTF_TITLEISLINKNAME;
+               }
                *pflags |= STARTF_USESHOWWINDOW;
                *pshow  = SW_HIDE;
+               bResult = true;
        }
 
        AllocConsole();
@@ -894,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);
+               }
+       }
 }
 
 /*----------*/
@@ -909,29 +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);
-       }
-       // \82±\82Ì\83\8b\81[\83v\82ð\92Ç\89Á
-       for(int i=0;!IsWindowVisible(gConWnd) && i<100;i++)
-       {
-         Sleep(10);
-       }
-       while(IsWindowVisible(gConWnd)) {
-               ShowWindow(gConWnd, SW_HIDE);
-               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);
 
@@ -1123,6 +1175,7 @@ static void _terminate()
        SAFE_DeleteObject(gFont);
        SAFE_DeleteObject(gBgBrush);
        SAFE_DeleteObject(gBgBmp);
+       ime_wrap_term();
 }
 
 #ifdef _DEBUG