[win32] - creating the form super class
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [win32] - creating the form super class

  1. #1
    Join Date
    Apr 2009
    Posts
    678

    [win32] - creating the form super class

    i'm trying build the form super class without sucess

    i can't get the old procedure
    Code:
    void setParent(HWND parent=GetDesktopWindow())
        {
                WNDCLASSEX FormClass;
                char classname[]="form";
                HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);
    
                FormClass.cbSize        = sizeof(WNDCLASSEX);
                FormClass.style         = 0;
                FormClass.lpfnWndProc   = WndProcForm;
                FormClass.cbClsExtra    = 0;
                FormClass.cbWndExtra    = 0;
                FormClass.hInstance     = mod;
                FormClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
                FormClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
                FormClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
                FormClass.lpszMenuName  = NULL;
                FormClass.lpszClassName = classname;
                FormClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
                // register the new window class"
                RegisterClassEx(&FormClass);
                SetProp(hwnd, formpropname, (HANDLE)FormClass.lpfnWndProc);
    
                hwnd = CreateWindowEx(0, classname, "The title of my window", WS_OVERLAPPEDWINDOW | WS_TABSTOP, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, parent, NULL, mod, (LPVOID) this);
    
                if (hwnd == NULL)
                    MessageBox(NULL, "Can't create the control", "error", MB_OK);
                SetProp(hwnd, formclassprop, (HANDLE)this);
                ShowWindow(hwnd, SW_NORMAL);
                UpdateWindow(hwnd);
    
                clrBackColor= GetBkColor(GetDC(parent));
                clrTextColor = GetTextColor(GetDC(parent));
    
    
            RECT a;
            GetClientRect(hwnd,&a);
            intTop=a.top;
            intLeft=a.left;
            intWidth=a.right-a.left;
            intHeight=a.bottom-a.top;
        }
    
    
    
    //window procedure:
     //preparing the message loop for be used in super class way
            //Getting the parent procedure
            WNDPROC oldproc = (WNDPROC)GetProp(GetDesktopWindow(), formpropname);
            if (oldproc == NULL)
                MessageBox(NULL, "Can't find old procedure", "error", MB_OK | MB_ICONEXCLAMATION);
    
            //add the instance class to inst pointer
            form *inst = (form*)GetProp(hwnd, formclassprop);
            
            if (inst == NULL && msg == WM_NCCREATE)
            {
                inst = (form*)(((LPCREATESTRUCT)lParam)->lpCreateParams);
                SetProp(hwnd, formclassprop, (HANDLE)inst);
            }
            if (inst == NULL)
                MessageBox(NULL, "Can't find the instance pointer", "error", MB_OK);
    why i can't get the old procedure?
    why i can't get the inst pointer?
    and see these message:
    Code:
    case WM_COMMAND:
                {
                    SendMessage(hwnd,WM_COMMAND,wParam,lParam);
                }
                break;
    why the windows(OS) give me an error and close my application, when i click on button?

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,553

    Re: [win32] - creating the form super class

    Code:
    SetProp(hwnd, formpropname, (HANDLE)FormClass.lpfnWndProc);
    You can't set a window property until the window has been created in the following line! You also should test RegistrClassEX() and SetProp() for return errors.

    Code:
    case WM_COMMAND:
                {
                    SendMessage(hwnd,WM_COMMAND,wParam,lParam);
                }
                break;
    You are handling the WM_COMMAND message and you send a WM_COMMAND message which then gets handled as a WM_COMMAND message which sends a WM_COMMAND message which .....................
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Apr 2009
    Posts
    678

    Re: [win32] - creating the form super class

    hello 2kaud thanks for answer me.
    "You can't set a window property until the window has been created in the following line! You also should test RegistrClassEX() and SetProp() for return errors."
    my mistake, but i continue with problems: i don't get the inst and oldproc correctly
    "You are handling the WM_COMMAND message and you send a WM_COMMAND message which then gets handled as a WM_COMMAND message which sends a WM_COMMAND message which ..................... "
    because these message is for my button\others controls class's prodedure

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,471

    Re: [win32] - creating the form super class

    Quote Originally Posted by Cambalinho View Post
    hello 2kaud thanks for answer me.
    "You can't set a window property until the window has been created in the following line! You also should test RegistrClassEX() and SetProp() for return errors."
    my mistake, but i continue with problems: i don't get the inst and oldproc correctly
    "You are handling the WM_COMMAND message and you send a WM_COMMAND message which then gets handled as a WM_COMMAND message which sends a WM_COMMAND message which ..................... "
    What are SetProp/GetProp?
    Are they your own functions? Then set a breakpoint, debug and see what and why goes wrong!

    Quote Originally Posted by Cambalinho View Post
    Code:
                SetProp(hwnd, formclassprop, (HANDLE)this);
    What is this here? I do not see any calss in your code snippets.

    PS: please use quote tags for quatation of other posts!
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2009
    Posts
    678

    Re: [win32] - creating the form super class

    Quote Originally Posted by VictorN View Post
    What are SetProp/GetProp?
    Are they your own functions? Then set a breakpoint, debug and see what and why goes wrong!

    What is this here? I do not see any calss in your code snippets.

    PS: please use quote tags for quatation of other posts!
    i didn't show all the class, because it's very big.
    the SetProp/GetProp are API functions

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,471

    Re: [win32] - creating the form super class

    Quote Originally Posted by Cambalinho View Post
    the SetProp/GetProp are API functions
    Well, then do you check their return values?
    Why don't you call GetLastError if SetProp fails?
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center