|
Hi all
I've been teaching C++ for about 10 years (unmanaged using Borland Compilers), and for the first time this year I am teaching managed C++ using MS Visual Studio .NET. The first part of the course concentrates on procedural programming in a console environment, and one of the topics is writing / reading to text files (which is OK), and printing data to a printer (local LPT1 printer). In unmanaged code, I would write is as follows :
#include <fstream.h>
void main(void)
{
char data[80];
ifstream infile;
ofstream printer;
infile.open("TEST.TXT", ios::in);
printer.open("PRN");
while (infile)
{
infile.getline(data,80);
if (infile)
{
printer << data << "\n";
}
}
};
However, I cant find a simple way to set up a stream to the local printer in a console based environment using managed code. The file handling part is fine, and would look as follows :
// Filein1.cpp
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
int _tmain()
{
String *record;
StreamReader * fileIn = File::OpenText(S"Test.txt");
// Need to set up stream to printer here
while ((record = fileIn->ReadLine()) != 0)
{
Console::WriteLine(S"{0}",record); // need to replace with output to printer stream
}
Console::ReadLine();
fileIn->Close();
return 0;
}
Can anyone help me fill in the gaps ?
Many thanks
Simon Cornish
|
|
|
|
|
|
I'm creating a procedure to add bitmap image on status bar.
The problem is i don't know how to do it. If you know some links,
articles or know how to do it, please reply to my post. Your help
would be greatly appreciated. Thanks!
|
|
|
|
|
Does anyone know how to use this!
I need to make the background of my AVI transparent. I'm capturing the OnCtlColorStatic message, but what next?
I search the docs and the web but have found conflicting examples. Should I be returning a BOOL from this message (to say I've handled it) or a HBRUSH? or something completely different!
I'm lost - Can anyone shed any light on this (a snippet of code would be useful!)
Kevin.
|
|
|
|
|
Have you set the ACS_TRANSPARENT style when you created the control? That should be all you have to do.
"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!
|
|
|
|
|
Hello
How can one make a tooltip alpha blended? I've grabbed the code from MSDN, and added a WS_EX_LAYERED style to the tooltip and call to SetLayeredWindowAttributes(), which seems to be enough. But it does not work. Here's code:
void CreateMyTooltip (HWND hwnd)
{
// struct specifying control classes to register
INITCOMMONCONTROLSEX iccex;
HWND hwndTT; // handle to the ToolTip control
// struct specifying info about tool in ToolTip control
LPTOOLINFO ti;
unsigned int uid = 0; // for ti initialization
char strTT[30] = "This is your ToolTip string.";
LPTSTR lptstr = strTT;
RECT rect; // for client area coordinates
/* INITIALIZE COMMON CONTROLS */
iccex.dwICC = ICC_BAR_CLASSES;
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCommonControlsEx(&iccex);
/* CREATE A TOOLTIP WINDOW */
hwndTT = CreateWindowEx(WS_EX_TOPMOST,
TOOLTIPS_CLASS,
NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | WS_EX_LAYERED| WS_EX_TOOLWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
300,
200,
hwnd,
NULL,
NULL,
NULL
);
SetLayeredWindowAttributes(hwndTT, 0, (255 * 70)/100, LWA_ALPHA);
gOldTooltipWndProc = (FARPROC)SetWindowLong(hwndTT,
GWL_WNDPROC,
(DWORD)TooltipWndProc);
/*SetWindowPos(hwndTT,
HWND_TOPMOST,
0,
0,
0,
0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);*/
/* GET COORDINATES OF THE MAIN CLIENT AREA */
GetClientRect (hwnd, &rect);
/* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
ti = new TOOLINFO;
ti->cbSize = sizeof(TOOLINFO);
ti->uFlags = TTF_ABSOLUTE | TTF_TRACK;
ti->hwnd = hwnd;
ti->hinst = NULL;
ti->uId = uid;
ti->lpszText = LPSTR_TEXTCALLBACK;//lptstr;
// ToolTip control will cover the whole window
ti->rect.left = 0;
ti->rect.top = 0;
ti->rect.right = 0;
ti->rect.bottom = 0;
/* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) ti);
SendMessage(hwndTT, TTM_TRACKACTIVATE, (WPARAM)TRUE, (LPARAM)(LPTOOLINFO)ti);
gHwnd = hwndTT;
gpTi = ti;
}
What am i doing wrong? Thanks for help
|
|
|
|
|
Hi All,
I am in a bottleneck and need your help to come out of it. I have a Shell DLL which will load from a USB CDROM media. When the shell is loaded and my computer is open the tray Icon on the system tray is not allowing me to stop the device. To overcome this I have to logoff logon each time. I tried the normal ways of Unloading the shell DLL (By using DllCanUnloadNow()) still no use.
Thanks for your help in advance,
Raja.
|
|
|
|
|
i am a final year student from uitm.right now i am doing my final year project. i got a problem on how to develop a chat appliCation by using c++ language. my thesis title is ipv6 multicast chat application. i have to create a chat application for this. it doesn't matter whether it is a simple one.but i do not have enough skills in programming language. i have try to do it but not success. so i really really hope that if someone here who are really capable of doing chat application using c++ programming to help me.
so someone please HELP me.
-- modified at 7:48 Thursday 24th November, 2005
|
|
|
|
|
Hello,
I'm trying to modify a black&white bmp file by replacing certain areas with the data obtained from other bitmaps. I have no problem in doing this with the gdi+ functions. My problems have arrived when I have tried to insert strings in some places in the bmp file. I just don´t know how to do it. Can anybody give me the clue?
Any help will be really appreciated,
Itziar
|
|
|
|
|
If you are using GDI+, use
DrawString( ) with SetTextRenderingHint() and SetInterpolationMode.
Cheers
Jugs
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
Thank you for your help. I´ll have a look at these functions, but one more question, aren´t they used to display images? You see, I want the text to be saved into the bmp file. I´m not displaying images.
Itziar
|
|
|
|
|
You can take the Graphics object of a bitmap and draw directly to it. You can then save the Bitmap using the Save method.
Cheers
Jugs
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
Thanks. It's worked fine for colored bmps.
Itziar
|
|
|
|
|
Hi !
I want to check if a specific folder exists. I looked in the MSDN but could not find anything...
Any idea ?
Thanks
|
|
|
|
|
Hello.
You can use stat() / _stat()
Or _access()
Kakan
|
|
|
|
|
Thanks
|
|
|
|
|
Try PathIsDirectory( ) or PathFileExists( )
Cheers
Jugs
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
Hi,
CreateDirectory will return ERROR_ALREADY_EXISTS if the specific directory already exists.
Bye
Cool Ju
Dream Ur Destiny
|
|
|
|
|
if( (DWORD)-1 == GetFileAttributes(szDirectory) ){
// does not exist
} else {
// file or directory exists
}
|
|
|
|
|
Hi,
I am creating a shell namespace extension to show FTP files. I implemented cut / copy and paste using CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR. I implemented IDataObject and IStream for this. After copying, when I choose to paste the files, I am getting all the files, But the problem is that, the directory structure is not retained.
If I am copying a folder say "Test", which contains 2 files
1. a.txt
2. b.txt
When I choose paste, I am getting 2 files ( a.txt and b.txt ) and a folder ( Test ) in the same place. In fact it should have been folder "Test" and the two files inside "Test". But that is not happening.
I believe I am missing something here...
Could somebody please help me in resolving this.
Thanks and Kind Regards
Jugs
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
I have made an ActiveX control (.OCX) for web interface.
It has some member variables. And I had not implemented Get/Set methods for
those variables.
Throught the web page, I can set the values of above variables by <param> tag.
But now, I want to set the values of above variables by container application.
I made MFC application project by VC++. Above ActiveX control is inserted.
But, I cannot find the way to set the values of ActiveX's variables by the
same way as the <param> tag.
I think there is the way to set value to these variables because the Internet
Explorer can set without Get/Set methods.
How can I set the values of ActiveX's variables?
Please understand my poor English. English is not my mother tongue.
Following codes are some piece of my ActiveX control.
//################## SampleCtrl.cpp #########################
.........
void CSampleCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
// TODO: Call PX_ functions for each persistent custom property.
PX_String(pPX,_T("sUserID"), strUserID );
PX_String(pPX,_T("sVerifyCode"), strVerifyCode );
PX_Short(pPX,_T("nLevel"), nLevel );
}
........
// ############## SampleCtrl.h #####################
class CSampleCtrl : public COleControl
{
....
private:
short int nLevel;
CString strVerifyCode;
CString strUserID;
};
// ############## test.html ####################
<OBJECT ID="Sample" WIDTH=340 HEIGHT=150 CLASSID="CLSID:D870D8B9-16CC-4445-9BE3-36BDFF5621E6">
<PARAM NAME="sUserID" VALUE="superman">
<PARAM NAME="sVerifyCode" VALUE="K4HVD-Q9TJ9-6CRX9-RQ2D3">
<PARAM NAME="nLevel" VALUE="3">
</OBJECT>
-- modified at 6:22 Thursday 24th November, 2005
|
|
|
|
|
If its your ActiveX control, then expose the variables using Properties. Create a new property for each of the variable and the IDE will generate the Getter and Setter.
From your HTML / Javscript code, you can directly access the variable using the property name as they are using IDispatch. From your VC++ code, you can use Getter and Setter methods.
Cheers
Jugs
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
Thank you for your reply.
Yes, the ActiveX control is made by me.
But, I don't want to modify the ActiveX control at all.
Just I want to know how can access it's variables as the Internet Explorer.
If I will modify my ActiveX control, I can solve this problem.
But I cannot find the way to access to such variable without Get/Set methods.
Is there another way to access?
|
|
|
|
|
Hi,
I want to resize a control in list subitem as I increase or decrease
column width.I am handling this in OnCustomDraw() but it is flickering.I want to set SetRedraw() to TRUE and FALSE but in which event should I do that?
|
|
|
|
|
If the flickering occurs when you are resizing, then try calling SetRedraw() in your OnSize() handler.
"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!
|
|
|
|