Create child window

235 views
Skip to first unread message

kannan

unread,
Apr 22, 2013, 1:38:38 AM4/22/13
to firebre...@googlegroups.com
Hi,

  I want to create a child window for my plugin... I have used following cod snippet in windows attached event... but I am not able to create it... Please suggest the correct way to do it...

 
    HWND messageWin = CreateWindowEx(
       WS_EX_WINDOWEDGE,
        L"FB",
        L"FB",
        WS_BORDER | WS_VSCROLL,
        0, 0, 100, 100,
       g_hWnd, NULL, NULL, NULL);


Thanks
Kannan

John Tan

unread,
Apr 22, 2013, 1:43:19 AM4/22/13
to firebre...@googlegroups.com
The 2nd parameter in CreateWindowEx is a Windows Class name which you must also create by calling the Win32 RegisterClass. The name you set in the WNDCLASS's lpszClassName will be the same name you set in the CreateWindowEx's 2nd parameter....

kannan Gandhi

unread,
Apr 22, 2013, 2:31:11 AM4/22/13
to firebre...@googlegroups.com
Hi,
Thanks for your quick reply....
 Creating child window for my plugin, I have follow these steps

 1.create WNDCLASSEX structure
 2.Register class
 3.Create child window using "CreateWindowEx"

 This is the code snippet for creating WNDCLASSEX structure


WNDCLASSEX wcx;
    wcx.cbClsExtra = 0;
    wcx.cbSize = sizeof( WNDCLASSEX );  // 1.  NEW!  must know its own size.
    wcx.cbWndExtra = 0;
    wcx.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
    wcx.hCursor = LoadCursor( NULL, IDC_ARROW );        
    wcx.hIcon = LoadIcon( NULL, IDI_APPLICATION );    
    wcx.hIconSm = NULL;                 // 2.  NEW!!  Can specify small icon.
    wcx.hInstance = hInstance;        
    wcx.lpfnWndProc = WndProc;        
    wcx.lpszClassName = TEXT("Philip");
    wcx.lpszMenuName = 0;
    wcx.style = CS_HREDRAW | CS_VREDRAW;


How can I create "WndProc" for wcx.lpfnWndProc in attached event.



--
 
---
You received this message because you are subscribed to the Google Groups "firebreath-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebreath-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

John Tan

unread,
Apr 22, 2013, 2:43:54 AM4/22/13
to firebre...@googlegroups.com
You can see the entire example here:
 

kannan Gandhi

unread,
Apr 22, 2013, 2:54:07 AM4/22/13
to firebre...@googlegroups.com
Ok john... I will go through it... and let you know

Thanks
Kannan

Richard Bateman

unread,
Apr 22, 2013, 12:10:43 PM4/22/13
to firebre...@googlegroups.com

Could you be abit more specific about what "not able to create it" means? What happens? Did you call GetLastError and such to get the error reported?

Richard

kannan Gandhi

unread,
Apr 22, 2013, 12:13:01 PM4/22/13
to firebre...@googlegroups.com
yes I called GetLastError and I got value as "1407"
Thanks
Kannan

Neil Griffiths

unread,
Apr 22, 2013, 12:13:54 PM4/22/13
to firebre...@googlegroups.com
Did you register a class called "FB" with your own message handling procedure?

kannan Gandhi

unread,
Apr 22, 2013, 12:26:29 PM4/22/13
to firebre...@googlegroups.com
HI,
 
  WNDCLASSEX wcx;
    wcx.cbClsExtra = 0;
    wcx.cbSize = sizeof( WNDCLASSEX );  // 1.  NEW!  must know its own size.
    wcx.cbWndExtra = 0;
    wcx.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
    wcx.hCursor = LoadCursor( NULL, IDC_ARROW );        
    wcx.hIcon = LoadIcon( NULL, IDI_APPLICATION );    
    wcx.hIconSm = NULL;                 // 2.  NEW!!  Can specify small icon.

    wcx.hInstance = hInstance;        
    wcx.lpfnWndProc = WndProc;    
   
    wcx.lpszClassName = TEXT("kannan");

    wcx.lpszMenuName = 0;
    wcx.style = CS_HREDRAW | CS_VREDRAW;

My question is how can I get hInstance and WndProc  In firebreath

Thanks
Kannan

Neil Griffiths

unread,
Apr 22, 2013, 12:32:11 PM4/22/13
to firebre...@googlegroups.com
So your classname is "kanna" but you were trying to use "FB" in CreateWindow()?

You really SHOULD provide your own WndProc for your own child window. Your problem is getting the instance. You can do that via GetWindowInfo (http://msdn.microsoft.com/en-us/library/windows/desktop/ms633516(v=vs.85).aspx).

Good luck!

kannan Gandhi

unread,
Apr 22, 2013, 12:38:40 PM4/22/13
to firebre...@googlegroups.com
How can I create WndProc for my plugin

Thanks
Kannan

Neil Griffiths

unread,
Apr 22, 2013, 12:41:19 PM4/22/13
to firebre...@googlegroups.com
...write it? It's just a function.


Read it, learn it, it'll help with most of your current problems. :)

kannan Gandhi

unread,
Apr 22, 2013, 12:46:17 PM4/22/13
to firebre...@googlegroups.com
actually I am very new to  C++ and Firebreath  so that only I have many doubts neil....

Neil Griffiths

unread,
Apr 22, 2013, 12:50:00 PM4/22/13
to firebre...@googlegroups.com
This isn't anything to do with C++ or FireBreath though, this is pretty basic Windows programming. And, unfortunately, you're making it harder for yourself by creating a child window. I don't know your reasons for doing that, all I can try to do is to help you by pointing you at the best resources that I know of.

Everybody was a beginner once, I haven't forgotten that. :)

John Tan

unread,
Apr 22, 2013, 6:25:15 PM4/22/13
to firebre...@googlegroups.com
From my experience, it's more stable to create a child window and do everything on the child window if you constantly draw something on the surface. Drawing on the fb window directly could crash when the browser maximize/restore. Perhaps its a bug on my thread synchonization part but adding a child window solvd it...

Neil Griffiths

unread,
Apr 22, 2013, 6:28:35 PM4/22/13
to firebre...@googlegroups.com
Oh, I render 3D games in my plugin so I didn't really have a choice but to create a child window.

But nobody would argue that it's _easier_ to do so. Especially if you're not used to Windows programming. It's confusing at first! :)


On Mon, Apr 22, 2013 at 5:25 PM, John Tan <tjk...@gmail.com> wrote:
From my experience, it's more stable to create a child window and do everything on the child window if you constantly draw something on the surface. Drawing on the fb window directly could crash when the browser maximize/restore. Perhaps its a bug on my thread synchonization part but adding a child window solvd it...

kannan Gandhi

unread,
Apr 23, 2013, 12:16:14 PM4/23/13
to firebre...@googlegroups.com
Finally I did it.... Thanks neil and john for your valuable suggestions...

Armin

unread,
Sep 11, 2013, 10:39:32 AM9/11/13
to firebre...@googlegroups.com
Hi kannan!

I have a similar Problem with my Plugin Window. I am able to register the class but I am not able to create a window. Would you mind sending me your working code for registering the class and creating the window?

Thanks,

Armin

kannan Gandhi

unread,
Sep 11, 2013, 11:41:44 PM9/11/13
to firebre...@googlegroups.com
Hi Armin,
 Go through the below code....

BOOL CWindow::createImgWin(){
    DWORD err;
    //1. Get instance of parent window.
    HINSTANCE hInstance = (HINSTANCE)GetWindowLong(m_hParentWnd, GWL_HINSTANCE);

    //2. Create window class style for acsys image window.
    WNDCLASSEX wcImg;
    ATOM clsAtom(NULL);
    std::wstring winName = L"ImageWindow";
    std::wstring className = L"ImageWindowClass";

    if (!clsAtom) {
        //3. structuring the Window Class
        wcImg.cbSize        = sizeof(WNDCLASSEX);
        wcImg.style         = CS_DBLCLKS | CS_NOCLOSE | CS_VREDRAW | CS_HREDRAW | CS_DROPSHADOW | CS_NOCLOSE;
        wcImg.lpfnWndProc   = &CWindow::acsysWinProc;
        wcImg.cbClsExtra    = 0;
            wcImg.cbWndExtra    = 0;
        wcImg.hInstance     = hInstance;
        wcImg.lpszMenuName  = NULL;
        wcImg.lpszClassName = className.c_str();
        wcImg.hIcon = NULL;
        wcImg.hCursor = NULL;
            wcImg.hIconSm = NULL;
            wcImg.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);

        //4. Registering Class
        if (!(clsAtom = ::RegisterClassEx(&wcImg))) {
            err = GetLastError();
            if (err != ERROR_CLASS_ALREADY_EXISTS) {
                throw std::runtime_error("Could not register window class");
            }
        }
    }

    //4. Create image window class
    g_hChildWin = CreateWindowEx(
        WS_EX_WINDOWEDGE | WS_EX_NOPARENTNOTIFY,        //Extended Window Styles - WS_EX_TOOLWINDOW, WS_OVERLAPPEDWINDOW, WS_OVERLAPPED, WS_EX_STATICEDGE
        className.c_str(),                                //window class name
        winName.c_str(),                                //window caption
        WS_CHILDWINDOW | WS_VISIBLE |
        WS_BORDER | WS_VSCROLL | WS_HSCROLL,            //window style WS_VSCROLL WS_HSCROLL ES_AUTOHSCROLL, WS_CHILD
        0,                                                //initial x position
        0,                                                //initial y position
        (int)getWndWidth(),                                //initial x size
        (int)getWndHeight(),                            //initial y size
        m_hParentWnd,                                    //parent window handle
        NULL,                                            //window menu handle
        hInstance,                                        //program instance handle
        NULL                                            //creation parameters
        );  
   
    if (!g_hChildWin) {
        throw std::runtime_error("Could not create Message Window");
        return FALSE;
    }
    int nCmdShow = SW_SHOWNORMAL;
    ShowWindow(g_hChildWin, nCmdShow);
    UpdateWindow(g_hChildWin);

    return TRUE;
}


Thanks
Kannan



Reply all
Reply to author
Forward
0 new messages