#define IDC_BUTTON1 100首先 我用的是
WM_COMMAND:
if(LOWORD(wParam)==IDC_BUTTON1)//这里根据按钮ID来判断是否点击,也可以根据句柄来判断
SendMessage(hwnd,WM_CLOSE,0,0);//点击按钮退出窗口但是调试 我发现 wParam 是0后来 我又把 wParam 改成了 lParam 调试发现lParam的值是 2080898816
LOWORD(lParam)的值是65280,压根就不是我期望的100,是怎么回事情呢
wParam 和 lParam 有什么区别,到底 该用哪个?
当然 我把判断语句去掉 窗口关闭还是能行的那个判断语句 我到底哪里用错了,付代码:#include "stdafx.h"
#include "browse.h"// forward defines (instead of using string tables)
#define IDS_APP_TITLE TEXT("Browse")
#define IDS_START_PAGE TEXT("file://\\Program Files\\Browse\\start.html")
#define WM_LAUNCHBROWSER (WM_USER + 1)
static HWND hwndButton;
static int cxClient,cyClient,cxChar,cyChar;
// Global Variables:
HINSTANCE g_hInst; // The current instance
int a;
#define IDC_BUTTON1 100
// Forward declarations of functions
ATOM MyRegisterClass(
HINSTANCE,
LPTSTR
);
BOOL InitInstance(
HINSTANCE,
int
);
LRESULT CALLBACK WndProc(
HWND,
UINT,
WPARAM,
LPARAM
);
//
// FUNCTION: WinMain()
//
// PURPOSE: Entry point for the application and sets up the Msg loop
//
int showhtml( LPTSTR filename )
{
HINSTANCE hInstance;
int nCmdShow=SW_SHOWMAXIMIZED;
MSG msg;
// Perform application initialization:
if (FALSE == InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
// Main Msg loop:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow
)
{
showhtml((LPTSTR)IDS_START_PAGE);
/*
MSG msg;
// Perform application initialization:
if (FALSE == InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
// Main Msg loop:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
*/
}//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(
HINSTANCE hInstance,
LPTSTR szWindowClass
)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BROWSE));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(
HINSTANCE hInstance,
int nCmdShow
)
{
HWND hWnd = NULL;
g_hInst = hInstance; // Store instance handle in our global variable
//If it is already running, then focus on the window
hWnd = FindWindow(IDS_APP_TITLE, IDS_APP_TITLE);
if (NULL != hWnd)
{
SetForegroundWindow (hWnd);
return FALSE;
}
MyRegisterClass(hInstance, IDS_APP_TITLE);
RECT rect;
GetClientRect(hWnd, &rect);
// create a full-screen window for the browser control
hWnd = CreateWindow(IDS_APP_TITLE, IDS_APP_TITLE, WS_VISIBLE,
0,50, 240, 320,
NULL, NULL, hInstance, NULL);
if (NULL == hWnd)
{
return FALSE;
}
HWND hRet = CreateDialog(hInstance, (LPCTSTR)IDD_MAIN_DLG,NULL, NULL);
if(hRet == NULL)
{
::MessageBox(NULL,_T("fail!"),_T("test"),MB_OK);}ShowWindow(hRet, SW_SHOW);
// Hide all the Shell parts and show the window in full screen mode.
//SHFullScreen(hWnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON); //ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_NOTIFY - Handle specific system notifications
// WM_CREATE - This code runs when the app starts
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit Msg and return
// WM_LAUNCHBROWSER - This code starts the browser control and loads a start page
//
//
LRESULT CALLBACK WndProc(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam)
{
WCHAR wszURL[1000];
HWND hWndHtml; switch (Msg)
{case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
cxChar=LOWORD(GetDialogBaseUnits());
cyChar=HIWORD(GetDialogBaseUnits());
return 0; case WM_CREATE:
// launch the browser control on startuphwndButton = CreateWindow(L"button"
,L"OK",WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,50, 150, 60,30,hWnd ,
NULL, g_hInst ,NULL);
PostMessage(hWnd, WM_LAUNCHBROWSER, NULL, NULL);
break;case WM_COMMAND :
a= LOWORD(lParam);
if( a == IDC_BUTTON1)//这里根据按钮ID来判断是否点击,也可以根据句柄来判断
SendMessage(hWnd,WM_CLOSE,0,0);//点击按钮退出窗口
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LAUNCHBROWSER:
// the only function call required to create a browser control instance
if (TRUE == InitHTMLControl(g_hInst))
{
// create the window for the control
hWndHtml = CreateWindow(TEXT("DISPLAYCLASS"), NULL, WS_VISIBLE, 20, 20,
24, 21,
hWnd, NULL, g_hInst, NULL);
ShowWindow(hWndHtml, SW_SHOW);
UpdateWindow(hWndHtml);
// load the start page into the browser window
SendMessage(hWndHtml, DTM_NAVIGATE, 0, (LPARAM)(LPTSTR)IDS_START_PAGE);
}
else
{
MessageBox(hWnd, TEXT("Unable to Launch Browser"), TEXT("Browser Control Problem:") , NULL);
DestroyWindow(hWnd);
}
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
解决方案 »
- 上位机
- 谁有UDP可靠传输文件的代码?
- debug正常运行,release出错
- 如何在一个位图背景上绘制图形,并且视图窗口大小改变、出现对话框覆盖视图窗口等等情况下,绘制的图形不会消失?(
- 用vc来提取电脑眼中的视频数据到底放在什么地方了?用什么函数?
- 哪里有vc的项目可以开发
- 为什么将一个文本文件的内容加入一个CEDIT 编辑框时总是有乱码出现.请看细节
- 关于自定义数据类型的问题(在线等待)
- 我在单位的主域服务器上用rc=SQLConnect(hdbc,server,SQL_NTS,uid,SQL_NTS,pwd,SQL_NTS);访问数据库,但是改成了独立管理器的形式就不能访问了。那是为什么?
- 关于GIMP
- 如何正确使用VC6.0的MSDN
- 结贴送分了
lparam中存放的是窗口句柄
你再试试这个(可能是你的顺序搞错了):
if(HIWORD(wParam)==IDC_BUTTON1)
,L"OK",WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,50, 150, 60,30,hWnd ,
NULL, g_hInst ,NULL);//(HMENU)IDC_BUTTON1
wID = LOWORD(wParam); //低位才是控件的ID
hwndCtl = (HWND) lParam;//控件的句柄wNotifyCode
Value of the high-order word of wParam. Specifies the notification code if the message is from a control. If the message is from an accelerator, this parameter is 1. If the message is from a menu, this parameter is 0.
wID
Value of the low-order word of wParam. Specifies the identifier of the menu item, control, or accelerator.
hwndCtl
Handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL. 以上来自MSDN