Click here to Skip to main content
15,905,614 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to run application at win2k startup? Pin
golden06062-Nov-03 21:28
golden06062-Nov-03 21:28 
AnswerRe: How to run application at win2k startup? Pin
Michael P Butler2-Nov-03 21:53
Michael P Butler2-Nov-03 21:53 
AnswerRe: How to run application at win2k startup? Pin
Xiangyang Liu 刘向阳3-Nov-03 0:10
Xiangyang Liu 刘向阳3-Nov-03 0:10 
Generalfind window Pin
`Alt+F4`2-Nov-03 20:53
`Alt+F4`2-Nov-03 20:53 
GeneralRe: find window Pin
Mumiozol2-Nov-03 22:23
Mumiozol2-Nov-03 22:23 
GeneralRe: find window Pin
Antti Keskinen2-Nov-03 22:28
Antti Keskinen2-Nov-03 22:28 
GeneralRe: find window Pin
`Alt+F4`3-Nov-03 9:34
`Alt+F4`3-Nov-03 9:34 
GeneralRe: find window Pin
Antti Keskinen5-Nov-03 3:17
Antti Keskinen5-Nov-03 3:17 
Ahh ok.

Let's create a general outline of the solution to this problem.

1. Find the window
2. Enumerate the views of this window
3. With each view, access the underlying document
4. Get this document's CString, and append the current date and time to the end.
5. Force window to save all it's open documents/views.

For a specific, Notepad-only solution, the outline is a bit different, because Notepad doesn't have any real views: it has one HUGE edit control.

Now, some code pieces. With the MFC-way, of course Smile | :)

<br />
// Create a new CWnd object<br />
CWnd* pNotepadWin = new CWnd;<br />
<br />
// Attach it to Notepad<br />
// Use Microsoft SPY to determine the class name of Notepad's window<br />
HWND hwndNotepad = ::FindWindow( ClassName, NULL ) );<br />
<br />
if ( hwndNotepad )<br />
{<br />
     pNotepadWin->Attach( hwndNotepad );<br />
}<br />
else<br />
{<br />
     delete pNotepadWin;<br />
     return FALSE;<br />
}<br />
<br />


Now we have the CWnd representation of the Notepad window.

<br />
// Create a CWnd pointer<br />
CWnd* pNotepadEdit;<br />
<br />
// Get the first child window of Notepad Window<br />
pNotepadEdit = pNotepadWin->GetTopWindow();<br />
<br />
// If the window has no children (It is not Notepad then !)<br />
if ( !pNotepadEdit )<br />
{<br />
    // Detach our CWnd from the Notepad.<br />
    pNotepadWin->Detach();<br />
<br />
    // Delete it<br />
    delete pNotepadWin;<br />
    return FALSE;<br />
}<br />
<br />
// Enumeration: Find a child window which qualifies as an edit control<br />
bool bContinue = true;<br />
while ( bContinue )<br />
{<br />
    // Variables<br />
    CString strName;<br />
<br />
    // Get this window's class name<br />
    ::GetClassName(pNotepadEdit->m_hWnd, (LPTSTR) strName, 20);<br />
<br />
    // Is it an edit control ?<br />
    if ( strName.CompareNoCase("Edit") == 0 )<br />
          bContinue = false;<br />
<br />
    // Nope, so try to get the next one<br />
    pNotepadEdit = pNotepadEdit->GetNextWindow(GW_HWNDNEXT);<br />
<br />
    if ( !pNotepadEdit )<br />
    {<br />
        // No more child windows<br />
        bContinue = false;<br />
    }<br />
}<br />
<br />


Phew. That was some coding. But now we have the CWnd of the edit control inside Notepad. After this, it's easy to use 'GetWindowText' and 'SetWindowText' to append the current date and time to the edit control's contents.

Perhaps I should turn this into an article Big Grin | :-D

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
Generaltemplate class Problem Pin
Mehran Ziadloo2-Nov-03 20:20
Mehran Ziadloo2-Nov-03 20:20 
GeneralRe: template class Problem Pin
Per Nilsson2-Nov-03 21:05
Per Nilsson2-Nov-03 21:05 
GeneralCFile::ReadHuge question Pin
BlackRider2-Nov-03 20:13
BlackRider2-Nov-03 20:13 
GeneralRe: CFile::ReadHuge question Pin
Steve S3-Nov-03 2:50
Steve S3-Nov-03 2:50 
QuestionHow to restore my application instead of running a new instance? Pin
julych2-Nov-03 20:03
julych2-Nov-03 20:03 
AnswerRe: How to restore my application instead of running a new instance? Pin
BlackRider2-Nov-03 20:33
BlackRider2-Nov-03 20:33 
AnswerRe: How to restore my application instead of running a new instance? Pin
Michael P Butler2-Nov-03 22:04
Michael P Butler2-Nov-03 22:04 
AnswerRe: How to restore my application instead of running a new instance? Pin
cmk2-Nov-03 22:30
cmk2-Nov-03 22:30 
GeneralPreCreateWindow Pin
Vancouver2-Nov-03 19:41
Vancouver2-Nov-03 19:41 
GeneralRe: PreCreateWindow Pin
Antti Keskinen2-Nov-03 22:36
Antti Keskinen2-Nov-03 22:36 
GeneralPreCreateWindow Pin
Vancouver3-Nov-03 6:50
Vancouver3-Nov-03 6:50 
GeneralRe: PreCreateWindow Pin
Antti Keskinen5-Nov-03 2:17
Antti Keskinen5-Nov-03 2:17 
GeneralOnSetFont Pin
Vancouver7-Nov-03 13:34
Vancouver7-Nov-03 13:34 
GeneralRe: OnSetFont Pin
Antti Keskinen8-Nov-03 9:41
Antti Keskinen8-Nov-03 9:41 
GeneralOnSetFont Pin
Vancouver8-Nov-03 19:55
Vancouver8-Nov-03 19:55 
GeneralSharing MFC objects among threads... Pin
Suhail Yousaf2-Nov-03 19:16
Suhail Yousaf2-Nov-03 19:16 
GeneralFiles and folders Pin
Selevercin2-Nov-03 17:26
Selevercin2-Nov-03 17:26 

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.