PDA

View Full Version : ai biết sử dụng MFC



thanha
02-12-2004, 14:27
ai biết thằng cu này thì gíup dzới, đang mù về nó đê.

litle
03-12-2004, 15:09
Bạn muốn hỏi gì về MFC???? Hỏi như vậy thì làm sao trả lời được

hnx
03-12-2004, 15:30
He he, bạn đọc sách kỹ chưa vậy.
Hoặc bạn lên trang www.codeproject.com mà đọc tut rồi down mấy example về mà xem

numen
11-12-2004, 21:20
Nếu chú chưa học thằng cu đó thì tui khuyên chú khỏi học luôn. Học Win32 API là số một, học cái đó sau này chỉ biết bám vào VC++. Sản phẩm thương mại lại phải nôn tiền cho M$

ngotau
17-01-2005, 16:27
Nếu chú chưa học thằng cu đó thì tui khuyên chú khỏi học luôn. Học Win32 API là số một, học cái đó sau này chỉ biết bám vào VC++. Sản phẩm thương mại lại phải nôn tiền cho M$

Không biết numen học ở đâu mà nói vậy nhỉ, Win32 API không phải là VC ++ à, Win32 API không triển khai trên VC++ à. Win32 API chỉ là cốt lõi để xây dựng ứng dụng trên Windows còn MFC là một phần của VC++ 6 và bây giờ là VC++ 7(Visual Studio.NET).

SkyMaster
17-01-2005, 18:21
haha... bạn nghĩ bạn học VC++ để làm 1 số chương trình be bé cho riêng bạn xài à ? Ngay cả VC++ bạn đang xài cũng phải cần mua bản quyền trên 800US / 1 license. Nếu bạn ra làm công ty phần mềm, hao tiền mua bản quyền Developer cũng sặc máu rùi.

twin
26-01-2005, 08:34
ban tra tien ban quyen nhieu. Nhung neu gioi thi so tien kiem ra con nhieu hon....

misty
27-01-2005, 00:01
twin hãy chỉ cho tôi 1 người "giỏi" theo định nghĩa của bạn đi (ở VN nha), nghĩa là trả tiền bản quyền vài ngàn USD và kiếm ra nhiều hơn từ soft do họ SX...

buimanhhung
15-03-2005, 19:35
trời ơi,cứ như các bác noi thì em học VC là sai lầm à,thế mà em đang cắm cổ học VC,hic hic.Không ngờ lại xui xẻo vậy.Nhưng theo như các bác nói thì các ngôn ngữ khác cũng rứa à,vậy thì dân ta biết học gì,hay là học ASM nhi,các bác cho ý hiến đi...

bichduyen_nt
15-03-2005, 23:25
Wow, có gì đâu mà phản đối ghê vậy hén, học VC cũng thú vị lắm đó, cái gì cũng phải bắt đầu mà, giống như ai mới đâu vô cũng phải cắm đầu cắm cổ vô học Pascal hay C, mà thiệt ra thì thực tế bây giờ có mấy ai xài nữa đâu, học thêm một ngôn ngữ là biết thêm nhiều điều mà, mà hình như bây giờ Java đang mạnh hén, để học VC xong rồi học Java thử, hè ...
Mà Duyên thấy đọc quyển Lập trình Windows Bằng Visual C ++ của Đặng Văn Đức và Lê Quốc Dũng cũng được, khá là cơ bản, mới đọc khúc đầu thôi nên không biết khúc sau sao, hi hi, giá bìa là 40 000 nhưng nếu bạn đến tiệm sách ông già trước trường KHTH thì bạn chỉ phải trả 34 000 thôi (giống quảng cáo quá ^_^)

shuto_uke
17-03-2005, 10:15
Xin hỏi các bạn về lập trình Win32 API có thể được thể hiện trong các môi trường nào ( ngôn ngữ, hệ điều hành...). Môi trường Linux có chấp nhận không ?
Mình chỉ biết rằng MFC là các tập các lớp dựng sẵn của Win32 API để người dùng "dễ" hơn trong việc lập trình.
Mình thấy học MFC còn chuối hơn Win32 API, không biết có đúng không ? Mong các cao thủ chỉ bảo cho cách học tốt MFC !

imweasel
17-03-2005, 10:33
hip, đã có chữ "Win" vào rồi mà còn xài được trên linux sao ? :D

nói chung MFC giống như GUI với kéo và thả, còn Win32 API (về mặt nào đó) giống như Bash với Shell với commandline

nangluc
21-03-2005, 13:15
www.codeguru.com
www.codeproject.com

shuto_uke
25-03-2005, 11:21
Hê hê, Trần Lực đấy à.
hn_autumn_g đây !

ntmq
27-03-2005, 11:46
Sử dụng các hàm MFC làm cho công việc lập trình trên VC++ đỡ phải rắc rồi lắm đó.
Vd như công việc trừ 2 ngày để tìm khoảng cách giữa 2 ngày có thể làm trực tiếp như sau : int n = ngay1 - ngay2; khi sử dụng các hàm MFC. Nếu không dùng vẫn có thể làm được nhưng rất rắc rối.

ntmq cần 1 số hàm khi khai báo 1 chuỗi kiểu CString.
1. Hàm tìm vị trí 1 kí tự trong chuỗi.
2. Hàm trích chuỗi từ 1 vị trí sang phải hoặc trái
3. Hàm biến chuỗi thành số và ngược lại.
ntmq cũng đang tìm nhưng chưa tìm ra, các bác giúp với nhen.

Kijuto Riddle
27-03-2005, 11:55
MFC - Microsoft Foundation Class: là thư viện các lớp đối tượng phần lớn là phục vụ lập trình GUI. Nhiều người nhấm lẫm MFC là công cụ kéo thả để thiết kế GUI, thật ra MFC chỉ là một đống (rác) class được Microsoft phát triển hỗ trợ lập trình viên thiết kế giao diện trên win.

shuto_uke
28-03-2005, 09:08
Có bài viết sau nhặt ở trên mạng, các bác tham khảo thêm:

Why you should learn the API before MFC

The Controversy
Too many people come on to IRC and ask "What is better, MFC or API?" and too many people are willing to say "MFC sucks" or "API sucks" either because of traumatic events involving one or the other in early childhood, or because everyone else is saying it.
The standard arguments are:
- API is too hard
- MFC is too confusing
- API is too much code
- MFC is bloated
- API doesn't have wizards
- MFC is badly designed
- API isn't Object Oriented
- MFC kicked my dog
- API stole my girlfriend
And so on...

My Answer
My opinion, although by no means the only one, is that you should use the right framework for
the right job.
First of all a clarification on what the API and MFC are. API is a generic term meaning
Application Programming Interface, however in the context of Windows programming, it means
specifically the Windows API, which is the lowest level of interaction between applications and
the windows operating system. Drivers of course have even lower levels, and different sets of
function calls to work with, but for the vast majority of windows development this is not an issue.
MFC is a Class Library, it's a bunch of C++ classes that have been written to reduce the amount of work it takes to do certain things with the API. It also introduces an (arguably) Object Oriented framework into the application that you can either take advantage of or ignore, which is what most beginners do since the framework isn't really aimed at writing MP3 players, IRC clients or games.
Every program, whether it is written with MFC, Delphi, Visual Basic, perl, or any other wacked out language or framework you can think of, is eventually built upon the API. In many cases this interaction is hidden, so you don't deal directly with the API, the runtime and support libraries do it for you. Some people ask, "MFC can do Blah Blah Blah, can the API?" The answer is that MFC can only do what the API can do, because it's built on top of it. However doing things yourself with the API may take considerably more code than using the pre-written MFC classes.
So what is the right framework? For starters, for people that are just learning to program, I strongly believe that you should work with the API untill you are comfortable with the way windows applications work and you understand all of the basic mechanics behind things like the message loop, GDI, controls, and maybe even multithreading and sockets. This way you will understand the fundamental building blocks of all windows applications, and can apply this common knowledge to MFC, Visual Basic, or whatever other framework you choose to work with later. It's also important because these other frameworks don't support everything that the API does, simply because it does a whole lot and they can't necessarily support all of the arcane little things that most people won't use. So when you finally do need to use them you need to add it yourself, you can't rely on the framework to do it for you and if you don't understand the API this could be quite the chore.
But isn't MFC easier? In a certain sense it's easier in that many common tasks are done for you, thus reducing the amount of code that you need to actually type. However, less code does not mean "easier" when you don't understand the code you DO need to write, or how all of the code that is there to support you actually works. Generally beginners who use the wizards to start there applications have no idea what most of the generated code does, and spend a great deal of time trying to figure out where to add things, or what changes to make to acheive a certain result. If you start your programs from scratch, either in the API or with MFC, then you know where everything is because you put it there, and you will only use features that you understand.
Another important factor is that most people that are learing the Win32 API for the first time don't already have a strong base in C++. To try and comprehend windows programming with MFC and learn C++ at the same time can be a monumental task. Although it's not impossible, it will take you considerably longer to become productive than if you already knew either C++ or the API.

So basically...
What it comes down to is that I think you should learn the API untill you feel comfortable with it, and then try out MFC. If it seems like it's making sense to you and saving you time, then by all means use it.
However, and this is important... if you work with MFC without understanding the API and then ask for help with something, and the answer you get is stated using the api (such as "Use the HDC provided in the WM_CTLCOLORSTATIC message") and you say "huh?" because you don't know how to translate an API subject into MFC on your own, then you are in trouble and people will get frustrated with you for not learning what you need to know before you try and use MFC.
I personally prefer to work with the API, it just suits me better, but if I were to write a database frontend, or a host for a set of ActiveX controls I would seriously consider using MFC, as it would eliminate a lot of code that I would need to reinvent otherwise.

ntmq
22-04-2005, 16:55
sao cũng được nhưng hiện giờ mình đang phải tìm hiểu về MFCvì yêu cầu ở trường là như vậy.

Mình mong các bác giúp đỡ mình 1 câu hỏi thôi :(không liên quan đến MFC)
Làm sao convert từ number sang String ? dùng hàm gì vậy các bác ?
Mình cũng có tra trong MSDN rồi, nó ra các hàm lung tung lắm không hiểu gì hết.

Mình dùng hàm này là để kết hớp với sử dụng CString.
Xét vd sau :
Mình cần xuất ra câu " Tang thu n duoc di chuyen tu A sang B"
ở đây n là 1 biến mình tính toán và đưa vào đó. Tất nhiên mình dùng hàm xuất riêng chứ không xuất ngay trong lúc xử lý, dó đó tất cả các thông tin về tầng nào được di chuyển sẽ gán vào 1 mảng kiểu CString, (mảng ở đây mình dùng CArray.\, các phần tử của mảng kiểu CString)
Sau đó mình có hàm xuất để xuất từng phần tử của mảng CString trên từng dòng.
Trên là vd thôi, các bác giải đáp giúp mình câu hỏi làm sao convert từ number sang String là được rồi.
Cám ơn bác nhiều.

imweasel
22-04-2005, 20:22
Mấy cái này có trên MSDN hết, bạn đã tìm chưa ?

Tôi nhớ không nhầm thì có thể sử dụng CString::Format

Hàm tương đương bên W32 API là wsprintf

Buffer limit của wsprintf là 1 kB, không biết bên CString thì ra sao

ntmq
22-04-2005, 21:41
CString::Format

void Format( LPCTSTR lpszFormat, ... );

void Format( UINT nFormatID, ... );

Parameters

lpszFormat

A format-control string.

nFormatID

The string resource identifier that contains the format-control string.

Remarks

Call this member function to write formatted data to a CString in the same way that sprintf formats data into a C-style character array. This function formats and stores a series of characters and values in the CString. Each optional argument (if any) is converted and output according to the corresponding format specification in lpszFormat or from the string resource identified by nFormatID.

The call will fail if the string object itself is offered as a parameter to Format. For example, the following code:

CString str = "Some Data";
str.Format("%s%d", str, 123); // Attention: str is also used in the parameter list.

will cause unpredictable results.

When you pass a character string as an optional argument, you must cast it explicitly as LPCTSTR. The format has the same form and function as the format argument for the printf function. (For a description of the format and arguments, see printf in the Run-Time Library Reference.) A null character is appended to the end of the characters written.

For more information, see sprintf in the Run-Time Library Reference.

Example

CString str;

str.Format(_T("Floating point: %.2f\n"), 12345.12345);
_tprintf("%s", (LPCTSTR) str);

str.Format(_T("Left-justified integer: %.6d\n"), 35);
_tprintf("%s", (LPCTSTR) str);

str.Format(IDS_SCORE, 5, 3);
_tprintf("%s", (LPCTSTR) str);


Output

If the application has a string resource with the identifier IDS_SCORE that contains the string "Penguins: %d\nFlyers : %d\n", the above code fragment produces this output:

Floating point: 12345.12
Left-justified integer: 000035
Penguins: 5
Flyers : 3

Lấy từ MSDN.

ntmq làm được rồi. Thanks imweasel nhiều.
Đây là đoạn code ví dụ của mình
int n = 123;
CString st;
st.Format("%5d",n);
cout<<st;
Kết quả là xuất ra là 123 và con số này ở dạng chuỗi.
Thật tình không tưởng tượng nổi, muốn chuyển đổi từ số sang chuỗi lẽ ra cần tra các hàm xử số vậy mà cái cần tra lại là CString::Format. Bo tay.

Không biết có bạn nào không biết MSDN online không ? Nếu đang ngồi tại tiệm net mà muốn tra MSDN thì các bạn vào msdn.microsoft.com