[RESOLVED] wxWidgets' wxFrame initialization of controls: A question I have
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: [RESOLVED] wxWidgets' wxFrame initialization of controls: A question I have

  1. #1
    Join Date
    Nov 2010
    Posts
    135

    [RESOLVED] wxWidgets' wxFrame initialization of controls: A question I have

    I have only been working with wxWidgets a short time. It's fine, however, I have a slight problem initializing controls.

    My code looks like this:

    Code:
    bool MyApp::OnInit()
    {
       if( !wxApp::OnInit() )
         return false;
    
       MyFrame *frame = new MyFrame;
       if(frame)
       {
          frame->OnInit();
          frame->Show(true);
       }
    }
    In the OnInit() method, I initialize some of my GUI controls such as text-boxes with some values of text-strings, and I call Refresh and Update. But it sometimes does NOT put the value in - perhaps 50% of the time. So I'm thinking that I should post a message and then do the initialization in OnCreate(wxWindowCreateEvent& WXUNUSED(evt)). By the way, I know the value of the string is always there before I try to write it into the textbox with WriteText. Perhaps I should call Update or Refresh on the textbox itself (perhaps the OS doesn't know that it's "invalidated" and I should control the behavior myself due to that)?

    Perhaps there is a sort of thread/event issue in the code that this might help solve?

    I will simply try this right now and see how it goes. I'm just not yet used to wxWidgets and I may need to do some reading and experimentation.

    Perhaps I'm missing something fundamental?

    Anyway, I'll try the two things I've mentioned and see if I can get rid of the inconsistent control-update problem.

    Any comments appreciated - not an emergency.
    Last edited by 2kaud; February 15th, 2018 at 05:01 AM. Reason: Added code tags

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,078

    Re: wxWidgets' wxFrame initialization of controls: A question I have

    Did you try to debug?
    Did you try to log all/some of your actions and the correspondent UI responds?
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2010
    Posts
    135

    Re: wxWidgets' wxFrame initialization of controls: A question I have

    Quote Originally Posted by VictorN View Post
    Did you try to debug?
    Did you try to log all/some of your actions and the correspondent UI responds?
    Hi, I can look at it in gdb tomorrow, but I have a hunch to try in the morning when I get back to this. I will just try using a different constructor and make sure I assign an ID to the frame this time. Everything always seems to work better in wxWidgets if you are careful of assigning IDs and also using Connect when needed. It seems to solve a lot of problems. If that doesn't work, then I'll start the debugger.

  4. #4
    Join Date
    Feb 2017
    Posts
    224

    Re: wxWidgets' wxFrame initialization of controls: A question I have

    Quote Originally Posted by WhatNow46 View Post
    I have only been working with wxWidgets a short time.
    Note that there is a dedicated official wxWidget forum here,

    https://forums.wxwidgets.org/

  5. #5
    Join Date
    Nov 2010
    Posts
    135

    Re: wxWidgets' wxFrame initialization of controls: A question I have

    Quote Originally Posted by wolle View Post
    Note that there is a dedicated official wxWidget forum here,

    https://forums.wxwidgets.org/
    Hi, thanks, about an hour ago, I joined that forum, I'm awaiting my activation link but it has not come yet.

  6. #6
    Join Date
    Nov 2010
    Posts
    135

    Re: wxWidgets' wxFrame initialization of controls: A question I have

    Still no activation link.

  7. #7
    Join Date
    Nov 2010
    Posts
    135

    Re: wxWidgets' wxFrame initialization of controls: A question I have

    The forum is not sending an activation link.

    Does anyone have a theory as to why the wxFrame class with some controls on it has controls on it that do not respond properly to WriteText and SetValue function calls. I have looked at the samples for wxWidgets and none of them are any different than what I'm doing.

    I guess I can try calling some sort of Create in the constructor?
    Last edited by WhatNow46; February 16th, 2018 at 02:48 PM.

  8. #8
    Join Date
    Nov 2010
    Posts
    135

    Re: wxWidgets' wxFrame initialization of controls: A question I have

    I guess just have to look at the samples and follow them. Perhaps I need a panel, but why?

  9. #9
    Join Date
    Nov 2010
    Posts
    135

    Re: wxWidgets' wxFrame initialization of controls: A question I have

    For now, I'll just create an event as a quick-fix and simply fire the event when I want an update. Should work.

  10. #10
    Join Date
    Nov 2010
    Posts
    135

    Re: wxWidgets' wxFrame initialization of controls: A question I have

    I've solved this thread for now by simply posting a message, marking things dirty, etc.. I post an event whenever I do a WriteText or SetValue on the wxTextCtrl. So far it seems like it's working as a quick-fix so I don't absolutely have to implement a wxPanel. So I guess this thread is solved. Any details wanted, feel free to ask. Pretty dull stuff.

    I am forcing an OnText event by simply posting it, then I handle the event and make sure things update. However, I believe that the OnText event is probably all that's needed so I plan to back my code out until I get to the root thing that makes it work. I just glossed over everything for now to get it working. Now to the "WHY" and "HOW".

    At least it shows now (and I would guess, consistently).
    Last edited by WhatNow46; February 16th, 2018 at 04:20 PM.

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




On-Demand Webinars (sponsored)