Multiple instances of form resource

This is a discussion on Multiple instances of form resource within the Windows Programming forums, part of the Platform Specific Boards category; When i create multiple instances of a form resource, strange things happen.. Do i have to create one instance for ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Multiple instances of form resource

    When i create multiple instances of a form resource, strange things happen..
    Do i have to create one instance for each(similar) form?
    The form comtains comfiguration settings, and has the same fields in all instances, only different data..

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>strange things happen<<

    That tells us a lot.

    >>Do i have to create one instance for each(similar) form?<<

    Probably not. If you maintain the form data within some sort of struct/class then you only need determine which is active and interface that data set to/from your dialog.

    If that seems utterly irrelevant or too ambiguous then you'll really have to elaborate on strange things happen. (unless CodePlug or anonytmouse or a few others are around as they're quite often psychic and may be along shortly with useful prognostications ).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Okay:
    I have a parent dialog.
    In this dialog i create X number of instances of a child form.
    These chilkd forms are created by the same function, below is a short example:

    Code:
    // Creation of child windows
    static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
    static void InitForm();
    static HWND hwThis;
    
    
    int frmSetup(HWND hWnd, ThData *data, void *tr){
      return((int)CreateDialog(GetModuleHandle(0), MAKEINTRESOURCE(FRM_SETUP), hWnd, DialogProc));
    }
    It seems that only the last created dialog responds to messages??
    I handle the WM_CTLCOLORSTATIC message to draw colored background on some labels. This only happens on the last instance of the form resource.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Does this have anything to do with the fact that DialogProc/hwThis is declared as static?
    As i've understood this, the static keyword only means that the variable can't be referenced from other files when it's in the global scope of the file..?

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    For the dialog procedure, probably not. If you are using that static dialog handle in your message loop in IsDialogMessage or GetMessage then that will be problematic.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Prevent Multiple Instances
    By Jaken Veina in forum Windows Programming
    Replies: 5
    Last Post: 01-16-2009, 09:18 AM
  2. multiple instances and variables
    By FOOTOO in forum Windows Programming
    Replies: 1
    Last Post: 04-07-2005, 11:54 AM
  3. Multiple instances of the same object.
    By suzakugaiden in forum Game Programming
    Replies: 12
    Last Post: 03-19-2005, 11:49 PM
  4. Replies: 4
    Last Post: 03-11-2005, 05:45 PM
  5. Multiple Resource files
    By doodlak in forum C++ Programming
    Replies: 0
    Last Post: 07-04-2002, 07:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21