VC skill set (3)

Source: Internet
Author: User
Tags drawtext

VC skill set (3)
He zhidan
1. fixed window size. The maximum value is (600,400), and the minimum value is (600,400 ).
Void cmainframe: ongetminmaxinfo (minmaxinfo far * lpmmi)
{
Lpmmi-> ptmaxtracksize. x = 600;
Lpmmi-> ptmaxtracksize. Y = 400;
Lpmmi-> ptmintracksize. x = 600;
Lpmmi-> ptmintracksize. Y = 400;
Cframewnd: ongetminmaxinfo (lpmmi );
}

2. Close the dialog box and window:
In fact, destorywindow () can be used for window destruction, and enddialiog () can be used for dialog box destruction ().
Enddialog (idok );
The return value of domodal () is idok, but the User-Defined onok is not executed.
As long as the wm_close message is sent, the response function will be processed.
Sendmessage (wm_close );
Postmessage (wm_close );
Void ctestdialog: onbutton1 ()
{
Getparent ()-> destroywindow ();
}
Close the window with the dialog box
Postmessage (wm_quit );
Sendmessage (wm_quit); // No
Destroywindow () is used in the modeless dialog box ();
Use enddialog
You can open the original dialog box again.

3. Use of global variables:
C *** app defines a cstring
Use Time
Void cdlgdlg: onbutton2 ()
{
(Cdlgapp *) afxgetapp ()-> STR = "test ";
}
Do not forget to include files

4. How to enable the DOS program to run automatically at startup without displaying Automatic Running? Write the registry run value, VC + Windows2000
Change main to winmain.

5. Clear the automatic password history
In the browser: Tools-> Internet Options-> content-> point "AutoComplete (u)" button-> clear password http://tzsvc.xiloo.com/skill/sys/clear.htm
Shdeletekey (HKEY_CURRENT_USER, _ T ("software/Microsoft // Internet Explorer // intelliforms "));

6. Execute an executable program
Method 1:
ShellExecute (this-> getsafehwnd (), "open", "F: // he.txt", null, null, sw_shownormal );
Method 2:
Process_information PI;
Startupinfo Si;
Si. cb = sizeof (startupinfo );
Si. lpreserved = NULL;
Si. lpdesktop = NULL;
Si. lptitle = NULL;
Si. dwflags = 0;
Si. cbreserved2 = 0;
Si. lpreserved2 = NULL;
Bool Bres = CreateProcess (null, "test a.txt B .txt", null, null, false, normal_priority_class, null, null, & Si, π );
If (Bres = false)
{
Afxmessagebox ("CreateProcess failed ");
}
Else
{
Closehandle (PI. hthread );
DWORD dwret = waitforsingleobject (PI. hprocess, 1000*30 );
Switch (dwret)
{
Case wait_object_0:
DWORD dwexitcode;
Bres = getexitcodeprocess (PI. hprocess, & dwexitcode );
Tchar exitmsgbuf [1024];
If (Bres)
{
Wsprintf (exitmsgbuf, "Exit code: % d", dwexitcode );
}
Else
Wsprintf (exitmsgbuf, "Exit Code failed to return ");
Afxmessagebox (exitmsgbuf );
Break;
Default:
Afxmessagebox ("exit for other reason ");
}

 

VC skill set (4)
He zhidan

1. Reading the program often needs to see where the value of this variable has changed.
CTRL + F searching is too troublesome
Add const to the variable
Error reported in the changed location

2. check whether a function is called by those functions.
Method:
1. In the debugging status, view-> debug window-> call stack
2. Select called by from the shortcut menu of Class View.


3. display the time on the far left of the status bar
Static uint indicators [] =
{
Id_separator, //
Id_separator,
Id_indicator_caps,
Id_indicator_num,
Id_indicator_scrl,
};
Int cmainframe: oncreate (maid)
{
... M_wndstatusbar.setpaneinfo (1, id_separtor, sbps_normal, 60 );
}
// Menu Response Function
Void cmainframe: ontest ()
{
Ctime T;
T = ctime: getcurrenttime ();
Cstring STR = T. Format ("% H-% m-% s ");
M_wndstatusbar.setpanetext (0, STR );
}

4. Simulate the mouse
: Setcursorpos (INT) ptmouse-> X, (INT) ptmouse-> Y );
: Mouse_event (mouseeventf_leftdown, 0, 0, 0 );
: Mouse_event (mouseeventf_leftup, 0, 0, 0 );
: Mouse_event (mouseeventf_leftdown, 0, 0, 0 );
: Mouse_event (mouseeventf_leftup, 0, 0, 0 );

5. What is word and DWORD?
Typedef unsigned short word
Typedef unsigned long DWORD

6. Mobile controls
Cwnd * pwnd = getdlgitem (idc_button1 );
Crect R;
Pwnd-> getwindowrect (& R );
R. Left + = 50;
R. Right + = 50;
Pwnd-> movewindow (R );

7. How to Make cedit in the dialog box respond to the Enter key and press enter?
Getdlgitem (idc_edit1)-> setwindowtext ("111/R/n22 ");
Right-click attribute
Choose sytle-> multiline
You 'd better select want return.

8. convert C language into assembly
VC ++ provides this feature.
Project-> Settings...
C/C ++ Tab
Category: Choose listing files
Listing file type:
Select "assembly with source code"

9. How to obtain the CPU time consumed by the process?
Bool getprocesstimes (handle hprocess, lpfiletime lpcreationtime, lpfiletime lpexittime, lpfiletime lpkerneltime, lpfiletime lpusertime );

10. How can I get the icon corresponding to the extension through the extension?
Shgetfileinfo (path, ATTR, & SFI, sizeof (shfileinfo), shgfi_usefileattributes | shgfi_icon | shgfi_typename );
How can I change the border of the dialog box by hour to make it change proportionally? Like what kind of wm_sizing message does the video playback software process?
Void ctest 1dlg: onsizing (uint fwside, lprect prect)
{
Cdialog: onsizing (fwside, prect );
If (fwside = wmsz_bottom) | (fwside = wmsz_top ))
Prect-> right = prect-> left + (prect-> bottom-prect-> top) * 2;
Else
Prect-> bottom = prect-> top + (prect-> right-prect-> left) * 0.5;
}

VC skill set (5)
He zhidan

1. Right-click a class or macro in VC to view its definition. But how can I return the initial position?
Install visual assist, and use Alt + left arrow
Press the back button in the menu (<-to 45 degrees)
It seems that another document has been opened. Just close it.

2. How to obtain the system menu and bring up the system menu?
Void ctestsysmenudlg: onok ()
{
// Click the OK button to Show System menu (masterz)
Point curpos;
Getcursorpos (& curpos );
Setforegroundwindow ();
Cmenu * pmenu = getsystemmenu (false );
Int nselection = pmenu-> trackpopupmenu (tpm_leftbutton | tpm_leftalign | tpm_bottomalign | tpm_nonostrap | tpm_returncmd, curpos. X, curpos. Y, this );
DWORD dwpos = curpos. x + (curpos. Y <16) & 0xffff0000 );
Sendmessage (wm_syscommand, nselection, dwpos );
Cstring MSG;
MSG. format ("X: % d, Y: % d; cursor. X = % d, cursor. y = % d ", loword (dwpos), hiword (dwpos), curpos. x, curpos. Y );
Outputdebugstring (MSG );
}

3. How to control the light-off of the three lights on the keyboard (Num Lock, Caps Lock srcoll lock)
# Include
Void setnumlock (bool bstate)
{
Byte keystate [256];
Getkeyboardstate (lpbyte) & keystate );
If (bstate &&! (Keystate [vk_numlock] & 1) | (! Bstate & (keystate [vk_numlock] & 1 )))
{
// Simulate a key press
Keybd_event (vk_numlock, 0x45, keyeventf_extendedkey | 0, 0 );
// Simulate a key release
Keybd_event (vk_numlock, 0x45, keyeventf_extendedkey | keyeventf_keyup, 0 );
}
}
Void main ()
{
Setnumlock (true );
}

4. How can I change it to English after selecting Chinese characters in the VC Appwizard?
Open the resource file in a file editor and find "language" in it. After finding the file, you can see the following:
// Chinese (P. r.c) Resources
# If! Defined (afx_resource_dll) | defined (afx_targ_chs)
# Ifdef _ Win32
Language lang_chinese, sublang_chinese_simplified
# Pragma code_page (936)
# Endif // _ Win32
This code section indicates that the currently used code page is 936, and the language is simplified Chinese. Replace the following code with the following code:
// English (U. S) Resources
# If! Defined (afx_resource_dll) | defined (afx_targ_enu)
# Ifdef _ Win32
Language lang_english, sublang_english_us
# Pragma code_page (1252)
# Endif // _ Win32

5. How to effectively determine whether the mouse points are in the control's rectangle area
Dword dw = getmessagepos ();
Cpoint Pt (loword (DW), hiword (DW); // screen coordinate of the mouse
Crect R;
Getdlgitem (idc_edit1)-> getclientrect (& R );
Getdlgitem (idc_edit1)-> clienttoscreen (& R );
If (R. ptinrect (PT ))
Afxmessagebox ("in control ");


6. Right-click the control and choose not from the Class Wizard.
Bool ccdialogdlg: pretranslatemessage (MSG * PMSG)
{
If (wm_mousemove = PMSG-> message)
If (PMSG-> hwnd = getdlgitem (idc_button1)-> getsafehwnd ())
{
Uint nflag = PMSG-> wparam; // status, for example, CTRL is not pressed
Int xpos = loword (PMSG-> lparam); // horizontal position of cursor
Int ypos = hiword (PMSG-> lparam); // vertical position of cursor
}
Return cdialog: pretranslatemessage (PMSG );
}

 

VC skill set (6)
He zhidan

1. How to obtain the checkbox status on the tree control ~
In oninit:
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 ("selected ");
}
Hitem = m_treectrl.getnextvisibleitem (hitem );
}
}

2. How can I use one program to send characters to another program and display them?
First, use findwindow to get the window handle of the Windows program, then use getdlgitem to get the window handle of the input box, and finally, send the wm_char message to the window handle to display the characters
For example, for the notepad window, you can enter a 'A' in the following way ':
Retrieve the window handle of notepad
Hwnd =: findwindow (null, "untitled-Notepad ");
Obtain the window handle of the input box.
Hwnd hedit =: getdlgitem (hwnd, 0x0f); // here, 0x0f is the ID of the edit box, which can be observed in spy ++.
Enter '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", T. getyear (), T. getmonth (), T. getday ());
STR + = T. Format ("-- % H-% m-% s ");
Afxmessagebox (STR );
Must use ctime: getcurrenttime (); getcurrenttime () is an 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. Acceleration key usage.
Add the following to the DLG header file:
Haccel m_haccel;
Load the accelerator key in the DLG constructor:
How does a dialog box-based program use the acceleration key?
M_haccel =: loadaccelerators (AfxGetInstanceHandle (), makeintresource (idr_accelerator1); // acceleration key ID
Overload the 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 can I save an object to another place?
If (! Copyfile ("F: // he.txt", "d: // he1.txt", true ))
{
If (idok = MessageBox ("there is a file with the same name, do you want to overwrite it? ", Null, mb_okcancel ))
{Copyfile ("F: // he.txt", "d: // he1.txt", false );}
}
Else
Return;
}

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

 

VC skill set (7)
He zhidan

1. Image Control
Right-click the property type: bitmap
You can select image directly.
ID of the idb_bitmap1 bitmap
M_ctrl is the control variable associated with the image control.
Void cdlg2dlg: onbutton1 ()
{
Cbitmap bitmap1;
Bitmap1.loadbitmap (idb_bitmap1 );
M_ctrl.setbitmap (bitmap1 );
}
Void cdlg2dlg: onbutton2 ()
{
Cbitmap bitmap2;
Bitmap2.loadbitmap (idb_bitmap2 );
M_ctrl.setbitmap (bitmap2 );
}

2. Why can't I see the cortrol ID when I assign a variable to the control?
1. Click the single-choice button to hook the group.
2. The static control changes the ID to non-idc_static.

3. ascll code of the keyboard
0-9 is different, but +,-is the same.

4. display the characters entered on the keyboard to avoid blinking.
Void csdiview: onchar (uint nchar, uint nrepcnt, uint nflags)
{
CDC * PDC = getdc ();
Stringdata + = nchar;
Crect R (0, 0, 0 );
PDC-> drawtext (stringdata, & R, dt_left | dt_calcrect );
Invalidaterect (R );
Cview: onchar (nchar, nrepcnt, nflags );
}
Void csdiview: ondraw (CDC * PDC)
{
PDC-> drawtext (stringdata, crect (0,0, 1000,1000), dt_left );
}

5. In dialog box a domodal (), a dialog box B is displayed. After clicking a button of B, you must call a function in Class.
Process in the response function of B:
(A *) getparent ()-> fun ();
Inlcude A's file in B

6. delete folders and files
# Include
Void deletedirfile (cstring Spath)
{
Win32_find_data FD;
Handle hfind =: findfirstfile (Spath + "*. *", & FD );
If (hfind! = Invalid_handle_value)
{
While (: findnextfile (hfind, & FD ))
{
// Determine whether it is a directory
If (FD. dwfileattributes & file_attribute_directory)
{
Cstring name;
Name = FD. cfilename;
// Determine whether it is a. And ..
If (name! = ".") & (Name! = ".."))
{
// Perform recursion for a real directory
Deletedirfile (Spath + FD. cfilename + "//");
}
}
}
Else
Deletefile (Spath + FD. cfilename );

: Findclose (hfind );
}
Removedirectory (Spath );
}



7. Change the font size of the control.
Logfont;
Cfont * pfont = m_ctrshowmessage.getfont ();
Pfont-> getlogfont (& logfont );
Logfont. lfheight = logfont. lfheight * 1.5;
Logfont. lfwidth = logfont. lfwidth * 1.5;
Cfont font;
Font. createfontindirect (& logfont );
M_ctrshowmessage.setfont (& font );

8. I want to use classwizard to create a class, but I found that the baseclass column does not contain the base class I want (coblist class)
Class type: Generic
Input by yourself

9, ctypedptrlist linelist;
Why does VC report the following error:
C:/Program/scribble/scribbledoc. H (50): Error c2143: syntax error: Missing '; 'before' <'
# Include "afxtempl. H"
It is the character l, not the number 1

10. What should I do if a member function is not prompted?
Cstring S1 = "dfdsf ";
S1.
Try the following three methods:
1. Build-> clean, Build-> rebuildall.
2. manually delete *. NCB
3. Install the auxiliary tool vc_00006

11. How do I divide six radio boxes into three groups?
Group the three radio boxes
It is divided into three groups.
Related to focus Sequence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.