在网上看了一些简单的SDK教程,好多人都是将Dialogproc回调函数参数放在winmain函数内,但自己在写的时候放在winmain函数的时候就显示本地函数定义是非法的,请大家指点一下。
#include <windows.h>
#include "resource.h"
INT_PTR CALLBACK DialogProc1(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam
);int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
INT_PTR CALLBACK DialogProc1(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
return 0;
}
return 0;
}
1>------ 已启动生成: 项目: test1, 配置: Debug Win32 ------
1>正在编译...
1>main.cpp
1>e:\c++练习\test1\main.cpp(56) : error C2601: “DiaProc”: 本地函数定义是非法的
#include <windows.h>
#include "resource.h"
INT_PTR CALLBACK DialogProc1(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam
);int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
INT_PTR CALLBACK DialogProc1(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
return 0;
}
return 0;
}
1>------ 已启动生成: 项目: test1, 配置: Debug Win32 ------
1>正在编译...
1>main.cpp
1>e:\c++练习\test1\main.cpp(56) : error C2601: “DiaProc”: 本地函数定义是非法的
#include "stdafx.h"
#include "windows.h"
#include <crtdbg.h>
#include "resource.h"
LRESULT CALLBACK DiaProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
static TCHAR szAppName[] = TEXT("HelloWin"); HWND hWnd;
MSG msg;
TCHAR name[10]; /* 存储到时间控件的数字 */ g_version = GetVersion(); /* 得到版本 */ hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)DiaProc);
_ASSERT(IsWindow(hWnd)); // 给时间控件插入元素
for (int count = 0; count < 60; count++)
{
if (count <= 9)
{
wsprintf(name, "0%d", count);
SendMessage(GetDlgItem(hWnd, IDC_HOUR), CB_ADDSTRING, 0, LPARAM(name));
SendMessage(GetDlgItem(hWnd, IDC_SECOND), CB_ADDSTRING, 0, LPARAM(name));
SendMessage(GetDlgItem(hWnd, IDC_MINUTE), CB_ADDSTRING, 0, LPARAM(name));
} // End if (count <= 9)
else
{
wsprintf(name, "%d", count);
if (count < 24)
{
SendMessage(GetDlgItem(hWnd, IDC_HOUR), CB_ADDSTRING, 0, LPARAM(name));
}
SendMessage(GetDlgItem(hWnd, IDC_SECOND), CB_ADDSTRING, 0, LPARAM(name));
SendMessage(GetDlgItem(hWnd, IDC_MINUTE), CB_ADDSTRING, 0, LPARAM(name));
} // End else
} // End for (int count = 0; count < 60; count++) ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd); while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK DiaProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
TCHAR time[50]; /* 格式时间 */
SYSTEMTIME st; /* 时间 */
static NOTIFYICONDATA notify; /* 托盘数组 */
static int hour = 0, minute = 0, second = 0; /* 设置小时,分钟,秒 */
static BOOL ok = FALSE; /* 是否开始,TRUE为开始标志,FALSE为不能开始标志 */
switch (uMsg)
{ case WM_INITDIALOG:
{
//给托盘结构初始化
notify.cbSize = sizeof(NOTIFYICONDATA);
notify.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON1));
notify.hWnd = hwnd;
strcpy(notify.szTip, ("定时关机程序"));
notify.uCallbackMessage = WM_ICON;
notify.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
notify.uID = IDI_ICON1;
// 得到时间
GetLocalTime(&st);
GetTimeFormat(NULL,
TIME_FORCE24HOURFORMAT,
&st,
"HH':'mm':'ss'",
time,
sizeof(time)
);
DialProc(HWND hwnd,......);int WinMain (....)
{
return 0;
}DialProc(HWND hwnd,......)
{
return 0;
}这样子就好了。