示例#1
1
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static int  cxChar, cxCaps, cyChar, cyClient, iVscrollPos ;
     HDC         hdc ;
     int         i, y ;
     PAINTSTRUCT ps ;
     TCHAR       szBuffer[10] ;
     TEXTMETRIC  tm ;

     switch (message)
     {
     case WM_CREATE:
          hdc = GetDC (hwnd) ;

          GetTextMetrics (hdc, &tm) ;
          cxChar = tm.tmAveCharWidth ;
          cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;
          cyChar = tm.tmHeight + tm.tmExternalLeading ;

          ReleaseDC (hwnd, hdc) ;

          SetScrollRange (hwnd, SB_VERT, 0, NUMLINES - 1, FALSE) ;
          SetScrollPos   (hwnd, SB_VERT, iVscrollPos, TRUE) ;
          return 0 ;

     case WM_SIZE:
          cyClient = HIWORD (lParam) ;
          return 0 ;

     case WM_VSCROLL:
          switch (LOWORD (wParam))
          {
          case SB_LINEUP:
               iVscrollPos -= 1 ;
               break ;
     
          case SB_LINEDOWN:
               iVscrollPos += 1 ;
               break ;
     
          case SB_PAGEUP:
               iVscrollPos -= cyClient / cyChar ;
               break ;
     
          case SB_PAGEDOWN:
               iVscrollPos += cyClient / cyChar ;
               break ;
     
          case SB_THUMBPOSITION:
               iVscrollPos = HIWORD (wParam) ;
               break ;
     
          default :
               break ;
          }

          iVscrollPos = max (0, min (iVscrollPos, NUMLINES - 1)) ;

          if (iVscrollPos != GetScrollPos (hwnd, SB_VERT))
          {
               SetScrollPos (hwnd, SB_VERT, iVscrollPos, TRUE) ;
               InvalidateRect (hwnd, NULL, TRUE) ;
          }
          return 0 ;

     case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps) ;
     
          for (i = 0 ; i < NUMLINES ; i++)
          {
               y = cyChar * (i - iVscrollPos) ;
     
               TextOut (hdc, 0, y,
                        sysmetrics[i].szLabel,
                        lstrlen (sysmetrics[i].szLabel)) ;
     
               TextOut (hdc, 22 * cxCaps, y,
                        sysmetrics[i].szDesc,
                        lstrlen (sysmetrics[i].szDesc)) ;
     
               SetTextAlign (hdc, TA_RIGHT | TA_TOP) ;
     
               TextOut (hdc, 22 * cxCaps + 40 * cxChar, y, szBuffer,
                        wsprintf (szBuffer, TEXT ("%5d"),
                             GetSystemMetrics (sysmetrics[i].iIndex))) ;
     
               SetTextAlign (hdc, TA_LEFT | TA_TOP) ;
          }
          EndPaint (hwnd, &ps) ;
          return 0 ;

     case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}
/*********************************************************************************************
 *
 * This is the dialog procedure for the beep dialog.
 *
 *      Message:                Action:
 *      ========                =======
 *      WM_INITDIALOG           initialize beep duration and frequency
 *      WM_CLOSE                end this dialog
 *      WM_PAINT                display text strings under each scroll bar to represent
 *                              the value of the slider
 *      WM_HSCROLL              adjust scroll bars and duration/frequency values
 *      WM_COMMAND              ID_BEEPNOW:  beep with the specified frequency/duration
 *                              ID_DONE: dismiss dialog box
 *
 *********************************************************************************************/
BOOL WINAPI BeepDiaProc(HWND hDlg, UINT messg, WPARAM wParam, LPARAM lParam)
{

        char lpstrOutString[256];        // string used to display text in dialog box
    RECT rect;
    HDC hdc;                                         // device context for painting
    PAINTSTRUCT ps;                          // paint structure for painting
    SIZE mySize;                 // used to place text in dialog box
    ULONG ulDlgUnitsToPixels;        // used to place text in dialog box
    static LONG ulBeepDuration; // beep duration - selected by slider
    static LONG ulBeepFreq;     // beep frequency - selected by slider
    LONG *pscrollpos;           // current slider value
    int id;                      // determines which slider
    char *templateStringMS = "Selected Value: %5d ms   ";
    char *templateStringHZ = "Selected Value: %5d hz   ";

    switch (messg) {
        /*
         * WM_INITDIALOG: initialize duration and frequency variables
         */
        case WM_INITDIALOG:
            ulBeepDuration = MINDURATION;
            ulBeepFreq = MINFREQ;
            break;
        /*
         * WM_CLOSE: Dismiss this dialog
         */
        case WM_CLOSE:
            EndDialog(hDlg,FALSE);
            break;
        /*
         * WM_PAINT: Determine position in dialog box for text output and
                 *           put the text strings there
         */
        case WM_PAINT:
            hdc = BeginPaint(hDlg,&ps);
            ulDlgUnitsToPixels = GetDialogBaseUnits();
            sprintf(lpstrOutString,templateStringHZ,ulBeepFreq*FREQSTEP);
            TextOut(hdc,(40*LOWORD(ulDlgUnitsToPixels))/4,(40*HIWORD(ulDlgUnitsToPixels))/8,lpstrOutString,strlen(lpstrOutString));
            sprintf(lpstrOutString,templateStringMS,ulBeepDuration*DURATIONSTEP);
            TextOut(hdc,(40*LOWORD(ulDlgUnitsToPixels))/4,(100*HIWORD(ulDlgUnitsToPixels))/8,lpstrOutString,strlen(lpstrOutString));
            EndPaint(hDlg,&ps);
            break;
        /*
         * WM_HSCROLL: handle horizontal scrolling.  For all scroll
         *             messages, determine which scroll bar this is (via GetDlgCtrlId)
         *             and set a pointer to the scroll value (pscrollpos).
         */
        case WM_HSCROLL:
            ulDlgUnitsToPixels = GetDialogBaseUnits();
            id = GetDlgCtrlID((HWND)lParam);
            hdc = GetDC(hDlg);
            GetTextExtentPoint(hdc,templateStringHZ,strlen(templateStringHZ),&mySize);
            DeleteDC(hdc);
            if (id==ID_FREQBAR) {
                SetScrollRange((HWND)lParam,SB_CTL,MINFREQ,MAXFREQ,TRUE);
                pscrollpos = &ulBeepFreq;
                rect.top = (40*HIWORD(ulDlgUnitsToPixels))/8;
                rect.bottom = rect.top + mySize.cy;
                rect.left = (40*LOWORD(ulDlgUnitsToPixels))/4;
                rect.right = rect.left + mySize.cx;
            } else {
                SetScrollRange((HWND)lParam,SB_CTL,MINDURATION,MAXDURATION,TRUE);
                pscrollpos = &ulBeepDuration;
                rect.top = (100*HIWORD(ulDlgUnitsToPixels))/8;
                rect.bottom = rect.top + mySize.cy;
                rect.left = (40*LOWORD(ulDlgUnitsToPixels))/4;
                rect.right = rect.left + mySize.cx;
            }
            switch(LOWORD(wParam)) {
                /*
                 * SB_LINERIGHT: user incremented by 1.  Update scroll
                 *               position and redraw.
                 */
                case SB_LINERIGHT:
                    (*pscrollpos)++;
                    if ((id==ID_FREQBAR) && (*pscrollpos > MAXFREQ)) {
                       *pscrollpos = MAXFREQ;
                    } else if ((id==ID_DURBAR) && (*pscrollpos > MAXDURATION)){
                       *pscrollpos = MAXDURATION;
                    }
                    SetScrollPos((HWND)lParam,SB_CTL,*pscrollpos,TRUE);
                    break;
                /*
                 * SB_LINELEFT: user decremented by 1.  Update scroll
                 *              position and redraw.
                 */
                case SB_LINELEFT:
                    (*pscrollpos)--;
                    if ((id==ID_FREQBAR) && (*pscrollpos < MINFREQ)) {
                       *pscrollpos = MINFREQ;
                    } else if ((id=ID_DURBAR) && (*pscrollpos < MINDURATION)) {
                       *pscrollpos = MINDURATION;
                    }
                    SetScrollPos((HWND)lParam,SB_CTL,*pscrollpos,TRUE);
                    break;
                /*
                 * SB_LINELEFT: user decremented by 1 "page".  Update scroll
                 *              position and redraw.
                 */
                case SB_PAGELEFT:
                    *pscrollpos -= BEEPSCROLLWIDTH;
                    if ((id==ID_FREQBAR) && (*pscrollpos < MINFREQ)) {
                       *pscrollpos = MINFREQ;
                    } else if ((id=ID_DURBAR) && (*pscrollpos < MINDURATION)) {
                       *pscrollpos = MINDURATION;
                    }
                    SetScrollPos((HWND)lParam,SB_CTL,*pscrollpos,TRUE);
                    break;
                /*
                 * SB_LINERIGHT: user incremented by 1 "page".  Update scroll
                 *               position and redraw.
                 */
                case SB_PAGERIGHT:
                    *pscrollpos += BEEPSCROLLWIDTH;
                    if ((id==ID_FREQBAR) && (*pscrollpos > MAXFREQ)) {
                       *pscrollpos = MAXFREQ;
                    } else if ((id==ID_DURBAR) && (*pscrollpos > MAXDURATION)){
                       *pscrollpos = MAXDURATION;
                    }
                    SetScrollPos((HWND)lParam,SB_CTL,*pscrollpos,TRUE);
                    break;
                /*
                 * SB_THUMBPOSITION: user moved to a specified position.  Update scroll
                 *                   position and redraw.
                 * SB_THUMBTRACK: same as SB_THUMBPOSITION
                 */
                case SB_THUMBPOSITION:
                case SB_THUMBTRACK:
                    *pscrollpos = HIWORD(wParam);
                    SetScrollPos((HWND)lParam,SB_CTL,*pscrollpos,TRUE);
                    break;
            }
            InvalidateRect(hDlg,&rect,FALSE);
            break;
        /*
         * WM_COMMAND: see individual actions
         */
        case WM_COMMAND:
            switch (LOWORD(wParam)) {
                /*
                 * ID_BEEPNOW: use Beep API to make the sound!
                 */
                case ID_BEEPNOW:
                    Beep(ulBeepFreq*FREQSTEP,ulBeepDuration*DURATIONSTEP);
                    break;
                /*
                 * ID_DONE: dismiss this dialog
                 */
                case ID_DONE:
                    EndDialog(hDlg,TRUE);
                    break;
                default:
                    return FALSE;
            }
            default:
                return FALSE;
        }
        return TRUE;
}
示例#3
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static int          nLineCount,lineNo;
    static int          cyClient, cxChar, cyChar;
    static int          xScroll;
    static HGLOBAL      hResource;
    static HWND         hwndScroll;
    static HWND         hScroll;

    CHAR        *szText;
    HINSTANCE   hInstance;
    HDC         hdc;
    PAINTSTRUCT ps;
    RECT        clientRect;
    int         i;

    switch(msg)
    {
    case WM_CREATE:
        hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
        lineNo = 0;
        //Load Text resource
        hResource = LoadResource(hInstance, FindResource(hInstance, TEXT("ANNABELLEE"), TEXT("TEXT")));
        szText = (CHAR *)LockResource(hResource);

        //Create Scrollbar
        hScroll = CreateWindow(TEXT("scrollbar"), NULL, SB_VERT | WS_CHILD | WS_VISIBLE, 
                    0, 0, 0, 0,
                    hwnd, (HMENU)1, hInstance, NULL);
        //calculate line count
        while(*szText != '\0' && *szText != '\\')
        {
            if (*szText == '\n')
                ++nLineCount;
            szText = AnsiNext(szText);
        }
        *szText == '\0';

        //Get char size
        cxChar = LOWORD(GetDialogBaseUnits());
        cyChar = HIWORD(GetDialogBaseUnits());
        xScroll = GetSystemMetrics(SM_CXVSCROLL);

        //Setup scroll 
        SetScrollRange(hScroll, SB_CTL, 0, nLineCount, TRUE);
        SetScrollPos(hScroll, SB_CTL, 0, TRUE);
        break;
    case WM_SIZE:
        {
            MoveWindow(hScroll, LOWORD(lParam) - xScroll, 0, xScroll, HIWORD(lParam), TRUE); 
            cyClient = HIWORD(lParam);
            SetFocus(hScroll);
            break;
        }
    case WM_SETFOCUS:
        {
            SetFocus(hScroll);
            break;
        }
    case WM_VSCROLL:
        {
            switch(wParam)
            {
                case SB_TOP:
                    lineNo = 0;
                    break;
                case SB_BOTTOM:
                    lineNo = nLineCount;
                    break;
                case SB_LINEDOWN:
                    lineNo++;
                    break;
                case SB_LINEUP:
                    lineNo--;
                    break;
                case SB_PAGEDOWN:
                    lineNo += cyClient / cyChar;
                    break;
                case SB_PAGEUP:
                    lineNo -= cyClient / cyChar;
                    break;
                default:
                    break;
            }
            lineNo = max(0, lineNo);
            lineNo = min(lineNo, nLineCount);
            SetScrollPos(hScroll, SB_CTL, lineNo, TRUE);
            InvalidateRect(hwnd, NULL, TRUE);
            break;
        }
    case WM_PAINT:
        {
            hdc = BeginPaint(hwnd, &ps);
            GetClientRect(hwnd, &clientRect);
            clientRect.left += cxChar;
            clientRect.top += cyChar*(1 - lineNo);
            szText = (CHAR *)LockResource(hResource);
            DrawTextA(hdc, szText, -1, &clientRect, DT_TOP); 
            EndPaint(hwnd, &ps);
            break;
        }
    case WM_DESTROY:
        {
            FreeResource(hResource);
            PostQuitMessage(0);
            break;
        }
    }
    return DefWindowProc(hwnd, msg, wParam, lParam);
}
示例#4
0
void TScrollBar::set_range(int rmin, int rmax, bool repaint/*=false*/)
{
  SetScrollRange(m_hwnd,m_type,rmin,rmax,repaint);
}
示例#5
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) {
    PAINTSTRUCT Ps;
    static HWND hWndList;
    static HWND hWndScroll, hWndWidthScroll, hWndHeightScroll;
    static RECT rcScroll, rcTODOList, rcInputTODO, rcQuantity;
    HBRUSH hBrushStatic;



    SetRect(&rcScroll, 315, 40, 25, 150);
    SetRect(&rcTODOList, 10, 10, 100, 40);
    SetRect(&rcInputTODO, 120, 150, 190, 25);
    SetRect(&rcQuantity, 210, 10, 300, 30);


    switch(msg) {
    case WM_CREATE: {

                //Create Scrolls
                hWndScroll = CreateWindowEx((DWORD)NULL,
                    TEXT("scrollbar"),
                    NULL,
                    WS_CHILD | WS_VISIBLE | SBS_VERT,
                    315, 40, 25, 150,
                    hWnd,
                    (HMENU) ID_SCROLL_BAR,
                    hInstance,
                    NULL);
                SetScrollRange(hWndScroll,SB_CTL, 0, 255, FALSE);
                SetScrollPos(hWndScroll, SB_CTL, 0, TRUE);

                hWndWidthScroll = CreateWindowEx((DWORD)NULL,
                    TEXT("scrollbar"),
                    NULL,
                    WS_CHILD | WS_VISIBLE | SBS_HORZ,
                    10, 230, 300, 20,
                    hWnd,
                    (HMENU)ID_WIDTH_SCROLL,
                    hInstance,
                    NULL);
                SetScrollRange(hWndWidthScroll, SB_CTL, 0, 100, TRUE);
                SetScrollPos(hWndWidthScroll, SB_CTL, 0, TRUE);

                hWndHeightScroll = CreateWindowEx((DWORD)NULL,
                    TEXT("scrollbar"),
                    NULL,
                    WS_CHILD | WS_VISIBLE | SBS_HORZ,
                    10, 260, 300, 20,
                    hWnd,
                    (HMENU)ID_HEIGHT_SCROLL,
                    hInstance,
                    NULL);
                SetScrollRange(hWndHeightScroll, SB_CTL, 0, 100, TRUE);
                SetScrollPos(hWndHeightScroll, SB_CTL, 45, TRUE);

                /**
                * Create ListBox
                */

                hWndList = CreateWindowEx((DWORD)NULL,
                    TEXT("listbox"),
                    "",
                    WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL | LBS_STANDARD | WS_BORDER,
                    10, 40,
                    300, 100,
                    hWnd,
                    (HMENU) IDC_TODO_LIST,
                    hInstance,
                    NULL);


                /**
                * Create AddTODO Button
                */
                HFONT hFont = CreateFont(30,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
                    CLIP_DEFAULT_PRECIS,NULL, VARIABLE_PITCH,TEXT("Impact"));

                HWND hButtonAddTODO = CreateWindowEx(NULL,
                    "BUTTON",
                    "Add a task",
                    WS_TABSTOP|WS_VISIBLE|
                    WS_CHILD|BS_DEFPUSHBUTTON|BS_TOP,
                    10,
                    150,
                    100,
                    25,
                    hWnd,
                    (HMENU)BUTTON_ADD_TODO,
                    GetModuleHandle(NULL),
                    NULL);

                /**
                * Create button ShowTODONumber
                */
                HWND hShowTODONumber = CreateWindowEx(NULL,
                    "BUTTON",
                    "Display a message",
                    WS_TABSTOP|WS_VISIBLE|
                    WS_CHILD|BS_DEFPUSHBUTTON|BS_TOP,
                    10,
                    180,
                    300,
                    40,
                    hWnd,
                    (HMENU)BUTTON_DISPLAY_TODO_NR,
                    GetModuleHandle(NULL),
                    NULL);
                SendMessage (hShowTODONumber, WM_SETFONT, WPARAM (hFont), TRUE);

                /**
                * Draw main Input TODO field
                */

                hInputTODO = CreateWindowEx(
                    (DWORD)NULL,
                    TEXT("edit"),
                    "",
                    WS_VISIBLE | WS_CHILD | WS_BORDER,
                    120,
                    150,
                    190,
                    25,
                    hWnd,
                    (HMENU)INPUT_TEXT_ADD_TODO,
                    GetModuleHandle(NULL),
                    NULL);

            }
            break;

    case WM_PAINT: {
            HDC hdc = BeginPaint(hWnd, &Ps);

            /**
            * Draw Text
            */

            // Second Text
            char TODONrMessage[40];
            char nr[50];
            LoadString (hInstance, IDS_TODONUMBER, TODONrMessage, 40) ;
            wsprintf (nr, TODONrMessage, TODONumber);

            SetBkMode(hdc, TRANSPARENT);

            DrawText( hdc, nr, -1, &rcQuantity, DT_SINGLELINE | DT_NOCLIP) ;

            // First Text
            HFONT hFont = CreateFont(25,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
            CLIP_DEFAULT_PRECIS,NULL, VARIABLE_PITCH,TEXT("Impact"));

            SelectObject(hdc, hFont);
            SetBkMode(hdc, OPAQUE);
            SetBkColor(hdc, RGB(scrollColor,scrollColor + 70, scrollColor+150));
            SetTextColor(hdc, RGB(fontColor[0], fontColor[1], fontColor[2]));
            DrawText(hdc, TEXT(firstText), -1, &rcTODOList, DT_NOCLIP);

            EndPaint(hWnd, &Ps);
        }
        break;

    case WM_CTLCOLOREDIT: {
            HDC hdc = (HDC)wParam;
            HWND hwnd = (HWND)lParam;
            HBRUSH color;

            if (GetDlgCtrlID(hwnd) == INPUT_TEXT_ADD_TODO) {
                color = CreateSolidBrush(RGB(225, 225, 225));
                SetTextColor(hdc, RGB(0, 0, 255));
                SetBkMode(hdc, TRANSPARENT);
                SetBkColor(hdc,(LONG)color);
            }
            return (LONG) color;
        }
        break;

    case WM_COMMAND: {
        switch(LOWORD(wParam)) {
        case BUTTON_ADD_TODO: {

                char buffer[256];
                SendMessage(hInputTODO,
                    WM_GETTEXT,
                    sizeof(buffer)/sizeof(buffer[0]),
                    reinterpret_cast<LPARAM>(buffer));


                if (strlen(buffer) > 0){
                    char newInput[255] = "- ";

                    strcat(newInput, buffer);

                    SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM)newInput);
                    SendMessage(hInputTODO, WM_SETTEXT, NULL, (LPARAM)"");
                    TODONumber++;
                    InvalidateRect(hWnd, &rcQuantity, TRUE);

                }
            }
            break;

        case BUTTON_DISPLAY_TODO_NR: {
                char buffer[255] = "";

                switch(TODONumber){
                case 0:
                case 1:
                case 2:
                case 3:
                    strcat(buffer, "You have fery few tasks. You should do them in time.");
                    break;
                case 4:
                case 5:
                case 6:
                    strcat(buffer, "Some tasks have been added to your daily routine.");
                    break;
                default:
                    strcat(buffer, "To eliminate the risk of procrastination, you have a bunch of tasks now. You should have finished them yesterday.");
                    break;
                }
                MessageBox(NULL,
                    buffer,
                    "Funny",
                    MB_ICONINFORMATION);
            }
            break;
        case ID_FILE_EXIT: {
                PostQuitMessage(0);
            }
            break;
        case ID_STUFF_ABOUT: {
                char aboutText[255] = "This program is a simple task list.\n It's Created by Macrinici Daniel in 2014";
                MessageBox(NULL,
                    aboutText,
                    "About",
                    MB_ICONINFORMATION);
            }
            break;
        case ID_EVENT_RED: {
                fontColor[0] = 255;
                fontColor[1] = 0;
                fontColor[2] = 0;
                InvalidateRect(hWnd, &rcTODOList, TRUE);
            }
            break;
        case ID_EVENT_GREEN: {
                fontColor[0] = 0;
                fontColor[1] = 255;
                fontColor[2] = 0;
                InvalidateRect(hWnd, &rcTODOList, TRUE);
            }
            break;
        case ID_EVENT_BLUE: {
                fontColor[0] = 0;
                fontColor[1] = 0;
                fontColor[2] = 255;
                InvalidateRect(hWnd, &rcTODOList, TRUE);
            }
            break;

        case IDC_TODO_LIST:{
                if (HIWORD(wParam) == LBN_DBLCLK) {
                    int index = SendMessage(hWndList, LB_GETCURSEL, 0, 0);
                    SendMessage(hWndList, LB_DELETESTRING, (WPARAM)index, 0);
                    TODONumber--;
                    InvalidateRect(hWnd, &rcQuantity, TRUE);
                }
            }
            break;
        }
    }
    break;

    case WM_SIZE: {
            /*INT nWidth = LOWORD(lParam);
            HWND hFunnyButton = GetDlgItem(hWnd, BUTTON_DISPLAY_TODO_NR);

            MoveWindow(hFunnyButton, 10, 180, nWidth - 17, 40, TRUE);

            HWND hShowTODOInput = GetDlgItem(hWnd, INPUT_TEXT_SHOW_TODO);
            HWND hAddTODO = GetDlgItem(hWnd, INPUT_TEXT_ADD_TODO);

            MoveWindow(hShowTODOInput, 10, 40, nWidth - 18, 100, TRUE);
            MoveWindow(hAddTODO, 120, 150, nWidth - 128, 25, TRUE);*/
        }
        break;

    case WM_VSCROLL: {
            switch (LOWORD(wParam)) {
            case SB_LINEDOWN: {
                    scrollColor = min (255, scrollColor + 1);
                }
                break;
            case SB_LINEUP: {
                    scrollColor = min (255, scrollColor - 1);
                }
                break;
            case SB_PAGEDOWN: {
                    scrollColor += 15;
                }
                break;
            case SB_PAGEUP: {
                    scrollColor -= 15;
                }
                break;
            case SB_BOTTOM: {
                    scrollColor = 255;
                }
                break;
            case SB_TOP: {
                    scrollColor = 0;
                }
                break;
            case SB_THUMBPOSITION:
            case SB_THUMBTRACK: {
                    scrollColor = HIWORD(wParam);
                }
                break;
            }

            SetScrollPos(hWndScroll, SB_CTL, scrollColor, TRUE);
            InvalidateRect(hWnd, &rcTODOList, TRUE);
        }
        break;

    case WM_HSCROLL: {
            RECT rect;
            GetWindowRect(hWnd, &rect);
            int iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            int iSysHeight = GetSystemMetrics(SM_CYSCREEN);
            int iWinWidth = rect.right - rect.left;
            int iWinHeight = rect.bottom - rect.top;

            switch (GetWindowLong((HWND)lParam, GWL_ID)) {
            case ID_WIDTH_SCROLL: {
                    switch(LOWORD(wParam)) {
                    case SB_LINELEFT:
                        widthScroll -= 1;
                        break;
                    case SB_LINERIGHT:
                        widthScroll += 1;
                        break;
                    case SB_THUMBPOSITION:
                        widthScroll = HIWORD(wParam);
                        break;
                    default:
                        break;
                    }
                    SetScrollPos(hWndWidthScroll, SB_CTL, widthScroll, TRUE);
                    MoveWindow(hWnd, rect.left, rect.top, (widthScroll * iSysWidth / 100), iWinHeight, TRUE);
                }
                break;
            case ID_HEIGHT_SCROLL: {
                    switch(LOWORD(wParam)) {
                    case SB_LINELEFT:
                        widthScroll--;
                        break;
                    case SB_LINERIGHT:
                        widthScroll++;
                        break;
                    case SB_THUMBPOSITION:
                        widthScroll = HIWORD(wParam);
                        break;
                    default:
                        break;
                    }
                    SetScrollPos(hWndHeightScroll, SB_CTL, widthScroll, TRUE);
                    MoveWindow(hWnd, rect.left, rect.top, iWinWidth, (widthScroll * iSysHeight / 100), TRUE);
                }
                break;
            }
        }
        break;

    case WM_GETMINMAXINFO: {
            MINMAXINFO * mmiStruct;
            mmiStruct = (MINMAXINFO*)lParam;

            POINT ptPoint;

            ptPoint.x = 335;    //Minimum width of the window.
            ptPoint.y = 260;    //Minimum height of the window.
            mmiStruct->ptMinTrackSize = ptPoint;

            ptPoint.x = GetSystemMetrics(SM_CXMAXIMIZED);   //Maximum width of the window.
            ptPoint.y = GetSystemMetrics(SM_CYMAXIMIZED);   //Maximum height of the window.
            mmiStruct->ptMaxTrackSize = ptPoint;
        }
        break;

    case WM_KEYDOWN: {
            switch (wParam) {

            case VK_SPACE : {
                    if (HIBYTE(GetAsyncKeyState(VK_LCONTROL))) {
                        scrollColor = 0;
                        SetScrollPos(hWndScroll, SB_CTL, scrollColor, TRUE);
                        InvalidateRect(hWnd, &rcTODOList, TRUE);
                        return 0;
                    }
                }
                break;
            case VK_F1: {
                    if (HIBYTE(GetAsyncKeyState(VK_LCONTROL))) {

                        SendMessage(hWndList, LB_RESETCONTENT, 0, 0);
                        TODONumber = 0;
                        InvalidateRect(hWnd, &rcQuantity, TRUE);

                    }
                }
                break;
            }
        }
        break;

    case WM_SETFOCUS: {
            SetFocus(hWnd);
        }
        break;
    case WM_DESTROY: {
            PostQuitMessage(0);
            return 0;
        }
        break;
    }



    return DefWindowProc(hWnd,msg,wParam,lParam);
}
int WINAPI WinMain(	HINSTANCE hinstance,
					HINSTANCE hprevinstance,
					LPSTR lpcmdline,
					int ncmdshow)
{

WNDCLASS winclass;	// this will hold the class we create
HWND	 hwnd;		// generic window handle
MSG		 msg;		// generic message
HDC      hdc;       // generic dc
PAINTSTRUCT ps;     // generic paintstruct

// first fill in the window class stucture
winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                          CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc	= WindowProc;
winclass.cbClsExtra		= 0;
winclass.cbWndExtra		= 0;
winclass.hInstance		= hinstance;
winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName	= NULL; 
winclass.lpszClassName	= WINDOW_CLASS_NAME;

// register the window class
if (!RegisterClass(&winclass))
	return(0);

// create the window, note the use of WS_POPUP
if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
						  "DirectSound WAV File Loading DEMO",	 // title
						  WS_OVERLAPPEDWINDOW | WS_VISIBLE,
					 	  0,0,	   // x,y
						  WINDOW_WIDTH,  // width
                          WINDOW_HEIGHT, // height
						  NULL,	   // handle to parent 
						  NULL,	   // handle to menu
						  hinstance,// instance
						  NULL)))	// creation parms
return(0);

// save the window handle and instance in a global
main_window_handle = hwnd;
main_instance      = hinstance;

// create some scroll controls to change volume, frequency
// and panning

// create the volume control scroller
volume_hwnd = CreateWindow("SCROLLBAR", // class
						  "",	    // title
						  WS_CHILD | WS_VISIBLE,
					 	  80,40,	    // x,y
						  160,       // width
                          16,      // height
						  hwnd,	    // handle to parent 
						  NULL,	    // handle to menu
						  hinstance,// instance
						  NULL);    // creation parms

// create the frequency control scroller
freq_hwnd = CreateWindow("SCROLLBAR", // class
						  "",	    // title
						  WS_CHILD | WS_VISIBLE,
					 	  80,100,	    // x,y
						  160,       // width
                          16,      // height
						  hwnd,	    // handle to parent 
						  NULL,	    // handle to menu
						  hinstance,// instance
						  NULL);    // creation parms

// create the stereo panning control scroller
pan_hwnd = CreateWindow("SCROLLBAR", // class
						  "",	    // title
						  WS_CHILD | WS_VISIBLE,
					 	  80,160,	// x,y
						  160,      // width
                          16,       // height
						  hwnd,	    // handle to parent 
						  NULL,	    // handle to menu
						  hinstance,// instance
						  NULL);    // creation parms


// set range and value of each scroll bar
SetScrollRange(volume_hwnd, SB_CTL, 0, 4000,TRUE);
SetScrollPos(volume_hwnd, SB_CTL,0,TRUE);

SetScrollRange(freq_hwnd, SB_CTL, 0, 50000,TRUE);
SetScrollPos(freq_hwnd, SB_CTL,11000,TRUE);

SetScrollRange(pan_hwnd, SB_CTL, 0, 20000,TRUE);
SetScrollPos(pan_hwnd, SB_CTL,10000,TRUE);

// perform all game console specific initialization
// start up the directsound sound
Game_Init();

// enter main event loop
while(1)
	{
	if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{ 
		// test if this is a quit
        if (msg.message == WM_QUIT)
           break;
	
		// translate any accelerator keys
		TranslateMessage(&msg);

		// send the message to the window proc
		DispatchMessage(&msg);
		} // end if
    
    // main game processing goes here
    Game_Main();

	} // end while

// shutdown game and release all resources
Game_Shutdown();

// return to Windows like this
return(msg.wParam);

} // end WinMain
示例#7
0
BOOL CScreenSpyDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	// when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_NO));
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		pSysMenu->AppendMenu(MF_SEPARATOR);
		pSysMenu->AppendMenu(MF_STRING, IDM_CONTROL, "控制屏幕(&Y)");
		pSysMenu->AppendMenu(MF_STRING, IDM_SEND_CTRL_ALT_DEL, "发送Ctrl-Alt-Del(&K)");
		pSysMenu->AppendMenu(MF_STRING, IDM_TRACE_CURSOR, "跟踪服务端鼠标(&T)");
		pSysMenu->AppendMenu(MF_STRING, IDM_BLOCK_INPUT, "锁定服务端鼠标和键盘(&L)");
		pSysMenu->AppendMenu(MF_STRING, IDM_BLANK_SCREEN, "服务端黑屏(&B)");
		pSysMenu->AppendMenu(MF_STRING, IDM_CAPTURE_LAYER, "捕捉层(导致鼠标闪烁)(&L)");
		pSysMenu->AppendMenu(MF_STRING, IDM_SAVEDIB, "保存快照(&S)");
		pSysMenu->AppendMenu(MF_SEPARATOR);
		pSysMenu->AppendMenu(MF_STRING, IDM_GET_CLIPBOARD, "获取剪贴板(&R)");
		pSysMenu->AppendMenu(MF_STRING, IDM_SET_CLIPBOARD, "设置剪贴板(&L)");
		pSysMenu->AppendMenu(MF_SEPARATOR);
		pSysMenu->AppendMenu(MF_STRING, IDM_ALGORITHM_SCAN, "隔行扫描算法(&S)");
		pSysMenu->AppendMenu(MF_STRING, IDM_ALGORITHM_DIFF, "差异比较算法(&X)");
		pSysMenu->AppendMenu(MF_SEPARATOR);
		pSysMenu->AppendMenu(MF_STRING, IDM_DEEP_1, "1 位黑白(&A)");
		pSysMenu->AppendMenu(MF_STRING, IDM_DEEP_4_GRAY, "4 位灰度(&B)");
		pSysMenu->AppendMenu(MF_STRING, IDM_DEEP_4_COLOR, "4 位彩色(&C)");
		pSysMenu->AppendMenu(MF_STRING, IDM_DEEP_8_GRAY,  "8 位灰度(&D)");
		pSysMenu->AppendMenu(MF_STRING, IDM_DEEP_8_COLOR, "8 位彩色(&E)");
		pSysMenu->AppendMenu(MF_STRING, IDM_DEEP_16, "16位高彩(&F)");
		pSysMenu->AppendMenu(MF_STRING, IDM_DEEP_32, "32位真彩(&G)");		
		
		pSysMenu->CheckMenuRadioItem(IDM_ALGORITHM_SCAN, IDM_ALGORITHM_DIFF, IDM_ALGORITHM_SCAN, MF_BYCOMMAND);
		pSysMenu->CheckMenuRadioItem(IDM_DEEP_4_GRAY, IDM_DEEP_32, IDM_DEEP_8_COLOR, MF_BYCOMMAND);
	}
	
	// TODO: Add extra initialization here
	CString str;
	str.Format("\\\\%s %d * %d", m_IPAddress, m_lpbmi->bmiHeader.biWidth, m_lpbmi->bmiHeader.biHeight);
	SetWindowText(str);

	m_HScrollPos = 0;
	m_VScrollPos = 0;
	m_hRemoteCursor = LoadCursor(NULL, IDC_ARROW);

	ICONINFO CursorInfo;
	::GetIconInfo(m_hRemoteCursor, &CursorInfo);
	if (CursorInfo.hbmMask != NULL)
		::DeleteObject(CursorInfo.hbmMask);
	if (CursorInfo.hbmColor != NULL)
		::DeleteObject(CursorInfo.hbmColor);
	m_dwCursor_xHotspot = CursorInfo.xHotspot;
	m_dwCursor_yHotspot = CursorInfo.yHotspot;

	m_RemoteCursorPos.x = 0;
	m_RemoteCursorPos.x = 0;
	m_bIsTraceCursor = false;

	// 初始化窗口大小结构
	m_hDC = ::GetDC(m_hWnd);
	m_hMemDC = CreateCompatibleDC(m_hDC);
	m_hFullBitmap = CreateDIBSection(m_hDC, m_lpbmi, DIB_RGB_COLORS, &m_lpScreenDIB, NULL, NULL);
	SelectObject(m_hMemDC, m_hFullBitmap);
	SetScrollRange(SB_HORZ, 0, m_lpbmi->bmiHeader.biWidth);  
	SetScrollRange(SB_VERT, 0, m_lpbmi->bmiHeader.biHeight);

	InitMMI();
	SendNext();
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}
示例#8
0
long FAR PASCAL DoWindowMessage ( 
   HWND hMain,
   unsigned message,
   WPARAM wParam,
   LONG lParam)

{  switch ( message )
   {  case WM_CREATE:
	 return (StartUpDDE());

      case WM_KEYDOWN:
		{  if ( LOWORD(wParam) == VK_SHIFT )
	 {  extern int ShiftKeyDown;
	    ShiftKeyDown = TRUE;
	 }
	 break;
      }

      case WM_KEYUP:
      {  if ( LOWORD(wParam) == VK_SHIFT )
	 {  extern int ShiftKeyDown;
	    ShiftKeyDown = FALSE;
	 }
	 break;
      }

      case WM_CHAR:
      {  GetUserCmd ( LOWORD(wParam), FALSE, 0 );
	 break;
      }

      case WM_ACTIVATEAPP:
		{   extern int ApplicationFocus;
	  ApplicationFocus = (int) LOWORD(wParam);
	  if (!ApplicationFocus )
		  UpdateCursor( ARROW_CURSOR );
	  break;
      }

      case WM_TIMER:
      {  static int value = 0;
	 extern HCURSOR NowCursor, WAIT[];
	 extern int ApplicationFocus;
	 value ++;
	 NowCursor = WAIT[value];
	 if (ApplicationFocus )
	    SetCursor ( NowCursor );
	 if (value > 7 )
	   value = 0;
	 break;
      }

      case WM_SETCURSOR:
      {  extern HCURSOR NowCursor;
	 SetCursor ( NowCursor );
	 break;
		}

      case WM_SETFOCUS:
		{  extern SCREEN WinDialog;
	 CreateCaret ( hMain, NULL, 1, WinDialog.LineSize);
	 ShowCaret ( hMain );
	 break;
      }

      case WM_KILLFOCUS:
      {  HideCaret ( hMain );
	 DestroyCaret();
	 break;
      }

		case WM_PAINT:
      {  PAINTSTRUCT ps;
	 HDC  hDC;
 
	 BeginPaint (hMain, (LPPAINTSTRUCT)&ps);
	    hDC = ps.hdc;
	    SetMapMode (hDC, MM_TEXT);
	    RedrawTerminal(hDC);
	    ValidateRect (hMain, (LPRECT)NULL);
	 EndPaint (hMain, (LPPAINTSTRUCT)&ps);
	 break;
      }

      case WM_SIZE:
      {  extern SCREEN WinDialog;
	 int min, max;

	 GetScrollRange (hMain,SB_VERT,&min, &max);
	 WinDialog.NoLines = (HIWORD (lParam) / WinDialog.LineSize) - 1;
	 SetScrollRange (hMain, SB_VERT, WinDialog.NoLines, max, TRUE );

	 InvalidateRect ( hMain, NULL, TRUE );
	 switch ( LOWORD(wParam) )
	 {  case SIZE_MINIMIZED:
			 PostMessage ( hMain, WM_COMMAND, IDC_WIN_MINIMIZE, 0);
	       break;

	    case SIZE_RESTORED:
	       PostMessage ( hMain, WM_COMMAND, IDC_WIN_MAXIMIZE, 0);
	       break;
	 }
	 break;
      }

      case WM_HSCROLL:
      {  extern SCREEN WinDialog;
	 int min, max, cp;
	 GetScrollRange (hMain,SB_HORZ,&min, &max);
	 cp = GetScrollPos ( hMain, SB_HORZ );
	 switch (LOWORD(wParam))
	 {   case SB_LINEDOWN:
	     {  cp++;
		break;
	     }
	     case SB_LINEUP:
		  {  cp--;
		break;
	     }
		  case SB_PAGEDOWN:
	     {  cp += WinDialog.NoLines;
		break;
	     }
	     case SB_PAGEUP:
	     {  cp -= WinDialog.NoLines;
		break;
	     }
	     case SB_THUMBTRACK:
		  {  cp = LOWORD(lParam);
		break;
	     }
		  default:
	     {   return (0);
	     }
	 }

	 if (cp > max) cp = max;
	 if (cp < min) cp = min;

	 SetScrollPos   (hMain, SB_HORZ, cp, TRUE );
	 InvalidateRect (hMain, NULL, TRUE );
	 break;
      }

      case WM_VSCROLL:
      {  extern SCREEN WinDialog;
	 int min, max, cp;
	 static int CaretON = TRUE;

	 GetScrollRange (hMain,SB_VERT,&min, &max);
	 cp = GetScrollPos ( hMain, SB_VERT );
	 switch (LOWORD(wParam))
	 {   case SB_LINEDOWN:
	     {  cp++;
		break;
		  }
	     case SB_LINEUP:
	     {  cp--;
		break;
	     }
	     case SB_PAGEDOWN:
	     {  cp += WinDialog.NoLines;
		break;
	     }
		  case SB_PAGEUP:
	     {  cp -= WinDialog.NoLines;
		break;
		  }
	     case SB_THUMBTRACK:
	     {  cp = LOWORD(lParam);
		break;
	     }
	     default:
	     {   return (0);
	     }
	 }

	 if (cp >= max)
	 {  cp = max;
		 ShowCaret ( hMain );
	    CaretON = TRUE;
	 }
	 else if ( CaretON )
	 {  HideCaret ( hMain );
	    CaretON = FALSE;
	 }

	 if (cp < WinDialog.NoLines)
		 cp = WinDialog.NoLines;

	 SetScrollPos   (hMain, SB_VERT, cp, TRUE );
	 InvalidateRect (hMain, NULL, TRUE );
	 break;
      }

      case WM_DESTROY:
		{  

	 /* Shut Down DDE Server. */
	 ShutDownDDE ( );

	 /* Free Dialog Window */
	 DeleteTerminal();

	 /* Quit Windows */
	 PostQuitMessage(0);
	 return 0;
      }

      /*-------------------------------+
      | Used to Update the Module Menu |
      +-------------------------------*/
		case WM_INITMENUPOPUP:
      {  int MenuID = GetMenuItemID((HMENU) wParam, 0);
	 if ( MenuID == IDM_MODULE_ONE )
		 UpdateModuleMenu ((HMENU)wParam);
	 break;
      }

      case WM_CLOSE:
	 PostMessage ( hMain, WM_COMMAND, IDM_FILE_QUIT, 0);
	 break;

      default:
	 return (DefWindowProc(hMain, message, wParam, lParam));
   }
   return (TRUE);
}
示例#9
0
void RedrawTerminal ( 
	HDC hDC)

{  extern SCREEN WinDialog;
	int x, max, min, pos, start, sbmax = 0;
	RECT Rect;
	char *buffer;
   
   /*----------------------------------------------+
   | Get current value of the vertical scroll bar. |
   +----------------------------------------------*/
   GetScrollRange ( WinDialog.hWnd, SB_VERT, &min, &max);
	pos = GetScrollPos (WinDialog.hWnd, SB_VERT );

   /*-----------------------------------------+
	| Locate the first visible line to display |
   +-----------------------------------------*/
   start = WinDialog.LastLine - ( max - pos ) - WinDialog.NoLines;

   if ( start == WinDialog.LastLine )
      start ++;

   /*----------------------------------------------+
   | If the start value is negative then check if  |
	| at a 'hard' top or if a wrap around is needed |
   +----------------------------------------------*/
   if ( start < 0 )
	{  if ( max == DIALOG_SIZE )
	 start = max + start + 1;
      else
	 start = 0;
   }

   /*------------------------------------------+
   | Get Position of the horizontal scroll bar |
   +------------------------------------------*/
	pos = GetScrollPos ( WinDialog.hWnd, SB_HORZ);

   /*----------------------------------------------------------+
	| Loop to display text in the visible portion of the screen |
   +----------------------------------------------------------*/
   for ( x = 0; x<= WinDialog.NoLines && Terminal[start] != NULL; x++ )
	{
	 int bufsize;

      GetClientRect (WinDialog.hWnd, &Rect);
      Rect.top = x * WinDialog.LineSize;

      /*------------------------------------+
      | Calculate Horizontal Scroll bar Max | 
		| based on what is displayed.         |
      +------------------------------------*/
      
		if (Terminal[start] != NULL)
	{ bufsize = strlen(Terminal[start]); }
      else
	{ bufsize = 0; }

      if ( bufsize > sbmax )  sbmax = bufsize;

      /*-----------------------------------+
      | Display each line of text adjusted |
		| for the horizontal scroll bar.     |
      +-----------------------------------*/
      buffer = NULL;
		if (( pos <= bufsize ) && (Terminal[start] != NULL))
      {  buffer = Terminal[start]+pos;
	 DrawText ( hDC, buffer, -1, &Rect, DT_LEFT|DT_NOCLIP | DT_NOPREFIX );
      }

      /*-------------------------------+
      | Check if wrap around is needed |
      +-------------------------------*/
      start ++;
		if ( start > DIALOG_SIZE )
	 start = 0;
   }
	/*-------------------------------------+
   | Calculate and display caret adjusted |
   |    for horizontal scroll bar.        |
   +-------------------------------------*/
   if ( buffer == NULL )
      buffer = "";
	DrawText ( hDC, buffer, -1, &Rect,
	          DT_LEFT|DT_NOCLIP|DT_CALCRECT );
	SetCaretPos (Rect.right, Rect.top);
	SetScrollRange ( WinDialog.hWnd, SB_HORZ, 0, sbmax-1, TRUE );
}
示例#10
0
int TrebuchetFormBuilder()
{
	char buffer[32];

	int nPadding; // Padding between elements
	int nRangeY, nRangeWidth, nRangeHeight, nRangeStaticY, nRangeStaticWidth; // Range edit and static
	int nRechargeY, nRechargeWidth, nRechargeHeight, nRechargeStaticX, nRechargeStaticY, nRechargeStaticWidth;
	int nMinX, nSMinX; // Minimum range edit box
	int nMaxX, nSMaxX; // Maximum range edit box
	int nTSCBx, nTSCBy, nTSCBwidth, nTSCBheight; // Scrollbar position
	int nTVRx, nTVRy, nTVRwidth, nTVRheight; // Value static position
	int nTSBx, nTSBwidth, nTSBheight; // Start button position
	int nTDBx, nTDBy, nTDBwidth, nTDBheight; // Duration static position

	nPadding = 20;

	nRangeY = DEFBUT_HEIGHT + nPadding;
	nRangeWidth = nPadding * 2;
	nRangeHeight = TAB_CHAT_HEIGHT ? TAB_CHAT_HEIGHT : TAB_STATIC_HEIGHT;
	nRangeStaticY = nRangeY + 2;
	nRangeStaticWidth = 60;

	nMinX = nPadding;
	nSMinX = nMinX + nRangeWidth + 5;

	nMaxX = nSMinX + nRangeStaticWidth + nPadding;
	nSMaxX = nMaxX + nRangeWidth + 5;

	// Scroll Bar position
	nTSCBx = nPadding;
	nTSCBy = (int)(nPadding / 2) + nRangeY + nRangeHeight;
	nTSCBwidth = UserSettings.ClientWidth - (nPadding * 7);
	nTSCBheight = (nPadding / 2);

	// Recharge Edit
	nRechargeY = (nPadding / 2) + nTSCBy + nTSCBheight;
	nRechargeWidth = nPadding *2;
	nRechargeHeight = TAB_CHAT_HEIGHT ? TAB_CHAT_HEIGHT : TAB_STATIC_HEIGHT;
	nRechargeStaticX = nPadding + nRechargeWidth + 5;
	nRechargeStaticY = nRechargeY + 2;
	nRechargeStaticWidth = 60;

	// Value Readout position
	nTVRx = nTSCBx + nTSCBwidth + (nPadding / 2);
	nTVRy = nTSCBy;
	nTVRwidth = nPadding * 5;
	nTVRheight = nPadding;

	// Start button position
	nTSBwidth = DEFBUT_WIDTH;
	nTSBheight = DEFBUT_HEIGHT;
	nTSBx = (UserSettings.ClientWidth - nPadding) - DEFBUT_WIDTH;
	g_nSBy = (UserSettings.ClientHeight - nPadding) - DEFBUT_HEIGHT - TAB_CHAT_HEIGHT;

	// Duration timer position
	nTDBx = nPadding;
	nTDBy = (UserSettings.ClientHeight - nPadding) - abs(nPadding / 2) - TAB_CHAT_HEIGHT;
	nTDBwidth = UserSettings.ClientWidth - (nPadding * 2) - DEFBUT_WIDTH;
	nTDBheight = nPadding;

	// Minimum range edit box
	memset(buffer, 0, sizeof(buffer));
	_snprintf(buffer, sizeof(buffer)-1, "%lu", UserSettings.TrebMin);
	GlobalSettings.hTrebMinEdit = CreateWindow(
		TEXT("edit"), NULL,
		WS_CHILDWINDOW | WS_VISIBLE | ES_RIGHT | WS_BORDER | ES_AUTOHSCROLL,
		nMinX, nRangeY, nRangeWidth, nRangeHeight,
		GlobalSettings.hMainWindow, NULL, GlobalSettings.hInstance, NULL);
	hMinStatic = CreateWindow(
		TEXT("static"), "Minimum",
		WS_CHILD | SS_EDITCONTROL,
		nSMinX, nRangeStaticY, nRangeStaticWidth, nRangeHeight,
		GlobalSettings.hMainWindow, NULL, GlobalSettings.hInstance, NULL);
	SendMessage(GlobalSettings.hTrebMinEdit, EM_SETLIMITTEXT, (WPARAM)MAXRNG, 0);
	SendMessage(GlobalSettings.hTrebMinEdit, WM_SETFONT, (WPARAM)GlobalSettings.hFont, 0);
	SendMessage(GlobalSettings.hTrebMinEdit, WM_SETTEXT, 0, (LPARAM)buffer);
	SendMessage(hMinStatic, WM_SETFONT, (WPARAM)GlobalSettings.hFont, 0);

	// Maximum range edit box
	memset(buffer, 0, sizeof(buffer));
	_snprintf(buffer, sizeof(buffer)-1, "%lu", UserSettings.TrebMax);
	GlobalSettings.hTrebMaxEdit = CreateWindow(
		TEXT("edit"), NULL,
		WS_CHILDWINDOW | ES_RIGHT | WS_BORDER | ES_AUTOHSCROLL,
		nMaxX, nRangeY, nRangeWidth, nRangeHeight,
		GlobalSettings.hMainWindow, NULL, GlobalSettings.hInstance, NULL);
	hMaxStatic = CreateWindow(
		TEXT("static"), "Maximum",
		WS_CHILD | SS_EDITCONTROL,
		nSMaxX, nRangeStaticY, nRangeStaticWidth, nRangeHeight,
		GlobalSettings.hMainWindow, NULL, GlobalSettings.hInstance, NULL);
	SendMessage(GlobalSettings.hTrebMaxEdit, EM_SETLIMITTEXT, (WPARAM)MAXRNG, 0);
	SendMessage(GlobalSettings.hTrebMaxEdit, WM_SETFONT, (WPARAM)GlobalSettings.hFont, 0);
	SendMessage(GlobalSettings.hTrebMaxEdit, WM_SETTEXT, 0, (LPARAM)buffer);
	SendMessage(hMaxStatic, WM_SETFONT, (WPARAM)GlobalSettings.hFont, 0);

	// Scroll bar
	GlobalSettings.hTrebSliderBar = CreateWindow(
		TEXT("scrollbar"), NULL,
		WS_CHILD | WS_VISIBLE | SBS_HORZ,
		nTSCBx, nTSCBy, nTSCBwidth, nTSCBheight,
		GlobalSettings.hMainWindow, NULL, GlobalSettings.hInstance, NULL);
	SetScrollRange(GlobalSettings.hTrebSliderBar, SB_CTL, UserSettings.TrebMin, UserSettings.TrebMax, FALSE);
	SetScrollPos(GlobalSettings.hTrebSliderBar, SB_CTL, UserSettings.TrebRange, FALSE);

	// Value readout
	GlobalSettings.hTrebSliderValue = CreateWindow(
		TEXT("static"), "Range: 0.00",
		WS_CHILD | WS_VISIBLE | SS_EDITCONTROL,
		nTVRx, nTVRy, nTVRwidth, nTVRheight,
		GlobalSettings.hMainWindow, NULL, GlobalSettings.hInstance, NULL);
	memset(buffer, 0, sizeof(buffer));
	_snprintf(buffer, sizeof(buffer)-1, "Range: %.2f", (((float)(UserSettings.TrebRange - UserSettings.TrebMin) / (float)(UserSettings.TrebMax - UserSettings.TrebMin)) * 100) );
	SendMessage(GlobalSettings.hTrebSliderValue, WM_SETFONT, (WPARAM)GlobalSettings.hFont, 0);
	SendMessage(GlobalSettings.hTrebSliderValue, WM_SETTEXT, 0, (LPARAM)buffer);

	// Recharge edit box
	memset(buffer, 0, sizeof(buffer));
	_snprintf(buffer, sizeof(buffer)-1, "%lu", UserSettings.TrebRecharge);
	GlobalSettings.hTrebRecharge = CreateWindow(
		TEXT("edit"), NULL,
		WS_CHILDWINDOW | ES_RIGHT | WS_BORDER | ES_AUTOHSCROLL,
		nPadding, nRechargeY, nRechargeWidth, nRechargeHeight,
		GlobalSettings.hMainWindow, NULL, GlobalSettings.hInstance, NULL);
	hRechargeStatic = CreateWindow(
		TEXT("static"), "Recharge",
		WS_CHILD | SS_EDITCONTROL,
		nRechargeStaticX, nRechargeStaticY, nRechargeStaticWidth, nRangeHeight,
		GlobalSettings.hMainWindow, NULL, GlobalSettings.hInstance, NULL);
	SendMessage(GlobalSettings.hTrebRecharge, EM_SETLIMITTEXT, (WPARAM)MAXRNG, 0);
	SendMessage(GlobalSettings.hTrebRecharge, WM_SETFONT, (WPARAM)GlobalSettings.hFont, 0);
	SendMessage(GlobalSettings.hTrebRecharge, WM_SETTEXT, 0, (LPARAM)buffer);
	SendMessage(hRechargeStatic, WM_SETFONT, (WPARAM)GlobalSettings.hFont, 0);

	// Start button
	GlobalSettings.hTrebStartButton = CreateWindow(
		TEXT("button"), "Start",
		WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
		nTSBx, g_nSBy, nTSBwidth, nTSBheight,
		GlobalSettings.hMainWindow, NULL, GlobalSettings.hInstance, NULL);
	SendMessage(GlobalSettings.hTrebStartButton, WM_SETFONT, (WPARAM)GlobalSettings.hFont, 0);

	// Duration box
	GlobalSettings.hTrebDurationBox = CreateWindow(
		TEXT("static"), "Runtime: 0.00s",
		WS_CHILD | WS_VISIBLE | SS_EDITCONTROL,
		nTDBx, nTDBy, nTDBwidth, nTDBheight,
		GlobalSettings.hMainWindow, NULL, GlobalSettings.hInstance, NULL);
	SendMessage(GlobalSettings.hTrebDurationBox, WM_SETFONT, (WPARAM)GlobalSettings.hFont, 0);

	return 1;
}
示例#11
0
void GetUserCmd ( 
  WORD wParam,      /* Key Code */
  BOOL ScreenOnly,  /* Send to Screen and or Command Buffer */
  int  InputSize)   /* Number of characters send to screen only */

  {
	extern int HorizScroll; /* Automatic Scrolling Enabled/Disabled */

	switch (wParam)
	  {
		extern SCREEN WinDialog;
		extern int UserInput;

		/*------------------+
		| Handle Back Space |
		+------------------*/

		case VK_BACK:
		  {
			/*-----------------------------------------------+
			| Init Values when sending to the command buffer |
			+-----------------------------------------------*/
			if (! ScreenOnly)
			  {
				HorizScroll = 1;
				if (GetCommandString() != NULL)
				  { InputSize = strlen(GetCommandString()); }
				else
				  { InputSize = 0; }
			  }

	 if (InputSize > 0 )
	 {
		 int size;

		 if (Terminal[WinDialog.LastLine] != NULL)
			{ size = strlen(Terminal[WinDialog.LastLine]); }
		 else
			{ size = 0; }

		 if (!ScreenOnly)
			 ExpandCommandString ('\b');

		 if (size > 0)
			 Terminal[WinDialog.LastLine][size - 1] = '\0';
		 else
		 {  int min, max;
			 extern int OldLine;

			 if ( Terminal[WinDialog.LastLine] != NULL )
			 {
		free(Terminal[WinDialog.LastLine]);
		Terminal[WinDialog.LastLine] = NULL;
	       }

			 WinDialog.LastLine --;
	       OldLine --;

	       if ( WinDialog.LastLine < 0 )
		  WinDialog.LastLine = DIALOG_SIZE;

	       GetScrollRange (WinDialog.hWnd, SB_VERT, &min, &max);
	       if ( WinDialog.NoLines < max && max < DIALOG_SIZE )
	       {  SetScrollRange ( WinDialog.hWnd, SB_VERT, WinDialog.NoLines, max-1, FALSE );
		  SetScrollPos   ( WinDialog.hWnd, SB_VERT, max-1, FALSE );
	       }
	       InvalidateRect ( WinDialog.hWnd, NULL, TRUE );
		 }
		 SendToScreen();
	 }
	 break;
      }

      /*--------------------------+
      | Remove Special Keys (ALT) |
      +--------------------------*/
      case '\f':
      case VK_MENU:
	 break;


      /*----------------+
      | Handle Tab Keys |
      +----------------*/
      case '\t':
		{  if ( !ScreenOnly)
	 {  if ( GetCommandString() == NULL)
	       SetCommandString("   ");
	    else
	       AppendCommandString("   ");
	 }
	 PrintCLIPS ("stdout", "   " );
	 break;
      }


      /*---------------------+
      | Return / Newline Key |
      +---------------------*/
      case '\r':
      case '\n':
      {  wParam = (int)'\n';
	 if (GetScrollPos (WinDialog.hWnd, SB_HORZ) != 0)
	 {  SetScrollPos ( WinDialog.hWnd, SB_HORZ, 0, TRUE );
	    InvalidateRect(WinDialog.hWnd, NULL, FALSE);
	    SendMessage ( WinDialog.hWnd, WM_PAINT, 0, 0 );
	 }
      }

      /*---------------------+
      | All other characters |
      +---------------------*/
      default:
      {  char text[2];

	 text[0] = (char) wParam;
	 text[1] = '\0';

	 if(isprint ( text[0]) || isspace (text[0]))
	 {  /*----------------------------+
	    | Add to CLIPS Command Buffer |
		 +----------------------------*/

	    if (!ScreenOnly)
	    {  if ( GetCommandString() == NULL)
		  SetCommandString(text);
	       else
		  AppendCommandString(text);
		 }

		 PrintCLIPS ("stdout", text );
	 }
	 break;
		}
	}
	HorizScroll = 0;
}
示例#12
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static CHOOSEFONT cf ;
     static int        iPage ;
     static LOGFONT    lf ;
     HDC               hdc ;
     int               cxChar, cyChar, x, y, i, cxLabels ;
     PAINTSTRUCT       ps ;
     SIZE              size ;
     TCHAR             szBuffer [8] ;
     TEXTMETRIC        tm ;
     WCHAR             ch ;

     switch (message)
     {
     case WM_CREATE:
          hdc = GetDC (hwnd) ;
          lf.lfHeight = - GetDeviceCaps (hdc, LOGPIXELSY) / 6 ;  // 12 points
          lstrcpy (lf.lfFaceName, TEXT ("Lucida Sans Unicode")) ;
          ReleaseDC (hwnd, hdc) ;

          cf.lStructSize = sizeof (CHOOSEFONT) ;
          cf.hwndOwner   = hwnd ;
          cf.lpLogFont   = &lf ;
          cf.Flags       = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS ;

          SetScrollRange (hwnd, SB_VERT, 0, 255, FALSE) ;
          SetScrollPos   (hwnd, SB_VERT, iPage,  TRUE ) ;
          return 0 ;

     case WM_COMMAND:
          switch (LOWORD (wParam))
          {
          case IDM_FONT:
               if (ChooseFont (&cf))
                    InvalidateRect (hwnd, NULL, TRUE) ;
               return 0 ;
          }
          return 0 ;

     case WM_VSCROLL:
          switch (LOWORD (wParam))
               {
               case SB_LINEUP:         iPage -=  1 ;  break ;
               case SB_LINEDOWN:       iPage +=  1 ;  break ;
               case SB_PAGEUP:         iPage -= 16 ;  break ;
               case SB_PAGEDOWN:       iPage += 16 ;  break ;
               case SB_THUMBPOSITION:  iPage = HIWORD (wParam) ;  break ;

               default:
                    return 0 ;
               }

          iPage = max (0, min (iPage, 255)) ;

          SetScrollPos (hwnd, SB_VERT, iPage, TRUE) ;
          InvalidateRect (hwnd, NULL, TRUE) ;
          return 0 ;

     case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps) ;

          SelectObject (hdc, CreateFontIndirect (&lf)) ;

          GetTextMetrics (hdc, &tm) ;
          cxChar = tm.tmMaxCharWidth ;
          cyChar = tm.tmHeight + tm.tmExternalLeading ;

          cxLabels = 0 ;

          for (i = 0 ; i < 16 ; i++)
          {
               wsprintf (szBuffer, TEXT (" 000%1X: "), i) ;
               GetTextExtentPoint (hdc, szBuffer, 7, &size) ;

               cxLabels = max (cxLabels, size.cx) ;
          }

          for (y = 0 ; y < 16 ; y++)
          {
               wsprintf (szBuffer, TEXT (" %03X_: "), 16 * iPage + y) ;
               TextOut (hdc, 0, y * cyChar, szBuffer, 7) ;

               for (x = 0 ; x < 16 ; x++)
               {
                    ch = (WCHAR) (256 * iPage + 16 * y + x) ;
                    TextOutW (hdc, x * cxChar + cxLabels,
                                   y * cyChar, &ch, 1);
               }
          }

          DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT)));
          EndPaint (hwnd, &ps) ;
          return 0 ;

     case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}
示例#13
0
DECLSPEC_HIDDEN BOOL WINAPI ITextHostImpl_TxSetScrollRange(ITextHost *iface, INT fnBar, LONG nMinPos, INT nMaxPos,
                                           BOOL fRedraw)
{
    ITextHostImpl *This = impl_from_ITextHost(iface);
    return SetScrollRange(This->hWnd, fnBar, nMinPos, nMaxPos, fRedraw);
}
示例#14
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static int  cxChar, cxCaps, cyChar, cyClient,
        iVscrollPos = 0, //竖直滑块当前位置
        row_num,
        col_num = 8;
    static wchar_t** data;
    static wchar_t* text;
    HDC         hdc;
    int         i, y;
    PAINTSTRUCT ps;
    TCHAR       szBuffer[10];
    TEXTMETRIC  tm;

    switch (message)
    {
    case WM_CREATE:
        hdc = GetDC(hwnd);
        GetTextMetrics(hdc, &tm);
        cyChar = tm.tmHeight + tm.tmExternalLeading;//字体高度
        ReleaseDC(hwnd, hdc);

        text = getFileContent();
        row_num = (int)ceil((double)wcslen(text) / col_num);
        data = (wchar_t**)malloc(sizeof(wchar_t*) * (row_num));
        SetScrollRange(hwnd, SB_VERT, 0, row_num - 1, FALSE);//范围
        SetScrollPos(hwnd, SB_VERT, iVscrollPos, TRUE);//初始位置
        return 0;

    case WM_SIZE:
        cyClient = HIWORD(lParam);
        return 0;

    case WM_VSCROLL:
        switch (LOWORD(wParam))
        {
        case SB_LINEUP://点滚动条上方的小箭头
            iVscrollPos -= 1;
            break;

        case SB_LINEDOWN://点滚动条下方的小箭头
            iVscrollPos += 1;
            break;

        case SB_PAGEUP://在滚动条上方点空白位置
            iVscrollPos -= cyClient / cyChar;
            break;

        case SB_PAGEDOWN://在滚动条下方点空白位置
            iVscrollPos += cyClient / cyChar;
            break;

        case SB_THUMBPOSITION://在滚动条上松开鼠标
            iVscrollPos = HIWORD(wParam);//这里用上了wParam
            break;

        default:
            break;
        }

        iVscrollPos = max(0, min(iVscrollPos, row_num - 1));

        if (iVscrollPos != GetScrollPos(hwnd, SB_VERT))//获取当前的位置
        {
            SetScrollPos(hwnd, SB_VERT, iVscrollPos, TRUE);//更新数值
            InvalidateRect(hwnd, NULL, TRUE);//刷新界面
        }
        return 0;

    case WM_PAINT:
        hdc = BeginPaint(hwnd, &ps);

        for (i = 0; i < row_num; i++) {
            y = cyChar * (i - iVscrollPos);
            *(data + i) = (wchar_t*)malloc(sizeof(wchar_t) * (col_num + 1));
            wcsncpy_s(*(data + i), col_num + 1, text + col_num * i, col_num);
            if (i != row_num - 1) {
                TextOut(hdc, 0, y, *(data + i), col_num);
            } else {
                if (!wcslen(text) % col_num) {
                    TextOut(hdc, 0, y, *(data + i), wcslen(text) % col_num);
                }
                else {
                    TextOut(hdc, 0, y, *(data + i), col_num);
                }
            }
        }
        EndPaint(hwnd, &ps);
        return 0;

    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}
示例#15
0
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    // Child windows' handles
    static HWND hwndListBox, hwndNewItem, hwndAddButton, hwndRemoveButton, hwndClearButton, hwndHeightScroll, hwndWidthScroll;
    static HINSTANCE hInstance;

    // Size and position variables
    int iSysWidth;
    int iSysHeight;
    int iWinWidth;
    int iWinHeight;

    int iWidth  = 60;   // Button width
    int iHeight = 30;   // Button height
    int x;
    int y;

    int i, cxChar, cyChar;

    // Menu & menu items
    HMENU hMenu;
    HMENU hSubMenu;

    // String
    char* szText;
    int iTextLength;

    // Paint and size structs
    TEXTMETRIC tm;
    SCROLLINFO si;
    HBRUSH brush;
    RECT rect, rct;
    int color;
    HDC hdc;


    hdc = GetDC(hwnd);
    GetTextMetrics(hdc, &tm);
    cxChar = tm.tmAveCharWidth;
    cyChar = tm.tmHeight;
    ReleaseDC(hwnd, hdc);

    switch(message) {

        case WM_CREATE:
            hwndListBox = CreateWindowEx(
                (DWORD)NULL,
                TEXT("ListBox"),
                NULL,
                WS_CHILD | WS_VISIBLE | WS_BORDER | LBS_NOTIFY | LBS_WANTKEYBOARDINPUT,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_LIST_BOX,
                hProgramInstance,
                NULL);

            hwndNewItem = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Edit"),
                TEXT("Input candidates"),
                WS_CHILD | WS_VISIBLE | WS_BORDER |ES_AUTOVSCROLL | ES_AUTOHSCROLL,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_NEW_ITEM,
                hProgramInstance,
                NULL);

            hwndWidthScroll = CreateWindow(
                "Scrollbar",
                NULL,
                WS_CHILD | WS_VISIBLE | SBS_HORZ | SBS_BOTTOMALIGN,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_WIDTH_SCROLL,
                hProgramInstance,
                NULL);
            SetScrollRange(hwndWidthScroll, SB_CTL, 0, 100, FALSE);
            SetScrollPos(hwndWidthScroll, SB_CTL, 0, FALSE);

            hwndHeightScroll = CreateWindow(
                "Scrollbar",
                NULL,
                WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_BOTTOMALIGN,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_HEIGHT_SCROLL,
                hProgramInstance,
                NULL);
            SetScrollRange(hwndHeightScroll, SB_CTL, 0, 100, TRUE);
            SetScrollPos(hwndHeightScroll, SB_CTL, 0, FALSE);

            hwndAddButton = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Button"),
                TEXT("Add"),
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_ADD_BUTTON,
                hProgramInstance,
                NULL);

            hwndRemoveButton = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Button"),
                TEXT("Remove"),
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_REMOVE_BUTTON,
                hProgramInstance,
                NULL);

            hwndClearButton = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Button"),
                TEXT("Clear"),
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_CLEAR_BUTTON,
                hProgramInstance,
                NULL);


            // Create menu
            hMenu = CreateMenu();

            // Add "File" menu, with "Exit" submenu
            hSubMenu = CreatePopupMenu();
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
            AppendMenu(hSubMenu, MF_STRING, IDC_FILE_EXIT, "&Exit");

            hSubMenu = CreatePopupMenu();
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Edit");
            AppendMenu(hSubMenu, MF_STRING, IDC_MOVE, "&Jump around");

            hSubMenu = CreatePopupMenu();
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Help");
            AppendMenu(hSubMenu, MF_STRING, IDC_HELP_ABOUT, "&About");

            // Set the menu
            SetMenu(hwnd, hMenu);
            break;

        case WM_SIZE:
            iWidth  = LOWORD(lParam);
            iHeight = HIWORD(lParam);

            // Set vertical scroll bar range and page size
            si.cbSize = sizeof(si);
            si.fMask = SIF_RANGE | SIF_PAGE;
            si.nMin = 0;
            si.nMax = ((iMinWindowHeight - 70) / cyChar);
            si.nPage = iHeight / cyChar;
            SetScrollInfo(hwnd, SB_VERT, &si, TRUE);

            // Set horizontal scroll bar range and page size
            si.cbSize = sizeof(si);
            si.fMask = SIF_RANGE | SIF_PAGE;
            si.nMin = 0;
            si.nMax = ((iMinWindowWidth - 20) / cxChar);
            si.nPage = iWidth / cxChar;
            SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);

            // CHILD WINDOWS REPOSITION BEGIN

            MoveWindow(hwndListBox, iWidth/2 - 210, iHeight/2 - 150, 300, 350, TRUE);
            MoveWindow(hwndNewItem, iWidth/2 - 210, iHeight/2 - 220, 300, 50, TRUE);
            MoveWindow(hwndWidthScroll, iWidth/2 - 210, iHeight/2 + 200, 410, 20, TRUE);
            MoveWindow(hwndHeightScroll, iWidth/2 + 180, iHeight/2 - 220, 20, 410, TRUE);
            MoveWindow(hwndAddButton, iWidth/2 + 100, iHeight/2 - 210, 60, 30, TRUE);
            MoveWindow(hwndRemoveButton, iWidth/2 + 100, iHeight/2 - 140, 60, 30, TRUE);
            MoveWindow(hwndClearButton, iWidth/2 + 100 , iHeight/2- 100, 60, 30, TRUE);

            // CHILD WINDOWS REPOSITION END
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            // Set width scrollbar position
            SetScrollPos(hwndWidthScroll, SB_CTL, (iWinWidth * 100 / iSysWidth), TRUE);

            // Set height scrollbar position
            SetScrollPos(hwndHeightScroll, SB_CTL, (iWinHeight * 100 / iSysHeight), TRUE);
            break;

        case WM_VSCROLL:
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            if(GetWindowLong((HWND)lParam, GWL_ID) == IDC_HEIGHT_SCROLL) {
                si.cbSize = sizeof(si);
                si.fMask = SIF_ALL;
                GetScrollInfo(hwndHeightScroll, SB_CTL, &si);
                y = si.nPos;
                switch(LOWORD(wParam)) {
                    case SB_LINELEFT:
                        si.nPos -= 1;
                        break;
                    case SB_LINERIGHT:
                        si.nPos += 1;
                        break;
                    case SB_THUMBPOSITION:
                        si.nPos = si.nTrackPos;
                        break;
                    default:
                        break;
                }
                si.fMask = SIF_POS;
                SetScrollInfo(hwndHeightScroll, SB_CTL, &si, TRUE);
                GetScrollInfo(hwndHeightScroll, SB_CTL, &si);
                if(si.nPos != y) {
                    SetScrollPos(hwndHeightScroll, SB_CTL, si.nPos, TRUE);
                }
                // Set window height
                MoveWindow(hwnd, rect.left, rect.top, iWinWidth, (si.nPos * iSysHeight / 100), TRUE);
                break;
            }


            // Get all the vertical scroll bar information
            si.cbSize = sizeof(si);
            si.fMask = SIF_ALL;
            GetScrollInfo(hwnd, SB_VERT, &si);

            // Save the position for later comparison
            x = si.nPos;


            switch(LOWORD(wParam)) {
                case SB_TOP:
                    si.nPos = si.nMin;
                    break;

                case SB_BOTTOM:
                    si.nPos = si.nMax;
                    break;

                case SB_LINEUP:
                    si.nPos -= 1;
                    break;

                case SB_LINEDOWN:
                    si.nPos += 1;
                    break;

                case SB_PAGEUP:
                    si.nPos -= si.nPage;
                    break;

                case SB_PAGEDOWN:
                    si.nPos += si.nPage;
                    break;

                case SB_THUMBTRACK:
                    si.nPos = si.nTrackPos;
                    break;

                default:
                    break;
            }

            // Set the position and then retrieve it
            si.fMask = SIF_POS;
            SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
            GetScrollInfo(hwnd, SB_VERT, &si);

            // If the position has changed, scroll the window and update it
            if(si.nPos != x) {
                ScrollWindow(hwnd, 0, cyChar * (y - si.nPos), NULL, NULL);
                UpdateWindow(hwnd);
            }
            break;

        case WM_HSCROLL:
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            if(GetWindowLong((HWND)lParam, GWL_ID) == IDC_WIDTH_SCROLL) {
                si.cbSize = sizeof(si);
                si.fMask = SIF_ALL;
                GetScrollInfo(hwndWidthScroll, SB_CTL, &si);
                x = si.nPos;
                switch(LOWORD(wParam)) {
                    case SB_LINELEFT:
                        si.nPos -= 1;
                        break;
                    case SB_LINERIGHT:
                        si.nPos += 1;
                        break;
                    case SB_THUMBPOSITION:
                        si.nPos = si.nTrackPos;
                        break;
                    default:
                        break;
                }
                si.fMask = SIF_POS;
                SetScrollInfo(hwndWidthScroll, SB_CTL, &si, TRUE);
                GetScrollInfo(hwndWidthScroll, SB_CTL, &si);
                if(si.nPos != x) {
                    SetScrollPos(hwndWidthScroll, SB_CTL, si.nPos, TRUE);
                }
                // Set window width
                MoveWindow(hwnd, rect.left, rect.top, (si.nPos * iSysWidth / 100), iWinHeight, TRUE);
                break;
            }

           // Get all the vertical scroll bar information
            si.cbSize = sizeof(si);
            si.fMask = SIF_ALL;
            GetScrollInfo(hwnd, SB_HORZ, &si);
            // Save the position for later comparison
            x = si.nPos;
            switch(LOWORD(wParam)) {
                case SB_LINELEFT:
                    si.nPos -= 1;
                    break;

                case SB_LINERIGHT:
                    si.nPos += 1;
                    break;

                case SB_PAGELEFT:
                    si.nPos -= si.nPage;
                    break;

                case SB_PAGERIGHT:
                    si.nPos += si.nPage;
                    break;

                case SB_THUMBPOSITION:
                    si.nPos = si.nTrackPos;
                    break;

                default:
                    break;
            }
            // Set the position and then retrieve it
            si.fMask = SIF_POS;
            SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
            GetScrollInfo(hwnd, SB_HORZ, &si);

            // If the position has changed, scroll the window and update it
            if(si.nPos != x) {
                ScrollWindow(hwnd, cxChar * (x - si.nPos), 0, NULL, 0);
                UpdateWindow(hwnd);
            }
            break;

        case WM_COMMAND:
            switch (LOWORD(wParam)) {
                case IDC_LIST_BOX:
                    switch (HIWORD(wParam)) {
                        case LBN_DBLCLK:
                            MessageBox(NULL, TEXT("Candidate Selected!"), TEXT("Congrats!"), MB_OK);
                            break;
                    }
                    break;

                case IDC_ADD_BUTTON:
                    iTextLength = SendMessage(hwndNewItem, WM_GETTEXTLENGTH, 0, 0);
                    szText = (char*)malloc(iTextLength+1);
                    SendMessage(hwndNewItem, WM_GETTEXT, iTextLength+1, (LPARAM)szText);
                    SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM)szText);
                    SendMessage(hwndNewItem, WM_SETTEXT, 0, (LPARAM)"");
                    free(szText);
                    break;

                case IDC_REMOVE_BUTTON:
                    i = SendMessage(hwndListBox, LB_GETCURSEL, 0, 0);
                    if(i != LB_ERR) {
                        SendMessage(hwndListBox, LB_DELETESTRING, i, 0);
                    }
                    break;

                case IDC_CLEAR_BUTTON:
                    SendMessage(hwndListBox, LB_RESETCONTENT, 0, 0);
                    break;

                case IDC_FILE_EXIT:
                    SendMessage(hwnd, WM_DESTROY, 0, 0);
                    break;

                case IDC_MOVE:
                            int xPos, yPos;
                            xPos = rand() % 1000;
                            yPos = rand() % 800;
                            SetWindowPos(hwnd, HWND_TOP, xPos, yPos, 0, 0, SWP_NOSIZE);
                            break;

                case IDC_HELP_ABOUT:
                    return DialogBox(hProgramInstance, MAKEINTRESOURCE(IDD_ABOUT), NULL, (DLGPROC)DialogProcedure);
                    break;

                default:
                    DefWindowProc(hwnd, WM_COMMAND, wParam, lParam);
                    break;
            }
            break;

        case WM_KEYDOWN:
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            // Move window right on Shift + Arrow Right
            if((wParam == VK_RIGHT)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.left >= iSysWidth - iWinWidth) {
                    MoveWindow(hwnd, iSysWidth - iWinWidth, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left + 5, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            // Move window left on Shift + Arrow Left
            if((wParam == VK_LEFT)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.left <= 0) {
                    MoveWindow(hwnd, 0, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left - 5, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            // Move window down on Shift + Arrow Down
            if((wParam == VK_DOWN)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.top >= iSysHeight - iWinHeight) {
                    MoveWindow(hwnd, rect.left, iSysHeight - iWinHeight, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left, rect.top + 5, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            // Move window up on Shift + Arrow Up
            if((wParam == VK_UP)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.top <= 0) {
                    MoveWindow(hwnd, rect.left, 0, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left, rect.top - 5, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            return DefWindowProc (hwnd, WM_PAINT, wParam, lParam);


        case WM_PAINT:
            return DefWindowProc (hwnd, WM_PAINT, wParam, lParam);
            break;

        case WM_DESTROY:
            PostQuitMessage (0);
            break;

        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
示例#16
0
int PrintFunction ( char* logicalname, char* buffer )

{  extern SCREEN WinDialog;       /* Data Structure for the Dialog Window */
	int Loc = 0;                /* Number of characters until line break */
	char *str;                  /* Subset of the buffer up to the line break */
	extern int HorizScroll;
   int oldsize, size;
	/*------------------------------------------------------------------------+
   | WinDialog.NoLines = Number of text lines that can be displayed per screen. |
   | WinDialog.LineSize = Number of pixels in height for each line of text.     |
   | WinDialog.LastLine = Virtual location for the bottom of the text area.     |
   +------------------------------------------------------------------------*/

   /*------------------------------------------+
	| Allocate room for the buffer to be parsed |
   +------------------------------------------*/
	str = (char *)malloc(strlen(buffer)+1);
   if (str == NULL)
      ExitToShell();



   /*-----------------------------------------------+
   | Loop through each 'part' of the buffer string  |
   | Note: 'part' is text between carriage returns. |
   +-----------------------------------------------*/
   while (Loc < strlen(buffer))
   {
     str[0] = '\0';
     
     /*----------------------------------+
		| Caputre text up to the line break |
      +----------------------------------*/
      sscanf(&(buffer[Loc]), "%[^\n]",str );


		/*----------------------------------------+
		| Allocate new memory if new line of text |
		| or reallocate if appending line of text |
		+----------------------------------------*/

		if (Terminal[WinDialog.LastLine] != NULL)
	{ oldsize = strlen( Terminal[WinDialog.LastLine] ); }
		else
	{ oldsize = 0; }

		size = oldsize + strlen(str)+1;
		if (Terminal[WinDialog.LastLine] != NULL)
	 Terminal[WinDialog.LastLine] = (char *) realloc(Terminal[WinDialog.LastLine], size);
		else
	 Terminal[WinDialog.LastLine] = (char *) malloc(size);
		if (Terminal[WinDialog.LastLine] == NULL)
	 ExitToShell();

		/*--------------------------------+
		|Copy String to the dialog window |
		+--------------------------------*/
		Terminal[WinDialog.LastLine][oldsize] = '\0';
		strcat (Terminal[WinDialog.LastLine], str);
		Loc += strlen( str );


		if (buffer[Loc] == '\n')
		{  int min, max;
	 /*------------------------------+
	 | Display line before advancing |
	 +------------------------------*/
	 SendToScreen ();
	 WinDialog.LastLine ++;
	 if (WinDialog.LastLine > DIALOG_SIZE ) WinDialog.LastLine = 0;

	 /*-----------------------+
	 | Free next line of text |
	 +-----------------------*/
	 if (Terminal[WinDialog.LastLine] != NULL)
	 {
	  free(Terminal[WinDialog.LastLine]);
		 Terminal[ WinDialog.LastLine ] = NULL;
	 }

	 /*-------------------+
	 | Update Scroll Bars |
	 +-------------------*/
	 GetScrollRange ( WinDialog.hWnd, SB_VERT, &min, &max );
	 if ( max < DIALOG_SIZE ) max = WinDialog.LastLine;
	 else max = DIALOG_SIZE;
	 if ( max > WinDialog.NoLines )
		 SetScrollRange ( WinDialog.hWnd, SB_VERT, WinDialog.NoLines, max, FALSE );
	 else
		 SetScrollRange ( WinDialog.hWnd, SB_VERT, 0,1 , FALSE );
	 SetScrollPos   ( WinDialog.hWnd, SB_VERT, max, TRUE );

	 GetScrollRange ( WinDialog.hWnd, SB_HORZ, &min, &max);
	 if ( max < size ) max = size;
	 SetScrollRange ( WinDialog.hWnd, SB_HORZ, 0, max, FALSE);
	 SetScrollPos   ( WinDialog.hWnd, SB_HORZ, 0, TRUE);
		}

		SendToScreen ();

		Loc ++;
	}
	free(str);
	return (TRUE);
}
示例#17
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static COLORREF crPrim[3] = { RGB (255, 0, 0), RGB (0, 255, 0),
                                   RGB (0, 0, 255) } ;
     static HBRUSH  hBrush[3], hBrushStatic ;
     static HWND    hwndScroll[3], hwndLabel[3], hwndValue[3], hwndRect ;
     static int     color[3], cyChar ;
     static RECT    rcColor ;
     static TCHAR * szColorLabel[] = { TEXT ("Red"), TEXT ("Green"), 
                                       TEXT ("Blue") } ;
     HINSTANCE      hInstance ;
     int            i, cxClient, cyClient ;
     TCHAR          szBuffer[10] ;
     
     switch (message)
     {
     case WM_CREATE :
          hInstance = (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) ;
          
               // Create the white-rectangle window against which the 
               // scroll bars will be positioned. The child window ID is 9.
          
          hwndRect = CreateWindow (TEXT ("static"), NULL,
                                   WS_CHILD | WS_VISIBLE | SS_WHITERECT,
                                   0, 0, 0, 0,
                                   hwnd, (HMENU) 9, hInstance, NULL) ;
          
          for (i = 0 ; i < 3 ; i++)
          {
                    // The three scroll bars have IDs 0, 1, and 2, with
                    // scroll bar ranges from 0 through 255.
               
               hwndScroll[i] = CreateWindow (TEXT ("scrollbar"), NULL,
                                             WS_CHILD | WS_VISIBLE | 
                                             WS_TABSTOP | SBS_VERT,
                                             0, 0, 0, 0, 
                                             hwnd, (HMENU) i, hInstance, NULL) ;
               
               SetScrollRange (hwndScroll[i], SB_CTL, 0, 255, FALSE) ;
               SetScrollPos   (hwndScroll[i], SB_CTL, 0, FALSE) ;
               
                    // The three color-name labels have IDs 3, 4, and 5, 
                    // and text strings "Red", "Green", and "Blue".
               
               hwndLabel [i] = CreateWindow (TEXT ("static"), szColorLabel[i],
                                             WS_CHILD | WS_VISIBLE | SS_CENTER,
                                             0, 0, 0, 0, 
                                             hwnd, (HMENU) (i + 3), 
                                             hInstance, NULL) ;
               
                    // The three color-value text fields have IDs 6, 7, 
                    // and 8, and initial text strings of "0".
               
               hwndValue [i] = CreateWindow (TEXT ("static"), TEXT ("0"),
                                             WS_CHILD | WS_VISIBLE | SS_CENTER,
                                             0, 0, 0, 0,
                                             hwnd, (HMENU) (i + 6), 
                                             hInstance, NULL) ;
               
               OldScroll[i] = (WNDPROC) SetWindowLong (hwndScroll[i], 
                                             GWL_WNDPROC, (LONG) ScrollProc) ;
               
               hBrush[i] = CreateSolidBrush (crPrim[i]) ;
          }
          
          hBrushStatic = CreateSolidBrush (
                              GetSysColor (COLOR_BTNHIGHLIGHT)) ;
          
          cyChar = HIWORD (GetDialogBaseUnits ()) ;
          return 0 ;
          
     case WM_SIZE :
          cxClient = LOWORD (lParam) ;
          cyClient = HIWORD (lParam) ;
          
          SetRect (&rcColor, cxClient / 2, 0, cxClient, cyClient) ;
          
          MoveWindow (hwndRect, 0, 0, cxClient / 2, cyClient, TRUE) ;
          
          for (i = 0 ; i < 3 ; i++)
          {
               MoveWindow (hwndScroll[i],
                           (2 * i + 1) * cxClient / 14, 2 * cyChar,
                           cxClient / 14, cyClient - 4 * cyChar, TRUE) ;
               
               MoveWindow (hwndLabel[i],
                           (4 * i + 1) * cxClient / 28, cyChar / 2,
                           cxClient / 7, cyChar, TRUE) ;
               
               MoveWindow (hwndValue[i],
                           (4 * i + 1) * cxClient / 28, 
                           cyClient - 3 * cyChar / 2,
                           cxClient / 7, cyChar, TRUE) ;
          }
          SetFocus (hwnd) ;
          return 0 ;
          
     case WM_SETFOCUS :
          SetFocus (hwndScroll[idFocus]) ;
          return 0 ;
          
     case WM_VSCROLL :
          i = GetWindowLong ((HWND) lParam, GWL_ID) ;
          
          switch (LOWORD (wParam))
          {
          case SB_PAGEDOWN :
               color[i] += 15 ;
                                             // fall through
          case SB_LINEDOWN :
               color[i] = min (255, color[i] + 1) ;
               break ;
               
          case SB_PAGEUP :
               color[i] -= 15 ;
                                             // fall through
          case SB_LINEUP :
               color[i] = max (0, color[i] - 1) ;
               break ;
               
          case SB_TOP :
               color[i] = 0 ;
               break ;
               
          case SB_BOTTOM :
               color[i] = 255 ;
               break ;
               
          case SB_THUMBPOSITION :
          case SB_THUMBTRACK :
               color[i] = HIWORD (wParam) ;
               break ;
               
          default :
               break ;
          }
          SetScrollPos  (hwndScroll[i], SB_CTL, color[i], TRUE) ;
          wsprintf (szBuffer, TEXT ("%i"), color[i]) ;
          SetWindowText (hwndValue[i], szBuffer) ;
          
          DeleteObject ((HBRUSH) 
               SetClassLong (hwnd, GCL_HBRBACKGROUND, (LONG) 
                    CreateSolidBrush (RGB (color[0], color[1], color[2])))) ;
          
          InvalidateRect (hwnd, &rcColor, TRUE) ;
          return 0 ;
          
     case WM_CTLCOLORSCROLLBAR :
          i = GetWindowLong ((HWND) lParam, GWL_ID) ;
          return (LRESULT) hBrush[i] ;
               
     case WM_CTLCOLORSTATIC :
          i = GetWindowLong ((HWND) lParam, GWL_ID) ;
               
          if (i >= 3 && i <= 8)    // static text controls
          {
               SetTextColor ((HDC) wParam, crPrim[i % 3]) ;
               SetBkColor ((HDC) wParam, GetSysColor (COLOR_BTNHIGHLIGHT));
               return (LRESULT) hBrushStatic ;
          }
          break ;
               
     case WM_SYSCOLORCHANGE :
          DeleteObject (hBrushStatic) ;
          hBrushStatic = CreateSolidBrush (GetSysColor (COLOR_BTNHIGHLIGHT)) ;
          return 0 ;
               
     case WM_DESTROY :
          DeleteObject ((HBRUSH)
               SetClassLong (hwnd, GCL_HBRBACKGROUND, (LONG) 
                    GetStockObject (WHITE_BRUSH))) ;
               
          for (i = 0 ; i < 3 ; i++)
               DeleteObject (hBrush[i]) ;
               
          DeleteObject (hBrushStatic) ;
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}
示例#18
0
/********************************************************************
* SendToScreen: Displays the current text line in the Dialog Window.
*********************************************************************/
void SendToScreen ( void )

{  extern SCREEN WinDialog;           /* D.S. Holding info about screen */
	RECT DRect;                     /* Client Area of Dialog Window */
	RECT Rect;                      /* Adjusted Area for scrolling */
	HDC hDC = GetDC ( WinDialog.hWnd); /* Handle to the device context */
	extern int OldLine;             /* Previous Line Printed */
	int min, max, pos;              /* Scroll Bar Values */
	int Scroll = 0;                 /* Scrolling Needed? */
	GetClientRect ( WinDialog.hWnd, &Rect );
	GetClientRect ( WinDialog.hWnd, &DRect );

	HideCaret ( WinDialog.hWnd );
	/*------------------------------------------------------+
	| Move to the bottom of the screen if not already there |
	+------------------------------------------------------*/
	GetScrollRange ( WinDialog.hWnd, SB_VERT, &min, &max );
	pos = GetScrollPos (WinDialog.hWnd, SB_VERT );
	if ( pos != max )
	{  InvalidateRect ( WinDialog.hWnd, NULL, TRUE );
		SetScrollPos (WinDialog.hWnd, SB_VERT, max, FALSE );
		SendMessage ( WinDialog.hWnd, WM_PAINT, 0, 0);
	}

	/*--------------------------------------------------------+
	| Determine if the screen is full and scrolling is needed |
	+--------------------------------------------------------*/
	if ( max > WinDialog.NoLines ) Scroll = 1;

	/*-------------------------------------------------------------+
	| Scroll Window if newline and text will not fit on the screen |
	+-------------------------------------------------------------*/
	if (Scroll && WinDialog.LastLine != OldLine)
	{  OldLine = WinDialog.LastLine;
		ScrollDC ( hDC, 0, -WinDialog.LineSize, &DRect, &DRect, NULL, &Rect );
	}

	/*----------------------------------------+
	| Calculate when text is to be displayed  |
	+----------------------------------------*/
	if ( !Scroll)
		Rect.top = (WinDialog.LastLine) * WinDialog.LineSize;
	else
		Rect.top = (WinDialog.NoLines) * WinDialog.LineSize;

	/*----------------------------+
	| Clear Line to be displayed  |
	+----------------------------*/
	{  HANDLE OldObject;
		OldObject = SelectObject (hDC, GetStockObject ( WHITE_PEN ) );
		Rectangle (hDC, Rect.left, Rect.top, Rect.right, Rect.bottom);
		SelectObject (hDC, OldObject);
	}

	/*--------------------------+
	| Display Text Adjusting    |
	| for the Horizontal scroll |
	+--------------------------*/
	pos = GetScrollPos (WinDialog.hWnd, SB_HORZ );

	if (Terminal[WinDialog.LastLine] == NULL)
	  { /* Do Nothing */ }
	else if ( pos < strlen (Terminal[WinDialog.LastLine]) )
	{
	 DrawText ( hDC, Terminal[WinDialog.LastLine]+pos, -1, &Rect,
			DT_LEFT | DT_NOCLIP | DT_SINGLELINE | DT_NOPREFIX );
	 DrawText ( hDC, Terminal[WinDialog.LastLine]+pos, -1, &Rect,
			DT_LEFT | DT_NOCLIP | DT_SINGLELINE | DT_CALCRECT | DT_NOPREFIX);
	}
	else
		Rect.right = 2;

	/*-----------+
	| Show Caret |
	+-----------*/
	SetCaretPos (Rect.right, Rect.top);
	ShowCaret ( WinDialog.hWnd );

	/*--------------------------------+
	| Automatic Horizontal Scrolling  |
	+--------------------------------*/

	if (Terminal[WinDialog.LastLine] != NULL)
	  {
		DrawText ( hDC, Terminal[WinDialog.LastLine]+pos, -1, &Rect,
		 DT_LEFT | DT_NOCLIP | DT_SINGLELINE | DT_NOPREFIX );
	  }
	if ( Rect.right > DRect.right && HorizScroll )
	{  GetScrollRange ( WinDialog.hWnd, SB_HORZ, &min, &max );
		pos ++;
		if ( max < pos) max = pos;
		SetScrollRange ( WinDialog.hWnd, SB_HORZ, 0, max, FALSE );
		SetScrollPos ( WinDialog.hWnd, SB_HORZ, pos, TRUE );
		InvalidateRect (WinDialog.hWnd, NULL, TRUE);
	}

	OldLine = WinDialog.LastLine;
	ReleaseDC ( WinDialog.hWnd, hDC);
}
示例#19
0
文件: flatsb.c 项目: AlexSteel/wine
/***********************************************************************
 *		FlatSB_SetScrollRange (COMCTL32.@)
 *
 * See SetScrollRange.
 */
INT WINAPI
FlatSB_SetScrollRange(HWND hwnd, int nBar, INT min, INT max, BOOL bRedraw)
{
    return SetScrollRange(hwnd, nBar, min, max, bRedraw);
}
示例#20
0
文件: drawmenu.c 项目: jossk/OrangeC
static void DoPaint(HWND hwnd, HDC hDC, LPPAINTSTRUCT lpPaint, RECT *r, struct resRes *menuData)
{
    RECT r1;
    NONCLIENTMETRICS m;
    HFONT font;
    SIZE sz;
    HDC compatDC, arrowDC;
    HBITMAP compatBitmap, arrowBitmap;
    int fontHeight;
    m.cbSize = sizeof(NONCLIENTMETRICS);
    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS),&m, NULL);
    fontHeight = (m.lfMenuFont.lfHeight < 0 ? - m.lfMenuFont.lfHeight : m.lfMenuFont.lfHeight)+6;
    font = CreateFontIndirect(&m.lfMenuFont);
    compatDC = CreateCompatibleDC(hDC);
    arrowDC = CreateCompatibleDC(hDC);
    font = SelectObject(compatDC, font);
    sz.cx = 0; 
    sz.cy = 0;
    GetSizeTopRow(compatDC, menuData->resource->u.menu->items, 0, 0, fontHeight, &sz);
    sz.cx +=GetSystemMetrics(SM_CXBORDER) * 2;
    sz.cy +=GetSystemMetrics(SM_CYBORDER) * 2;
    if (sz.cx < r->right)
        sz.cx = r->right;
    if (sz.cy < r->bottom)
        sz.cy = r->bottom;
    arrowBitmap = arrImage;
    arrowBitmap = SelectObject(arrowDC, arrowBitmap);
    compatBitmap = CreateCompatibleBitmap(hDC, 1000, 1000);
    compatBitmap = SelectObject(compatDC, compatBitmap);
    r1.left = r1.top = 0;
    r1.right = 1000;
    r1.bottom = 1000;
    FillRect(compatDC,&r1, (HBRUSH)(COLOR_APPWORKSPACE + 1));
    SetTextColor(compatDC, GetSysColor(COLOR_WINDOWTEXT));
    PaintTopRow(compatDC, arrowDC, menuData->resource->u.menu->items, menuData->gd.selectedMenu, 0, 0, font, fontHeight);
    font = SelectObject(compatDC, font);
    menuData->gd.scrollMax.x = sz.cx;
    menuData->gd.scrollMax.y = sz.cy;
    if (sz.cx <= r->right)
    {
        menuData->gd.scrollPos.x = 0;
    }
    else
    {
        SetScrollRange(hwnd, SB_HORZ, 0, sz.cx, FALSE);
        r->bottom -= GetSystemMetrics(SM_CYHSCROLL);
    }
    ShowScrollBar(hwnd, SB_HORZ, sz.cx > r->right);
    ShowScrollBar(hwnd, SB_VERT, sz.cy > r->bottom);
    if (sz.cy <= r->bottom)
    {
        menuData->gd.scrollPos.y = 0;
    }
    else
    {
        SetScrollRange(hwnd, SB_VERT, 0, sz.cy, FALSE);
        r->right -= GetSystemMetrics(SM_CXVSCROLL);
    }
    menuData->gd.scrollMax.x = sz.cx;
    menuData->gd.scrollMax.y = sz.cy;
    BitBlt(hDC, r->left+10, r->top+10, r->right+10, r->bottom+10,
           compatDC, menuData->gd.scrollPos.x, menuData->gd.scrollPos.y, SRCCOPY);
    compatBitmap = SelectObject(compatDC, compatBitmap);
    arrowBitmap = SelectObject(arrowDC, arrowBitmap);
    DeleteObject(compatBitmap);
    DeleteDC(compatDC);
    DeleteDC(arrowDC);
    DeleteObject(font);
}
示例#21
0
void CGraphListCtrl::ResetScrollBars()
{
	if( !::IsWindow(GetSafeHwnd())) 
	{
		return;
	}

	CRect rt;
	GetClientRect(rt);

	if (rt.left == rt.right || rt.top == rt.bottom)
	{
		return;
	}

	if (IsVisibleVScroll())
	{
		rt.right += 
			(GetSystemMetrics(SM_CXVSCROLL) + GetSystemMetrics(SM_CXBORDER)) ;//- 20;
	}
	if (IsVisibleHScroll())
	{
		rt.bottom += 
			(GetSystemMetrics(SM_CYHSCROLL) + GetSystemMetrics(SM_CYBORDER));
	}

	CRect VisibleRect(rt);
	CRect VirtualRect = GetVirtualRect();

	SCROLLINFO si;
	si.cbSize = sizeof(SCROLLINFO);
	si.fMask = SIF_PAGE;
	si.nPage = VisibleRect.Width();
	SetScrollInfo(SB_HORZ, &si, FALSE); //pk
	si.nPage = VisibleRect.Height();
	SetScrollInfo(SB_VERT, &si, FALSE);

	if (VisibleRect.Height() < VirtualRect.Height()) //pk  
		VisibleRect.right -= ::GetSystemMetrics(SM_CXVSCROLL);
	if (VisibleRect.Height() < VirtualRect.Height()) //pk  
	{
		if (IsVisibleVScroll()) EnableScrollBars(SB_VERT, TRUE); 
		m_nVScrollMax = VirtualRect.Height(); 
	}
	else
		m_nVScrollMax = 0;

	if (VisibleRect.Width() < VirtualRect.Width())   //pk  
		VisibleRect.bottom -= ::GetSystemMetrics(SM_CYHSCROLL);


	if (VisibleRect.Width() < VirtualRect.Width())
	{
		if (IsVisibleHScroll()) EnableScrollBars(SB_HORZ, TRUE);  //pk
		m_nHScrollMax = VirtualRect.Width() ;// 
	}
	else
		m_nHScrollMax = 0;

	ASSERT(m_nVScrollMax < INT_MAX && m_nHScrollMax < INT_MAX); // This should be fine

	//pk
	if( m_bSortByFixedRow ) m_nVScrollMax = 0;
	else					m_nHScrollMax = 0;

 	if (IsVisibleVScroll()) SetScrollRange(SB_VERT, 0, m_nVScrollMax, TRUE);
	if (IsVisibleHScroll()) SetScrollRange(SB_HORZ, 0, m_nHScrollMax, TRUE); //pk
}
示例#22
0
void CXTPPropertyPage::UpdateBars()
{
	if (m_totalDev == CSize(0, 0) || !m_bCreated)
		return;

	// UpdateBars may cause window to be resized - ignore those resizings
	if (m_bInsideUpdate)
		return;         // Do not allow recursive calls

	// Lock out recursion
	m_bInsideUpdate = TRUE;

	// update the horizontal to reflect reality
	// NOTE: turning on/off the scrollbars will cause 'OnSize' callbacks
	ASSERT(m_totalDev.cx >= 0 && m_totalDev.cy >= 0);

	CRect rectClient;
	BOOL bCalcClient = TRUE;

	CSize sizeClient;
	CSize sizeSb;

	// get client rect
	if (!GetTrueClientSize(sizeClient, sizeSb))
	{
		// no room for scroll bars (common for zero sized elements)
		CRect rect;
		GetClientRect(&rect);
		if (rect.right > 0 && rect.bottom > 0)
		{
			// if entire client area is not invisible, assume we have
			//  control over our scrollbars
			EnableScrollBarCtrl(SB_BOTH, FALSE);
		}
		m_bInsideUpdate = FALSE;
		return;
	}

	// enough room to add scrollbars
	CSize sizeRange;
	CPoint ptMove;
	CSize needSb;

	// get the current scroll bar state given the true client area
	GetScrollBarState(sizeClient, needSb, sizeRange, ptMove, bCalcClient);
	if (needSb.cx)
		sizeClient.cy -= sizeSb.cy;
	if (needSb.cy)
		sizeClient.cx -= sizeSb.cx;

	// first scroll the window as needed
	ScrollToDevicePosition(ptMove); // will set the scroll bar positions too

	// this structure needed to update the scrollbar page range
	SCROLLINFO info;
	info.fMask = SIF_PAGE|SIF_RANGE;
	info.nMin = 0;

	// now update the bars as appropriate
	EnableScrollBarCtrl(SB_HORZ, needSb.cx);
	if (needSb.cx)
	{
		info.nPage = sizeClient.cx;
		info.nMax = m_totalDev.cx-1;
		if (!SetScrollInfo(SB_HORZ, &info, TRUE))
			SetScrollRange(SB_HORZ, 0, sizeRange.cx, TRUE);
	}
	EnableScrollBarCtrl(SB_VERT, needSb.cy);
	if (needSb.cy)
	{
		info.nPage = sizeClient.cy;
		info.nMax = m_totalDev.cy-1;
		if (!SetScrollInfo(SB_VERT, &info, TRUE))
			SetScrollRange(SB_VERT, 0, sizeRange.cy, TRUE);
	}

	// remove recursion lockout
	m_bInsideUpdate = FALSE;
}
示例#23
0
void CScrollWnd::UpdateBars()
{
	// UpdateBars may cause window to be resized - ignore those resizings
	if (m_bInsideUpdate)
		return;         // Do not allow recursive calls

	// Lock out recursion
	m_bInsideUpdate = TRUE;

	// update the horizontal to reflect reality
	// NOTE: turning on/off the scrollbars will cause 'OnSize' callbacks
	ASSERT(m_totalDev.cx >= 0 && m_totalDev.cy >= 0);

	CRect rectClient;
	BOOL bCalcClient = TRUE;

	// allow parent to do inside-out layout first
	CWnd* pParentWnd = GetParent();
	if (pParentWnd != NULL)
	{
		// if parent window responds to this message, use just
		//  client area for scroll bar calc -- not "true" client area
		if ((BOOL)pParentWnd->SendMessage(WM_RECALCPARENT, 0,
			(LPARAM)(LPCRECT)&rectClient) != 0)
		{
			// use rectClient instead of GetTrueClientSize for
			//  client size calculation.
			bCalcClient = FALSE;
		}
	}

	CSize sizeClient;
	CSize sizeSb;

	if (bCalcClient)
	{
		// get client rect
		if (!GetTrueClientSize(sizeClient, sizeSb))
		{
			// no room for scroll bars (common for zero sized elements)
			CRect rect;
			GetClientRect(&rect);
			if (rect.right > 0 && rect.bottom > 0)
			{
				// if entire client area is not invisible, assume we have
				//  control over our scrollbars
				EnableScrollBarCtrl(SB_BOTH, FALSE);
			}
			m_bInsideUpdate = FALSE;
			return;
		}
	}
	else
	{
		// let parent window determine the "client" rect
		GetScrollBarSizes(sizeSb);
		sizeClient.cx = rectClient.right - rectClient.left;
		sizeClient.cy = rectClient.bottom - rectClient.top;
	}

	// enough room to add scrollbars
	CSize sizeRange;
	CPoint ptMove;
	CSize needSb;

	// get the current scroll bar state given the true client area
	GetScrollBarState(sizeClient, needSb, sizeRange, ptMove, bCalcClient);
	if (needSb.cx)
		sizeClient.cy -= sizeSb.cy;
	if (needSb.cy)
		sizeClient.cx -= sizeSb.cx;

	// first scroll the window as needed
	ScrollToDevicePosition(ptMove); // will set the scroll bar positions too

	// this structure needed to update the scrollbar page range
	SCROLLINFO info;
	info.fMask = SIF_PAGE|SIF_RANGE;
	info.nMin = 0;

	// now update the bars as appropriate
	EnableScrollBarCtrl(SB_HORZ, needSb.cx);
	if (needSb.cx)
	{
		info.nPage = sizeClient.cx;
		info.nMax = m_totalDev.cx-1;
		if (!SetScrollInfo(SB_HORZ, &info, TRUE))
			SetScrollRange(SB_HORZ, 0, sizeRange.cx, TRUE);
	}
	EnableScrollBarCtrl(SB_VERT, needSb.cy);
	if (needSb.cy)
	{
		info.nPage = sizeClient.cy;
		info.nMax = m_totalDev.cy-1;
		if (!SetScrollInfo(SB_VERT, &info, TRUE))
			SetScrollRange(SB_VERT, 0, sizeRange.cy, TRUE);
	}

	// remove recursion lockout
	m_bInsideUpdate = FALSE;
}
示例#24
0
BOOL CALLBACK DlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static BOOL         bShutOff, bClosing ;
     static HWAVEOUT     hWaveOut ;
     static HWND         hwndScroll ;
     static int          iFreq = FREQ_INIT ;
     static PBYTE        pBuffer1, pBuffer2 ;
     static PWAVEHDR     pWaveHdr1, pWaveHdr2 ;
     static WAVEFORMATEX waveformat ;
     int                 iDummy ;
     
     switch (message)
     {
     case WM_INITDIALOG:
          hwndScroll = GetDlgItem (hwnd, IDC_SCROLL) ;
          SetScrollRange (hwndScroll, SB_CTL, FREQ_MIN, FREQ_MAX, FALSE) ;
          SetScrollPos   (hwndScroll, SB_CTL, FREQ_INIT, TRUE) ;
          SetDlgItemInt  (hwnd, IDC_TEXT, FREQ_INIT, FALSE) ;
          
          return TRUE ;
          
     case WM_HSCROLL:
          switch (LOWORD (wParam))
          {
          case SB_LINELEFT:   iFreq -=  1 ;  break ;
          case SB_LINERIGHT:  iFreq +=  1 ;  break ;
          case SB_PAGELEFT:   iFreq /=  2 ;  break ;
          case SB_PAGERIGHT:  iFreq *=  2 ;  break ;
               
          case SB_THUMBTRACK:
               iFreq = HIWORD (wParam) ;
               break ;
               
          case SB_TOP:
               GetScrollRange (hwndScroll, SB_CTL, &iFreq, &iDummy) ;
               break ;
               
          case SB_BOTTOM:
               GetScrollRange (hwndScroll, SB_CTL, &iDummy, &iFreq) ;
               break ;
          }
          
          iFreq = max (FREQ_MIN, min (FREQ_MAX, iFreq)) ;
          
          SetScrollPos (hwndScroll, SB_CTL, iFreq, TRUE) ;
          SetDlgItemInt (hwnd, IDC_TEXT, iFreq, FALSE) ;
          return TRUE ;
          
     case WM_COMMAND:
          switch (LOWORD (wParam))
          {
          case IDC_ONOFF:
                    // If turning on waveform, hWaveOut is NULL
               
               if (hWaveOut == NULL)
               {
                         // Allocate memory for 2 headers and 2 buffers

                    pWaveHdr1 = malloc (sizeof (WAVEHDR)) ;
                    pWaveHdr2 = malloc (sizeof (WAVEHDR)) ;
                    pBuffer1  = malloc (OUT_BUFFER_SIZE) ;
                    pBuffer2  = malloc (OUT_BUFFER_SIZE) ;

                    if (!pWaveHdr1 || !pWaveHdr2 || !pBuffer1 || !pBuffer2)
                    {
                         if (!pWaveHdr1) free (pWaveHdr1) ;
                         if (!pWaveHdr2) free (pWaveHdr2) ;
                         if (!pBuffer1)  free (pBuffer1) ;
                         if (!pBuffer2)  free (pBuffer2) ;

                         MessageBeep (MB_ICONEXCLAMATION) ;
                         MessageBox (hwnd, TEXT ("Error allocating memory!"),
                                     szAppName, MB_ICONEXCLAMATION | MB_OK) ;
                         return TRUE ;
                    }

                         // Variable to indicate Off button pressed

                    bShutOff = FALSE ;
                         
                         // Open waveform audio for output
                         
                    waveformat.wFormatTag      = WAVE_FORMAT_PCM ;
                    waveformat.nChannels       = 1 ;
                    waveformat.nSamplesPerSec  = SAMPLE_RATE ;
                    waveformat.nAvgBytesPerSec = SAMPLE_RATE ;
                    waveformat.nBlockAlign     = 1 ;
                    waveformat.wBitsPerSample  = 8 ;
                    waveformat.cbSize          = 0 ;
                         
                    if (waveOutOpen (&hWaveOut, WAVE_MAPPER, &waveformat,
                                     (DWORD) hwnd, 0, CALLBACK_WINDOW)
                              != MMSYSERR_NOERROR)
                    {
                         free (pWaveHdr1) ;
                         free (pWaveHdr2) ;
                         free (pBuffer1) ;
                         free (pBuffer2) ;

                         hWaveOut = NULL ;
                         MessageBeep (MB_ICONEXCLAMATION) ;
                         MessageBox (hwnd, 
                              TEXT ("Error opening waveform audio device!"),
                              szAppName, MB_ICONEXCLAMATION | MB_OK) ;
                         return TRUE ;
                    }

                         // Set up headers and prepare them

                    pWaveHdr1->lpData          = pBuffer1 ;
                    pWaveHdr1->dwBufferLength  = OUT_BUFFER_SIZE ;
                    pWaveHdr1->dwBytesRecorded = 0 ;
                    pWaveHdr1->dwUser          = 0 ;
                    pWaveHdr1->dwFlags         = 0 ;
                    pWaveHdr1->dwLoops         = 1 ;
                    pWaveHdr1->lpNext          = NULL ;
                    pWaveHdr1->reserved        = 0 ;
                    
                    waveOutPrepareHeader (hWaveOut, pWaveHdr1, 
                                          sizeof (WAVEHDR)) ;

                    pWaveHdr2->lpData          = pBuffer2 ;
                    pWaveHdr2->dwBufferLength  = OUT_BUFFER_SIZE ;
                    pWaveHdr2->dwBytesRecorded = 0 ;
                    pWaveHdr2->dwUser          = 0 ;
                    pWaveHdr2->dwFlags         = 0 ;
                    pWaveHdr2->dwLoops         = 1 ;
                    pWaveHdr2->lpNext          = NULL ;
                    pWaveHdr2->reserved        = 0 ;
                    
                    waveOutPrepareHeader (hWaveOut, pWaveHdr2,
                                          sizeof (WAVEHDR)) ;
               }
                    // If turning off waveform, reset waveform audio
               else
               {
                    bShutOff = TRUE ;
                    waveOutReset (hWaveOut) ;
               }
               return TRUE ;
          }
          break ;

               // Message generated from waveOutOpen call
               
     case MM_WOM_OPEN:
          SetDlgItemText (hwnd, IDC_ONOFF, TEXT ("Turn Off")) ;

               // Send two buffers to waveform output device
                    
          FillBuffer (pBuffer1, iFreq) ;
          waveOutWrite (hWaveOut, pWaveHdr1, sizeof (WAVEHDR)) ;
                    
          FillBuffer (pBuffer2, iFreq) ;
          waveOutWrite (hWaveOut, pWaveHdr2, sizeof (WAVEHDR)) ;
          return TRUE ;

               // Message generated when a buffer is finished
                    
     case MM_WOM_DONE:
          if (bShutOff)
          {
               waveOutClose (hWaveOut) ;
               return TRUE ;
          }

               // Fill and send out a new buffer

          FillBuffer (((PWAVEHDR) lParam)->lpData, iFreq) ;
          waveOutWrite (hWaveOut, (PWAVEHDR) lParam, sizeof (WAVEHDR)) ;
          return TRUE ;
          
     case MM_WOM_CLOSE:
          waveOutUnprepareHeader (hWaveOut, pWaveHdr1, sizeof (WAVEHDR)) ;
          waveOutUnprepareHeader (hWaveOut, pWaveHdr2, sizeof (WAVEHDR)) ;

          free (pWaveHdr1) ;
          free (pWaveHdr2) ;
          free (pBuffer1) ;
          free (pBuffer2) ;

          hWaveOut = NULL ;
          SetDlgItemText (hwnd, IDC_ONOFF, TEXT ("Turn On")) ;
          
          if (bClosing)
               EndDialog (hwnd, 0) ;
          
          return TRUE ;
          
     case WM_SYSCOMMAND:
          switch (wParam)
          {
          case SC_CLOSE:
               if (hWaveOut != NULL)
               {
                    bShutOff = TRUE ;
                    bClosing = TRUE ;
                    
                    waveOutReset (hWaveOut) ;
               }
               else
                    EndDialog (hwnd, 0) ;
               
               return TRUE ;
          }
          break ;
     }
     return FALSE ;
}
示例#25
0
LRESULT CALLBACK HexviewProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    static unsigned char **pBuffer = NULL ;
    unsigned char	ascii, *bin_data;
    static int  cxChar, cxCaps, cxClient, cyClient,
           iVscrollPos, iVscrollMax,
           cyChar, xCaret = 6, yCaret;
    HDC         hdc ;
    int			y, i, nResult, iVscrollInc;
    static int	iPaintBeg, iPaintEnd;
    char		szFilename[MAX_PATH], szBuffer[256];

    RECT			rect = {50, 50, 620, 300};
    PAINTSTRUCT		ps;
    TEXTMETRIC		tm;
    static HFONT	hFont;
    HDROP			hDrop;


    switch (iMsg)
    {
    //case WM_INITDIALOG:
    case WM_CREATE :
        hdc = GetDC (hwnd) ;
        hFont = CreateFont(12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FIXED_PITCH | FF_DONTCARE, "Courier");
        SelectObject (hdc, hFont) ;
        GetTextMetrics (hdc, &tm) ;
        cxChar = tm.tmAveCharWidth ;
        cyChar = tm.tmHeight ;
        ReleaseDC (hwnd, hdc) ;

        pBuffer = CreateBuffer(64);
        return 0 ;


    case WM_SIZE :
        cxClient = LOWORD (lParam) ;
        cyClient = HIWORD (lParam) ;

        iVscrollMax = max (0, rows + 2 - cyClient / cyChar) ;
        iVscrollPos = min (iVscrollPos, iVscrollMax) ;

        SetScrollRange (hwnd, SB_VERT, 0, iVscrollMax, FALSE) ;
        SetScrollPos   (hwnd, SB_VERT, iVscrollPos, TRUE) ;

        return 0;


    case WM_VSCROLL:
        switch (LOWORD(wParam))
        {
        case SB_TOP:
            iVscrollInc = -iVscrollPos;
            break;

        case SB_BOTTOM:
            iVscrollInc = iVscrollMax = iVscrollPos;
            break;

        case SB_LINEUP:
            iVscrollInc = -1;
            break;

        case SB_LINEDOWN:
            iVscrollInc = 1;
            break;

        case SB_PAGEUP:
            iVscrollInc = min(-1, -cyClient / cyChar);
            break;

        case SB_PAGEDOWN:
            iVscrollInc = max(1, cyClient / cyChar);
            break;

        case SB_THUMBTRACK:
            iVscrollInc = HIWORD(wParam) - iVscrollPos;
            break;

        default:
            iVscrollInc = 0;
        }

        iVscrollInc = max (-iVscrollPos,
                           min (iVscrollInc, iVscrollMax - iVscrollPos));

        if (iVscrollInc != 0)
        {
            iVscrollPos += iVscrollInc;
            ScrollWindow(hwnd, 0, -cyChar * iVscrollInc, NULL, NULL);
            SetScrollPos(hwnd, SB_VERT, iVscrollPos, TRUE);

            xCaret = 6;
            yCaret = 0;
            SetCaretPos (xCaret * cxChar, 0) ;
            //UpdateWindow(hwnd);
            InvalidateRect(hwnd, NULL, TRUE);
        }

        return 0;


    case WM_SETFOCUS :
        // create and show the caret

        CreateCaret (hwnd, NULL, cxChar, cyChar) ;
        SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
        ShowCaret (hwnd) ;
        return 0 ;

    case WM_KILLFOCUS :
        // hide and destroy the caret
        HideCaret (hwnd) ;
        DestroyCaret () ;
        return 0 ;

    case WM_KEYDOWN :
        switch (wParam)
        {
        case VK_HOME :
            xCaret = 6 ;
            break ;

        case VK_PRIOR :
            yCaret = 0 ;
            break ;

        case VK_LEFT :
            xCaret = max (xCaret - 1, 6);
            if (pBuffer[yCaret][xCaret] == ' ')
                xCaret = max (xCaret - 1, 6);
            break ;

        case VK_RIGHT :
            ++xCaret;

            if (lastrow && (yCaret + iPaintBeg == rows-1))
                if (xCaret > (4 + lastrow*3))
                {
                    --xCaret;
                    break;
                }

            if (xCaret > 52)
            {
                xCaret = 6;
                ++yCaret;
                if (yCaret + iPaintBeg> rows - 1)
                {
                    --yCaret;
                    xCaret = 52;
                }
            }
            if ((xCaret % 3) == 2)
                ++xCaret;
            break ;

        case VK_UP :
            yCaret = max (yCaret - 1, 0) ;
            break ;

        case VK_DOWN :
            if (lastrow && (xCaret > (4 + lastrow*3)))
                yCaret = min(yCaret + 1, rows - iPaintBeg - 2);
            else
                yCaret = min(yCaret + 1, rows - iPaintBeg - 1);
            break ;
        }

        SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
        return 0 ;

    case WM_CHAR :
        for (i = 0 ; i < (int) LOWORD (lParam) ; i++)
        {
            if (!((wParam >= '0' && wParam <='9') || (wParam >= 'a' && wParam <= 'f')))
                return 0;


            HideCaret (hwnd) ;
            hdc = GetDC (hwnd) ;

            SelectObject (hdc, hFont);

            pBuffer[yCaret + iPaintBeg][xCaret] = wParam;
            TextOut(hdc, xCaret * cxChar, (yCaret) * cyChar, &pBuffer[yCaret + iPaintBeg][xCaret], 1);

            if (pBuffer[yCaret + iPaintBeg][xCaret-1] == ' ')
                ascii = hextoint(pBuffer[yCaret + iPaintBeg][xCaret], pBuffer[yCaret + iPaintBeg][xCaret + 1]);
            else
                ascii = hextoint(pBuffer[yCaret + iPaintBeg][xCaret - 1], pBuffer[yCaret + iPaintBeg][xCaret]);

            if (ascii > 33 && ascii < 125)
            {
                pBuffer[yCaret + iPaintBeg][(xCaret/3) + 54] = ascii;
                TextOut(hdc, ((xCaret/3) + 54)* cxChar, yCaret * cyChar, &pBuffer[yCaret + iPaintBeg][(xCaret/3) + 54], 1);
            }
            else
            {
                pBuffer[yCaret + iPaintBeg][(xCaret/3) + 54] = '.';
                TextOut(hdc, ((xCaret/3) + 54)* cxChar, yCaret * cyChar, &pBuffer[yCaret + iPaintBeg][(xCaret/3) + 54], 1);
            }

            ShowCaret (hwnd) ;
            ReleaseDC (hwnd, hdc) ;

            SendMessage(hwnd, WM_KEYDOWN, VK_RIGHT, 0);
            break ;
        }
        return 0 ;


    case WM_DROPFILES:
        hDrop = (HANDLE) wParam;
        DragQueryFile(hDrop, 0, szFilename, sizeof(szFilename));
        pBuffer = LoadPacket(szFilename);
        GetWindowRect(hwnd, &rect);
        SendMessage(hwnd, WM_SIZE, 0, MAKEWPARAM(rect.bottom - rect.top, rect.right - rect.left));
        InvalidateRect(hwnd, NULL, TRUE);
        return 0;


    case WM_PAINT :
        hdc = BeginPaint (hwnd, &ps) ;
        SelectObject (hdc, hFont) ;

        iPaintBeg = max (0, iVscrollPos + ps.rcPaint.top / cyChar );
        iPaintEnd = min (rows,
                         iVscrollPos + ps.rcPaint.bottom / cyChar);

        i =0;
        for (y = iPaintBeg; y < iPaintEnd; y++, i++)
            TextOut(hdc, 0, i * cyChar, pBuffer[y], 72);

        EndPaint (hwnd, &ps) ;
        return 0 ;

    case WM_DESTROY :
        DeleteBuffer(pBuffer);
        DeleteObject(hFont);
        return 0 ;
    }
    return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
示例#26
0
/*
 * SpeedDlgProc - processes messages for the speed dialogue box.
 *
 * Allows the user to select speeds for the target or lightning bolt,
 * depending on which selection was chosen.
 */
BOOL _EXPORT FAR PASCAL SpeedDlgProc( HWND dialog_wnd, unsigned msg,
                                WORD wparam, LONG lparam )
/********************************************************/
{
    extra_data              *edata_ptr;
    short                   speed;
    static short            old_speed = 0; /* in case the user hits CANCEL */
    static short            what_are_we_setting = 0;
    static short            fastest_speed = 0;
    static short            slowest_speed = 0;
    HWND                    scrollbar;

    edata_ptr = (extra_data *) GetWindowLong(
                 GetWindow( dialog_wnd, GW_OWNER ), EXTRA_DATA_OFFSET );

    switch( msg ) {
    case WM_INITDIALOG:
        what_are_we_setting = (short)lparam;
        if( what_are_we_setting == SET_TARGET_SPEED ) {
            SetDlgItemText( dialog_wnd, SET_WHAT, (LPSTR)"Set Target Speed" );
            old_speed = edata_ptr->target_speed;
            fastest_speed = FASTEST_TARGET_SPEED;
            slowest_speed = SLOWEST_TARGET_SPEED;
        } else {
            SetDlgItemText( dialog_wnd, SET_WHAT, (LPSTR)"Set Lightning Bolt Speed" );
            SetDlgItemText( dialog_wnd, TEST, (LPSTR)"Click RIGHT mouse button to test." );
            /*
             * we want fastest on left, slowest on right,
             * so use negative numbers for bolt speed
             */
            old_speed = -edata_ptr->bolt_speed;
            fastest_speed = -FASTEST_BOLT_SPEED;
            slowest_speed = -SLOWEST_BOLT_SPEED;
        }
        scrollbar = GetDlgItem( dialog_wnd, SPEED_SCROLL );
        SetScrollRange( scrollbar, SB_CTL, fastest_speed, slowest_speed, FALSE );
        SetScrollPos( scrollbar, SB_CTL, old_speed, FALSE );
        return( TRUE );

    case WM_RBUTTONDOWN:
        if( what_are_we_setting == SET_BOLT_SPEED ) {
            /*
             * shoot bolt diagonally accross the screen as a test
             */
            edata_ptr->aim.x = edata_ptr->client_rect.left;
            edata_ptr->aim.y = edata_ptr->client_rect.bottom;
            ShootBolt( GetWindow( dialog_wnd, GW_OWNER ) );
        }
        break;
    case WM_HSCROLL:
        speed = ( what_are_we_setting == SET_TARGET_SPEED )
                ? edata_ptr->target_speed : -edata_ptr->bolt_speed;
        scrollbar = GetDlgItem( dialog_wnd, SPEED_SCROLL );
        switch( wparam ) {
        case SB_PAGEDOWN:
            speed += 15;    /* note - no break - flow through to next case */
        case SB_LINEDOWN:
            speed = min( slowest_speed, ++speed );
            break;
        case SB_PAGEUP:
            speed -= 15;    /* note - no break - flow through to next case */
        case SB_LINEUP:
            speed = max( fastest_speed, --speed );
            break;
        case SB_TOP:
            speed = fastest_speed;
            break;
        case SB_BOTTOM:
            speed = slowest_speed;
            break;
        case SB_THUMBPOSITION:
        case SB_THUMBTRACK:
            speed = LOWORD( lparam );
            break;
        default:
            return( FALSE );
        }
        SetScrollPos( scrollbar, SB_CTL, speed , TRUE );
        if( what_are_we_setting == SET_TARGET_SPEED ) {
            edata_ptr->target_speed = speed;

            /* restart timer at new speed */
            KillTimer( GetWindow( dialog_wnd, GW_OWNER), TARGET_TIMER );
            SetTimer( GetWindow( dialog_wnd, GW_OWNER), TARGET_TIMER,
                      speed, ( FARPROC ) NULL );
        } else {
            /* change speed back to positive value */
            edata_ptr-> bolt_speed = -speed;
        }
        break;
    case WM_COMMAND:
        switch( wparam ) {
        case IDOK:
            EndDialog( dialog_wnd, TRUE );
            return( TRUE );
        case IDCANCEL:
            /* change speed back to old value */
            if( what_are_we_setting == SET_TARGET_SPEED ) {
                edata_ptr->target_speed = old_speed;
            } else {
                edata_ptr->bolt_speed = -old_speed;
            }
            EndDialog( dialog_wnd, TRUE );
            return( TRUE );
        break;
        }
    }
    return( FALSE );

} /* SpeedDlgProc */
示例#27
0
文件: test.cpp 项目: LeeSangJae/18533
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	WinProc_sub = hWnd;
	PAINTSTRUCT ps;
	HGDIOBJ hfDefault;
	RECT rt = { 100,100,1000,1000 };
	static char str[256];
	int xlnc, ylnc;
	int Lines;
	int nScroll;

	/* 하단 상태바 부분 */
	int SBPart[4];
	RECT prt;	

	/* 플로팅 팝업 메뉴 부분 */
	static COLORREF Color = RGB(255, 0, 0);
	HBRUSH hBrush;
	RECT crt;
	BOOLEAN delresult;

	switch (iMessage) {
	case WM_CREATE:
		AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hPopup, "즐겨찾기목록");
		SetMenu(hWnd, hMenu);
		favorite_page_create(hWnd);
		EdittextBox = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", NULL, WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, 115, 10, 300, 21, hWnd, (HMENU)IDC_MAIN_EDIT, NULL, NULL);
		hfDefault = GetStockObject(DEFAULT_GUI_FONT);
		SendMessage(EdittextBox, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
		SendMessage(EdittextBox, WM_SETTEXT, NULL, (LPARAM)"주소입력창");
		button = CreateWindow("BUTTON", "이동", WS_VISIBLE | WS_CHILD | WS_BORDER, 415, 10, 100, 20, hWnd, (HMENU)IDC_MAIN_BUTTON, NULL, NULL);
		SendMessage(button, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
		/* 디렉토리 버튼 */
		
		directory_button = CreateWindow("BUTTON", "방문기록보기", WS_VISIBLE | WS_CHILD | WS_BORDER, 520, 10, 100, 20, hWnd, (HMENU)IDC_VISITPAGE_BUTTON, NULL, NULL);
		SendMessage(directory_button, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
		back_button = CreateWindow("BUTTON", "<-", WS_VISIBLE | WS_CHILD | WS_BORDER, 10, 10, 20, 20, hWnd, (HMENU)BACK_BUTTON, NULL, NULL);
		front_button = CreateWindow("BUTTON", "->",WS_VISIBLE | WS_CHILD | WS_BORDER, 30, 10, 20, 20, hWnd, (HMENU)FRONT_BUTTON, NULL, NULL);
		refresh_button = CreateWindow("BUTTON", "새로고침", WS_VISIBLE | WS_CHILD | WS_BORDER, 50, 10, 60, 20, hWnd, (HMENU)REFRESH_BUTTON, NULL, NULL);
		SendMessage(refresh_button, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
		favorite_button = CreateWindow("BUTTON", "★", WS_VISIBLE | WS_CHILD | WS_BORDER, 622, 10, 20, 20, hWnd, (HMENU)FAVORITE_BUTTON, NULL, NULL);
		SendMessage(favorite_button, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
		SetFocus(EdittextBox);
		OldEditProc = (WNDPROC)SetWindowLongPtr(EdittextBox, GWLP_WNDPROC, (LONG_PTR)SubEditProc);

		/* 스크롤바 부분 시작*/
		xPos = 0;
		yPos = 0;
		xMax = 1000;
		yMax = 1000;
		SetScrollRange(hWnd, SB_VERT, 0, yMax, TRUE);
		SetScrollPos(hWnd, SB_VERT, 0, TRUE);
		SetScrollRange(hWnd, SB_HORZ, 0, xMax, TRUE);
		SetScrollPos(hWnd, SB_HORZ, 0, TRUE);
		SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &Lines, 0);
		WheelUnit = WHEEL_DELTA / Lines;

		/* 하단 상태바 부분 시작*/
		InitCommonControls();
		hState = CreateStatusWindow(WS_CHILD | WS_VISIBLE, "", hWnd, 0);
		SBPart[0] = 200;
		SBPart[1] = 500;
		SBPart[2] = 700; //남는 공간 나머지 할당
		SBPart[3] = -1;
		
		SendMessage(hState, SB_SETPARTS, 4, (LPARAM)SBPart);
		SendMessage(hState, SB_SETTEXT, 0, (LPARAM) ""); //Progress bar
		SendMessage(hState, SB_SETTEXT, 1, (LPARAM) ""); //이미지 파일 이름 저장되는 공간
		SendMessage(hState, SB_SETTEXT, 2, (LPARAM) ""); //다운로드파일 버튼
		
		/* 프로그레스바 부분 시작 */
		if (Pos) return 0;
		SendMessage(hState, SB_GETRECT, 0, (LPARAM)&prt);
		hProg = CreateWindow(PROGRESS_CLASS, NULL, WS_CHILD | PBS_SMOOTH | WS_VISIBLE, prt.left, prt.top, prt.right - prt.left, prt.bottom - prt.top, hState, NULL, g_hInst, NULL);
		Pos = 0;
		SendMessage(hProg, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
		SendMessage(hProg, PBM_SETPOS, Pos, 0);
		ShowWindow(hProg, SW_SHOW);
	

		//SendMessage(hState, SB_GETRECT, 2, (LPARAM)&prt); //두번째 빈칸 나중에 활용하기
		break;


		//This is where we change the color of the static to blue. If you only want the cursor
		//to change to a hand when the mouse passes over you don't need this stuff.
	case WM_CTLCOLORSTATIC:
		SetTextColor((HDC)wParam, RGB(0, 0, 255));
		SetBkMode((HDC)wParam, TRANSPARENT);
		return (LONG)GetStockObject(NULL_BRUSH);

		/* 하이퍼링크 부분*/
		/*
	case WM_SETCURSOR:
		if ((HWND)wParam == hwndStatic)
		{
			if (colormsg == 1) return TRUE;
			SendMessage(hwndStatus, SB_SETTEXT, 0, (LONG) "Email : [email protected]");
			SendMessage(hwndStatic, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 1);
			colormsg = 1;
			InvalidateRgn((HWND)hWnd, 0, 1);
			SetCursor(mycur);
			return TRUE;
		}
		//If not on the static, change the font back to normal. You don't have to worry
		//about the cursor, it will change back to the arrow automatically. I use the
		//'colormsg' flag so it doesn't continually set the font when the cursor is moving
		//around, because it causes it to flicker. If you only use the cursor change and
		//don't worry about the font change you don't have to worry.
		if (colormsg == 1)
		{
			colormsg = 0;
			SendMessage(hwndStatus, SB_SETTEXT, 0, 0);
			SendMessage(hwndStatic, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
			InvalidateRgn((HWND)hWnd, 0, 1);
		}
		
		break;
		*/

	/* 마우스 오른쪽 팝업 메뉴 */
	case WM_CONTEXTMENU:
		hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU1));
		hPopup = GetSubMenu(hMenu, 0);

		TrackPopupMenu(hPopup, TPM_LEFTALIGN, (short)LOWORD(lParam), (short)HIWORD(lParam), 0, hWnd, NULL);
		DestroyMenu(hMenu);
		break;
		
	case WM_LBUTTONDOWN:
		//BitBlt(GetDC(hWnd), 0, 0, 1000, 1000, 0, 0, 0, WHITENESS); //그냥 화면을 하얗게만 할 뿐 뒤에 남아있음
		//image_hyperlink_maker(WinProc_sub, "www.daum.net");
		break;

	case WM_SIZE:
		SendMessage(hState, WM_SIZE, wParam, lParam);
		MoveWindow(hList, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);//디렉터리 탐색창
		break;

	case WM_COMMAND:
		if ((HWND)lParam == hwndStatic) {
			//ShellExecute(Main_hWnd, "open", "www.naver.com", 0, 0, 0);
			cases = 2; //케이스 2번으로 하고 해야 계속해서 링크를 통해 이미지를 받아올 수 있음
			clientsocket(textbox_buffer, PORT_NUM); //cases = 2이기 때문에 그냥 바로 요청하면 된다.
			//input_valid_check(textbox_buffer); // 주소체크하고 dns 실행할지말지 결정
			InvalidateRect(Main_hWnd, NULL, WM_ERASEBKGND);
			UpdateWindow(Main_hWnd);
		}

		switch (LOWORD(wParam)) {
		case 50001:	favorite_clicked(50001);break; case 50002: favorite_clicked(50002);break; case 50003: favorite_clicked(50003);break;
		case 50004:	favorite_clicked(50004);break; case 50005: favorite_clicked(50005);break; case 50006: favorite_clicked(50006);break;
		case 50007:	favorite_clicked(50007);break; case 50008: favorite_clicked(50008);break; case 50009: favorite_clicked(50009);break;
		case 50010:	favorite_clicked(50010);break; case 50011: favorite_clicked(50011);break; case 50012: favorite_clicked(50012);break;

		case IDC_MAIN_BUTTON: // when button is clicked, this will happen: 버튼부분
			SendMessage(EdittextBox, WM_GETTEXT, sizeof(textbox_buffer) / sizeof(textbox_buffer[0]), reinterpret_cast<LPARAM>(textbox_buffer));
			image_file_name = NULL;
			Save_visit_page(textbox_buffer);
			input_valid_check(textbox_buffer); // 주소체크하고 dns 실행할지말지 결정
			InvalidateRect(Main_hWnd, NULL, WM_ERASEBKGND);
			UpdateWindow(Main_hWnd);
			break;

		case IDC_VISITPAGE_BUTTON:
			printf("방문기록보기 버튼 클릭!\n");
			Search_visit_page();
			SetWindowText(Main_hWnd, "방문기록보기");
			//ShellExecute(NULL, "open", "http://www.google.com", NULL, NULL, SW_SHOWNORMAL);
			InvalidateRect(Main_hWnd, NULL, WM_ERASEBKGND);
			UpdateWindow(Main_hWnd);
			break;

		case BACK_BUTTON:
			back_button_page(textbox_buffer);
			InvalidateRect(Main_hWnd, NULL, WM_ERASEBKGND);
			UpdateWindow(Main_hWnd);
			break;

		case FRONT_BUTTON:
			front_button_page(textbox_buffer);
			InvalidateRect(Main_hWnd, NULL, WM_ERASEBKGND);
			UpdateWindow(Main_hWnd);
			break;

		case REFRESH_BUTTON: //새로고침
			if (textbox_buffer[0] == NULL)
				break;
			input_valid_check(textbox_buffer); // 주소체크하고 dns 실행할지말지 결정
			InvalidateRect(Main_hWnd, NULL, WM_ERASEBKGND);
			UpdateWindow(Main_hWnd);
			break;

		case FAVORITE_BUTTON: //즐겨찾기 등록
			favorite_page(textbox_buffer, strlen(textbox_buffer), hWnd);
			break;

		case ID_FILE_40001: //잘라내기
			
			break;
		case ID_FILE_40003: //복사
			
			break;
		case ID_FILE_40004: //삭제
			delresult = DeleteFile("lenna.bmp"); //현재 미구현 디폴트상황
			if(delresult == TRUE)
				MessageBox(NULL, "파일삭제 성공!", "파일삭제!", MB_ICONINFORMATION);
			else
				MessageBox(NULL, "파일이 없습니다!(이미 삭제되거나 없는 파일)", "파일삭제실패!", MB_ICONINFORMATION);
			break;
		case ID_FILE_RENAME: //이름바꾸기
			
			break;
		case ID_FILE_PROPERTY: //속성
			
			break;
		}
		break;
		/*
		case WM_CHAR: //사용자로부터 그냥 입력받을 때 동작
		len = strlen(str);
		str[len] = (TCHAR)wParam;
		str[len + 1] = 0;
		InvalidateRect(hWnd, NULL, FALSE);
		break;
		*/

	case WM_PAINT: //사용자로부터 입력받은 것을 화면에 뿌려줌
		hdc = BeginPaint(hWnd, &ps);
		DrawText(hdc, totalresult, -1, &rt, DT_CENTER | DT_WORDBREAK | DT_NOCLIP);
		Draw_Image(hdc, image_file_name, 300, 300);
		SendMessage(hState, SB_SETTEXT, 1, (LPARAM)image_file_name); //하단 상태바에 받은 이미지 파일 이름 출력
		EndPaint(hWnd, &ps);
		SendMessage(hwndStatic, WM_ENABLE | WM_ERASEBKGND | WM_DESTROY, NULL, 1);
		break;
		

	case WM_MOUSEWHEEL:
		nScroll = 0;
		SumDelta += (short)HIWORD(wParam);
		while (abs(SumDelta) >= WheelUnit) {
			if (SumDelta > 0) {
				nScroll--;
				original_position--;
				SumDelta -= WheelUnit;
			}
			else { //스크롤바 내려갈때
				nScroll++;
				original_position++;
				SumDelta += WheelUnit;
			}
		}
		while (nScroll != 0) {
			if (nScroll > 0) {
				SendMessage(hWnd, WM_VSCROLL, MAKELONG(SB_PAGEDOWN, 0), 0);
				nScroll--;
			}
			else {
				SendMessage(hWnd, WM_VSCROLL, MAKELONG(SB_PAGEUP, 0), 0);
				nScroll++;
			}
		}
		if (original_position == 0) {
			InvalidateRect(Main_hWnd, NULL, TRUE);
			UpdateWindow(Main_hWnd);
		}
		break;

	case WM_HSCROLL: //가로스크롤
		xlnc = 0;
		switch (LOWORD(wParam)) {
		case SB_LINELEFT:
			xlnc = -1;
			break;
		case SB_LINERIGHT:
			xlnc = -20;
			break;
		case SB_PAGELEFT:
			xlnc = -20;
			break;
		case SB_PAGERIGHT:
			xlnc = 20;
			break;
		case SB_THUMBTRACK:
			xlnc = HIWORD(wParam) - xPos;
			break;
		default:
			InvalidateRect(Main_hWnd, NULL, TRUE);
			UpdateWindow(Main_hWnd);
			break;
		}
		//새로운 위치는 최소한 0 이상
		if (xPos + xlnc < 0)
			xlnc = -xPos;
		//새로운 위치는 최대한 xMax 이하
		if (xPos + xlnc > xMax)
			xlnc = xMax - xPos;
		//새로운 위치 계산
		xPos = xPos + xlnc;
		//스크롤 시키고 썸 위치를 다시 계산한다.
		ScrollWindow(hWnd, -xlnc, 0, NULL, NULL);
		SetScrollPos(hWnd, SB_HORZ, xPos, TRUE);
		break;

	case WM_VSCROLL: //세로 스크롤
		ylnc = 0;
		switch (LOWORD(wParam)) {
		case SB_LINEUP:
			ylnc = -1;
			break;
		case SB_LINEDOWN:
			ylnc = 1;
			break;
		case SB_PAGEUP:
			ylnc = -20;
			break;
		case SB_PAGEDOWN:
			ylnc = 20;
			break;
		case SB_THUMBTRACK:
			ylnc = HIWORD(wParam) - yPos;
			break;
		default:
			InvalidateRect(Main_hWnd, NULL, TRUE);
			UpdateWindow(Main_hWnd);
			break;
		}
		//새로운 위치는 최소한 0 이상
		if (yPos + ylnc < 0)
			ylnc = -yPos;
		//새로운 위치는 최대한 yMax 이하
		if (yPos + ylnc > yMax)
			ylnc = yMax - yPos;
		//새로운 위치 계산
		yPos = yPos + ylnc;
		//스크롤 시키고 썸 위치를 다시 계산한다.
		ScrollWindow(hWnd, 0, -ylnc, NULL, NULL);
		SetScrollPos(hWnd, SB_VERT, yPos, TRUE);
		break;

	case WM_DESTROY:
		SetWindowLongPtr(EdittextBox, GWLP_WNDPROC, (LONG_PTR)OldEditProc);
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, iMessage, wParam, lParam);
	}
}
示例#28
0
/*
 * WindowProc - handle messages for the main application window
 */
LONG _EXPORT FAR PASCAL WindowProc( HWND window_handle, unsigned msg,
                                     WORD wparam, LONG lparam )
/*************************************************************/
{
    FARPROC             proc;
    HANDLE              inst_handle;
    extra_data          *edata_ptr;
    HDC                 hdc;
    PAINTSTRUCT         ps;
    RECT                rect;
    HBRUSH              brush;

    /*
     * if the message window is ON, send all messages we want to display to the
     * message window, so that we can see what is happening
     * ( before we actually process the message )
     */
    if( MessagesOn ) {
        switch( msg ) {
        case WM_COMMAND:
        case WM_MOUSEMOVE:
        case WM_LBUTTONUP:
        case WM_LBUTTONDOWN:
        case WM_LBUTTONDBLCLK:
        case WM_RBUTTONUP:
        case WM_RBUTTONDOWN:
        case WM_RBUTTONDBLCLK:
        case WM_KEYDOWN:
        case WM_KEYUP:
        case WM_CHAR:
        case WM_TIMER:
        case WM_HSCROLL:
        case WM_VSCROLL:
            SendMessage( MessageWnd, msg, wparam, lparam );
            break;
        }
    }

    /*
     * now process the message
     */
    switch( msg ) {
    case WM_CREATE:
        inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
        /*
         * make sure message window is turned OFF to start
         */
        MessagesOn = FALSE;
        CheckMenuItem ( GetMenu( window_handle ), MENU_MESSAGE_WINDOW_ON,
                        MF_BYCOMMAND | MF_UNCHECKED );
        break;
    case WM_LBUTTONDOWN:
        /*
         * zap the target with a lightning bolt!
         */
        edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                            EXTRA_DATA_OFFSET );
        /*
         * set the aim point to where the mouse was just clicked
         * set the bolt start point to the top left corner of the window
         */
        edata_ptr->aim = MAKEPOINT( lparam );
        edata_ptr->bolt.x = edata_ptr->client_rect.right - BOLTWIDTH;
        edata_ptr->bolt.y = edata_ptr->client_rect.top;
        /*
         * shoot the bolt from the current bolt position to the aim point
         */
        ShootBolt( window_handle );
        break;
    case WM_SIZE:
        edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                            EXTRA_DATA_OFFSET );
        /*
         * store the new size of the window
         */
        GetClientRect( window_handle, &edata_ptr->client_rect );
        SetScrollRange( window_handle, SB_HORZ, edata_ptr->client_rect.left,
                        edata_ptr->client_rect.right, TRUE );
        SetScrollRange( window_handle, SB_VERT, edata_ptr->client_rect.top,
                        edata_ptr->client_rect.bottom, TRUE );
        break;
    case WM_COMMAND:
        switch( wparam ) {
        case MENU_ABOUT:
            inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
            proc = MakeProcInstance( (FARPROC)About, inst_handle );
            DialogBox( inst_handle,"AboutBox", window_handle, (DLGPROC)proc );
            FreeProcInstance( proc );
            break;
        case MENU_EXIT:
            SendMessage( window_handle, WM_CLOSE, 0, 0L );
            break;
        case MENU_SET_TARGET_SPEED:
            inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
            proc = MakeProcInstance( (FARPROC)SpeedDlgProc, inst_handle );
            DialogBoxParam( inst_handle,"SpeedDlg", window_handle, (DLGPROC)proc,
                            (DWORD)SET_TARGET_SPEED );
            FreeProcInstance( proc );
            break;
        case MENU_SET_BOLT_SPEED:
            inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE );
            proc = MakeProcInstance( (FARPROC)SpeedDlgProc, inst_handle );
            DialogBoxParam( inst_handle,"SpeedDlg", window_handle, (DLGPROC)proc,
                            (DWORD)SET_BOLT_SPEED );
            FreeProcInstance( proc );
            break;
        case MENU_SCORE_WINDOW_ON:
            /*
             * toggle the score window on or off
             */
            edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                                EXTRA_DATA_OFFSET );
            if( !edata_ptr->score_on ) {
                TurnScoreWindowOn( window_handle );
                CheckMenuItem ( GetMenu( window_handle ),
                                wparam, MF_BYCOMMAND | MF_CHECKED );
                edata_ptr->score_on = TRUE;
            } else {
                SendMessage( ScoreWnd, WM_CLOSE, 0, 0L );
                CheckMenuItem ( GetMenu( window_handle ), wparam,
                    MF_BYCOMMAND | MF_UNCHECKED );
                edata_ptr->score_on = FALSE;
            }
            break;
        case MENU_SOUND_ON:
            /*
             * toggle the sound on or off
             */
            edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                                EXTRA_DATA_OFFSET );
            if( !edata_ptr->sound_on ) {
                CheckMenuItem ( GetMenu( window_handle ),
                                wparam, MF_BYCOMMAND | MF_CHECKED );
                edata_ptr->sound_on = TRUE;
            } else {
                CheckMenuItem ( GetMenu( window_handle ), wparam,
                    MF_BYCOMMAND | MF_UNCHECKED );
                edata_ptr->sound_on = FALSE;
            }
            break;
        case MENU_MESSAGE_WINDOW_ON:
            /*
             * toggle the message window on or off
             */
            if( !MessagesOn ) {
                TurnMessageWindowOn( window_handle );
                CheckMenuItem ( GetMenu( window_handle ),
                                wparam, MF_BYCOMMAND | MF_CHECKED );
                MessagesOn = TRUE;
            } else {
                SendMessage( MessageWnd, WM_CLOSE, 0, 0L );
                CheckMenuItem ( GetMenu( window_handle ), wparam,
                    MF_BYCOMMAND | MF_UNCHECKED );
                MessagesOn = FALSE;
            }
            break;
        }
        break;
    case WM_PAINT:
        edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                            EXTRA_DATA_OFFSET );
        hdc = BeginPaint (window_handle, &ps);
        /*
         * paint the invalid area with the background colour
         */
        brush = CreateSolidBrush( BACKGROUND );
        FillRect( hdc, &ps.rcPaint, brush );
        DeleteObject( brush );

        rect.left   = edata_ptr->target.x;
        rect.top    = edata_ptr->target.y;
        rect.right  = rect.left + edata_ptr->size.x;
        rect.bottom = rect.top + edata_ptr->size.y;

        /*
         * if part of the target bitmap is invalid, redraw it
         */
        if( IntersectRect( &rect, &rect, &ps.rcPaint ) ) {
            DrawBitmap( hdc, edata_ptr->target_bmp,
                        edata_ptr->target.x, edata_ptr->target.y );
        }
        EndPaint(window_handle, &ps);
        break;
    case WM_HSCROLL:
    case WM_VSCROLL:
        /*
         * use the scrollbars to move the target around
         */
        {
            short position; /* the x or y position of the scrollbar */
            short max;
            short min;

            edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                                EXTRA_DATA_OFFSET );
            position = ( msg == WM_HSCROLL ) ?
                       edata_ptr->target.x : edata_ptr->target.y;

            switch( wparam ) {
            case SB_PAGEDOWN:
                position += 15;
                break;
            case SB_LINEDOWN:
                position++;
                break;
            case SB_PAGEUP:
                position -= 15;
                break;
            case SB_LINEUP:
                position--;
                break;
            case SB_THUMBPOSITION:
            case SB_THUMBTRACK:
                position = LOWORD( lparam );
                break;
            default:
                return( 0L );
            }
            if( msg == WM_HSCROLL ) {
                GetScrollRange( window_handle, SB_HORZ, (LPINT)&min, (LPINT)&max );
                edata_ptr->target.x = max( min( position, max ), min );
                SetScrollPos( window_handle, SB_HORZ, edata_ptr->target.x , TRUE );
            } else {
                GetScrollRange( window_handle, SB_VERT, (LPINT)&min, (LPINT)&max );
                edata_ptr->target.y = max( min( position, max ), min );
                SetScrollPos( window_handle, SB_VERT, edata_ptr->target.y, TRUE );
            }
            InvalidateRect( window_handle, &edata_ptr->client_rect, FALSE );
        }
        break;
    case WM_MOVE_TARGET:

        /*
         * move the target to a random location on the screen
         */

        edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                            EXTRA_DATA_OFFSET );
        rect.left   = edata_ptr->target.x;
        rect.top    = edata_ptr->target.y;
        rect.right  = rect.left + edata_ptr->size.x;
        rect.bottom = rect.top + edata_ptr->size.y;
        InvalidateRect( window_handle, &rect, TRUE );

        edata_ptr->target = RandPoint( edata_ptr->client_rect, edata_ptr->size );

        rect.left   = edata_ptr->target.x;
        rect.top    = edata_ptr->target.y;
        rect.right  = rect.left + edata_ptr->size.x;
        rect.bottom = rect.top + edata_ptr->size.y;
        InvalidateRect( window_handle, &rect, TRUE );

        /* set the scrollbars to indicate the new position */
        SetScrollPos( window_handle, SB_HORZ, edata_ptr->target.x , TRUE );
        SetScrollPos( window_handle, SB_VERT, edata_ptr->target.y, TRUE );

        break;
    case WM_TIMER:
        SendMessage( window_handle, WM_MOVE_TARGET, 0, 0L );
        break;
        break;
    case WM_DESTROY:
        edata_ptr = (extra_data *) GetWindowLong( window_handle,
                                                  EXTRA_DATA_OFFSET );
        KillTimer( window_handle, TARGET_TIMER );       /* Stops the timer */
        FreeProcInstance( edata_ptr->message_window_proc );
        FreeProcInstance( edata_ptr->score_window_proc );
        PostQuitMessage( 0 );
        break;

    default:
        return( DefWindowProc( window_handle, msg, wparam, lparam ) );
    }
    return( 0L );

} /* WindowProc */
示例#29
0
long CALLBACK EXPORT ConsoleFunc(HWND hwnd,unsigned message,WPARAM wParam,
                                 LPARAM lParam)
{
  CONSOLE *con;
  PAINTSTRUCT ps;
  RECT rect;

  switch (message) {
  case WM_CHAR:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      /* store in a key queue */
      if ((con->keyq_end+1)%KEYQUEUE_SIZE==con->keyq_start) {
        MessageBeep(MB_OK);
        break;
      } /* if */
      con->keyqueue[con->keyq_end]=(short)wParam;
      con->keyq_end=(con->keyq_end+1)%KEYQUEUE_SIZE;
    } /* if */
    break;

  case WM_CREATE:
    /* The "hwnd" member of the CONSOLE structure has not yet been set, which
     * means that Hwnd2Console() cannot work on the real "hwnd". There should
     * at every instant be only one CONSOLE structure with a NULL handle,
     * however.
     */
    if ((con=Hwnd2Console(NULL))!=NULL) {
      con->hwnd=hwnd;
      SetConsoleFont(con,con->cheight);
      GetWindowRect(hwnd, &rect);
      SetRect(&rect,rect.left,rect.top,
              rect.left+con->cwidth*con->columns,
              rect.top+con->cheight*con->winlines);
      AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE);
      if (con->winlines<con->lines)
        rect.right+=GetSystemMetrics(SM_CXVSCROLL);
      ClampToScreen(&rect);
      SetWindowPos(hwnd,NULL,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,
                   SWP_NOZORDER);
    } /* if */
    break;

  case WM_DESTROY:
    if ((con=Hwnd2Console(hwnd))!=NULL)
      DoDeleteConsole(con);
    break;

  case WM_GETMINMAXINFO:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      MINMAXINFO FAR *lpmmi=(MINMAXINFO FAR*)lParam;
      int rx,ry,hsize,vsize;
      GetClientRect(hwnd,&rect);
      rx= (rect.right < con->columns*con->cwidth) ? con->columns*con->cwidth-rect.right : 0;
      ry= (rect.bottom < con->lines*con->cheight) ? con->lines*con->cheight-rect.bottom : 0;
      hsize= (ry>0) ? GetSystemMetrics(SM_CXVSCROLL) : 0;
      vsize= (rx>0) ? GetSystemMetrics(SM_CYHSCROLL) : 0;
      SetRect(&rect,0,0,con->cwidth*con->columns+hsize,con->cheight*con->lines+vsize);
      AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE);
      lpmmi->ptMaxTrackSize.x=rect.right-rect.left;
      lpmmi->ptMaxTrackSize.y=rect.bottom-rect.top;
      lpmmi->ptMaxSize=lpmmi->ptMaxTrackSize;
    } /* if */
    break;

  case WM_SYSKEYDOWN:
  case WM_KEYDOWN:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      TCHAR str[20];
      int i;
      str[0]=__T('\0');
      switch (LOWORD(wParam)) {
      case VK_F1:
      case VK_F2:
      case VK_F3:
      case VK_F4:
      case VK_F5:
      case VK_F6:
      case VK_F7:
      case VK_F8:
      case VK_F9:
      case VK_F10:
      case VK_F11:
      case VK_F12:
        if (LOWORD(wParam)<=VK_F5)
          _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F1+11);
        else if (LOWORD(wParam)==VK_F10)
          _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F6+17);
        else
          _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F11+23);
        break;
      case VK_ADD:
      case VK_SUBTRACT:
        /* check Ctrl key */
        if ((GetKeyState(VK_CONTROL) & 0x8000)!=0) {
          POINT pt;
          int newheight=con->cheight;
          int oldheight=newheight;
          int incr= (LOWORD(wParam)==VK_SUBTRACT) ? -1 : 1;
          do {
            newheight+=incr;
            /* make a new font, re-create a caret and redraw everything */
            SetConsoleFont(con,newheight);
          } while (newheight>5 && (oldheight==con->cheight || con->hfont==NULL));
          if (con->hfont==NULL) /* reset to original on failure */
            SetConsoleFont(con,oldheight);
          GetClientRect(hwnd,&rect);
          DestroyCaret();
          CreateCaret(hwnd,NULL,con->cwidth,2);
          RefreshCaretPos(con);
          /* redraw the window */
          InvalidateRect(hwnd,NULL,TRUE);
          /* resize the window */
          SetRect(&rect,0,0,con->cwidth*con->columns,con->cheight*con->winlines);
          AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE);
          pt.x=pt.y=0;
          ClientToScreen(hwnd,&pt);
          OffsetRect(&rect,pt.x,pt.y);
          ClampToScreen(&rect);
          SetWindowPos(hwnd,NULL,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,
                       SWP_NOZORDER);
        } /* if */
        break;
      case VK_UP:
        _tcscpy(str,__T("\033[A"));
        break;
      case VK_DOWN:
        _tcscpy(str,__T("\033[B"));
        break;
      case VK_RIGHT:
        _tcscpy(str,__T("\033[C"));
        break;
      case VK_LEFT:
        _tcscpy(str,__T("\033[D"));
        break;
      case VK_HOME:
        _tcscpy(str,__T("\033[1~"));
        break;
      case VK_END:
        _tcscpy(str,__T("\033[4~"));
        break;
      case VK_INSERT:
        _tcscpy(str,__T("\033[2~"));
        break;
      case VK_DELETE:
        _tcscpy(str,__T("\033[3~"));
        break;
      case VK_PRIOR:  /* PageUp */
        _tcscpy(str,__T("\033[5~"));
        break;
      case VK_NEXT:   /* PageDown */
        _tcscpy(str,__T("\033[6~"));
        break;
      default:
        return DefWindowProc(hwnd,message,wParam,lParam);
      } /* switch */
      for (i=0; str[i]!=__T('\0'); i++) {
        if ((con->keyq_end+1)%KEYQUEUE_SIZE!=con->keyq_start) {
          con->keyqueue[con->keyq_end]=(short)str[i];
          con->keyq_end=(con->keyq_end+1)%KEYQUEUE_SIZE;
        } /* if */
      } /* for */
    } /* if */
    break;

  case WM_KILLFOCUS:
    HideCaret(hwnd);
    DestroyCaret();
    break;
  case WM_SETFOCUS:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      CreateCaret(hwnd,NULL,con->cwidth,2);
      RefreshCaretPos(con);
      ShowCaret(hwnd);
    } /* if */
    break;

  case WM_LBUTTONDOWN:
    SetFocus(hwnd);
    break;

  case WM_PAINT:
    HideCaret(hwnd);
    BeginPaint(hwnd, &ps);
    if ((con=Hwnd2Console(hwnd))!=NULL && con->buffer!=NULL) {
      TCHAR *string;
      string=malloc(con->columns*sizeof(TCHAR));
      if (string!=NULL) {
        int l,c,bpos,start;
        TCHAR attr;
        HFONT hfontOrg;
        int scrollx=GetScrollPos(hwnd,SB_HORZ);
        int scrolly=GetScrollPos(hwnd,SB_VERT);
        GetClientRect(hwnd,&rect);
        hfontOrg=SelectObject(ps.hdc,con->hfont);
        SetBkMode(ps.hdc,OPAQUE);
        for (l=0; l<con->lines; l++) {
          bpos=l*con->columns*2;
          c=0;
          while (c<con->columns) {
            /* find stretches with the same attribute */
            attr=con->buffer[bpos+1];
            start=c;
            while (c<con->columns && con->buffer[bpos+1]==attr) {
              assert(c-start>=0);
              assert(c-start<con->columns);
              string[c-start]=con->buffer[bpos];
              c++;
              bpos+=2;
            } /* if */
            SetTextAttribute(ps.hdc,attr);
            TextOut(ps.hdc,start*con->cwidth-scrollx,l*con->cheight-scrolly,string,c-start);
          } /* while */
        } /* for */
        SelectObject(ps.hdc,hfontOrg);
        free(string);
      } /* if */
    } /* if */
    EndPaint(hwnd, &ps);
    ShowCaret(hwnd);
    break;

  case WM_SIZE:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      int rx,ry;
      /* add/remove/recalculate scroll bars */
      GetClientRect(hwnd,&rect);
      rx= (rect.right < con->columns*con->cwidth) ? con->columns*con->cwidth-rect.right : 0;
      ry= (rect.bottom < con->lines*con->cheight) ? con->lines*con->cheight-rect.bottom : 0;
      /* adjust scrolling position, if necessary */
      if (GetScrollPos(hwnd,SB_HORZ)>=rx) {
        SetScrollPos(hwnd,SB_HORZ,rx,FALSE);
        InvalidateRect(hwnd,NULL,FALSE);
      } /* if */
      if (GetScrollPos(hwnd,SB_VERT)>=ry) {
        SetScrollPos(hwnd,SB_VERT,ry,FALSE);
        InvalidateRect(hwnd,NULL,FALSE);
      } /* if */
      SetScrollRange(hwnd,SB_HORZ,0,rx,TRUE);
      SetScrollRange(hwnd,SB_VERT,0,ry,TRUE);
    } /* if */
    break;

  case WM_HSCROLL:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      int scrollx=GetScrollPos(hwnd,SB_HORZ);
      int oldpos=scrollx;
      int min,max;
      GetScrollRange(hwnd,SB_HORZ,&min,&max);
      switch (LOWORD(wParam)) {
      case SB_TOP:
        scrollx=min;
        break;
      case SB_BOTTOM:
        scrollx=max;
        break;
      case SB_LINELEFT:
        scrollx=(scrollx>min) ? scrollx-1 : min;
        break;
      case SB_LINERIGHT:
        scrollx=(scrollx<max) ? scrollx+1 : max;
        break;
      case SB_PAGELEFT:
        scrollx=(scrollx>min) ? scrollx-50 : min;
        break;
      case SB_PAGERIGHT:
        scrollx=(scrollx<max) ? scrollx+50 : max;
        break;
      case SB_THUMBTRACK:
        scrollx=(int)HIWORD(wParam);
        break;
      } /* switch */
      if (oldpos!=scrollx) {
        SetScrollPos(hwnd,SB_HORZ,scrollx,TRUE);
        InvalidateRect(hwnd,NULL,FALSE);
        RefreshCaretPos(con);
      } /* if */
    } /* if */
    break;
  case WM_VSCROLL:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      int scrolly=GetScrollPos(hwnd,SB_VERT);
      int oldpos=scrolly;
      int min,max;
      GetScrollRange(hwnd,SB_VERT,&min,&max);
      switch (LOWORD(wParam)) {
      case SB_TOP:
        scrolly=min;
        break;
      case SB_BOTTOM:
        scrolly=max;
        break;
      case SB_LINELEFT:
        scrolly=(scrolly>min) ? scrolly-1 : min;
        break;
      case SB_LINERIGHT:
        scrolly=(scrolly<max) ? scrolly+1 : max;
        break;
      case SB_PAGELEFT:
        scrolly=(scrolly>min) ? scrolly-50 : min;
        break;
      case SB_PAGERIGHT:
        scrolly=(scrolly<max) ? scrolly+50 : max;
        break;
      case SB_THUMBTRACK:
        scrolly=(int)HIWORD(wParam);
        break;
      } /* switch */
      if (oldpos!=scrolly) {
        SetScrollPos(hwnd,SB_VERT,scrolly,TRUE);
        InvalidateRect(hwnd,NULL,FALSE);
        RefreshCaretPos(con);
      } /* if */
    } /* if */
    break;

  default:
    return DefWindowProc(hwnd,message,wParam,lParam);
  } /* switch */
  return 0L;
}
示例#30
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	PAINTSTRUCT ps;
	Render *render;
	RECT rc;
	//int iHThumb;
	//int iVThumb;
	SCROLLINFO si;
	//int result;

	switch (iMessage) {

	case WM_CREATE:	//window 창이 생성되자마자 Edit와URI가 생성.
		hEdit = CreateWindow(TEXT("edit"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL, 70, 10, 500, 25, hWnd, (HMENU)ID_EDIT, g_hInst, NULL);
		CreateWindow(TEXT("STATIC"), TEXT("URL"), WS_VISIBLE | WS_CHILD, 20, 10, 50, 25, hWnd, (HMENU)ID_STATIC, NULL, NULL);
		Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);	//Gdiplus code
		originalProc = (WNDPROC)SetWindowLongPtr(hEdit, GWLP_WNDPROC, (LONG_PTR)EditProc);	//set subclass
		//scroll bar
		//iHThumb = GetSystemMetrics(SM_CXHTHUMB); ->  모니터의 크기를 받아오는 함수.
		//iVThumb = GetSystemMetrics(SM_CYVTHUMB);
		GetClientRect(hWnd, &rMain);	//Main Window 좌표값 받아오기
		hWndHorzScroll = CreateWindow("SCROLLBAR", (LPSTR)NULL, WS_CHILD | WS_VISIBLE | SBS_HORZ | SBS_BOTTOMALIGN, rMain.left, rMain.bottom - 20, rMain.right - rMain.left - 20, 20, hWnd, (HMENU)IDC_HSCROLL, g_hInst, NULL);
		SetScrollRange(hWndHorzScroll, SB_CTL, rMain.left, rMain.right, TRUE);
		SetScrollPos(hWndHorzScroll, SB_CTL, rMain.left, TRUE);
		hWndVertScroll = CreateWindow("SCROLLBAR", (LPSTR)NULL, WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_RIGHTALIGN, rMain.right - 20, rMain.top, 20, rMain.bottom - 20, hWnd, (HMENU)IDC_HSCROLL, g_hInst, NULL);
		SetScrollRange(hWndVertScroll, SB_CTL, rMain.top, rMain.bottom, TRUE);
		SetScrollPos(hWndVertScroll, SB_CTL, rMain.top, TRUE);
		SetFocus(hEdit);
		return 0;

	case WM_SIZE:	//window의 크기가 변경 됐을 때, 호출.
		GetClientRect(hWnd, &rMain);	//Main Window 좌표값 받아오기
		si.cbSize = sizeof(SCROLLINFO);
		si.fMask = SIF_ALL | SIF_DISABLENOSCROLL;
		si.nMin = rMain.left;
		si.nMax = rMain.right;
		si.nPage = LOWORD(lParam);	//lParam의 하위워드 : 변경 된 후의 윈도우 폭.
		si.nPos = hScrollPos;
		SetScrollInfo(hWndHorzScroll, SB_HORZ, &si, TRUE);
		//InvalidateRect(hWnd, NULL, TRUE);
		RedrawWindow(hMain, 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);
		return 0;

	case WM_COMMAND:
	
		switch (LOWORD(wParam))
		{
		case ID_EDIT:
			switch (HIWORD(wParam))
			{
			case EN_CHANGE:	//Edit 창에 키보드 입력이 들어올때마다 url 배열에 저장.
				GetWindowText(hEdit, url, sizeof(url));
				break;
			}
		}

		return 0;

	case WM_HSCROLL:
		switch (LOWORD(wParam))
		{
		case SB_LINERIGHT:
			hScrollPos = min(rMain.right, hScrollPos + 100);
			break;
		case SB_LINELEFT:
			hScrollPos = max(rMain.left, hScrollPos - 100);
			break;
		case SB_PAGELEFT:
			hScrollPos = max(rMain.left, hScrollPos - 100);
			break;
		case SB_PAGERIGHT:
			hScrollPos = min(rMain.right, hScrollPos + 100);
			break;
		}
		SetScrollPos((HWND)lParam, SB_CTL, hScrollPos, TRUE);
		RedrawWindow(hMain, 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);
		return 0;

	case WM_VSCROLL:
		switch (LOWORD(wParam))
		{
		case SB_LINEUP:
			vScrollPos = max(rMain.top, vScrollPos - 100);
			break;
		case SB_LINEDOWN:
			vScrollPos = min(rMain.bottom, vScrollPos + 100);
			break;
		case SB_PAGEUP:
			vScrollPos = max(rMain.top, vScrollPos - 100);
			break;
		case SB_PAGEDOWN:
			vScrollPos = min(rMain.bottom, vScrollPos + 100);
			break;
		}
		SetScrollPos((HWND)lParam, SB_CTL, vScrollPos, TRUE);
		RedrawWindow(hMain, 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);
		return 0;

	case WM_SETFOCUS:
		return 0;

	case WM_PAINT:

		/*if (htmlparser->getIsParsed())
		{
			htmlparser->setIsParsed(false);
			render = new Render(htmlparser->getDocumentNode(), urlparser, HWNDpool,g_hInst, hWnd);
			htmlparser->setIsParsed(false);
			render->travellingParseTree(hdc);
		}*/
		//GetClientRect(hWnd, &rMain);	//Main Window 좌표값 받아오기
		if (g_flag)
		{
			printf("render tree print\n");
			//g_flag = false;
			hdc = BeginPaint(hWnd, &ps);
			render = new Render(htmlparser->getDocumentNode(), urlparser, HWNDpool, g_hInst, hWnd);
			render->travellingParseTree(hdc);
			EndPaint(hWnd, &ps);
		}
		else
		{
			hdc = BeginPaint(hWnd, &ps);
			GetClientRect(hWnd, &rMain);	//Main Window 좌표값 받아오기
			
			TextOut(hdc, 300, 300, "Enter URL........", strlen("Enter URL........"));
			EndPaint(hWnd, &ps);
		}

		//htmlparser->setIsParsed(true);
		//Sleep(5000);
		return 0;

	case WM_DESTROY:
		Gdiplus::GdiplusShutdown(gdiplusToken);	//closeGdiplus
		SetWindowLongPtr(hEdit, GWLP_WNDPROC, (LONG_PTR)originalProc);	//close subclass
		PostQuitMessage(0);
		
		return 0;

	}

	return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}