|
I saw a code chunk like this:
// MP3FRAMEHEADER structure
struct MP3FRAMEHEADER
{
unsigned emphasis : 2; // M
unsigned original : 1; // L
unsigned copyright : 1; // K
unsigned modeext : 2; // J
unsigned chanmode : 2; // I
unsigned privbit : 1; // H
unsigned padding : 1; // G
unsigned samplerate : 2; // F
unsigned bitrate : 4; // E
unsigned hascrc : 1; // D
unsigned mpeglayer : 2; // C
unsigned mpegver : 2; // B
unsigned framesync : 11; // A
};
There,the number like 2,1,1,... means what?
It does not look like the initialized number of its front member?
Who would like to tell why the writer coding like above?
Thanks.
GOOD LUCK!
|
|
|
|
|
|
It is called as bit-fields. Have a look at link provided by Nitin.
Prasad
MS MVP - VC++
|
|
|
|
|
Oh,I see.
Thank you very much.
|
|
|
|
|
I know it now.
Thank you very much.
BEST WISHES.
|
|
|
|
|
All the values following “:” are just instructions to the compiler. They tell it to pack the variable into that number of bits. What that means, in the code you presented, is that the entire structure is stored in 32 bits, because it only requires 31 bits (it will be slower, but take up less memory).
Well that is enough for you to figure it out. Apparently the writer did not expect more than two versions of the code, because he only allowed one bit for that.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Hi,
I've been trying to figure out how to get the owner process or a window.
Basically, I want to use GetForegroundWindow() to identify the current window that has focus and then be able to, from this, get the process that owns the window. It should be possible as it's the very same thing Task Manager does.
If anyone knows how to do it, I'd be grateful.
Thanks.
|
|
|
|
|
The GetWindowThreadProcessId() API can help.
This came up recently here and I can't remember how to get the name from the process ID.
I think you need to enumerate the processes on the system and find the one that matches the ID.
A couple ways to enumerate processes:
CreateToolhelp32Snapshot()/Process32First()/Process32Next()
Use WMI and the Win32_Process class
Tydia-kun wrote: It should be possible as it's the very same thing Task Manager does.
I'm not sure why task manager would use window handles to find processes when there's many
methods available for enumerating processes and task manager also shows processes that don't
have any windows. I'd guess that task manager uses WMI.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I'd guess that task manager uses WMI.
Nah... probably DDE... so a couple tin cans and some string. But you can't find the documentation online because it was chiseled into stone tablets.
|
|
|
|
|
I had to sign a NDA for Microsoft so I'm not allowed to talk about The Stone Tablets.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Found some additional info on getting the exe name from the process ID
See the second Q/A here[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
If you persist in this reading of the documentation I am going to suggest that Maunder revoke your membership.
or
NOT FAIR! Getting answers from the documentation! It's not like we all have access to that!
|
|
|
|
|
led mike wrote: It's not like we all have access to that!
Thank goodness! it's job security!!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I've thought of getting the handle, then enumerating processes and trying to enumate windows for those processes and matching the handles, but that's seems just so far fetched. Isn't there an easier way?
|
|
|
|
|
The link I posted shows a way to do it without enumerating. The caveat is it's for NT 4+.
For Windows versions back to 95, it seems to me it would be simpler to get the process ID from the window
handle and enumerate the processes until you find the matching ID.
Much less work than enumerating the processes AND enumerating the windows for each process!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Sure, I'll use it if there's no better way, but it's pretty much the same - get the handle and compare it to the process's handles, if I read correctly.
There has to be a way to get a process handle from a window handle. A process must own that window, and it's possible to enumerate a process's windows, so why not the other way?
|
|
|
|
|
Tydia-kun wrote: There has to be a way to get a process handle from a window handle.
See the first sentence in my first reply[^]
To get a handle from the ID, open one with OpenProcess().
led mike's not going to like this, but there's a whole bunch of process-related
APIs to play with - they're documented ... Process and Thread Functions[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a window handle, but not a process id or process handle, because I don't know how to get either from a WINDOW handle.
I know there's lots of functions and I've looked over them once or twice, but there's no function that returns a process id or handle from a window handle from what I can see.
|
|
|
|
|
Tydia-kun wrote: but there's no function that returns a process id or handle from a window handle
Mark wrote a couple times: GetWindowThreadProcessId
Once again, it was in the first reply, first sentence
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I really must have missed it or interpreted the message wrong.
Thanks again.
This non-linear way of showing posts in this forum really makes a mess out of things -_-
|
|
|
|
|
No problem!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Tydia-kun wrote: This non-linear way of showing posts in this forum really makes a mess out of things -_-
Yeah, I guess there's a problem with the way MS does the documentation as well, I wonder why the rest of us are ok with all this.... hmmmm maybe we CAN READ!
This loser could use some Led Zeppelin[^]
|
|
|
|
|
Also, your first post, to me, implied you had the window handle already.
That's why I ask why enumerate every window when you have it already?
Don't you just need the information for the process that created that window?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes, I have the hwnd. But as I mentioned, unless there's a way to get the process id or handle from a hwnd, I need to enumerate all processes and enumerate all their windows and compare those handles to the handle for the window I want to find, thus finding the owning process.
Get me?
|
|
|
|
|
GetWindowThreadProcessId()
GetWindowThreadProcessId()
GetWindowThreadProcessId()
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|