Click here to Skip to main content
16,005,149 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralAPI call Required Pin
30-Aug-01 10:41
suss30-Aug-01 10:41 
GeneralProgramatically updating windows 'appearance' color settings, such as desktop and title bar Pin
Jase Jennings30-Aug-01 10:29
Jase Jennings30-Aug-01 10:29 
GeneralRe: Programatically updating windows 'appearance' color settings, such as desktop and title bar Pin
Tomasz Sowinski30-Aug-01 10:33
Tomasz Sowinski30-Aug-01 10:33 
GeneralRe: Programatically updating windows 'appearance' color settings, such as desktop and title bar Pin
Jase Jennings30-Aug-01 10:58
Jase Jennings30-Aug-01 10:58 
Questionwhat's alpha and intel platform ? Pin
30-Aug-01 10:23
suss30-Aug-01 10:23 
AnswerRe: what's alpha and intel platform ? Pin
Tomasz Sowinski30-Aug-01 10:37
Tomasz Sowinski30-Aug-01 10:37 
GeneralRe: what's alpha and intel platform ? Pin
30-Aug-01 11:05
suss30-Aug-01 11:05 
GeneralWindow in a DLL Pin
Jamie Nordmeyer30-Aug-01 10:18
Jamie Nordmeyer30-Aug-01 10:18 
I have a dll that implements a debug console (i.e. an application can send messages to it during run time) made of a window with a textbox on it. It's set up so that the first call to ConInit creates the window and displays it, but subsequent calls to ConInit simply return TRUE. In this way, the same console is used by several apps. My problem is that if I run 2 or more applications, when I shut down the first one, it kills my debug console. How can I lock the window so it's not destroyed until the last reference to it is gone (and yes, I'm using reference counting, so that's not it). Anyway, here's some of the pertininet code:

HINSTANCE	g_hInstance=			NULL;
HMENU		g_hMenu=				NULL;
HWND		g_hOwner=				NULL;

#pragma data_seg(".SHARED")
HWND		g_hWnd=					NULL;
HWND		g_hTextBox=				NULL;
WNDPROC		g_hOldTextBoxProc=		NULL;
COLORREF	g_clrTextColor=			RGB(192,192,192);
COLORREF	g_clrBackColor=			0;
HBRUSH		g_hBrush=				NULL;
HFONT		g_hFont=				NULL;
BOOL		g_bShowTime=			FALSE;
BOOL		g_bShowSourceHwnd=		FALSE;
BOOL		g_bShowSourceCaption=	FALSE;
UINT		g_uRefCount=			0;
#pragma data_seg()


BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	switch(dwReason)
	{
	case DLL_PROCESS_ATTACH:
		g_hInstance=hInstance;
		g_uRefCount++;
		break;
	case DLL_PROCESS_DETACH:
		g_uRefCount--;
		if (g_uRefCount==0)
		{
			DeleteObject(g_hBrush);
			DeleteObject(g_hFont);
			SetWindowLong(g_hTextBox, GWL_WNDPROC, (LONG)g_hOldTextBoxProc);
			DestroyWindow(g_hWnd);
		}
		break;
	}
	return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	RECT rect;
	LOGFONT lf;

	switch(uMsg)
	{
	case WM_CREATE:
		g_hTextBox=CreateWindowEx(WS_EX_CLIENTEDGE,
			"EDIT",
			NULL,
			WS_VISIBLE|WS_CHILD|WS_BORDER|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_NOHIDESEL,
			1,
			1,
			1,
			1,
			hWnd,
			NULL,
			g_hInstance,
			NULL);
		if (!g_hTextBox)
			return -1;
		lf.lfCharSet=ANSI_CHARSET;
		lf.lfClipPrecision=CLIP_DEFAULT_PRECIS;
		lf.lfEscapement=0;
		strcpy(lf.lfFaceName, "Courier");
		lf.lfHeight=-10;
		lf.lfItalic=0;
		lf.lfOrientation=0;
		lf.lfOutPrecision=OUT_DEFAULT_PRECIS;		
		lf.lfPitchAndFamily=FF_ROMAN|DEFAULT_PITCH;
		lf.lfQuality=DRAFT_QUALITY;
		lf.lfStrikeOut=0;
		lf.lfUnderline=0;
		lf.lfWeight=FW_NORMAL;
		lf.lfWidth=0;
		g_hFont=CreateFontIndirect(&lf);
		SendMessage(g_hTextBox, WM_SETFONT, (WPARAM)g_hFont, 0);
		g_hOldTextBoxProc=(WNDPROC)SetWindowLong(g_hTextBox, GWL_WNDPROC, (LONG)EditWndProc);
		return 0;
		break;
//Other cases as well...
}

BOOL WINAPI ConInit(HWND hWndOwner)
{
	WNDCLASS wc;
	g_hOwner=hWndOwner;
	if (!g_hWnd)
	{
		memset(&wc, 0, sizeof(WNDCLASS));
		wc.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
		wc.hCursor=LoadCursor(NULL, IDC_ARROW);
		wc.hInstance=g_hInstance;
		wc.lpfnWndProc=WndProc;
		wc.lpszClassName="DebugConsole";

		if (!RegisterClass(&wc))
			return FALSE;

		g_hWnd=CreateWindow("DebugConsole",
			"Debug Console",
			WS_OVERLAPPEDWINDOW&~WS_MAXIMIZEBOX,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			600,
			300,
			NULL,
			NULL,
			g_hInstance,
			NULL);
		if (!g_hWnd)
			return FALSE;
		g_hMenu=CreateMenu();
		AppendMenu(g_hMenu, MF_STRING, IDM_CLOSE, "Close");
		SetMenu(g_hWnd, g_hMenu);
		g_hBrush=CreateSolidBrush(g_clrBackColor);
	}
	return TRUE;
}


Thanks for any advice.

Jamie Nordmeyer
Portland, Oregon, USA
GeneralRe: Window in a DLL Pin
Tomasz Sowinski30-Aug-01 10:31
Tomasz Sowinski30-Aug-01 10:31 
Generalmemset Pin
30-Aug-01 9:22
suss30-Aug-01 9:22 
GeneralRe: memset Pin
Ravi Bhavnani30-Aug-01 9:30
professionalRavi Bhavnani30-Aug-01 9:30 
Questionftp & smb support...what should I use? Pin
Amit Dey30-Aug-01 8:44
Amit Dey30-Aug-01 8:44 
QuestionHow to show vertical scroll bar always in a CRichEditView Pin
Shrini30-Aug-01 8:35
Shrini30-Aug-01 8:35 
QuestionKilling Threads? Pin
neilbennevis30-Aug-01 8:31
neilbennevis30-Aug-01 8:31 
AnswerRe: Killing Threads? Pin
Tomasz Sowinski30-Aug-01 8:39
Tomasz Sowinski30-Aug-01 8:39 
AnswerRe: Killing Threads? Pin
Joaquín M López Muñoz30-Aug-01 8:57
Joaquín M López Muñoz30-Aug-01 8:57 
GeneralOle Word Automation Pin
AJ12330-Aug-01 8:24
AJ12330-Aug-01 8:24 
GeneralString formatting Pin
30-Aug-01 8:10
suss30-Aug-01 8:10 
GeneralRe: String formatting Pin
Nemanja Trifunovic30-Aug-01 8:14
Nemanja Trifunovic30-Aug-01 8:14 
GeneralRe: String formatting Pin
Tomasz Sowinski30-Aug-01 8:24
Tomasz Sowinski30-Aug-01 8:24 
GeneralSchizo list box Pin
Josh Knox30-Aug-01 6:53
Josh Knox30-Aug-01 6:53 
GeneralRe: Schizo list box Pin
Ben Burnett30-Aug-01 7:56
Ben Burnett30-Aug-01 7:56 
GeneralRe: Schizo list box Pin
Tomasz Sowinski30-Aug-01 7:56
Tomasz Sowinski30-Aug-01 7:56 
GeneralWord Automation - Document.SaveAs Pin
AJ12330-Aug-01 6:44
AJ12330-Aug-01 6:44 
GeneralProblems accessing CFile member within a Worker Thread Pin
30-Aug-01 6:26
suss30-Aug-01 6:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.