|
Hi All
I've just started with MFC and need some help.
My application is a SDI with a splitter. The controls side is derived from CFormView (called CControlsView) the other side is an output. In the controls part I added a tab control and when a tab is pressed I display the mattching dialog in the tab client area. The tab dialogs have contols on them too.
This is my problem: the controls on the tab dialogs are not getting any messages. Only the CControlsView and the tab control on it are getting OnLButtonDown. So in the CControlsView::PreTranslateMessage I check for a WM_LBUTTONDOWN and if it is found I use "SendMessage" to pass it to the dialog that coresponds to the tab selected. The dialog gets the message but the controls on the dialog don't get any messages.
Any Ideas why? I'd also be glad if someone could explain or refer me to some explenation on how this messageing works (who gets the messages and so on). Also am I going at this the right way at all? Should I use a PropertyPage for the dialogs? Couldn't find a way to use a PropertyPage as a view (the way I use the CFormView).
Thanks.
|
|
|
|
|
Check / search for "DemoTab" ( sorry, I can't remember where I got it).
It has CTabView class which works fine for me. Nothing fancy, but I like KISS concept.
There are articles on this board using tree control to select items in the associated pane if you want something fancy.
BTW I tried to do similar thing using splitter and found it to "convoluted" to pass messages between panes.
Right now I am strugling with putting controls into the "tabs" dynamically.
Vaclav
|
|
|
|
|
Thanks, actually I found a nice demo called "Property Sheet View" on this site (don't know how I managed to miss it all this time). Does exactly what I wanted
About the splitter, its going to have to be like that . I need to see the output in one window while playing with the controls in the other.
|
|
|
|
|
Vaclav wrote:
Right now I am strugling with putting controls into the "tabs" dynamically.
Why would you need such a capability? In what context could one possibly use it? I am curious to know.
|
|
|
|
|
Vivic wrote:
Why would you need such a capability? In what context could one possibly use it? I am curious to know.
Currently I'm working on a terrain editor, but I'd think being able to see the results in one window while playing with controls in the other is common functionality. You can think of it as a standart menu, just spread out.
I wouldn't mind being corrected, since this is my first MFC program
|
|
|
|
|
The situation is as follows:
I have to store some unicode characters in an excel file (japanese kanji actually). The MFC based programm has to access the file and display the contents of the database sheet. But as I use a CRecordset derived class, all I get with it's GetFieldValue() function is "????" output string. As excel displays the kanji and I checked that without ODBC all works fine (input in the window and storing in CString), I think there is something with CRecordset class or some sort of settings that I don't know.
I defined _UNICODE for the project and wWinMainCRTStartup for the entry-point.
Please, tell me what can I do, to get those chars to display using ODBC?
-------------
RusDuke
|
|
|
|
|
Hi RusDuke,
Already find something about this stuff?
I've the same problem with a MS Access database I try to get some text in Russian from the data base and I get also ???? (e.g. [м/мин] becomes [?/???]).
Because of the encapsulation of MFC with CDatabase en CRecordset you can't see what's happening inside. Does it use SQLConnect instead of SQLConnectW (Wide character based)? Nobody knows(?).
I'll let you known if I find something.
|
|
|
|
|
Hi all,
My MFC-generated dialog application is whizzing along nicely. A quick question though - how do I modify the text "Client MFC Application" that sits under my application name in a Tiles view in Windows Explorer?
Cheers
Ritcho
|
|
|
|
|
|
Hi! Look at my code:
FILE *gen; int i = 50;
gen = fopen("gen.txt", "w");
fprintf("Test:%d", i);
The resulting file would contain the string "TEST:50". How can I add a byte of value 50 to the file rather than adding the string "50"?
Thanks!
|
|
|
|
|
Post the code that writes data to the file.
Kuphryn
|
|
|
|
|
fprintf (gen, "Test:%c",i);
That should work.
fwrite ("Test:", 5, 1, gen);
char c = (char) i;
fwrite (&c, 1, 1, gen);
That will also work.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
|
I was making a game of cards and i wanted to show the player how much time he has before the game ends; just like a negative progress bar, or a burning candle, or an hour glass the hour glass seems kinda cool. so that i started working on it the hour glass should be updated in each ontimer event and the sand in the hourglass should be deposited on the lower glass; i have a picture of an hour glass and i must make the part where the glass is transparent and should draw the sand gradient in behind BUt i don't know how to make a bitmap or part of a bitmap trasparent how can i do that; by the way if u know of making a burning candle llok real i would like to know thanks
|
|
|
|
|
Not too sure if I know what Im talking about but I did something similar in VB once. Apparently in a bitmap every pixel has a red, green, blue and alpha value. The alpha value(0 - 255) is for transparency. You could change the alpha values of each pixel and have different levels of transparency. This transparency value only works under certain scenarios though - maybe google could help out on this one.
|
|
|
|
|
InflatableGarfield wrote:
Not too sure if I know what Im talking about
Sorry, you don't
32 bit images have an extra bit that can be used for alpha, but Windows does not use it at all.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
If you use GDI+, you can make the bits of the image you want transparent a color that you don't use, and specify that color as your transparency mask. Be careful - if you use lossy compression to store your bitmaps, this will fail as colors will change. For example, jpg is right out.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Maybe, this example helps you. The example shows how to create an hour glass progress bar.
class CChildView : public CWnd
{
private:
int m_nPos;
CBitmap m_bmpBk;
CBitmap m_bmpFgMono; the foreground (sand) bitmap
SIZE m_sizeBk;
SIZE m_sizeFg;
CPoint m_ptFgOffset;
CBitmap m_bmpFgMaskMono;
CBitmap m_bmpBkTmp;
CBitmap m_bmpFgTmp;
}
CChildView::CChildView()
{
m_nPos = 0;
m_bmpBk.LoadBitmap(IDB_HGBACKGROUND);
m_bmpFgMono.LoadBitmap(IDB_HGSAND);
BITMAP bm;
m_bmpBk.GetBitmap(&bm);
m_sizeBk.cx = bm.bmWidth;
m_sizeBk.cy = bm.bmHeight;
m_bmpFgMono.GetBitmap(&bm);
m_sizeFg.cx = bm.bmWidth;
m_sizeFg.cy = bm.bmHeight;
HDC hDC = ::GetDC(NULL);
m_bmpBkTmp.CreateCompatibleBitmap(CDC::FromHandle(hDC),m_sizeBk.cx,m_sizeBk.cy);
m_bmpFgTmp.CreateCompatibleBitmap(CDC::FromHandle(hDC),m_sizeFg.cx,m_sizeFg.cy);
::ReleaseDC(NULL,hDC);
m_bmpFgMaskMono.CreateBitmap(m_sizeFg.cx,m_sizeFg.cy,1,1,NULL);
m_ptFgOffset = CPoint(3,3);
}
void CChildView::OnPaint()
{
CPaintDC dc(this);
CDC dcMemBkTmp;
dcMemBkTmp.CreateCompatibleDC(&dc);
CBitmap* pBmpOldBkTmp = dcMemBkTmp.SelectObject(&m_bmpBkTmp);
CDC dcMemBk;
dcMemBk.CreateCompatibleDC(&dc);
CBitmap* pBmpOldBk = dcMemBk.SelectObject(&m_bmpBk);
dcMemBkTmp.BitBlt(0,0,m_sizeBk.cx,m_sizeBk.cy,&dcMemBk,0,0,SRCCOPY);
CDC dcMemFgTmp;
dcMemFgTmp.CreateCompatibleDC(&dc);
CBitmap* pBmpOldFgTmp = dcMemFgTmp.SelectObject(&m_bmpFgTmp);
CDC dcMemFgMono;
dcMemFgMono.CreateCompatibleDC(&dc);
CBitmap* pBmpOldFgMono = dcMemFgMono.SelectObject(&m_bmpFgMono);
CDC dcMemFgMaskMono;
dcMemFgMaskMono.CreateCompatibleDC(&dc);
CBitmap* pBmpOldFgMaskMono = dcMemFgMaskMono.SelectObject(&m_bmpFgMaskMono);
dcMemFgMaskMono.FillSolidRect(CRect(0,0,m_sizeFg.cx,m_sizeFg.cy),RGB(0,0,0));
dcMemFgMaskMono.FillSolidRect(CRect(0,(m_nPos*m_sizeFg.cy)/200,m_sizeFg.cx,m_sizeFg.cy/2),RGB(255,255,255));
dcMemFgMaskMono.FillSolidRect(CRect(0,m_sizeFg.cy-(m_nPos*m_sizeFg.cy)/200,m_sizeFg.cx,m_sizeFg.cy),RGB(255,255,255));
dcMemFgMaskMono.BitBlt(0,0,m_sizeFg.cx,m_sizeFg.cy,&dcMemFgMono,0,0,SRCAND);
COLORREF oldBkColor = dcMemFgTmp.SetBkColor(RGB(255,255,0));
COLORREF oldTxtColor = dcMemFgTmp.SetTextColor(RGB(255,0,255));
dcMemFgTmp.BitBlt(0,0,m_sizeFg.cx,m_sizeFg.cy,&dcMemFgMaskMono,0,0,SRCCOPY);
dcMemFgTmp.SetTextColor(oldTxtColor);
dcMemFgTmp.SetBkColor(oldBkColor);
HINSTANCE hDll = AfxLoadLibrary(_T("msimg32.dll"));
UINT (PASCAL* pfnTransparentBlt)(HDC,int,int,int,int,HDC,int,int,int,int,UINT);
if(hDll)
{
(FARPROC&)pfnTransparentBlt=GetProcAddress(hDll,"TransparentBlt");
if(pfnTransparentBlt)
pfnTransparentBlt(dcMemBkTmp.m_hDC,m_ptFgOffset.x,m_ptFgOffset.y,m_sizeFg.cx,m_sizeFg.cy,dcMemFgTmp.m_hDC,0,0,m_sizeFg.cx,m_sizeFg.cy,RGB(255,0,255));
AfxFreeLibrary(hDll);
}
dc.StretchBlt(0,0,m_sizeBk.cx*10,m_sizeBk.cy*10,&dcMemBkTmp,0,0,m_sizeBk.cx,m_sizeBk.cy,SRCCOPY);
dcMemFgMaskMono.SelectObject(pBmpOldFgMaskMono);
dcMemFgMono.SelectObject(pBmpOldFgMono);
dcMemBk.SelectObject(pBmpOldBk);
dcMemBkTmp.SelectObject(pBmpOldBkTmp);
dcMemFgTmp.SelectObject(pBmpOldFgTmp);
}
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
SetTimer(1,40,NULL);
return 0;
}
void CChildView::OnTimer(UINT nIDEvent)
{
m_nPos++;
m_nPos = m_nPos%100;
Invalidate(FALSE);;
CWnd ::OnTimer(nIDEvent);
}
BOOL CChildView::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
|
|
|
|
|
I have created an ActiveX button control on C++ 6 that uses the UxTheme.dll. All works fine except for when I hover the mouse over the button it doesn't repaint in the hover theme. My code for ::OnOcmDrawItem( ... ) is as below:
LRESULT CCmdButtonCtrl::OnOcmDrawItem(WPARAM wParam, LPARAM lParam)<br />
{<br />
UINT nIDCtl = (UINT) wParam;<br />
LPDRAWITEMSTRUCT lpDrawItemStruct = (LPDRAWITEMSTRUCT) lParam;<br />
HDC dc = lpDrawItemStruct->hDC;<br />
CDC* pDC = CDC::FromHandle(dc);<br />
<br />
BOOL bIsSelected = (lpDrawItemStruct->itemState & ODS_SELECTED);<br />
BOOL bIsFocussed = (lpDrawItemStruct->itemState & ODS_FOCUS);<br />
BOOL bIsDisabled = (lpDrawItemStruct->itemState & ODS_DISABLED);<br />
<br />
CRect rect;<br />
rect.CopyRect(&lpDrawItemStruct->rcItem);<br />
<br />
#ifdef _VISUALSTYLE_XP_H_<br />
if( g_xpStyle.IsAppThemed() )<br />
{<br />
HTHEME hTheme = g_xpStyle.OpenThemeData(GetSafeHwnd(), L"BUTTON");<br />
int state = 1;<br />
<br />
if(bIsSelected)<br />
state = 2;<br />
if(m_bLMouseButtonDown)<br />
state = 3;<br />
<br />
CRect rcContent = rect;<br />
InflateRect(&rcContent, -3, -3);<br />
<br />
HRESULT hr = g_xpStyle.DrawThemeBackground(hTheme, dc, 1, state , &rect, NULL);<br />
hr = g_xpStyle.GetThemeBackgroundContentRect(hTheme, dc, 1, state, &rect, &rcContent);<br />
<br />
if(!m_szCaption.IsEmpty())<br />
{<br />
LPWSTR lpszCaption = new WCHAR[m_szCaption.GetLength()];<br />
LPSTR lpStr = m_szCaption.GetBuffer(m_szCaption.GetLength());<br />
int nLen = MultiByteToWideChar(CP_ACP, 0, lpStr, -1, NULL, NULL);<br />
MultiByteToWideChar(CP_ACP, 0, lpStr, -1, lpszCaption, nLen);<br />
<br />
CFont* pOldFont = SelectStockFont(pDC);<br />
hr = g_xpStyle.DrawThemeText(hTheme, dc, 1, state, lpszCaption, wcslen(lpszCaption), <br />
DT_CENTER | DT_VCENTER | DT_SINGLELINE,<br />
0, &rect);<br />
pDC->SelectObject(pOldFont);<br />
hr = g_xpStyle.CloseThemeData(hTheme);<br />
}<br />
}<br />
else<br />
{<br />
#endif<br />
...
#ifdef _VISUALSTYLE_XP_H_<br />
}<br />
#endif<br />
<br />
return 0;<br />
}
Could someone PLEASE PLEASE tell me what I need to do to get the hover working, do I need to supress the default ::OnDraw( ... ) method if hover is on?
|
|
|
|
|
In XP theme your button (PUSHBUTTON) can be drawn in 5 states: NORMAL(1), HOT(2), PRESSED(3), DISABLED(4) and DEFAULTED(5).
You set HOT state of the button in this line bIsSelected=lpDrawItemStruct->itemState & ODS_SELECTED . The ODS_SELECTED flag doesn't mean HOT.
To get the hover working make the following changes:
1. Change the name of your variable from bIsSelected to m_bIsHot .
2. Declare m_bIsHot in your class.
3. Set m_bIsHot=TRUE and call _TrackMouseEvent with dwFlag=TME_LEAVE when the mouse cursor is over the button (WM_MOUSEMOVE ).
4. Set m_bIsHot=FALSE when the mouse leaves the client area of the button (WM_MOUSELEAVE ).
5. Modify CCmdButtonCtrl::OnOcmDrawItem :
if(m_bIsHot)
state = 2;
Also, your control should support DISABLED and DEFAULTED states.
Here's a link you can find more information on this subject:
http://www.codeproject.com/buttonctrl/CustomBitmapButtonDemo.asp
|
|
|
|
|
Thanks for the help, I will try it out tomorrow when I get back to the office, and will let you know how I get on.
|
|
|
|
|
Thanks for your help, it worked. Well you knew it would anyway. I will read your article on the subject.
|
|
|
|
|
hello,
I just want to know how to generate a random number on 4 bytes, I saw that rand returns an int but it's too short for my purposal, any suggestion? In my project I DON'T use MFC, I searched on codeproject but all I found was MFC sample, thanks
Paolo
|
|
|
|
|
Paolo Ponzano wrote:
generate a random number on 4 bytes
Do you mean that the range of random random numbers should span values that fit in 4 bytes? If so, you could just use rand() after seeding it with a random (or as random as you can get) int .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
i jus tried my 1st c++ to read from a text file to input into an edit box.
Line by line.
How can i do it?
|
|
|
|
|