Graduation Project (simple network protocol analyzer) (iii)

Source: Internet
Author: User

Tragedy ~~~ The blog post I just wrote was inexplicably lost at the time of release ~~ Is it because of chrome ??? Ah, ah, ah ~~~ I wrote it again with Firefox 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src ="/neweditor/editor/images/smiley/22.gif" alt = ""/>

March 18

Two days after the last update, I did a little bit today. In general, the device information is displayed.

Let's take a look at the results.

650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1I2422939-0.png "/>

I encountered several problems.

1. How to dynamically change the caption attribute of the dialog box

Solution: Use setwindowtext

My code

 
 
  1. BOOL CDevStatus: OnInitDialog (void)
  2. {
  3. CDialog: OnInitDialog ();
  4. This-> SetWindowTextA (LPCTSTR (CPublic: DevName ));
  5. // The following content is omitted

Creates a class for the pop-up window on the right, overrides the OnInitDialog method in CDialog, and uses the this pointer and a global variable CPublic: DevName to change the caption.

 

2. Global variables. What should I do if some variables need to be shared between the two dialogs? The easiest thing to think of is to use global variables for transmission. But how does one define global variables in MFC? I checked some information and found a method to define a PUBLIC class, which is specially used to place global variables. When used, it is referenced by scope. In fact, there are some problems in this process, I haven't solved it yet, and I don't think the method of using global variables is too good. Now, the processing is just a matter of expediency ~~

Code:

 

 
 
  1. # Pragma once
  2.  
  3. # Include "pcap. h"
  4. // CPublic is used to define global variables/functions
  5.  
  6. Class CPublic: public CWnd
  7. {
  8. DECLARE_DYNAMIC (CPublic)
  9.  
  10. Public:
  11. CPublic ();
  12. Virtual ~ CPublic ();
  13. Static CString DevName; // Save the selected device name
  14. Protected:
  15. DECLARE_MESSAGE_MAP ()
  16. };

 

3. About the forced conversion of LPTCSTR. In the following code, d-> description is char *, and DevName is CString. We wanted to convert it to the same one for comparison. However, after conversion, the if statement is always false, leading to NULL pointer

 

 
 
  1. For (d = alldevs; d! = NULL; d = d-> next ){
  2. If (d-> description = CPublic: DevName) // Why is there a problem after the forced conversion of DevName using the LPCTSTR ??
  3. Break;
  4. }

If you do not perform forced conversion, there is no problem. I checked some information and still did not understand it...

 

4. About running programs on other computers.

This is because the graduation project will always have a day to answer the question. Maybe there will be no way to use your own computer at that time, so the running problems in different situations should also be solved. I have prepared a pure xp Virtual Machine dedicated for testing. In the previous console program, you can change the compilation option to/MT. However, MFC does not seem to be able to do this. It only needs to be compiled using a static library.

 

650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1I242GL-1.png "/>

However, this process is much larger ~~

 

5. for some functions, when using functions such as setwindowsText, I found a problem. In VS2008, the Code prompts a function such as setwindowtextw or setwindowtexta, so what are the differences between these users ???

I found this on the Internet.

"I have seen A saying on the Internet that there are two sets of code for functions in VC ++, one for ANSI and the other for UNICODE, and the other for ANSI ends with, functions in UNICODE end with W. At the same time, the function name after removing the ending character can refer to two functions at the same time, when the compiler explains it, it depends on whether your project is defined in UNICODE"

Later, I tried to change the character set, as though it was.

 

Due to the loss of the previously written blog post, I am very depressed. If I write it again, I am not so serious. Sorry.

As a matter of fact, there are a lot of problems that have not been solved today. While catching up with the progress, we still have to understand these things.

 

Graduation Project simple network protocol analyzer) Compilation course 3) completed

This article from "learning is a pleasure" blog, please be sure to keep this source http://eaglexhh.blog.51cto.com/1345400/519049

Related Article

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.