共有三种方式:
1、声明一个全局的hInst变量,在WinMain里面hInst = hInstance
2、((LPCREATESTRUCT)lParam)->hInstance,通过CREATESTRUCT结构获得
3、hInst = GetWindowLong (hwnd, GWL_HINSTANCE);
ps: CREATESTRUCT结构包含了窗体创建初始化时的各种信息:
typedef struct tagCREATESTRUCT {
LPVOID lpCreateParams;
HINSTANCE hInstance;
HMENU hMenu;
HWND hwndParent;
int cy;
int cx;
int y;
int x;
LONG style;
LPCTSTR lpszName;
LPCTSTR lpszClass;
DWORD dwExStyle;
} CREATESTRUCT;