|
In my app, I applied SetMapMode() to CView's DC for zoom in-out purpose, drawing (such as LineTo()) and bitmap (such as StretchBlt()) are changed properly with zoom's change.
Problem is that text size (such as by TextOut()) keeps the same even zoom is changed.
Do you know how to change text size automatically when zoom is changed? -- do not use SetFont() or similar functions to change font size.
thx
|
|
|
|
|
|
As I tested, the function can not change text size.
|
|
|
|
|
Friends,
I want to launch command prompt window from my application running on Windows Vista. For this purpose i am using CreateProcess. What i want is that command prompt window shoul be launched with Administrative priviliges. Please tell me how can i do so ?
Imtiaz
|
|
|
|
|
I'm not sure about CreateProcess().
But maybe this:
::ShellExecute(NULL, _T("runas"), _T("c:\\Windows\\System32\\cmd.exe"), _T(""), _T(""), SW_SHOWNORMAL);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Not counting the run as administrator part, I'd do it like this:
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <shellapi.h>
#include <malloc.h>
#pragma comment(lib, "shell32.lib")
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
DWORD size = GetEnvironmentVariable(_T("ComSpec"), NULL, 0);
LPTSTR pPath = static_cast<LPTSTR>(_alloca(size*sizeof(TCHAR)));
GetEnvironmentVariable(_T("ComSpec"), pPath, size);
ShellExecute(NULL, NULL, pPath, NULL, NULL, SW_SHOWNORMAL);
return 0;
}
This code makes no assumptions about the location of the windows folder or the location and name of the command interpreter.
Steve
modified on Wednesday, March 5, 2008 10:08 PM
|
|
|
|
|
Sweet! Thanks for that!!
Just add the runas verb and it will prompt for elevation...
ShellExecute(NULL, _T("runas"), pPath, NULL, NULL, SW_SHOWNORMAL);
Filed for future reference, thanks!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In addition to Mark's reply, see here[^].
Steve
|
|
|
|
|
Imtiaz Murtaza wrote: For this purpose i am using CreateProcess. What i want is that command prompt window shoul be launched with Administrative priviliges
have a look at CreateProcessWithLogon, CreateProcessWithToken, CreateProcessAsUser.
|
|
|
|
|
I would really like to use CWinThread class.
I have an odd situation where i am in a dll and would like to use a thread. For come reason CWinThread is not accessible here.
When i try to inclde afxwin.h before my stdafx.h
I would not compile on :
CWinThread *pThread;
I get the following errors
error C2143: syntax error: missing ';' before'*'
error C2501: 'CWinThread':missing storage-class or type specifiers.
Any idea what is going on here?
|
|
|
|
|
Maybe there is something in my 'properties' that i am missing ?? 
|
|
|
|
|
Why not include afxwin.h IN stdafx.h?
Build a quick temporary MFC project with the project wizard and you'll see a working arrangement
for the MFC header files.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Have the same problem if i include afxwin.h IN stdafx.h
Could it be that my .dll is a win32 and cannot run MFC classes?
|
|
|
|
|
How would i get around this using a Win32 dll trying to implement an MFC class like CwinThread? If this is not possible, what are my thread options. I am simply creating a waitable timer but wanted to do this in a thread.
thanks,
|
|
|
|
|
If all you are using is CWinThread from MFC, then you really don't need the
entire MFC library. Just use what's appropriate for a given module:
Module uses Use this to create a thread
------------ -------------------------------
MFC: CWinThread
CRT (no mMFC): _beginthread()/_beginthreadex()
No CRT or MFC: CreateThread() Windows API
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
An MFC DLL is a Win32 DLL. Getting it to compile has nothing to do with
the type of DLL.
The MFC header file(s) and/or Windows SDK header files need to be included
in a certain order.
Again, if you need to know for sure how to order the includes correctly,
create a temporary MFC project with the wizard and copy the way
stdafx.h is layed out. It's better than trying to guess.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi ,
I have a requirement , where I want one entity to be persistent in the computer.
I am struggling to decide on what this entity will be .
My model is such that I want to be able to intercept USB device notifications utilizing the WM_DEVICE_CHANGE messages by creating a hidden window in this entity and then update the elements of a system tray icon ( which exposes a Menu ) .
So my requirement does not fit the Client Server model , yet I am leaning towards COM to provide one EXE that does it all . So in other words , this entity will not provide any APIs for other clients to use . Am I unnecessarily using COM ?
So finally I need to finalize the form that this need to take .
Service - actually the Visual Studio 6 gives the option to create a COM Object as a Service.
COM DLL
COM EXE
Standalone EXE ?
Your inputs are really appreciated
Engineering is the effort !
|
|
|
|
|
I think a stand alone exe will do the trick. You can prevent more than one instance running at a time easily enough with a named mutex. You can have the main window as your hidden window which keeps things simple, perhaps one DLL to encapsulate the system tray icon stuff, I've seen that done well although it's not easy unless you're targetting only XP or only Server 200?, and another to encapsulate the USB WM_DEVICE_CHANGE stuff, I've written one like that but it's closed source . I can tell you that you may need to download a DDK to get the correct headers for the defines you might need, again if you use any XP and upward only defines it won't work on earlier system. Win2K in the earliest that has usably reliable USB device stuff although some things work a bit on Win98.
Do you need COM? You might need a little to get the System tray stuff to work, It's been too long since I looked at it, but nothing more complex than emulating a VB enumeration type if that.
A Service? No as long as you can start your app on or near startup and automatically I can't see the need for it being a service. A service shouldn't interact with the UI anyway so not if it's going to have an icon. Remember to scan for already plugged in USB devices on startup and also that they can be reported as fixed or removable, sometimes depending on the chipset revision on the removable media in the removable drive!
Enjoy
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I have two different object CLX_MITSUBISHI_POLLING and CLX_LENZE_POLLING. These two classes both inherit four other classes that are similar but not identical. The functions names and parameter of the different inherited classes are identical but the code is not.
I am have difficultly finding a way to create a generic class object pointer and then useing the new operator. I am finding it difficult because, i don't have a way to create a generic base class because of the four other objects inherited(CLX_LENZE_LIFT_INVERTOR,etc.) I was thinking may i could do something with templates or null pointer( void *inverter; inverter = new CLX_MITSUBISHI_POLLING();) Unfortunately, the null pointer did not work. Any recommendations would be greatly a appreciated.
Cheers Scott
<br />
CLX_POLLING *Invertors;<br />
<br />
if( inverter_type == MITSUBISHI )<br />
Invertors = new CLX_MITSUBISHI_POLLING;<br />
else <br />
Invertors = new CLX_LENZE_POLLING;<br />
My CLX_MITSUBISHI_POLLING clases
<br />
#pragma once<br />
#include "windows.h"<br />
#include "ClxThread.h"<br />
#include "ClxSafeQue.h"<br />
#include "ClxMitsubishiParameters.h"<br />
#include "ClxMitsubishiLiftInvertor.h"<br />
#include "ClxMitsubishiPitchInvertor.h"<br />
#include "ClxMitsubishiRollInvertor.h"<br />
#include "ClxMitsubishiCounterWeightInvertor.h"<br />
<br />
class CLX_MITSUBISHI_POLLING : <br />
public ClxThread,<br />
public CLX_MITSUBISHI_PITCH_INVERTOR,<br />
public CLX_MITSUBISHI_ROLL_INVERTOR,<br />
public CLX_MITSUBISHI_LIFT_INVERTOR,<br />
public CLX_MITSUBISHI_COUNTERWEIGHT_INVERTOR<br />
{<br />
public:<br />
CLX_MITSUBISHI_POLLING(void);<br />
~CLX_MITSUBISHI_POLLING(void);<br />
bool mStartPolling(void){ return CreateNewThread(); } <br />
<br />
<br />
private:
unsigned short m_BaudRate;<br />
int m_CommPort;<br />
int m_SerialPortHandlePolling; <br />
public: <br />
bool mvInitComm( int comm_port, int baud_rate );<br />
bool mvCloseComm( void );<br />
bool mvRestartComm( void ); <br />
void mvSetBaudRate(int value);<br />
unsigned short mvGetBaudRate(void);<br />
void mvSetCommPort(int value);<br />
unsigned short mvGetCommPort(void);<br />
int mvGetSerialPortHandle( void );<br />
void mvSetSerialPortHandle( int );<br />
private:<br />
int mvPutByte( char txdata );<br />
int mvPutPacket( int lenght, char txdata[] ); <br />
int mvGetBytes( void );<br />
int mvFlushRxBuf( void );<br />
int mvFlushTxBuf( void );<br />
int mvGetRxBuf(void);<br />
int mvGetTxBuf(void); <br />
bool mvIsOverrunErrors(void);<br />
bool mvIsParityErrors(void);<br />
bool mvIsRxBufferEmpty(void);<br />
bool mvIsTxBufferEmpty(void);<br />
int mvGetRxBufferSize(void);<br />
int mvGetTxBufferSize(void);<br />
private: <br />
void ThreadRun(void);<br />
CRITICAL_SECTION m_csMitsubishiPolling;<br />
};
My CLX_LENZE_POLLING clases
#pragma once<br />
#include "windows.h"<br />
#include "ClxThread.h"<br />
#include "ClxSafeQue.h"<br />
#include "ClxLenzeRollInvertor.h"<br />
#include "ClxLenzeLiftInvertor.h"<br />
#include "ClxLenzePitchInvertor.h"<br />
#include "ClxLenzeCounterWeightInvertor.h"<br />
<br />
<br />
<br />
class CLX_LENZE_POLLING : <br />
public ClxThread,<br />
public CLX_LENZE_PITCH_INVERTOR,<br />
public CLX_LENZE_ROLL_INVERTOR,<br />
public CLX_LENZE_LIFT_INVERTOR,<br />
public CLX_LENZE_COUNTERWEIGHT_INVERTOR<br />
{<br />
public:<br />
CLX_LENZE_POLLING(void);<br />
~CLX_LENZE_POLLING(void);<br />
bool mStartPolling(void){ return CreateNewThread(); } <br />
<br />
private: <br />
void ThreadRun(void);<br />
CRITICAL_SECTION m_csLenzePolling;<br />
<br />
private:
unsigned short m_BaudRate;<br />
int m_CommPort;<br />
int m_AllSerialPortHandle; <br />
public: <br />
bool mvInitComm( int comm_port, int baud_rate );<br />
bool mvCloseComm( void );<br />
bool mvRestartComm( void ); <br />
void mvSetBaudRate(int value);<br />
unsigned short mvGetBaudRate(void);<br />
void mvSetCommPort(int value);<br />
unsigned short mvGetCommPort(void);<br />
int mvGetSerialPortHandle( void );<br />
void mvSetSerialPortHandle( int );<br />
private:<br />
int mvPutByte( char txdata );<br />
int mvPutPacket( int lenght, char txdata[] ); <br />
int mvGetBytes( void );<br />
int mvFlushRxBuf( void );<br />
int mvFlushTxBuf( void );<br />
int mvGetRxBuf(void);<br />
int mvGetTxBuf(void); <br />
bool mvIsOverrunErrors(void);<br />
bool mvIsParityErrors(void);<br />
bool mvIsRxBufferEmpty(void);<br />
bool mvIsTxBufferEmpty(void);<br />
int mvGetRxBufferSize(void);<br />
int mvGetTxBufferSize(void);<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
};
All the below classes are identical except for function name which will be Lift, Roll, Pitch, or CounterWeight accordingly. The inherited PARAMETERS contains function to send and recieve packets. It also has a some virtual function such as mvGetByte, mvPutByte. mvSetCommPort. This virtual function are overrided in CLX_MITSUBISHI_POLLING and CLX_LENZE_POLLING so the all the inherited classes use the same serial port. The only differents in LENZE or MITSUBISHI is in the individual functions.
CLX_LENZE_PITCH_INVERTOR
CLX_LENZE_ROLL_INVERTOR
CLX_LENZE_LIFT_INVERTOR
CLX_LENZE_COUNTERWEIGHT_INVERTOR
CLX_MITSUBISHI_PITCH_INVERTOR
CLX_MITSUBISHI_ROLL_INVERTOR
CLX_MITSUBISHI_LIFT_INVERTOR
CLX_MITSUBISHI_COUNTERWEIGHT_INVERTOR
<br />
#pragma once<br />
#include "Windows.h"<br />
#include "ClxSafeQue.h"<br />
#include "ClxMitsubishiParameters.h"<br />
<br />
<br />
class CLX_MITSUBISHI_LIFT_INVERTOR : <br />
public CLX_MITSUBISHI_PARAMETERS<br />
{<br />
public:<br />
CLX_MITSUBISHI_LIFT_INVERTOR(void);<br />
~CLX_MITSUBISHI_LIFT_INVERTOR(void);<br />
<br />
void LiftSetAddress( char address ); <br />
char LiftGetAddress( void ); <br />
<br />
void LiftSetJogFrequency( double value );<br />
double LiftGetJogFrequency( void );<br />
<br />
void LiftSetConfigurationVoltage( int volts ); <br />
int LiftGetConfigurationVoltage( void ); <br />
<br />
bool LiftisConnected( void );<br />
bool LiftisInhibited( void );<br />
bool LiftisActiveFault( void );<br />
bool LiftisBootMode( void );<br />
bool LiftisSerialMode( void );<br />
bool LiftisAnalogMode( void );<br />
bool LiftisUnknownMode( void ); <br />
<br />
bool LiftGetBusVoltage( double *dTemp);<br />
bool LiftGetOutputVoltage( double *dTemp); <br />
bool LiftGetOutputCurrent( double *dTemp); <br />
bool LiftGetOutputFrequencey( double *dTemp); <br />
bool LiftGetOutputTemperature( double *dTemp );<br />
bool LiftGetPoweronTime( double *dTemp); <br />
bool LiftGetOperatingTime( double *dTemp); <br />
<br />
bool LiftGetActiveFault( int *iTemp ); <br />
bool LiftGetLastFault( int *iTemp); <br />
bool LiftGetLastFault2( int *iTemp); <br />
bool LiftGetLastFault3( int *iTemp); <br />
<br />
bool LiftInitDefaultsCmd(void); <br />
bool LiftDriveStateCmd(void); <br />
bool LiftAutotuneCmd(void); <br />
bool LiftEnableCmd( void ); <br />
bool LiftDisableCmd( void ); <br />
bool LiftAnalogModeCmd( void ); <br />
bool LiftAnalogBrakeNormalCmd( void ); <br />
bool LiftAnalogBrakeInvertedCmd( void );<br />
bool LiftSerialModeCmd( void ); <br />
bool LiftSerialBrakeNormalCmd( void ); <br />
bool LiftSerialBrakeInvertedCmd( void ); <br />
bool LiftResetFaultsCmd( void ); <br />
bool LiftJogCwCmd( void ); <br />
bool LiftJogCcwCmd( void ); <br />
bool LiftJogStopCmd( void ); <br />
<br />
void LiftDisableParity( void ) { DisableParity(); }<br />
void LiftEnableParity( void ) { EnableParity(); }<br />
bool LiftGetParity( void ) { GetParity(); }<br />
void LiftSetRxTimeout( unsigned long value ) { SetReceiveTimeout(value); }<br />
int LiftGetRxTimeout( void ) { return GetReceiveTimeout(); }<br />
void LiftSetRxRetryNum( int value ); <br />
int LiftGetRxRetryNum( void );<br />
<br />
void LiftRun( void );<br />
<br />
private:<br />
bool LiftActivateCmd( char incmd );<br />
<br />
ClxSafeQue<char> m_sqCmdQue;<br />
CRITICAL_SECTION m_csLock; <br />
<br />
char m_cAddress;
double m_dJogFrequency;
int m_cConfigurationVoltage; <br />
bool m_bActiveFault;
bool m_bConnected;
bool m_bInhibited;
bool m_bIsBootMode;
bool m_bIsSerialMode;
bool m_bIsAnalogMode;
bool m_bIsUnknownMode;
bool m_bValidDriveState; <br />
double m_dBusVoltage;
bool m_bValidBusVoltage; <br />
double m_dOutputVoltage;
bool m_bValidOutputVoltage; <br />
double m_dOutputCurrent; <br />
bool m_bValidOutputCurrent; <br />
double m_dOutputFrequencey; <br />
bool m_bValidOutputFrequencey; <br />
double m_dOutputTemperature; <br />
bool m_bValidOutputTemperature; <br />
double m_dOperatingTime; <br />
bool m_bValidOperatingTime; <br />
double m_dPowerOnTime;
bool m_bValidPowerOnTime; <br />
int m_iActiveFault;
bool m_bValidActiveFault; <br />
int m_iLastFault; <br />
bool m_bValidLastFault; <br />
<br />
int m_iLastFault2;
bool m_bValidLastFault2; <br />
<br />
int m_iLastFault3;
bool m_bValidLastFault3; <br />
<br />
<br />
unsigned long m_lCurrentNumTxPktFailed; <br />
unsigned long m_iMaxinumNumTxPktFailures; <br />
unsigned long m_lTotalNumTxPktFailed; <br />
unsigned long m_lTotalNumTxPktCount; <br />
char m_cPollingCommandIndex;<br />
<br />
<br />
};<br />
<br />
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
Are you sure you provided the smallest amount of code required to understand your problem?
From "How to get an answer to your question":
#4 Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
led mike
|
|
|
|
|
It's not a easy simple C++ Question.
Scott
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
|
|
Mark Salsbery wrote: See what I've done here?
No, but I can picture you flopping all around inside his boat.
led mike
|
|
|
|
|