|
|
Hi to all,
can we change a text(static text) dynamically. I know the name itself says its static. But I ma sure there will be someway to change it in the code, exactly like labels in vb.
could anyone please tell me is there any way to do that in MFC
thanks in advance
I am a beginner
|
|
|
|
|
Hello himangshuS,
1) First change the id of static control from IDC_STATIC to something else like IDC_STATIC_NAME.
2) Get the static control by GetDlgItem() and set text by SetWindowText() .
GetDlgItem( IDC_STATIC_NAME)->SetWindowText( "Hello World" );
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Fo work with static controls you always need to set id for them and usually you need to set notify for them(of course here it doesnt need) then you can use of SetWidowText.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hamid. wrote: then you can use of SetWidowText.
Like so:
GetDlgItem(IDC_MOURNING)->SetWidowText (L"My husband died, and now I'm sad.")
?
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
No your code has a bug!
GetDlgItem(IDC_HAPPY)->SetWidowText (L"My husband is great man and now I'm happy.")
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hi,
I want to check whether active windows is desktop or not ? is it possible to check it using GetDesktopWindow(), please give me hint or short example.
thanx
|
|
|
|
|
Use GetActiveWindow() and GetDesktopWindow() and compare if the HWND s returned are the same.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
But GetActiveWindow() fails when I click on tray icon, it returns null
|
|
|
|
|
I am trying to get this program to work. It is only the first part of a Sudoku assignment but everything works until it goes to print out. I try to compile it and get an error when it gets to printing the structure. Help please asap!
#include <stdio.h>
#include <stdlib.h>
struct grid{
int row;
int col;
};
void readArray(struct grid *z);
void printArray(struct grid y);
main(){
struct grid x;
x.row = 0;
x.col = 0;
readArray(&x);
printArray(x);
system ("pause");
return 0;
}
void readArray (struct grid *z){
int i;
int gridRow;
int gridCol;
int area;
z->row = 0;
z->col = 0;
while(z->row <= 0){
printf("Enter the number of rows in each box. Number must be positive.\n");
scanf("%d", &(z->row));
}
while(z->col <= 0){
printf("Enter the number of columns in each box. Number must be positive.\n");
scanf("%d", &(z->col));
}
gridRow = (z->row)*(z->col);
gridCol = gridRow;
area = gridRow * gridCol;
struct grid *xPtr = NULL;
xPtr = (struct grid *)malloc(sizeof(struct grid));
if(xPtr == NULL){
printf("Error, could not allocate enough memory. Exiting program.\n");
exit(-1);
}
printf("Enter numbers you want in the puzzle.\n", area);
for(i=0; i scanf("%d", &((xPtr)[i]));
}
}
void printArray (struct grid y){
int rows;
int cols;
rows = y.row * y.col;
cols = rows;
if((y.row<=0) || (y.col<=0)){
printf("printArray error: one or more of the entered dimensions is less than or equal to zero.\n");
return;
}
int i, j, k;
for(j=0;j<rows;j++){>
if ((j%y.row) == 0){
for(i=0;i<(5*cols+(cols/y.col)+1);i++){
printf("-");
}
printf("\n");
}
for(i=0;i<cols;i++){>
k = j*rows + i;
if ((i%y.col)==0){
printf("|");
}
if(y[k] == 0){
printf(" ");
}
else{
printf("%3d ",y[k]);
}
}
printf("|\n");
}
for(i=0;i<(5*cols+(cols/y.col)+1);i++){
printf("-");
}
printf("\n");
}
</stdlib.h></stdio.h>
|
|
|
|
|
If you want help, you should:
a) shorten the sample code to the offending lines.
b) Edit your answer to show the files you're including. CP can occasionally be a pain.
c) Show what errors you are actually having. We might not get the same errors on our PCs, as we could have different versions of header files / OS's etc.
d) Well done on using the pre tag though! Too many people don't...
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
That is good to know for the next time I have problems but I finally figured out what the problem was. Thank you though.
|
|
|
|
|
I am looking at the book, “Windows 95 with MFC” by Jeff Prosise. In this book, there are two techniques for implementing scroll bars given. One approach is to process the messages ON_WM_VSCROLL and ON_WM_HSCROLL. The other approach is to use the class CScrollView.
I am currently using the first approach and I find that my application has the following problem: If I run the program and using the mouse I make the window small (in the horizontal direction) a horizontal scroll bar shows up. This is to be expected. I then use the mouse to move the scroll bar to the middle of the window. Now, I minimize the window and then maximize the window. After doing this, I would expect the text and the input field (of type CEdit) to be drawn aligned on the screen. However, this is not the case. The text is shifted to the right (at least relative to the input field). I do not understand why and I am hoping somebody here can tell me what I am missing.
Do you think switching to CScrollView will solve my problem?
Thanks
Bob
|
|
|
|
|
I think I figured out what I was doing wrong. When the window gets resized, I need to move
the child windows that I have in my application. The way to do this is to use the method
CWnd::MoveWindow.
The window gets moved by the offset of the scrollbar. Does this make sense? What, if any, am I missing?
Thanks
Bob
|
|
|
|
|
Your error will be heavily dependent on the fine detail of your application.
But you need to handle the WM_SIZE message to change the details of your scroll bars.
Have a look at the SCROLLINFO structure, and also the nPage member.
Then you'll want to call GetScrollInfo in your painting routine, so you know to offset your painting by a certain amount.
If you *can* use CScrollView, it does all this work for you. And set's up the DC you draw on to with SetViewportOrg etc so it's invisible for you.
I don't use it, and I do all this scroll bar myself - and there's quite a few things to trip you up.
Reading your message again... I'm not sure where this CEdit is coming in. Maybe you should be using a CFormView, put your controls on a dialog, and letting MFC do all this work instead?
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Iain,
Thanks for the response. I have a field of type CEdit defined in the main window class of the application. I will definitely take a look at the class CFormView.
Is there a reason why I might not be able use CScrollView?
Thanks
Bob
|
|
|
|
|
/* IM TRYING TO WRITE IT SO THAT I CAN SEE EACH LETTER AS IT IS BEING WRITTEN BY THE COMPUTER*/
/* Thanks in advance*/
#include <stdio.h>
main()
{
printf("\n\nH");
sleep(2);
printf("e");
sleep(2);
printf("y");
sleep(2);
return 0;
}
/* Im trying to run it one letter at a time*/
modified on Monday, March 9, 2009 8:30 PM
|
|
|
|
|
I think this is what you want:
#include <stdio.h><br />
main()<br />
{<br />
printf("\n\nH");<br />
printf("e"); ;<br />
printf("y");<br />
<br />
printf( "\n" );<br />
return 0;<br />
}
Bob
|
|
|
|
|
Yes thats good but i want two second delay between each letter written, and going horizontally
|
|
|
|
|
Now, if our goal is to write this in portable C, then there is no way to write the sleep function. However, if you use Windows Specific functions, then I believe you can do it. Here is how:
#include <windows.h><br />
<br />
#include <stdio.h><br />
<br />
main()<br />
{<br />
printf("\n\nH");<br />
Sleep( 2000 );<br />
printf("e");<br />
Sleep( 2000 );<br />
printf("y");<br />
<br />
printf( "\n" );<br />
return 0;<br />
}
The argument to Sleep is the time in milliseconds. I hope this helps. Feel free to ask a follow up question.
Bob
|
|
|
|
|
Assuming you want a 2ms delay (which is not discernable by the human eye) in between each letter, what you have is fine.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hello,
I need to translate some header file for function calls from Basic to C++ .... I am clueless when it comes to VBasic syntax...could someone provide me with some help on something like the following:
Declare Function Draw Lib "PDF_In_The_Box.dll" (ByVal hBox As Long, ByVal aX As Long, ByVal aY As Long, ByVal hBitmap As Long) As Long
Sub CallBox(ByVal aFunctionCall As Long)
Dim Msg As String * 255
Dim n As Long
If aFunctionCall = -1 Then
n = GetErrorMsg(Msg)
MsgBox Msg, 16, "PDF In-The-Box"
Stop
End If
End Sub
Function GetStr(ByVal aBoxHandle As Long, ByVal aPropID As Long) As String
Dim Result As String * 255
CallBox GetStrProp(aBoxHandle, aPropID, Result)
GetStr = Result
End Function
sft
|
|
|
|
|
For a start, the Draw function should come with a header file. If it doesn't, then load "PDF_In_The_Box.dll" using LoadLibrary(), use GetProcAddress() to get the address of the Draw() function, and call the function pointer (I think you may need to do an explicit cast here)
As for the rest:
String * 255 is a pointer to a fixed length char array of length 255 (I think it's a pointer, not sure here)
MsgBox just shows a box, it's easily ignorable
Long seems to be either a 32 or 64 bit integer - use int or long here
Stop is just a break statement
So overall the code looks a little like this
void CallBox(int aFunctionCall)
{
char[255] *msg;
if(aFunctionCall == -1)
{
GetErrorMessage(msg);
break;
}
}
char[255] *GetStr(long aBoxHandle, long aPropId)
{
char[255] *result;
CallBox(GetStrProp(aBoxHandle, aPropId, result));
return result;
}
|
|
|
|
|
Good starting point.
Thanks
sft
|
|
|
|
|
Hello all,
After installing the Visual C++ Express Edition, I've noticed that the Win32 Application Wizard does not allow you to create a DLL as the Application Type. Is there any way around this?
Thanks
|
|
|
|