Newbie to Winapi.Learnt the basics of winapi and tips of creating child window in firebreath plugin. Searched tutorials,got answers.But don't know What Am i Doing wrong here? Following is my code>>My main objective is to create a textbox functioning like that in MSWord on aparent plugin(windowed firebreath plugin) window handle whereby I can edit,modify the text as well as move and resize the textbox.Also, I am not able to fire many events like WM_LBUTTONDOWN and more on the child window.

int WINAPI childwindow::LoadForm()
{
    HWND pluginWnd=win->getHWND();
    HINSTANCE pluginInstance = (HINSTANCE)GetWindowLong(pluginWnd, GWL_HINSTANCE);
    HWND demoWnd = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"),TEXT("text to be written"),WS_CHILD|WS_VISIBLE|
        ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL|WS_BORDER|WS_VSCROLL|WS_HSCROLL, 10, 10, 300, 100, pluginWnd, (HMENU)IDC_MAIN_EDIT, pluginInstance , NULL);

    //SUBCLASSING=============REFERENCE>>(http://cboard.cprogramming.com/windows-programming/148771-subclassing-edit-box.html)
    PreviousSubclassedEditProc=(WNDPROC)GetWindowLong(demoWnd, GWL_WNDPROC);//WNDPROC PreviousSubclassedEditProc;
    SetWindowLong(demoWnd, GWL_WNDPROC,(LONG_PTR)&childwindow::CustomWinProc);
    SetWindowText(demoWnd,_T("LALALA"));
    //======================
    ShowWindow(demoWnd, SW_SHOWNORMAL);
    UpdateWindow(demoWnd);
    return EXIT_SUCCESS;
}

LRESULT CALLBACK childwindow::CustomWinProc( HWND chWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    HWND textBoxInput,button,tempHandle=0;
    HINSTANCE hInstance = (HINSTANCE)GetWindowLong(chWnd, GWL_HINSTANCE);
    switch(uMsg)
    {
        case WM_CREATE:
            {
                return 0;
                break;
            }
        case WM_MOUSEACTIVATE:
            {
                SetFocus(chWnd);
                break;
            }
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            }

        case WM_LBUTTONDOWN:
            {
                dragWindow = true;
                tempHandle=SetCapture(chWnd);
                break;
            }
        case WM_LBUTTONUP:
            {
                ReleaseCapture();
                tempHandle=NULL;
                dragWindow = false;
                break;
            }
        case WM_MOUSEMOVE:
            {
                if(dragWindow==true)
                {
                    RECT mainWindowRect;
                    POINT pos;
                    int windowWidth, windowHeight;

                    pos.x = (int)(short) LOWORD(lParam);
                    pos.y = (int)(short) HIWORD(lParam);

                    GetWindowRect(chWnd,&mainWindowRect);
                    windowHeight = mainWindowRect.bottom - mainWindowRect.top;
                    windowWidth = mainWindowRect.right - mainWindowRect.left;

                    ClientToScreen(chWnd, &pos);
                    SetWindowPos(chWnd, NULL, pos.x, pos.y, windowWidth,windowHeight, SWP_NOZORDER);
                    ShowWindow(chWnd,SW_SHOWNORMAL);
                }
                break;
            }
        case WM_KILLFOCUS:
            {
                LPCWSTR buffer[1024];
                SendMessage(chWnd,
                    WM_GETTEXT,
                    sizeof(buffer)/sizeof(buffer[0]),
                    reinterpret_cast<LPARAM>(buffer));
                break;
            }
        default:
            {
                return DefWindowProc(chWnd,uMsg,wParam,lParam);
            }
    }
    return TRUE;
}

The above child window is being made on a parent windowed firebreath plugin handle. I also want to get the text from the child textbox window.but that's not possible till I get this right.I saw one google grouptutorials and this which has helped me a lot to get the basics.But the above problem is bugging me from last day. Any takers for this question?

有帮助吗?

解决方案

You can't RegisterClass for "EDIT" and hope that your class will magically behave like an "Edit". You have two solutions:

First one: drop your Class Registration Code and use "Edit" (or WC_EDIT) as Class Name in CreateWindowEx.

Second One: use GetClassInfo to query the Windows "Edit" class informations, and use the Window Procedure from the class (lpfnWndProc) in place of DefWindowProc.

If you choose the fisrt solution, you can provide your own Window Procedure with subclassing:

As for moving/resizing a Child Window, provided that you have the hWnd, use either SetWindowPos or MoveWindow.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top