// Start
CStatic *pStaPicHolder = (CStatic*)GetDlgItem(IDC_STATIC);
if (NULL == pStaPicHolder)
return;
BOOL b = pStaPicHolder->ModifyStyle(~0, (DWORD)(SS_BITMAP, WS_CHILD |
WS_VISIBLE));
//pHBitmap = LoadBitmap(theApp.GetResModuleHandle(),
MAKEINTRESOURCE(nBitmapID));
HBITMAP pHBitmap1 = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
"BallaStream.Bmp", IMAGE_BITMAP, 90, 30, LR_LOADFROMFILE);
if (NULL != pHBitmap1)
{
HBITMAP pBt = pStaPicHolder->SetBitmap(pHBitmap1);
}
//End
But iam not seeing bitmap getting displayed in static control in
dialog.
Why aren't you simply using a Picture control?
I'm still trying to wrap my head around your ModifyStyle call! Does that
compile?
AliR.
"Gurikar" <msgu...@gmail.com> wrote in message
news:d6cc0324-71e9-42e0...@r15g2000prh.googlegroups.com...
>HI ,
>I have created one dialog application, in that i have added one
>CStatic control.
>Then i have added below code in OnInitDialog()
>
>// Start
> CStatic *pStaPicHolder = (CStatic*)GetDlgItem(IDC_STATIC);
****
Forget you ever heard of GetDlgItem. Its use is very retro, and it should be written no
more than once a year, at most. This is not a case where it makes sense. Create a
CStatic class member using "Add Variable" (in VS > 6, right click on the control to get
the Add Variable selection).
>
> if (NULL == pStaPicHolder)
> return;
****
This test can be eliminated
****
>
> BOOL b = pStaPicHolder->ModifyStyle(~0, (DWORD)(SS_BITMAP, WS_CHILD |
>WS_VISIBLE));
****
So why didn't you do this at design time? Note that most of these bits should not be
touched. ~0 should not be used as the first parameter, because that says to clear every
bit, which is probably wrong. Very wrong. Setting the visible bit does not change
visibility. Changing the child bit at any point is erroneous. There is no need for a
DWORD cast. This line should not exist.
****
> //pHBitmap = LoadBitmap(theApp.GetResModuleHandle(),
>MAKEINTRESOURCE(nBitmapID));
>
> HBITMAP pHBitmap1 = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
>"BallaStream.Bmp", IMAGE_BITMAP, 90, 30, LR_LOADFROMFILE);
****
Values like 90 and 30 should noto exist. 0,0 would be correct (use the size from the
file). There is no possible way to know that 90 or 30 make sense. Even if they make
sense today, for one particular bitmap, they may not next week. Get rid of them.
Don't forget _T() around the string literal. And you don't need an instance handle when
you are loading from a file. Why is it not a resource?
****
>
> if (NULL != pHBitmap1)
> {
> HBITMAP pBt = pStaPicHolder->SetBitmap(pHBitmap1);
> }
>
>
>//End
>
>But iam not seeing bitmap getting displayed in static control in
>dialog.
****
Note that some style bits affect how the control is *created*, and modifying them later
has zero effect on the behavior of the window. There is no reason to modify styles here;
that's what the dialog editor is for. The error probably occurs because you are doing a
SetBitmap to a non-bitmap static.
joe
****
>
>
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
>first thing first, you can't call GetDlgItem on id IDC_STATIC. All static
>controls on a dialog are by default given IDC_STATIC. If you want to
>programmatically change things with the static control, you have to give it
>a different ID. IDC_XXXX
****
I missed the IDC_STATIC. Sigh.
****
>
>Why aren't you simply using a Picture control?
****
That's where the problem arises. A picture control with a Bitmap style should work. A
generic CStatic probably won't
****
>
>I'm still trying to wrap my head around your ModifyStyle call! Does that
>compile?
****
Actually it makes perfect sense, in that the OP is indicating that all bits should be
cleared and some bits set. Other than the fact that this will have zero net effect
because it is far too late, it could work, but it is a really, really bad way to get the
desired effect of setting only some bits (and leaving everything else untouched).
The line should disappear.
joe
****
>
>AliR.
>
>
>"Gurikar" <msgu...@gmail.com> wrote in message
>news:d6cc0324-71e9-42e0...@r15g2000prh.googlegroups.com...
>> HI ,
>> I have created one dialog application, in that i have added one
>> CStatic control.
>> Then i have added below code in OnInitDialog()
>>
>> // Start
>> CStatic *pStaPicHolder = (CStatic*)GetDlgItem(IDC_STATIC);
>>
>> if (NULL == pStaPicHolder)
>> return;
>>
>> BOOL b = pStaPicHolder->ModifyStyle(~0, (DWORD)(SS_BITMAP, WS_CHILD |
>> WS_VISIBLE));
>> //pHBitmap = LoadBitmap(theApp.GetResModuleHandle(),
>> MAKEINTRESOURCE(nBitmapID));
>>
>> HBITMAP pHBitmap1 = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
>> "BallaStream.Bmp", IMAGE_BITMAP, 90, 30, LR_LOADFROMFILE);
>>
>> if (NULL != pHBitmap1)
>> {
>> HBITMAP pBt = pStaPicHolder->SetBitmap(pHBitmap1);
>> }
>>
>>
>> //End
>>
>> But iam not seeing bitmap getting displayed in static control in
>> dialog.
>>
>>
>>
>
Those little syntax glitches are difficult to see because we've trained and
conditioned our mind to see certain patterns. It's easy to miss these sorts
of syntax errors because we're not used to seeing them. The brain sees the
cast and the first few characters after that, and then fills in the blanks
for you, assuming that pattern that you are used to seeing is, actually
there. Buggy Brains!
"Joseph M. Newcomer" <newc...@flounder.com> wrote in message
news:5kicf491ckkbvepp5...@4ax.com...
"Joseph M. Newcomer" <newc...@flounder.com> wrote in message
news:cbvff4dfsn7ogh35f...@4ax.com...