VC++函数(win32_exe)

1.windows输出,以对话框的方式。

int MessageBox( HWND hWnd, // handle to owner window

         LPCTSTR lpText, // text in message box

        LPCTSTR lpCaption, // message box title

        UINT uType // message box style);

UINT uType 表示消息盒子的款式,返回值表示选择了什么按键。

2.添加资源脚本,“文件”-》“新建”-》“file”

对应汉语版和英文版的Vc

资源脚本名字一般和工程名相同

3.右键插入资源

里面有各种资源类型Icon表示软件运行图标,编辑图标后直接编译即可。当有多个图标资源时,软件默认使用最小ID编号的图标

4.在资源中加入对话框后,编译但仍然没有显示,因为winMain中没有包含

5.导入图标,不用自己画了。是.ico格式

、、、、、、

6.DialogMox(IDD_DIALOG1,);调用对话框

7.消息回调函数:当在对话框中有任何点击按钮、输入内容等,都会调用回调函数。

8.使用OutputDebugString()在Debug窗口显示调试信息。

VOID OutputDebugString( LPCTSTR lpOutputString // string to be displayed

);

char s[256];
sprintf(s,"uMsg =%d ",uMsg);
OutputDebugString(s);

9.从对话框中中的控件中获取

UINT GetDlgItemInt(

HWND hDlg, // handle to dialog box--对话框句柄

int nIDDlgItem, // control identifier--具体控件id

BOOL*lpTranslated, // success state--一般都成功,NULL

BOOL bSigned // signed or unsigned value--有无符号TRUE(有符号),FALSE(无符号)

);

------------------------

将数值打印到指定窗口的指定控件

BOOL SetDlgItemInt(

HWND hDlg, // handle to dialog box--窗口句柄

int nIDDlgItem, // control identifier--控件ID

UINT uValue, // value to set--设置的值

BOOL bSigned // signed or unsigned indicator--有无符号

);

10.INT_PTR DialogBox(  //winMain中加载资源

HINSTANCE hInstance, // handle to module---入参为hInstance,winmain的第一个入参,进程句柄

LPCTSTR lpTemplate, // dialog box template---(LPCSTR)DLGID,要将DLGID强制转换为LPCSTR类型--窗口ID关联到回调函数中的句柄(DLGID<->)

HWND hWndParent, // handle to owner window---NULL,不依附于某个窗口

DLGPROC lpDialogFunc // dialog box procedure---回调函数,当对应的DLGID有任何操作都会调用此函数,类似中断

);

11.//定义一个回调函数,函数名自定

BOOL CALLBACK funProc1(
HWND hwndDlg, // handle to dialog box--窗口句柄
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)

12.关闭一个窗口 

BOOL EndDialog(

HWND hDlg, // handle to dialog box--要关闭窗口的句柄

INT_PTR nResult // value to return--返回值

);

13.调试时,局部变量要加断点才能看到调试过程中的值,不然程序快速飞过,啥都看不见

14.不使用控制台,改用对话框时,要用回调函数,消息机制。用户在界面任何操作,对应一种事件,调用消息回调函数,根据消息相关参数做响应的事。

15.主函数

int APIENTRY WinMain(

HINSTANCE hInstance,//资源总管
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,  //传入参,使用打开命令+ 程序名+参数
int nCmdShow  //用来设置程序是明着启动还是暗着启动,缺省为1

)

原文地址:https://www.cnblogs.com/fx427103/p/4023839.html