#include "resource.h"
#include <windowsx.h>
#include <windows.h>LRESULT CALLBACK windpro(HWND, UINT, WPARAM, LPARAM);
TCHAR qq[4];
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
HWND hDialog;
MSG msg;
hDialog = CreateDialog(hInstance,MAKEINTRESOURCE (IDD_DIAL),0,(DLGPROC )windpro);
if (!hDialog)
{
//formats and stores a series of characters and values in a buffer
MessageBox(0,"error","CreateDialog",MB_ICONEXCLAMATION | MB_OK);
return 1;
}ShowWindow(hDialog, nCmdShow);
UpdateWindow(hDialog);
while (GetMessage(&msg,0,0,0))
{
if (!IsDialogMessage(hDialog,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return FALSE;
} LRESULT CALLBACK windpro(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
static unsigned int hour,minute;
static BOOL begin=FALSE;
static HINSTANCE hInstance;
static HMENU htaskmenu;
UINT uID;
POINT point;
UINT uMsg;
NOTIFYICONDATA nid;
nid.cbSize =sizeof(NOTIFYICONDATA);
nid.uID =IDI_CON;
nid.hIcon =LoadIcon(hInstance,LPSTR(IDI_CON));
nid.hWnd =hDlg;
nid.uCallbackMessage =WM_NOTIFYCON;
nid.uFlags =NIF_MESSAGE|NIF_ICON|NIF_TIP;
switch (message)
{
case WM_INITDIALOG:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;//初始化获得程序实句柄。
//
htaskmenu=LoadMenu(hInstance,"IDR_MENU1");//读入菜单,获得菜单句柄。
htaskmenu=GetSubMenu(htaskmenu,0);
return 0;
case WM_NOTIFYCON:
uID=wParam;
uMsg=lParam;
if(uID==IDI_ICON1)
{
switch(uMsg)
{
case WM_RBUTTONDOWN:
GetCursorPos(&point);
TrackPopupMenuEx(htaskmenu,TPM_VERTICAL|TPM_LEFTALIGN,point.x,point.y,hDlg,NULL);
break;
}
}
return 0;
case WM_CLOSE:
DestroyWindow(hDlg);
return 0;
case WM_DESTROY:
Shell_NotifyIcon(NIM_DELETE,&nid);
PostQuitMessage(0);
return 0;
default:
return FALSE;
}
} 上段的程序编译并没有错,但一运行就出错了,如果把
switch(..)
{
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;//初始化获得程序实句柄
上面的这句注消掉就行了,为什么会这样?请高手指教一二。
}
#include <windowsx.h>
#include <windows.h>LRESULT CALLBACK windpro(HWND, UINT, WPARAM, LPARAM);
TCHAR qq[4];
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
HWND hDialog;
MSG msg;
hDialog = CreateDialog(hInstance,MAKEINTRESOURCE (IDD_DIAL),0,(DLGPROC )windpro);
if (!hDialog)
{
//formats and stores a series of characters and values in a buffer
MessageBox(0,"error","CreateDialog",MB_ICONEXCLAMATION | MB_OK);
return 1;
}ShowWindow(hDialog, nCmdShow);
UpdateWindow(hDialog);
while (GetMessage(&msg,0,0,0))
{
if (!IsDialogMessage(hDialog,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return FALSE;
} LRESULT CALLBACK windpro(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
static unsigned int hour,minute;
static BOOL begin=FALSE;
static HINSTANCE hInstance;
static HMENU htaskmenu;
UINT uID;
POINT point;
UINT uMsg;
NOTIFYICONDATA nid;
nid.cbSize =sizeof(NOTIFYICONDATA);
nid.uID =IDI_CON;
nid.hIcon =LoadIcon(hInstance,LPSTR(IDI_CON));
nid.hWnd =hDlg;
nid.uCallbackMessage =WM_NOTIFYCON;
nid.uFlags =NIF_MESSAGE|NIF_ICON|NIF_TIP;
switch (message)
{
case WM_INITDIALOG:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;//初始化获得程序实句柄。
//
htaskmenu=LoadMenu(hInstance,"IDR_MENU1");//读入菜单,获得菜单句柄。
htaskmenu=GetSubMenu(htaskmenu,0);
return 0;
case WM_NOTIFYCON:
uID=wParam;
uMsg=lParam;
if(uID==IDI_ICON1)
{
switch(uMsg)
{
case WM_RBUTTONDOWN:
GetCursorPos(&point);
TrackPopupMenuEx(htaskmenu,TPM_VERTICAL|TPM_LEFTALIGN,point.x,point.y,hDlg,NULL);
break;
}
}
return 0;
case WM_CLOSE:
DestroyWindow(hDlg);
return 0;
case WM_DESTROY:
Shell_NotifyIcon(NIM_DELETE,&nid);
PostQuitMessage(0);
return 0;
default:
return FALSE;
}
} 上段的程序编译并没有错,但一运行就出错了,如果把
switch(..)
{
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;//初始化获得程序实句柄
上面的这句注消掉就行了,为什么会这样?请高手指教一二。
}
估计是初始化还没有开始hInstance不存在吧."获得程序实句柄。"??---为什么这么做呢.直接用hInstance就OK了,hInstance是WinMain的参数阿.