|
Yes, this appers useful. I will look at this example in details later today.
Sincerely,
Max Pastchenko
|
|
|
|
|
LoadImage does this, just use the LR_LOADFROMFILE flag.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
What does this flag indicate?
Sincerely,
Max Pastchenko
|
|
|
|
|
That you're loading an image from a file. You can use it to load from resources as well, from memory.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Read all about LoadImage in MSDN[^]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
I am trying to launch a program executable(Program A) from another program's menu (Program B). I coded the program B such that it searches the registry for the installation path of program B's executable. This works fine under an administrator login but not for non-admins. I thought it was because I did not grant proper security access by adding KEY_READ to the following line of code:
bRetVal = regKey.Open(HKEY_LOCAL_MACHINE ,(LPCTSTR)strTmp, KEY_READ);
But when I do include KEY_READ, under an admin login, the above code fails. Why is that? For non-admins, it fails either way. The entire code is shown below. Thanks!
CProgramB::Notify(DataNotificationType notifyType, VARIANT data)
{
STARTUPINFO stStartUpInfo;
PROCESS_INFORMATION pProcessInfo;
memset(&stStartUpInfo, 0, sizeof(STARTUPINFO));
stStartUpInfo.cb = sizeof(STARTUPINFO);
stStartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
stStartUpInfo.wShowWindow = SW_SHOWDEFAULT;
CRegKey regKey;
BOOL bRetVal;
CString strTmp = "Software\\ProgramA";
if (bRetVal==ERROR_SUCCESS)
{
CString key = "InstallDir";
char getValue[256] ;
DWORD d = 255;
bRetVal=regKey.QueryValue( getValue , (LPCTSTR)key , &d);
if (bRetVal==ERROR_SUCCESS)
{
char comLine[300];
CString keyValue = (CString)getValue;
strcpy(comLine, keyValue);
strcat(comLine, "programA.exe");
CreateProcess(NULL, comLine, NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS, NULL, NULL, &stStartUpInfo,
&pProcessInfo);
}
else
AfxMessageBox("Query Failed");
}
else
{
AfxMessageBox( "Program Fail to open.");
}
regKey.Close();
return S_OK;
}
|
|
|
|
|
elephantstar wrote:
bRetVal = regKey.Open(HKEY_LOCAL_MACHINE ,(LPCTSTR)strTmp, KEY_READ);
Does this mean that the default security access of KEY_ALL_ACCESS works?
elephantstar wrote:
BOOL bRetVal;
...
if (bRetVal==ERROR_SUCCESS)
At this point, bRetVal has not been assigned a value.
elephantstar wrote:
bRetVal=regKey.QueryValue( getValue , (LPCTSTR)key , &d);
You can't call QueryValue() without having first called Open() .
elephantstar wrote:
CString keyValue = (CString)getValue;
Why the unnecessary cast?
Use of the <pre> tag will make your code much easier to read.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
when I click on the debug menu, it brings up a find symbols window and asks me to enter the path for vc60.pdb. I don't know what I should do.
Thanks,
|
|
|
|
|
valerie99 wrote:
I don't know what I should do.
How about entering the path to the vc60.pdb file? Most likely this is in the project's Debug folder.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Thanks for the quick reply. I entered the one in the project's debug folder, it says "a file with correct name was found in this directory, but it is not the currect one"
I was running this application last week, it never happened like this, not sure what's going on......
thanks again!
|
|
|
|
|
I would suggest rebuilding the entire project. This will generate a new .pdb file.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
thank you so much!!! it works.
|
|
|
|
|
This code to create bitmaps for the two states of a button works well under Windows 2000 but under Windows XP I get blank light brown buttons. Could anyone please help me with this problem. (Compiled under VC++ 6.0)
void CMyButton::SetText(CString str)
{
int x=0;
int y=0;
BITMAPINFOHEADER bi;
BITMAPINFOHEADER* lpbi;
HBITMAP hBitmap;
HDC hDC, hMemDC;
HANDLE hDIB;
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = 75;
bi.biHeight = 20;
bi.biPlanes = 1;
bi.biBitCount = 24;
bi.biCompression = BI_RGB;
bi.biSizeImage = 75*20*3;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
hDC = ::GetDC(m_hWnd);
hBitmap = CreateDIBitmap(hDC, &bi, 0L, NULL, NULL, 0);
hDIB = GlobalAlloc(GHND, sizeof(BITMAPINFOHEADER)+
16 * sizeof(RGBQUAD));
lpbi = (BITMAPINFOHEADER*)GlobalLock(hDIB);
*lpbi = bi;
GetDIBits(hDC, hBitmap, 0, 19, NULL, (LPBITMAPINFO)lpbi,
DIB_RGB_COLORS);
GlobalUnlock(hDIB);
hMemDC = CreateCompatibleDC(hDC);
SelectObject(hMemDC, hBitmap);
CBrush brush1,brush2;
brush1.CreateSolidBrush(RGB(200,200,200));
brush2.CreateSolidBrush(RGB(0,0,255));
SelectObject(hMemDC, (HBRUSH)brush1);
Rectangle(hMemDC,0,0,100,20);
SetBkColor(hMemDC,RGB(200,200,200));
SetTextColor(hMemDC,RGB(0,0,0));
CFont font;
font.CreatePointFont(97,"arial bold");
SelectObject(hMemDC, (HFONT)font);
int n=str.GetLength();
if(n>=12) x=2;
else if(n==9) x=4;
else x=(14-n)*2;
y=2;
TextOut(hMemDC, x, y,str.GetBuffer(0),str.GetLength());
int w= 75*3;
char bits1[20*75*3];
char bits2[20*75*3];
GetDIBits(hDC, hBitmap, 0, 19, bits1, (LPBITMAPINFO)lpbi,
DIB_RGB_COLORS);
for(int i=1;i<20;i++)
{
memcpy(&bits2[i*w-56],&bits1[(19-i)*w],w);
}
m_bmp1.SetBitmapBits(20*74*3,&bits2[0]);
SelectObject(hMemDC, (HBRUSH)brush2);
Rectangle(hMemDC,0,0,100,20);
SetBkColor(hMemDC,RGB(0,0,255));
SetTextColor(hMemDC,RGB(0,0,0));
TextOut(hMemDC, x, y,str.GetBuffer(0),str.GetLength());
GetDIBits(hDC, hBitmap, 0, 19, bits1, (LPBITMAPINFO)lpbi,
DIB_RGB_COLORS);
for(i=1;i<20;i++)
{
memcpy(&bits2[i*w-56],&bits1[(19-i)*w],w);
}
m_bmp2.SetBitmapBits(20*74*3,&bits2[0]);
font.DeleteObject();
brush1.DeleteObject();
brush2.DeleteObject();
DeleteDC(hMemDC);
GlobalFree(hDIB);
::ReleaseDC(m_hWnd, hDC);
}
Thanks for you help
|
|
|
|
|
I have two buttons on a form "Save" and "New". "New" is disabled. "Save" is enabled. When I click or press "Save" I want to enable "New", set the focus to it and then disable "Save"
OnSave(){
m_Save.EnableWindow(FALSE);
m_New.EnableWindow(TRUE);
m_New.SetFocus();
}
The problem is (tell me if I'm wrong) that the focus is still with the "Save" button until the function is over. So I get the focus rectangle to the "New" button but it doesn't function like it has the focus i.e. it is inoperable unless clicked (doesn't respond to a "enter key press"
So I then did the CCmdUI update processing (responds to flag) that would detect the proper flag and set the buttons state accordingly. It does do that but the focus is still trapped. The idle status processing must occur after the focus is set on the disabled button.
OnSave()
{
ModeStatus=PRISTINE;
//CmdUI will then set the state of the buttons accordingly
m_New.SetFocus();
}
I want to get the focus to the "New button so user doesn't have to take their hands off the keyboard to activate (i.e. the focus is on the proper button and they press the "enter" key).
Seems like I'm missing something simple. Any help would be appreciated.
|
|
|
|
|
Try hiding and (re)showing m_Save . (This is a guess .
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Typically, I enable and set focus to the OTHER window before disabling the 'current' window, and that has worked for me.
In your case, try this, it might work fine (just rearrange the order):
OnSave(){<br />
m_New.EnableWindow(TRUE);<br />
m_New.SetFocus();<br />
m_Save.EnableWindow(FALSE);<br />
}
|
|
|
|
|
Thanks for the replies.
I thought the same thing too Blake. But it doesn't work. I'm guessing it is because the focus shifts back to the disabled window because the function is completing in the disabled window.
I would have bet the CmdUI was the ticket but apparently not.
|
|
|
|
|
This is a default button issue rather than a focus issue. You need to call SetDefID() at the end of OnSave() to make the New button the default.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
David, I think you may have hit on something here. SetDefID is a CDialog function and I am using a CFormView derived class. There must be a similar way for CFormViews.
|
|
|
|
|
mx483 wrote:
There must be a similar way for CFormViews
Just send it a DM_SETDEFID message.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I revisited this. Regardless of whether a default button is set, any button will generate a command event by pressing the enter key IF it has the focus. I'm not trying to get default behavior regardless of what control has the focus but merely put the focus to a button from a button that is going night night.
SendMessage(DM_SETDEFID,IDC_NEW); idea was a good one and I appreciate your email.
I think I might try this. Setting the focus to the control of choice..NEW from the SAVE and once the control gets the focus (i.e. I'm out of the SAVE button code) then have the NEW button onfocus disable the SAVE. I notice though that there is not an onfocus event for the CButton.
|
|
|
|
|
David,
I think you were right. I got it to work. Thanks for pointing me in the right direction. I didn't realize it was a default property thing.
I erroneously assumed that things that have the focus automatically should have the default property as well. What was confusing me was..
The fact that you can set a default property to a button but it changes to the next button you tab to.
I thought once you set the default button it was the defacto default button throughout. Not so.
Why I had the problem.
When I disabled a button I trapped the default button property in the disabled button until the user tabbed to another button. Then the default and focus rectangle would agree.
I guess my next question is why would the default property change when you tab to another button. Default button must just mean the starting point for this behavior until you tab to another button.
Thanks for the great help.
|
|
|
|
|
This can get weird fast with the command buttons.
If you make a group of command buttons, you can change the focus with the arrow keys, but I am pretty sure the default button is only changed with the TAB key. The SpaceBar will activate the button that has the focus, but the ENTER key will activate the button that is the default button.
|
|
|
|
|
Hello everyone. I know it is a message board for VC++, but I haven't found one for "plain" C++ here (under linux, i.e.). The following code sequence produces an "A" on stdout, and I cannot figure it out why. PLEASE help !
stringstream os;
string buf;
os.str("");
buf=os.str();
cout << buf << flush;
|
|
|
|
|
why do you pass thru a StringStream ?
couldn't you just do :
cout << string("") << flush;
or at least :
String buf = "";
cout << but << flush;
what happens if you move the flush outside the line ? (calling cout.flush() after)...?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|