Do Dialog (SDK Version) from Zero - Details in VC + MSDN

zhaozj2021-02-16  51

(Generally, it is very simple to be a Dialog, so this tutorial is written to beginners. However, due to the space limit, it is not introduced to the form process or event driver.) Ok, the words retired. Let's do it right away. Open your VC6 (if there is a project, please callspace), select New Project (Win32 Application - An Empty Project, remember to select the save path), then create a .cpp file (such as Winmain.cpp) in the path, last Where there is Add Files to Project, select Add Files To Project, join the newly created Winmain.cpp to the project. Ok, you have a project file now, if you want to join your own definition dialog, you have to make a resource file, and include it in your project, just like WinMain.cpp. In the VC6 menu "Insert" - "Resource ... Ctrl R", it is necessary to join a Dialog, select "New" (not IMPORT). Then you can get a dialog of a default template, just set some properties to this new Dialog (Double-click the title bar to which the dialog can get the dialog box for setting the property), say, the ID: the default Is IDD_DIALOG1, you change it to "mydialog" (please remember to add double quotes to ID, the default is no quotation, this is to do not contain resource.h's header file); follow you like To change the title, fill in the MY First Dialog in Caption:. Ok, the rest is saved. Please select Save All, select Save the resource file in your project (I choose Resource.rc). Ok, now the resource file has already been, the rest is to join it into the project, and the method can refer to WinMain.cpp, no longer tap (add) in FileView).

Ok, the rest of the following is to edit your Winmaiin.cpp, and it is also where I can take it.

First, you must first join this sentence: #include . Then one line, type the F1 button after typing WinMain. Have you seen MSDN? The definition and parameter of WinMain can be copy, it is ok, it will be used. Delete the Winmain just typed, replace it from the MSDN COPY. It can be the following look (also add RETURN 0; statement).

#include

int WINAPI WinMain (HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state) {// you can insert your code here return 0; }

Ok, you try to compile it, see if you can compile it? OK? The first step is successful. Now the function entry is finally coming, but if you have a dialog, you need a dialog of the Callback process. Here is a small way to take a small way. This process is actually a function. If you want to use in WinMain, you must define before WinMain. Then please enter DialogProc before the definition of WinMain, then enter DialogProc and press F1 again, Call out MSDN. Haha, the definition and parameters of DialogProc can be copied. Instead of you just typed DialogProc it through after processing as in the following way: INT_PTR CALLBACK DialogProc (HWND hwndDlg, // handle to dialog box UINT uMsg, // message WPARAM wParam, // first message parameter LPARAM lParam // second message Parameter) {// You can insert your code in this return 0;} This is not, you have to process the message, add the following sentence: Switch (umsg) {case wm_command: if (loword (wparam) == idok) Enddialog (hwnddlg, 0); if (loword (wparam) == idcancel) enddialog (hwnddlg, 0);

There is only one thing left, that is, call the Dialogbox function in WinMain, (Detailed parameters, see MSDN) is also written there in the first sentence inside WinMain:

DialogBox (Hinstance, "MyDialog", NULL, (DLGPROC) DialogProc);

It is now fully compiled and called. Try it, how is the effect? Is it simple to come and look more professional? ? Hahaha, it is actually satisfied with a little lazy psychology that I have (not really skillfully! It was cheated ....). Detailed code is seen below,

// WinMain.cpp source program #include

INT_PTR CALLBACK DIALOGPROC (HWND HWNDDLG, // Handle to Dialog Box Uint UMSG, // Message WParam WPARAM, // First Message Parameter LParam Lparam // Second Message Parameter) {Switch (UMSG) {

Case WM_COMMAND: IF (WPARAM) == iDok) enddialog (hwnddlg, 0); if (loword (wparam) == idcancel) Enddialog (hwnddlg, 0);

} // end of switch (umsg)

Return 0;}

int WINAPI WinMain (HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state) {DialogBox (NULL, "MYDIALOG", NULL, (DLGPROC) DialogProc); return 0;} // end of source file

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

New Post(0)