|
Many thanks for the link, should have tried msdn myself
ScorpioMidget
|
|
|
|
|
I'm making a mfc dialog app and was wondering if this type of program can access a seperate file. I was hopping for the user to be able to input data (mainly text) while the mfc dialog app was running, be able to save it in some type of file, and then retrieve it at a later date. I'm new to mfc, any help would be great, if possible please state which functions need to be used to create/retrieve the data or where they can be found on the internet. Thank you.
|
|
|
|
|
http://msdn.microsoft.com[^]
"It is better to remain silent and be thought a fool than to open one's mouth and remove all doubt." - Abraham Lincoln
|
|
|
|
|
Anonymous wrote:
...if possible please state which functions need to be used to create/retrieve the data or where they can be found on the internet.
It sounds like you'll need to use a CStdioFile object for reading from and writing to a text file. Google the Internet for tons of examples. MSDN has plenty, too.
CStdioFile file("mainly.txt", CFile::modeCreate | CFile::modeWrite);
file.WriteString("This is some text that the user entered\n");
...
CString strText;
file.ReadString(strText);
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I need a way to write some binary data to a floppy. I tried using fopen("A:\\","wb") but that doesnt work because it cant open the file descriptor. In linux u can do something like that though. So how do i get a handle to the floppy? (I'm not talking about any files here or anything, i need to be able to write to the bootsector)
Thanks!
Kuniva
--------------------------------------------
|
|
|
|
|
|
fopen() requires a filename, not just a path.
FILE *f = fopen("a:\\myfile", "wb");<br />
fprintf(f, ...);<br />
fclose(f);
Now, in order to write to the disk's boot sector, I'm not sure how that'd be done. I have a suspicion that CreateFile() might be used as it can access physical disks, rather than just drives like C: and D:
Windows NT comes with a utility called DiskProbe, which is a low-level disk editor.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
hey,
I want to change my process security token to another user.
basically what I need is when the app loads, it displays a user/pass dialog.
and then it changes the security token of the process as if it was run as the entered user/pass. according to what I heard, I can do something like this in two ways. 1) making another application that will display the dialog and then open my application with Api's like CreateProcessAsUser or CreateProcessWithLogon. 2) Use impersonation to change the security token of the process. I really prefer the second way, but I don't know where to start. and I don't know if it really is possible, I only found clues on how to impersonate a thread.. not a process.
Waiting for answer..
Arik Poznanski
|
|
|
|
|
Use LogonUser(), and pass the resulting handle into ImpersonateLoggedOnUser(). Just use RevertToSelf() to switch back to "the real you".
|
|
|
|
|
If you want your app to run on things other than XP (ie W2K, NT4) then there is another issue, which is that you must run your app from an account which originally has SeTCBPrivilege. This is off by default (sensibly) for most users. With NT and W2K you can use the NTRIGHTS app from the resource kit to turn it on, but I'd think about why, to be honest, since it's a potential hole in system security.
Steve S
|
|
|
|
|
Is it possible to display an Image say .GIF, .JPEG in a picture control?? I need to display picture in a dialog , is there any other way except .BMP
Warm Regards,
KKR
|
|
|
|
|
Start here:
http://www.codeproject.com/bitmap/
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I am writing a piece of code to read in data a piece of hardware at a byte at a time.
I have a structure which is made up as follows:
typedef struct {<br />
unsigned short int U16_DemandedDeflection; <br />
unsigned short int U16_DemandedToolface;<br />
unsigned short int U16_Beta; <br />
char U8_Toolface_K; <br />
unsigned short int U16_PumpBackThreshold;<br />
unsigned short int U16_RpmAveragingFactor;<br />
unsigned short int U16_WalkAroundAngle;<br />
char U8_WalkAroundDwellTime;<br />
unsigned short int U16_DemandedMagneticToolface<br />
unsigned short int U16_MagneticBeta;<br />
char U8_ToolfaceControlMode;
unsigned short int U16_NeutralThreshold;<br />
char U8_Spare[3];<br />
}SCB_ControlSystem;
I have set up a pointer to point to the start of the structure
unsigned char * pSCB_Byte_Pointer;<br />
<br />
pSCB_Byte_Pointer = (unsigned char *)&SCB_ControlSystem;
The visual C++ program does the following:
Repeat
Read in the char
Put the char into the memory pointed to by pSCB_Byte_Pointer
If it is a two byte number reverse the contents of memory
Until
The read in and the poke part of the program works fine, but when I look at the structure the value for U16_PumpBackThreshold is incorrect. (
After single stepping and looking at the Microsoft website I have found that short int’s are setup on the even boundary.
I want to force the compiler to be able to put short int’s on an odd or even boundary.
Or
Come up with an efficient way of writing the code (The structure of the data has not been finalised yet)
The Fox
|
|
|
|
|
TheFox wrote:
I want to force the compiler to be able to put short int’s on an odd or even boundary.
Try using #pragma pack(1). This forces the compiler to use packing alignment for structure and union members. Make sure you use #pragma pack (push, ...) and #pragma pack (pop, ...) either side so that you don't realign other data structures.
|
|
|
|
|
In my mFC app,i have 2 CPP files.In CPP 1 i have a array of structs as like this:
struct Menu{
char* pcTitle;
char* pcItem;
int nCount;
int nID;
};
struct Menu arrMenu[10];
I want to access this arrMenu[10] in my 2nd CPP file and declared as
extern struct Menu arrMenu[10];
When try to use this struct in CPP2 file i get error as :
" 'struct Menu *' : unknown size
"use of undefined type 'Menu'"
Pls help how to use arrMenu[10] as extern variable and use it in CPP 2 file..
Thnks
Ram
|
|
|
|
|
Declare the Menu structure in the header of CPP1, and include that file in CPP2. Thats all...
"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."
|
|
|
|
|
A .H file...
---------------------------------------------
#ifndef Some_H
#define Some_H
#import "Some.tlb" no_namespace, \
named_guids
#endif // Some_H
---------------------------------------------
and the Compiler is giving following stupid error...
---------------------------------------------
error C4772: #import referenced a type from a missing type library; '__missing_type__' used as a placeholder
---------------------------------------------
Helppppppppp!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! requested
mE
---------------------
A gasp of breath,
A sudden death:
The tale begun.
A rustled page
Passes an age:
The tale is done.
|
|
|
|
|
The type library you have referenced uses another type library that was not referenced with #import. This other .tlb file was not found by the compiler, so go and check it out.
"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'm trying to exit my MFC application but from a different thread
The separate thread is started using timeSetEvent(), this separate timer is used to loop through received udp messages. When one of this messages tells me that the overall application(made os differennt exec) setup is wrong, I must exit.
when using PostMessage with WM_QUIT, I get a bunch of pointers which are null
Is there a better way to exit... or maybe I should not use the timeSetEvent() function?
|
|
|
|
|
A better way would be to signal your main thread, that some thing has gone wrong and terminate the application.
Are you using a CWnd->PostMessage or ::PostMessage( HWND ). You are not supposed to access any of the objects created by other threads, So use only ::PostMessage( HWND ).
"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."
|
|
|
|
|
A better way would be to signal your main thread that something has gone wrong and terminate the application using PostQuitMessage( ).
Are you using CWnd->PostMessage( ) or ::PostMessage( HWND ). You are not supposed to access objects created by other threads. So always use ::PostMessage( HWND ) from threads.
"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 actually tried both ways and none of them worked...
I used...
HWND _hwnd = AfxGetApp()->GetMainWnd()->m_hWnd;
PostMessage(_hwnd, WM_QUIT, a_ExitCode, 0);
I have tried with WM_CLOSE as well
|
|
|
|
|
AfxGetApp()->GetMainWnd()->m_hWnd
'AfxGetApp()->GetMainWnd()' this is where the bug resides. You are not supposed to access the Main window from your thread. You have to some how pass the HWND of the main window to the thread fn. Then you can use this HWND to send the ::PostMessage( HWND, WM_QUIT,..)
If you are using the AfxBeginThread fn, you can pass this parameter as LPVOID. Since you are using timeSetEvent, you can pass the HWND on DWORD_PTR parameter.
"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."
|
|
|
|
|
Okay, i have this problem with a screensaver i'm writing. Basically i want to write a screensaver that plays a video.
Then when the mouse is moved (or a key pressed) the program quits.
Everything works fine, except when the mouse is moved over the area of the video playing.
the following function doesnt get any "WM_MOUSEMOVE" callback while the mouse is over the video area
LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
///////////////
my guess is that it might be a problem with the following
MCI_DGV_WINDOW_PARMS mciWindow;
mciWindow.dwCallback = 0L; //Here
mciWindow.hWnd = hWnd;
mciWindow.nCmdShow = SW_SHOW;
anyways, the
mciSendCommand(gwMCIDeviceID, MCI_PLAY, dwFlags, (DWORD)(LPMCI_DGV_PLAY_PARMS)&mciPlay);
function doesnt return any "WM_NOTIFY" call back or anything to the ScreenSaverProc
Any help with this would be greatly appriciated
|
|
|
|
|
I'm having problems with the CMemDC inside a CStatic derived class.
void MyStatic::OnPaint()<br />
{<br />
CPaintDC dc(this);<br />
CMemDC memDC(&dc);
<br />
CBrush brush(RGB(255,0,0));<br />
CPen pen(PS_SOLID,1,RGB(0,0,0));<br />
<br />
HBRUSH oldbrush=(HBRUSH)memDC->SelectObject(brush);<br />
HPEN oldpen=(HPEN)memDC->SelectObject(pen);<br />
<br />
memDC->Rectangle(&r);<br />
<br />
memDC->SelectObject(oldbrush);<br />
memDC->SelectObject(oldpen);<br />
}<br />
<br />
BOOL MyStatic::OnEraseBkgnd(CDC* pDC)<br />
{<br />
return TRUE;<br />
}
If I use this inside a derived CSliderCtrl, for example, a nice red box will be drawn with a black outline on a gray dialog. Top!
But inside a derived CStatic, the dialog is entirely white, nothing else. I've 2 different versions of CMemDC (both currently on codeproject), there's one that returns a white dialog, the other gives some random colors, like a corrupt bitmap.
What am I doing wrong here?
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
|
|
|
|