打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
关于hinstance,该如何解决
关于hinstance
在winmain函数中有个hinstance参数,由系统传参,在给wndclass这个结构体填空时会有:
  WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclass.hIcon=LoadIcon(NULL,IDI_WINLOGO);
wndclass.hInstance=hInstance;//这一句不写则运行时,看不到窗口,但能在任务管理器里看到其进程,
  // wndclass.hInstance=NULL 当给其赋值空时,能正常运行。
  // wndclass.hInstance=hPreinstance(也就是winmain的第二个参数)这样也能正常运行,
希望各位大人给小弟我讲一个原因,我是新手;另外,winmain的几个参数到底有什么用,如何用,也请指点一二。

------解决方案--------------------
hinstance是这个应用程序的实例句柄,也就是系统将可执行文件的映象加载到进程空间的基本地址,如果需要程序内包含的资源的时候就需要这个实例句柄了。
第二个参数用于16位程序中,
第三个是程序执行参数。
第四个是程序的显示方式。
------解决方案--------------------
我用它作串口句柄
------解决方案--------------------
当你要用到你在rc文件里面定义的东西的时候,比如Icon,Bitmap,Dialog等等的时候。就要用到hInstance了。
------解决方案--------------------
msdn原文。。。
-------
The WinMain function is called by the system as the initial entry point for a Windows-based application. 

int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
);
Parameters
hInstance 
[in] Handle to the current instance of the application. 
hPrevInstance 
[in] Handle to the previous instance of the application. This parameter is always NULL. 
If you need to detect whether another instance already exists, create a uniquely named mutex using the CreateMutex function. CreateMutex will succeed even if the mutex already exists, but the GetLastError function will return ERROR_ALREADY_EXISTS. This indicates that another instance of your application exists, because it created the mutex first. 

lpCmdLine 
[in] Pointer to a null-terminated string specifying the command line for the application, excluding the program name. To retrieve the entire command line, use the GetCommandLine function. 
nCmdShow 
[in] Specifies how the window is to be shown. This parameter can be one of the following values. Value Meaning 
SW_HIDE Hides the window and activates another window. 
SW_MAXIMIZE Maximizes the specified window. 
SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order. 
SW_RESTORE Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window. 
SW_SHOW Activates the window and displays it in its current size and position.
SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window. 
SW_SHOWMINIMIZED Activates the window and displays it as a minimized window. 
SW_SHOWMINNOACTIVE Displays the window as a minimized window. 
This value is similar to SW_SHOWMINIMIZED, except the window is not activated.
 
SW_SHOWNA Displays the window in its current size and position. 
This value is similar to SW_SHOW, except the window is not activated.
 
SW_SHOWNOACTIVATE Displays a window in its most recent size and position. 
This value is similar to SW_SHOWNORMAL, except the window is not actived.
 
SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time. 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
孙鑫VC视频教程笔记之第一课“Windows程序的内部运行原理”
Win32编程基础知识_天空总是蓝色的
day01
想学习C/C 来写游戏程序么?大神告诉你游戏框架怎么写
演练:创建 Windows 桌面应用程序 (C++)
第一个真正的Windows程序(在C语言中程序都是黑屏的称为控制台程序(Console Application)这套教程要讲的是带界面的Windows程序(Windows Application)GU
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服