HINSTANCE and Help
I have to questien.
1. I have start programing c++ with windows platform and I am wondring what HINSTANCE is.
2. The second thing I am wondring is why my program jumps out as son as I use any menu. Here is the code:
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_STUFF_GO:
MessageBox(NULL, "Go where?", "Go", MB_OK);
break;
case ID_HELP_ABOUT:
MessageBox(NULL, "This program was made by Jonatan Tingström", "About", MB_OK);
break;
case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
}
I know why the exit jumps out but why does About and GO do it??
Mullvad
Mullvad
HINSTANCE is a handle to a module - typically your program itself. Most often you''ll see it passed as a parameter to resource retrieval functions. You can store the value for your program obtained from WinMain or you can also call GetModuleHandle(NULL) - even though that function returns HMODULE. The two types are the same in 99% of cases.
What to you mean by "jumps out"? That snippet looks fine - the problem might be found some other place.
‘But truth's a menace, science a public danger.’ Brave New World, Aldous Huxley
What to you mean by "jumps out"? That snippet looks fine - the problem might be found some other place.
‘But truth's a menace, science a public danger.’ Brave New World, Aldous Huxley
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Maybe the program is exiting because code execution is falling through from WM_COMMAND to whatever is being handled after it? ..maybe WM_CLOSE? you might be missing an additional break; from the scope of WM_COMMAND?
-Z
I have fixed the problem the problem why the program keept jumping out it was a break; i hade forgot so the program jumped to a exit case. But i didnt under stand your explanasion on HINSTANCE cant ypu explain it a little more easyer like if you were explaining it for a child. Its becuse my english isnt so good but thanks anyway for the answer.
Mullvad
Mullvad
Mullvad
When a window is created, an ID code is made for it that represents that unique window. That code is stored in HINSTANCE (a handle to an instance of the window) so that in your Windows program you can uniquely identify what window you want to perform an operation on.
Danny
Danny
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement