|
I am not after a ckeckbox list, all i want to do is to read a checkbox value from database and display it accordingly (true/false) in a list box. I am able to read rest of the fields but not the check box...
any help would be nice
thanks
Gpat
|
|
|
|
|
GPat24 wrote: ...all i want to do is to read a checkbox value from database...
It is a BOOL , which is actually an int .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello,
I have a Win32 dialog that is created using CreateDialog and dlgProc is the call back method for that dialog. I have n number of controls on the dialog. When i click on any control the dlgProc receives WM_COMMAND only after mouse click is released. I have scenario where something has to be done on mouse press and some other thing on mouse relese. i am unable to implement this. Any help would be appreciated.
Thanks,
Hari krishna.
|
|
|
|
|
WM_COMMAND comes about because of the detection of a WM_LBUUTONDOWN followed by a WM_LBUTTONUP occuring on the same control. Handle those messages yourself instead of the WM_COMMAND.
Judy
|
|
|
|
|
Thanks Judy. I tried handling WM_LBUTTONDOWN for mouse press but this is called if user clicks on the window not on the controls on the window. If clicked on the controls (for ex: Button) dlgProc doesn't receive this message.
|
|
|
|
|
2 things
1) override OnParentNotify in the dialog class
2) remove the style WS_EX_NOPARENTNOTIFY from each of the dialog controls you want to receive messages for
Judy
|
|
|
|
|
You'll need to subclass the control(s) to intercept the appropriate mouse messages
before the control's window proc handles them.
Subclassing Controls[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello All,
Thanks for your reply.
I learnt that subclassing is nothing but having a call back method which handles events for the control.
I have one more question. I have 30 controls on the dialog, do i need to have a call back method for every control or can i handle events related to all the controls in one call back method.
Thanks,
Hari krishna.
|
|
|
|
|
Adarapu Harikrishna wrote: do i need to have a call back method for every control or can i handle events related to all the controls in one call back method.
With the old SetWindowLongPtr() subclassing method:
Different type controls may have different window procedure entry points so
if you use only one subclass WNDPROC, you'll need a way to call the correct
window proc for each control.
With the newer (XP+) SetWindowSubclass() subclassing method you can use one
SUBCLASSPROC since the system handles routing messages up the subclass chain when
you call DefSubclassProc().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello Mark,
I have a strange problem after subclassing the controls on the dialog. As you know we can view the caption of the control in Spy++ that comes with Visual Studio.
One of the control is a button and its caption is "&A", & is for shortcut. Before subclassing i could see the whole caption when i select this control in Spy++ and after subclassing i am able to see only "&". I am able to see the correct caption in the Properties of the button. So i am not sure where its going wrong?
Any ideas?
Thanks in Advance,
Hari krishna
|
|
|
|
|
I'm having trouble figuring out how to change the color of text in an edit control when it is disabled; such that the light grey (disabled) is black instead.
Let's just say I have an edit control ('IDC_EDIT1').
CFont font; //in header
font.CreatePointFont(280, "Arial Bold");
CWnd *pWnd = ((CWnd*)GetDlgItem(IDC_EDIT1);
pWnd->EnableWindow(FALSE); //disables window
//now I'd like to change the color of the text so it stays black.
Any help would be greatly appreciated.
|
|
|
|
|
What about making the edit control read-only instead of disabling it?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hrm, actually that a good idea; but, I don't know how to do that, either.
I searched the web a little and found ES_READONLY.
Further reading landed me EM_SETREADONLY.
As I understand it, I need to call SendMessage to the window (editcontrol)
I tried:
pWnd->SendMessage(EM_SETREADONLY);
and
pWnd->SendMessage(ES_READONLY);
But neither work - I am still able to edit the contents.
What am I missing?
thanks.
|
|
|
|
|
Like2Byte wrote: I tried:
pWnd->SendMessage(EM_SETREADONLY);
Try:
pWnd->SendMessage(EM_SETREADONLY, (WPARAM)TRUE);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ah, geez.
I'm going to go put my head in the sand. Gimme 10 minutes.
Sincerely, thanks for the help!
|
|
|
|
|
Like2Byte wrote: I'm going to go put my head in the sand.
Haha - that's the hard way to code!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: that's the hard way to code!
No, that's the new age way to code. Having your head in the sand, or other equally dark places, is fine as long as you keep typing!
led mike
|
|
|
|
|
Hi
I have a basic question about classic message loop of Win32 programs.
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Why doesn't this message loop take all processor time?
I also increment the priority level:
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
In another MFC application i created a new thread with infinite loop( I mean in function there is only "infinite while loop", as classic win32 message loop) and also set priority to THREAD_PRIORITY_HIGHEST. That loop blocked all other threads. But why doesn't win32 message loop block other threads?
Thanks.
|
|
|
|
|
sawerr wrote: Why doesn't this message loop take all processor time?
Because GetMessage() blocks until a message is available in the queue.
If you want it to spin and consume nearly all of the CPU time for a core,
use PeekMessage() instead of GetMessage().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Because GetMessage() blocks until a message is available in the queue.
Is this something like that:
GetMessage()
{
while(true)
{
if(queue == EMPTY)
Sleep(100);
}
}
|
|
|
|
|
We all would hope the Windows kernel is event driven, and not polling all the time.
|
|
|
|
|
OK, but how can its pseudo-code be?
|
|
|
|
|
Hi,
GetMessage() {
if(queue == EMPTY) {
queue.AddWaiter(currentThread);
SwitchToForemostReadyThread();
}
return queue.RemoveMsg();
}
PutMessage(Message msg) {
queue.AddMsg(msg);
if(queue.HasWaitersWithHigherPriority(myPriority)) {
Thread thread=queue.RemoveWaiter();
SwitchToThread(thread);
}
}
Not a single busy-wait or polling loop!
The heart in the matter is the SwitchTo...Thread() methods save the current thread
state on its stack, and load another thread's state from its stack, effectively
performing a "thread switch".
|
|
|
|
|
sawerr wrote: Is this something like that
No, not at all.
Within GetMessage(), there's something like
GetMessage(...)
{
WaitForSingleObject(QueuedMessageEvent)
return message to caller
}
If the event isn't signalled when GetMessage() is called,
WaitForSingleObject() puts the thread in a "wait state", a state
where the thread is almost completely suspended - it uses VERY little
CPU time.
Using Sleep as you've shown is extremely inefficient.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for answers. ![Rose | [Rose]](https://codeproject.global.ssl.fastly.net/script/Forums/Images/rose.gif)
|
|
|
|