|
The hwndParent parameter isnt pointing to CMainFrame. This is a child CWnd fomr a child window from a CMainFrame's child window. So, its CMainFrame great grandaugther.
Also, is there a way i can declare a global variable pointing to CMainFrame?
|
|
|
|
|
You should be abl to set a global variable to a valid CMainFrame in your CMainFrame::OnCreate() member function as long as it is after the call to the base class's OnCreate() function.
I have not tried this, but here goes:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
g_MyGlobalMainFrame = this;
...
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Im having no problem in creating a global variable. The problem is that it must be declared in a file that every other header can include it. If my child window is declared as an include in CMainframe, and the global is also in CMainframe, i cant include CMainframe in the child, cause it gives me a Linking error cause im going recursive in includes.
So, can i just create a separate file (or use StdAfx?), create the global there, initialize it within CMainframe and include it in each class i want?
|
|
|
|
|
Do not declare global variables in any header files. Declare them in one, and only one cpp file, and any cpp file that needs to use them imports it using the extern keyword
...
#include "MainFrm.h"
CMainFrame *g_MyGlobalMainFrame = NULL;
...
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
g_MyGlobalMainFrame = this;
...
#include "MainFrm.h"
extern CMainFrame *g_MyGlobalMainFrame
...
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks!!
|
|
|
|
|
Hi,
I have made some bitmaps dynamically. I wish to add the notify ability to them. I tried WS_NOTIFY, but it told me that it doesn't exist. How do I give the notify ability to my bitmaps?
Thanks,
~ Selevercin
If you have a problem with my spelling, just remember that's not my fault. I [as well as everyone
else who learned to spell after 1976] blame it on
Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
There's probably a dozen different ways to do this. I create dynamic bitmaps by deriving a custom bitmap control from CWnd and override the OnLButtonDown message. But your implementation might be different.
Marc
|
|
|
|
|
Sorry, but how would you derive a custom bitmap control from CWnd? Is there a tutorial for this?
~ Selevercin
If you have a problem with my spelling, just remember that's not my fault. I [as well as everyone
else who learned to spell after 1976] blame it on
Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
I usually display bitmaps that have been loaded from a file, not a resource. Here's a code snippet:
<br />
BitmapControl::BitmapControl(CWnd* parent) : CWnd(), hInternalImage(0)<br />
{<br />
}<br />
<br />
void BitmapControl::Create(const CWnd* v, const CRect& r, const int id)<br />
{<br />
HCURSOR cursor=AfxGetApp()->LoadCursor(IDC_ARROW);<br />
const char* className=AfxRegisterWndClass(0, cursor, (HBRUSH) GetStockObject(WHITE_BRUSH));<br />
CWnd::CreateEx(0, className, "", WS_CHILD | WS_VISIBLE, r, (CWnd*)v, id);<br />
}<br />
<br />
void BitmapControl::LoadImage(const AutoString& imageFile)<br />
{<br />
if (hInternalImage)<br />
{<br />
DeleteObject(hInternalImage);<br />
}<br />
hInternalImage=::LoadImage(0, imageFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);<br />
InvalidateRect(NULL);<br />
}<br />
<br />
void BitmapControl::OnLButtonDown(UINT nFlags, CPoint point)<br />
{<br />
int x=point.x;<br />
int y=point.y;<br />
CWnd::OnLButtonDown(nFlags, point);<br />
}<br />
<br />
void BitmapControl::OnPaint(void)<br />
{<br />
HANDLE h=hInternalImage;<br />
<br />
CRect r=GetClientRect();<br />
PAINTSTRUCT ps;<br />
CDC* dc=BeginPaint(&ps);<br />
if (h)<br />
{<br />
CDC src;<br />
src.CreateCompatibleDC(NULL);<br />
CBitmap* bitmap=CBitmap().FromHandle((HBITMAP)h);<br />
BITMAP bm;<br />
bitmap->GetBitmap(&bm);<br />
src.SelectObject(bitmap);<br />
int destW=r.right-r.left;<br />
int destH=r.bottom-r.top;<br />
int srcW=bm.bmWidth;<br />
int srcH=bm.bmHeight;<br />
dc->FillSolidRect(0, 0, destW, destH, COLORREF(0x00FFFFFF));<br />
dc->BitBlt((destW-srcW)/2, (destH-srcH)/2, r.right-r.left, r.bottom-r.top, &src, 0, 0, SRCCOPY);<br />
EndPaint(&ps);<br />
}<br />
else<br />
{<br />
int destW=r.right-r.left;<br />
int destH=r.bottom-r.top;<br />
dc->FillSolidRect(0, 0, destW, destH, COLORREF(0x00FFFFFF));<br />
EndPaint(&ps);<br />
}<br />
CWnd::OnPaint();<br />
}<br />
<br />
---
Marc
|
|
|
|
|
Use a static control to display the bitmap (using CStatic::SetBitmap()), and set the static control's SS_NOTIFY style
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
WOW!!! Thank you SO much, PJ Arends! You solved a BIG problem that I've been ignoring for the past month (I haven't programmed since I got SO frustrated with my problem).
This is what the problem was. I created a bunch of dynamic bitmaps for a card game. I wanted to be able to click them, so origionally, I used the OnLeftButtonDwn() with CPoint for every position on the card (there about 30ish cards). Needless to say, after the 3rd card I realized it would take an army of programmers to finish it.
Finally, I came up with the idea of making a bunch of static bitmaps, change their resource number to the ID numbers of the bitmaps, add a BN_CLICKED message for my static bitmaps, and finally delete the static bitmaps. My plan didn't appear to be working, until today I realized my whole problem was that I needed a notify message.
Thanks again! (If you want to see the card game when I'm finished let me know)
~ Selevercin
If you have a problem with my spelling, just remember that's not my fault. I [as well as everyone
else who learned to spell after 1976] blame it on
Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
Selevercin wrote:
Thanks again!
No prob
Selevercin wrote:
If you want to see the card game when I'm finished let me know
Sounds like an article;);)
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
High
What message is sent when a window is minimizing/minimized?
I want to create some tool (don't ask me Y...) which can determine if a window
is minimizing. I'm sure that if I've a CWnd derived obj, some message is sent
to it when some other window is minimized/ing. if this messge handler contain
some info about the window that's min's it will be mu(n)ch better
Hope you can figure what I'm saying (cause' I'm not so sure I do...).
Good night everybooty, I've left the building.
--BlackSmith--
"With the help of all mighty", 2001, Me.
|
|
|
|
|
WM_SIZE
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
WM_GETMINMAXINFO is sent when a window is about to be resized. U can override this if you want'd to specify a minimum or maximum size as a limit that the window could be resized to.
|
|
|
|
|
Under VS7 (but not VS6), I consistently get an exception error during the mfc70.dll cleanup process:
AFX_MODULE_STATE::~AFX_MODULE_STATE()
{
#ifndef _AFX_NO_DAO_SUPPORT
delete m_pDaoState;
#endif
...
on the delete statement. I'm properly closing my DAO database, etc. No asserts are happening. Does anyone have any idea? This looks like an MFC70.DLL bug to me.
Marc
|
|
|
|
|
WHen i try to compile a program including commdlg.h i get 102 compiling errors. almost everyone of them are because of undeclared identifiers like APIENTRY, UINT and DWORD. i don't understand why it gives me so many errors and why it can't recognize DWORD and UINT. what's wrong?
|
|
|
|
|
are you including "windows.h" before including commdlg.h ?
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
This is probably really simple but my poor brain hurts.
I have some code that checks if it can make sense of the data loaded during serialisation in my CDocument derived class.
void CPERDoc::Serialize(CArchive& ar)<br />
{<br />
AfxMessageBox("Data not recognisable");<br />
}
When AfxMessageBox is called, The dialog box appears and I then get 'Debug Assertion Failed at line 628 of wincore.cpp'
the relevant bit of code in wincore.cpp is this..
void AFXAPI AfxHookWindowCreate(CWnd* pWnd)<br />
{<br />
_AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();<br />
if (pThreadState->m_pWndInit == pWnd)<br />
return;<br />
<br />
if (pThreadState->m_hHookOldCbtFilter == NULL)<br />
{<br />
pThreadState->m_hHookOldCbtFilter = ::SetWindowsHookEx(WH_CBT,<br />
_AfxCbtFilterHook, NULL, ::GetCurrentThreadId());<br />
if (pThreadState->m_hHookOldCbtFilter == NULL)<br />
AfxThrowMemoryException();<br />
}<br />
ASSERT(pThreadState->m_hHookOldCbtFilter != NULL);<br />
ASSERT(pWnd != NULL);<br />
### ASSERT(pWnd->m_hWnd == NULL);
<br />
ASSERT(pThreadState->m_pWndInit == NULL);
pThreadState->m_pWndInit = pWnd;<br />
}
During debug, the little yellow arrow stops by the three hashes.
I can work my way around it but can anybody tell me why this does not work?
It happens if I call AfxMessageBox() from anywhere in CDocument. Funnily enough GetMainWnd()->MessageBox() causes the same error if put in the CDocument Class.
Would appreciate some help! Many Thanks!!
Adam.
"I spent a lot of my money on booze, birds and fast cars. The rest I just squandered"
George Best.
|
|
|
|
|
Okay... I am totally totally barking up the wrong tree. Sorry about that. The problem was an entirely different bug.
I was trying to create a modeless dialog that had not been prev. destroyed with DestroyWindow()
thicko or what!
"I spent a lot of my money on booze, birds and fast cars. The rest I just squandered"
George Best.
|
|
|
|
|
The following code adds to the "Menu Commands" for a Document. In the Debug
version, everything works fine. In the Release version, the routine
FindMenuTitle fails. After a little research in to the problem, in
the routine "FindMenuTitle" the call to "::IsMenu" fails.
I have included the code for "FindMenuTitle" and the overridden routine
"GetDefaultMenu". If you have any insight, it would be greatly appreciated.
int<br />
CTachmateDoc::FindMenuTitle(CMenu& menu, LPCTSTR searchfor)<br />
{<br />
UINT i;<br />
CString title;<br />
CString msg;<br />
<br />
ASSERT(menu);<br />
ASSERT(::IsMenu(menu.GetSafeHmenu()));<br />
<br />
if (::IsMenu(menu.GetSafeHmenu())) {<br />
for (i = 0; i < menu.GetMenuItemCount(); i++) {<br />
menu.GetMenuString(i, title, MF_BYPOSITION);<br />
<br />
if (title == searchfor) return(i);<br />
}<br />
}<br />
<br />
return(-1);<br />
}<br />
<br />
HMENU CTachmateDoc::GetDefaultMenu()<br />
{<br />
BOOL menu_changed = FALSE, map_found = FALSE, histo_found = FALSE;<br />
int menu_pos;<br />
CString edit_menu, graph_menu, map_menu, histo_menu;<br />
CString msg;int results;<br />
CMenu menu;<br />
POSITION pos;<br />
CView *pView;<br />
<br />
graph_menu.LoadString(IDS_GRAPH_MENU_STRING);<br />
edit_menu.LoadString(IDS_EDIT_MENU_STRING);<br />
map_menu.LoadString(IDS_MAP_MENU_STRING);<br />
histo_menu.LoadString(IDS_HISTO_MENU_STRING);<br />
<br />
pos = GetFirstViewPosition();<br />
while (pos != NULL) {<br />
pView = GetNextView(pos);<br />
if (pView->IsKindOf(RUNTIME_CLASS(CTrackView))) {<br />
map_found = TRUE;<br />
menu_pos = FindMenuTitle(m_DefaultMenu, map_menu);<br />
<br />
if ((pView->IsWindowEnabled() || pView->IsWindowVisible()) && (menu_pos == -1)) {<br />
menu_changed = TRUE;<br />
<br />
menu_pos = FindMenuTitle(m_DefaultMenu, graph_menu);<br />
ASSERT(menu_pos != -1);<br />
menu_pos++;
<br />
ASSERT(menu.LoadMenu(IDR_TRACKMAP_ADD));<br />
results = m_DefaultMenu.InsertMenu(menu_pos, MF_BYPOSITION | MF_STRING | MF_POPUP,<br />
(UINT)menu.Detach(), map_menu);<br />
}<br />
else if (!pView->IsWindowVisible() && (menu_pos != -1)) {<br />
menu_changed = TRUE;<br />
<br />
m_DefaultMenu.RemoveMenu(menu_pos, MF_BYPOSITION);<br />
}<br />
}<br />
else if (pView->IsKindOf(RUNTIME_CLASS(CHistogramView))) {<br />
histo_found = TRUE;<br />
menu_pos = FindMenuTitle(m_DefaultMenu, histo_menu);<br />
<br />
if ((pView->IsWindowEnabled() || pView->IsWindowVisible()) && (menu_pos == -1)) {<br />
menu_changed = TRUE;<br />
<br />
menu_pos = FindMenuTitle(m_DefaultMenu, edit_menu);<br />
<br />
ASSERT(menu.LoadMenu(IDR_HISTOGRAM_ADD));<br />
m_DefaultMenu.InsertMenu(menu_pos, MF_BYPOSITION | MF_STRING | MF_POPUP,<br />
(UINT)menu.Detach(), histo_menu);<br />
}<br />
else if (!pView->IsWindowVisible() && (menu_pos != -1)) {<br />
menu_changed = TRUE;<br />
<br />
m_DefaultMenu.RemoveMenu(menu_pos, MF_BYPOSITION);<br />
}<br />
}<br />
}<br />
<br />
if (!map_found) {<br />
menu_pos = FindMenuTitle(m_DefaultMenu, map_menu);<br />
if (menu_pos != -1) {<br />
menu_changed = TRUE;<br />
<br />
m_DefaultMenu.RemoveMenu(menu_pos, MF_BYPOSITION);<br />
}<br />
}<br />
<br />
if (!histo_found) {<br />
menu_pos = FindMenuTitle(m_DefaultMenu, histo_menu);<br />
if (menu_pos != -1) {<br />
menu_changed = TRUE;<br />
<br />
m_DefaultMenu.RemoveMenu(menu_pos, MF_BYPOSITION);<br />
}<br />
}<br />
<br />
return(m_DefaultMenu.m_hMenu);<br />
}
Eldon Zacek
Czech-Mate Enterprises, LLC
|
|
|
|
|
Eldon Zacek wrote:
ASSERT(menu.LoadMenu(IDR_HISTOGRAM_ADD));
in release mode, ASSERTs go away, compeletely, along with anything inside them. use VERIFY if you want the code to execute in release mode (in addition to asserting on 0 in debug mode).
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
The problem is NOT with the ASSERTS not being present during the Release version. The problem is that ::IsMenu returns TRUE during execution in
in the Debug version but fails in the Release mode. In "FindMenuTitle",
there is an "If" clause to test the validity of ::IsMenu. In the release
mode this test fails, and thus changes are made to the menu.
Thanks for the response and I hope this clarifies the problem a little
better.
Eldon Zacek
Czech-Mate Enterprises, LLC
|
|
|
|
|
Chris,
You pointed out a problem with the code that I missunderstood. What you
found was an eventual problem but not what was wrong with what I
was seeing. After digging through the code, I found that "m_DefaultMenu"
was being loaded with an "ASSERT" macro. Thus the reason "FindMenuTitle"
was failing.
Thanks for the answer!
Eldon Zacek
Czech-Mate Enterprises, LLC
|
|
|
|
|
hey guys.. got three seperate questions.. there pretty quick tho..
1)In Win95/98(1st edition) my CTreeCtrl will not show its checkboxes. Is there any way around this, or am I screwed? (i have no idea how to takle this without using checkboxes, and the data needs to be in a tree to understand it)
2)I have read alot on this oleaut.dll and .Net and win95 issue, and everyone apparently is upset about this, but they say you can get rid of the problem by delay loading the oleaut.dll. i get this message when i compile:
LINK : warning LNK4199: /DELAYLOAD:oleacc.dll ignored; no imports found from oleacc.dll
and i get this message when i try to run it on win95:
A required .DLL file, OLEACC.DLL was not found.
it says it cant delay load it cause its not used, but i cant run my program without it.. i dont get it? i can install the active accessability, but its 1.46 megs which is too big for a floppy.. which is really cruddy since my whole install and help fits on one diskette.. any other suggestsions?
3)What is up with msdn.microsoft.com? it seems like they reformated their site.. now if i search for 'CListCtrl' i get NO responces?! whats up with msdn? anyone else tried it since tuesday?
-dz
|
|
|
|
|