Click here to Skip to main content
15,895,192 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to dynamically change a window class name? Pin
yjzh29-Jun-06 5:12
yjzh29-Jun-06 5:12 
AnswerRe: How to dynamically change a window class name? Pin
ovidiucucu29-Jun-06 5:24
ovidiucucu29-Jun-06 5:24 
GeneralRe: How to dynamically change a window class name? Pin
Tara1429-Jun-06 5:45
Tara1429-Jun-06 5:45 
AnswerRe: How to dynamically change a window class name? [modified] Pin
ovidiucucu29-Jun-06 6:08
ovidiucucu29-Jun-06 6:08 
GeneralRe: How to dynamically change a window class name? Pin
Tara1429-Jun-06 7:15
Tara1429-Jun-06 7:15 
QuestionRe: How to dynamically change a window class name? Pin
yjzh29-Jun-06 16:51
yjzh29-Jun-06 16:51 
QuestionRe: How to dynamically change a window class name? Pin
yjzh29-Jun-06 15:33
yjzh29-Jun-06 15:33 
AnswerRe: How to dynamically change a window class name? [modified] Pin
ovidiucucu29-Jun-06 23:34
ovidiucucu29-Jun-06 23:34 
Ugh, those hackercrackers controlling poor dialogs found with FindWindow... Smile | :) Smile | :)
Even I have not entirely got the point or even for fun or for sake of code digging, here is a solution.

Override CDialog::DoModal to modyfy DLGTEMPLATE structure passed to CreateDlgIndirect function.
Copy/paste the code from default CDialog::DoModal implementation then make some cosmetics.
Below is a trivial example which makes some assumptions, to simplify code and be easier to get the idea.
You must read carefully the DLGTEMPLATEEX structure documentation, focusing on menu and windowClass members that have variable length and modify my example to take care of each case (has a menu or not, and so on...).

  • we have a DIALOGEX resource.
  • the dialog has attached a menu with ID in the .rc file (not a name).
  • a CLASS statement was inserted in .rc file, that we'll replace with a class name with the same length.

      #include <AFXPRIV.H>
      #include <AFXIMPL.H>
      #define DELETE_EXCEPTION(e) do { e->Delete(); } while (0)
      // ...
      int CMyDialog::DoModal() 
      {
      // ... original code ...
      
         TRY
         {
            // create modeless dialog
            AfxHookWindowCreate(this);
            ////////////////////////// INSERTED CODE //////////////////////////
            // you can register "Tata Leone" class here (see my previous example).
            DLGTEMPLATEEX* lpDlgTemplateEx = (DLGTEMPLATEEX*)lpDialogTemplate;
            WCHAR* pClassName = ((WCHAR*)lpDlgTemplateEx 
                                 // skip DLGTEMPLATEEX structure
                                 + sizeof(DLGTEMPLATEEX) / sizeof(WCHAR) 
                                 // skip menu
                                 + 2 * sizeof(WORD) / sizeof(WCHAR));
      
            wcscpy(pClassName, L"Tata Leone"); // replace "Mama Leone".
            //////////////////////// END INSERTED CODE ////////////////////////
            if (CreateDlgIndirect(lpDialogTemplate,
                    CWnd::FromHandle(hWndParent), hInst))
      // ... the rest of original code ...
      }

      Of course "Mama Leone" is defined in resources CLASS statement, and "Tata Leone" is a registered class.
      And of course the class name can be randomly generated or using a GUID.

      Ovidiu Cucu
      Microsoft MVP - Visual C++

      -- modified at 5:41 Friday 30th June, 2006

QuestionRe: How to dynamically change a window class name? Pin
yjzh30-Jun-06 21:04
yjzh30-Jun-06 21:04 
AnswerRe: How to dynamically change a window class name? [modified] Pin
ovidiucucu1-Jul-06 22:38
ovidiucucu1-Jul-06 22:38 
GeneralRe: How to dynamically change a window class name? Pin
yjzh3-Jul-06 18:16
yjzh3-Jul-06 18:16 
QuestionRe: How to dynamically change a window class name? Pin
yjzh3-Jul-06 19:03
yjzh3-Jul-06 19:03 
AnswerRe: How to dynamically change a window class name? Pin
ovidiucucu3-Jul-06 22:33
ovidiucucu3-Jul-06 22:33 
GeneralRe: How to dynamically change a window class name? Pin
yjzh3-Jul-06 23:06
yjzh3-Jul-06 23:06 
GeneralRe: How to dynamically change a window class name? Pin
yjzh3-Jul-06 23:07
yjzh3-Jul-06 23:07 
QuestionRe: How to dynamically change a window class name? Pin
yjzh4-Jul-06 18:10
yjzh4-Jul-06 18:10 
AnswerRe: How to dynamically change a window class name? [modified] Pin
ovidiucucu4-Jul-06 21:08
ovidiucucu4-Jul-06 21:08 
QuestionRe: How to dynamically change a window class name? Pin
yjzh4-Jul-06 23:40
yjzh4-Jul-06 23:40 
AnswerRe: How to dynamically change a window class name? Pin
ovidiucucu5-Jul-06 2:42
ovidiucucu5-Jul-06 2:42 
QuestionRe: How to dynamically change a window class name? Pin
yjzh5-Jul-06 20:31
yjzh5-Jul-06 20:31 
Questionwhat is wrong Pin
Tara1429-Jun-06 4:56
Tara1429-Jun-06 4:56 
AnswerRe: what is wrong Pin
cje29-Jun-06 5:04
cje29-Jun-06 5:04 
GeneralRe: what is wrong Pin
Tara1429-Jun-06 5:07
Tara1429-Jun-06 5:07 
AnswerRe: what is wrong Pin
Viorel.29-Jun-06 5:23
Viorel.29-Jun-06 5:23 
GeneralRe: what is wrong Pin
Tara1429-Jun-06 5:27
Tara1429-Jun-06 5:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.