|
So do you need to respond to the WM_SETCURSOR message?
"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
|
|
|
|
|
How can I get the value of the alpha channel for every pixel in a bitmap?
danginkgo
|
|
|
|
|
Is this a bitmap in a file, from an HBITMAP?
There are loads of resources in MSDN that will help. If you start with GetDIBits, you can follow the documentation from there.
*IF* a bitmap has an alpha layer, it will be 4 bytes per pixel, one for R, G, B, and A respectively. (Ok, I'm pretty sure A comes first).
You can look at the bitmap header, and see 32 bits per pixel set.
It's quite a bit of fiddly work, but not rocket science.
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
OK, thank you for help.
danginkgo
|
|
|
|
|
I use ::GetOpenFileName instead CFileDialog to show the OpenFile Dialog.
accidently I found it(the dialog) a modeless dialog, user can click the button to show as many OpenFile Dialogs as she/he wants, this is not the thing I want.
Is it possible to make ::GetOpenFileName openfile Dialog modal?
|
|
|
|
|
You could try something like this perhaps: Code removed
Sandip's answer is the best way to go about it.
modified on Thursday, July 10, 2008 2:45 AM
|
|
|
|
|
Specify valid window handle in parameter hwndOwner
if you specify NULL it would create modless dialog.
i hope it helps.
Regards,
Sandip.
|
|
|
|
|
I always specify the hwndOwner, it doesn't work.
|
|
|
|
|
i tried this and it works fine for me.
void CTrialMFCDlg::OnOK()
{
OPENFILENAME ofn;
char szFile[260];
HWND hwnd;
HANDLE hf;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = this->GetSafeHwnd();
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn)==TRUE)
MessageBox("Open");
else
MessageBox("Cancel");
}
Regards,
Sandip.
|
|
|
|
|
And I found a misunderstanding problem, when I first show the openfile Dialog,
it just shows on the topmost corner in the screen(it means the openfile dialog shows in the (0,0) according the screen coordination).
But when show the openfile dialog after, it shows in the center relative to the main dialog.
Who can tell me why?
|
|
|
|
|
fantasy1215 wrote: the openfile dialog shows in the (0,0) according the screen coordination).
But when show the openfile dialog after, it shows in the center relative to the main dialog.
I see this behavior, only when the owner of the dialog opened is not specified. Specify the handle of your application's window as the owner of the dialog that you open.
|
|
|
|
|
Thanks all of you. I specify the wrong hwndOwner handle, I reCreate a simple project, it works fine.
BTW, is it possible to SetIcon for the ::GetOpenFileDialog dialog?
It always use the IDR_MAINFRAME icon.
|
|
|
|
|
Hi,
I have 2 threads in my app.
one is main application thread which has UI.
second is the worker thread.
second thread will get some status from a database and send the information to the main thread using SendMessageAPI. One of the parameters in the SendMessage API is a global variable across the threads.
After the recieving the message from second thread, first thread will display the error to the user and return the control so that the second thread can monitor the status continuously.
But at some point, my app hangs.
I suspect that the hang happens in this loop.
As the return depends on the response from the main thread (thru user input via messagebox), i could not use SendMessageTimeout API in this case.
1. Is it because of the global variable usage in SendMessage function?
Can you please let me know how can i come out of this problem.
Any help is appreciated.
Selva
|
|
|
|
|
Please post some code: from your worker thread when you send the message and from the main thread where you handle this message.
By 'hangs' you mean that your UI freeze completely and you can't do anything anymore with your app ?
|
|
|
|
|
Hi,
Thanks for the reply.
Code will look like below.
int g_nInt;
Main thread
LRESULT CMyDlg::OnProcessMsg(WPARAM wparam, LPARAM lparam)
{
Display Message box ....... Get result from user.
return 0;
}
Worker thread
{
get status from DB.
GetMainWnd()->SendMessage(PROC_MSG, wp, g_nInt);
.....
GetMainWnd()->SendMessage(PROC_MSG2, wp, lp);
.........
}
Yes. My main app window looks like freezed (continuous even after an hour).
Thanks in advance.
Selva
|
|
|
|
|
SendMessage is a blocking function: it will only return once the message has been processed by the other window. In your case, it will return only after the user has closed the MessageBox. You didn't provide enough code for me to verify this but you probably have a deadlock: your worker thread is waiting for the UI thread (because of the SendMessage function) which is in turn waiting for the worker thread.
If your design allows it, try with PostMessage instead of SendMessage: PostMessage puts the message in the message queue of the window and returns immediately.
|
|
|
|
|
Hi,
Thanks for the reply.
Main thread won't be waiting for the worker thread..
only if the second request from the worker thread comes, it will be processing.
But i too suspect that its because of the deadlock.
But my doubt is,
whether passing the global variable (which will be accessed by both the threads) causes this hang. any way storing the value in global variable will happen with proper locks from both the threads.
But whether passing this as the parameter to the SendMessage causes any problem?
Thanks in advance.
Selva
|
|
|
|
|
Sorry but your question is not really clear. Please post some more relevant code instead of explaining what your code does. Anyway, why do you pass the value in the message ? It is globally available so, there's no need to pass it in the message. But accessing this variable from two threads won't make your UI hang (unless you are using critical section to access it, then the problem might come from that).
SelvaKr wrote: any way storing the value in global variable will happen with proper locks from both the threads.
I'm not sure what that means but if you are using critical section, then this is probably the problem.
Did you try with PostMessage as I told you ? What happened ?
|
|
|
|
|
Hi,
Thanks for the reply.
I will try postmessage instead of SendMessage and
reply in case of any problems.
Thanks a lot.
Selva
|
|
|
|
|
Perhaps your problem is using the MainWnd object across threads (you didn't say if this is MFC or not, but I suspect it is).
It would be safer to either pass the hWnd of your main window in the thread parameters when you start the thread, or to use GetSafeHwnd() when you send your message.
For example:
Worker thread
{
get status from DB.
::SendMessage(GetMainWnd()->GetSafeHwnd(),PROC_MSG, wp, g_nInt)
.....
::SendMessage(GetMainWnd()->GetSafeHwnd(),PROC_MSG, wp, g_nInt)
.........
}
Also, you say the code will "look like" below. Post your actual code, including how you start the thread.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Hi all,
How can use enter key on ListCtrl.
I m using NM_RETURN but its not working, i m also check NM_KEYDOWN.
But problem is not shortout.
I want on which row of list cotrol the user pressed the enter key then the purticular relevant Column or row information get from listctrol.
How can i do this please help me for this.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
I think you should first derive a class called CMyListCtrl from CListCtrl.
from the menu [Insert]->[Class], Create your CMyListCtrl.
then open the MyListCtrl.cpp file, press CTRL+W to show the ClassWizard.
In the [Message Maps] tab, you choose the NM_RETURN, to add a function to deal with the message that the user press the ENTER key in the ListCtrl.
then in your Dlg class substitute CListCtrl with CMyListCtrl.
Hope I express my mind. And Hope it works.
|
|
|
|
|
Please tell me with example.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
LPNMLVKEYDOWN pLVKeyDow = reinterpret_cast<LPNMLVKEYDOWN>(pNMHDR);
NMLVKEYDOWN* nmkd = (NMLVKEYDOWN*)pNMHDR;
switch(nmkd->wVKey)
{
case VK_SPACE:
int nIndex= GetNextItem(-1, LVNI_SELECTED);
CString strItem = GetItemText(nIndex, 0);
AfxMessageBox(strItem );
}
*pResult = 0;
i m using thisfor keydown ,i m using key space if i m using VK_RETURN in place of VK_SPACE than its not working.(Means the message box not show)
and in case of VK_SPACE its working but after this Unhandeled exeception occur the message of exeception is "Unhandled exception at 0x5d0f0892 in Test.exe: 0xC0000094: Integer division by zero."
Please help me for this.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Do be sorry for my first reply, I've tried my first code, it doesn't work at all, sorry.
I can't see which message do you handle, But you do can ovrride the PreTranslateMessage method to achive your goal.
BOOL CListCtrlEnterKeyDlg::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message) {
case WM_KEYDOWN:
if (VK_RETURN == (INT)pMsg->wParam && ::GetFocus() == m_ctlList.GetSafeHwnd())
{
int iSelMask = -1;
iSelMask = m_ctlList.GetSelectionMark();
if (iSelMask != -1)
{
LVITEM lvi = {0};
lvi.iItem = iSelMask;
lvi.iSubItem = 0;
lvi.mask = LVIF_TEXT;
TCHAR szBuf[50] = {0};
lvi.pszText = szBuf;
lvi.cchTextMax = 50;
VERIFY( m_ctlList.GetItem(&lvi) );
::AfxMessageBox(szBuf);
}
}
return TRUE;
default:
break;
}
BOOL bRet = CDialog::PreTranslateMessage(pMsg);
return bRet;
}
I hope this time everything will go fine.^_^
|
|
|
|