VC sculptor small technology set (six)

zhaozj2021-02-16  53

VC sculptor small technology set (six)

He Zhidan

1, how to get CheckBox status on Tree Control ~

Oninit plus:

m_treectrl.insertitem ("item1");

m_treectrl.insertitem ("item2");

Void ccDialogdlg :: onbutton1 ()

{

HtreeItem HITEM = m_treectrl.getrootItem ();

While (NULL! = HITEM)

{

CString str = m_treectrl.getitemtext (HITEM);

IF ("item2" == STR)

{

IF (m_treectrl.getcheck (hItem))

AfxMessageBox ("Select");

}

HITEM = m_treectrl.getnextVisibleItem (HITEM);

}

}

2, how to send characters to another with another program and make it displayed

First get the window handle of the Windows program via FindWindow.

Then get the window handle of the input box by getDLGITEM.

Finally, send a WM_CHAR message to the window handle to display characters.

For example, for the NOTEPAD window, you can enter one 'a' in the following manner:

Take a notepad's window handle

HWND HWND = :: FindWindow (NULL, "Unexpected Title - Notepad");

Take the window handle of the input box

HWND HEDIT = :: getdlgitem (hwnd, 0x0f); // 0x0f here is the ID of the edit box, can be observed in SPY

Fill in 'a' in the input box

:: SendMessage (Hedit, WM_CHAR, (WPARAM) 'A', 0x00000001);

3, current time:

CTIME T = CTIME :: getcurrenttime ();

CString Str; str.format ("% D-% D-% D", T.Getyear (), T.getMonth (), T.GetDay ());

Str = T.Format ("-% H-% M-% S");

AfxMessageBox (STR);

Be sure to use CTIME :: getCurrentTime (); getCurrentTime () is a outdated function.

4, // change the background color of the button.

Hbrush CRECTWINDOW2VIEW :: ONCTLCOLOR (CDC * PDC, CWND * PWND, UINT NCTLCOLOR)

{

Hbrush Hbr = CFormview :: ONCTLCOLOR (PDC, PWND, NCTLCOLOR);

Switch (nctlcolor)

{

Case CTLColor_BTN:

{

CBRUSH Brush (RGB (128, 0, 128)); // Your color

CBRUSH * POLDBRUSH = PDC-> SelectObject (& brush);

PDC-> SELECTOBJECT (POLDBRUSH);

}

}

Return CFormview :: ONCTLCOLOR (PDC, PWND, NCTLCOLOR);

}

5. Use of accelerator keys.

Add in the DLG's header file:

Haccel M_Haccel;

Add the accelerator in the DLG constructor:

How does the program based on the dialog box use acceleration keys?

m_haccel = :: loadaccelerators (AFXGETITISTANCEHANDLE (), makeintResource (idR_accelerator1)); // Accelerator key ID overload PretranslateMessage function:

Bool CDLG :: PretranslateMessage (MSG * PMSG)

{

// Todo: Add Your Specialized Code Here and / or Call The Base Class

IF (M_Haccel! = NULL)

IF (:: translateAccelerator (m_hwnd, m_haccel, pmsg))

Return True;

Return CDIALOG :: PretranslateMessage (PMSG);

}

6, how do you save a file to other places?

IF (! CopyFile ("f: //he.txt", "d: //he1.txt", true))

{

IF (IDOK == Messagebox ("Is there a file, do you have to overwrite?", NULL, MB_OKCANCEL)

{

Copyfile ("f: //he.txt", "d: //he1.txt", false);

}

Else

Return;

}

Deletefile ("f: //he.txt");

转载请注明原文地址:https://www.9cbs.com/read-25713.html

New Post(0)