这是资源文件Res.rc//Microsoft Developer Studio generated resource script.
//
#include "resource.h"#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS/////////////////////////////////////////////////////////////////////////////
// Chinese (中国) resources#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#endif //_WIN32#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Cursor
//IDC_CURSOR CURSOR DISCARDABLE "cursor1.cur"/////////////////////////////////////////////////////////////////////////////
//
// Icon
//// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON ICON DISCARDABLE "icon1.ico"
QQ ICON DISCARDABLE "ico00001.ico"/////////////////////////////////////////////////////////////////////////////
//
// Menu
//WITHMENU MENU DISCARDABLE
BEGIN
POPUP "窗口操作"
BEGIN
MENUITEM "&关闭窗口", IDM_DESTROY
END
POPUP "关于"
BEGIN
MENUITEM "&作者", IDM_AUTHER
END
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
"ABOUT_ME", DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 180
TOPMARGIN, 7
BOTTOMMARGIN, 89
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//ABOUT_ME DIALOGEX 50, 50, 187, 96
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "作者信息"
FONT 14, "黑体"
BEGIN
DEFPUSHBUTTON "确定",IDOK,130,7,50,14
PUSHBUTTON "取消",IDCANCEL,130,24,50,14
CTEXT "汪俊",IDC_STATIC,105,47,68,27,0,WS_EX_STATICEDGE
ICON "QQ",IDC_STATIC,34,25,13,13
END#endif // Chinese (中国) resources
/////////////////////////////////////////////////////////////////////////////#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
#include <windows.h>
#include <stdio.h>
#include "resource.h"
BOOL CALLBACK DialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
char AppName[]="WithMenu";
MSG msg;
HWND hwnd;
WNDCLASS wnd; wnd.cbClsExtra=0;
wnd.cbWndExtra=0;
wnd.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wnd.hCursor=LoadCursor(hInstance,MAKEINTRESOURCE(IDC_CURSOR));
wnd.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON));
wnd.hInstance=hInstance;
wnd.lpfnWndProc=WindowProc;
wnd.lpszClassName=AppName;
wnd.lpszMenuName=AppName;
wnd.style=CS_HREDRAW | CS_VREDRAW; RegisterClass(&wnd); hwnd=CreateWindow(
AppName, // registered class name
AppName, // window name
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // horizontal position of window
CW_USEDEFAULT, // vertical position of window
CW_USEDEFAULT, // window width
CW_USEDEFAULT, // window height
NULL, // handle to parent or owner window
NULL, // menu handle or child identifier
0, // handle to application instance
NULL // window-creation data
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static HINSTANCE hInstance;
switch(uMsg)
{
case WM_CREATE:
hInstance=((LPCREATESTRUCT)lParam)->hInstance;
break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDM_DESTROY:
{
if(IDYES==MessageBox(hwnd,TEXT("是否退出?"),TEXT("退出确认"),MB_YESNO))
{
SendMessage(hwnd,WM_DESTROY,0,0);
}
else
{
MessageBox(hwnd,TEXT("continue"),TEXT("continue"),MB_OK);
}
break;
}
case IDM_AUTHER:
{
DialogBox(
hInstance, // handle to module
TEXT("About_Me"), // dialog box template
hwnd, // handle to owner window
DialogProc // dialog box procedure
);
break;
}
}
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
BOOL CALLBACK DialogProc (
HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch (uMsg)
{
case WM_INITDIALOG :
return TRUE ;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDOK:
case IDCANCEL:
EndDialog (hwndDlg, 0) ;
return TRUE;
}
break ;
}
return FALSE ;
}
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Res.rc
//
#define IDC_CURSOR 102
#define IDI_ICON 103
#define IDC_OK 1000
#define IDM_DESTROY 40001
#define IDM_AUTHER 40002// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 113
#define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_CONTROL_VALUE 1004
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
我的menu名字为:"WITHMENU"
我的Dialog名字为:"ABOUT_ME"
ico00001.ico和icon1.ico 能得到效果是
应用程序的大图标是ico00001.ico;窗口左上角图标是icon1.ico;鼠标图标是cursor1.CUR可能是你把图标文件的位置没放对,你要把它们和工程的**.dsw文件放在同一目录..
::SendMessage(m_hWnd, WM_SETICON, FALSE, (LPARAM)hIcon);
另外用SPY++查一下对话框上面有没有static控件,风格是不是SS_ICON。
IDC_CURSOR CURSOR DISCARDABLE "cursor1.cur" IDI_ICON ICON DISCARDABLE "icon1.ico"
QQ ICON DISCARDABLE "ico00001.ico"
并把它们放在和**.dsw同一目录下..
APPICON ICON DISCARDABLE "icon.ico"