|
And what does that have to do with C/C++/MFC?
|
|
|
|
|
Hi,
i want to create a composite activex control to put together several contols. The control must be fully transparent and consist of several self written and 3rd party controls. I was searching the web for several days now and cannot find any sample / tutorial for this.
Thanks in advance!
|
|
|
|
|
If Google does not find any then you may have to do the design yourself.
|
|
|
|
|
Yes, right, that's the question!
How can i load / create the additional controls, if not at designtime, maybe at runtime, without getting a linker error? Positioning the additional control will be done at runtime, when the contol changes size, anyway. I have included the LIB-file of my control into the references, but the error stays. Have you got a code snippet of how to create a control at runtime? I am really desperate for this.
|
|
|
|
|
Member 12785864 wrote: Have you got a code snippet of how to create a control at runtime? No: as I said, if Google cannot find one then you most likely have to figure it out yourself.
|
|
|
|
|
You can do it via the resource system, you can extend it to even deal with custom controls and even activeX ones.
Search "Win32 dialog template at runtime" it is fairly commonly done with dialog templates but you can do it with windows or anything else.
Essentially the WM_CREATE (OnCreate in MFC) loads the dialog template from a resource and you create the setup on the fly.
In vino veritas
|
|
|
|
|
Hello Leon,
I have included the Controls .h file and created a member variable in the new control's class, but when i try to show the <control>.ShowWindow(SW_SHOW) or MoveWindow function in the OnCreate or OnDraw nothing shows up.
I could not add the contol to the ressource editor, because I don't want to / need a dialog in the new control. Have you got any other idea?
Thanks a lot.
Richard
|
|
|
|
|
You don't have to add the resource you make a memory template, its the exact opposite of a resource ... I am not sure you are really getting it
In code you do this creating a memory block which you make the template in
bool CreateRotation (HWND parent){
int nchar, ret;
HGLOBAL hgbl;
LPDLGTEMPLATE lpdt;
LPWORD lpw;
LPWSTR lpwsz;
hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024);
if (!hgbl) return false;
lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl);
lpdt->style = WS_POPUP | WS_CAPTION | WS_SYSMENU;
lpdt->cdit = 0;
lpdt->x = 80;
lpdt->y = 80;
lpdt->cx = 300;
lpdt->cy = 100;
lpw = (LPWORD)(lpdt + 1);
*lpw++ = 0;
*lpw++ = 0;
lpwsz = (LPWSTR)lpw;
nchar = 1 + MultiByteToWideChar(CP_ACP, 0, LanguageString[652],
-1, lpwsz, 50);
lpw += nchar;
*lpw++ = 0;
GlobalUnlock(hgbl);
ret = (int)DialogBoxIndirectParam(GetModuleHandle(0),
(LPDLGTEMPLATE)hgbl,
parent,
(DLGPROC)RotationHandler,
0);
GlobalFree(hgbl);
if (ret == ID_Ok) {
PostMessage(parent, WM_COMMAND, WSC_UPDATEEVERYTHING, 0);
return true;
} else return false;
};
They are called runtime dialogs or dynamic dialogs but you can always know you are on the right track when you see the use of GlobalAlloc because you have to lock a block of memory to create the dialog in, which is why you don't need resource files etc.
Dynamic Dialog Boxes and C++ | Dr Dobb's[^]
In vino veritas
|
|
|
|
|
i tries but the rest lies here.
#include <conio.h>
#include <stdio.h>
int main(){
int num[50], i=0, largest, count =0;
int k, j;
printf("Enter 0 to exit entering integers.\n\nEnter your integers:\n");
do{
scanf("%d", &num[i]);
i++;
count++;
}while(num[i-1]!=0);
while(count>=0){
largest = 0;
for(j=0; j<=count-1; j++){
if(num[j] > largest){
largest = num[j];
j=k;
}
}
printf("%d", largest);
for(j=k; j<=count-1; j++){
num[j] = num[j+1];
}
count = count - 2;
}
return 0;
}
|
|
|
|
|
Maybe take a look at this[^] thread.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
So what's the problem? Can we assume you've stepped through the code, line by line, using the debugger (to see the value of each variable along the way)?
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
You need to stop writing code for a while and spend more time thinking about the problem. What steps are needed to accomplish your goal? Write them down on paper, line by line to understand what needs to be done at each step. I already showed you how to find the largest number in a sequence and you are still making it more complicated. As you read in the integers in the first loop you can check for the largest as you store them, you do not need a second loop. You also need to look at the statement in the second loop:
largest = num[j];
j=k;
What is the value of k at this point?
And in the final loop you are just moving numbers, with no regard to whether they are in any order.
|
|
|
|
|
What you basically need to do is to sort the array in descending order.
There are several sorting algorithms.
This the first google search link I found for sorting - Sorting Arrays[^]
Go through them, try them and understand them.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
#include <stdio.h>
#define N 50
int main()
{
int num[N], i=0, count =0;
printf("Enter 0 to exit entering integers.\n\nEnter your integers:\n");
do
{
if( scanf("%d", &num[i]) != 1) break;
++i;
count++;
} while ( i<N && num[i-1] !=0 );
int k = 0;
while(k < count-1)
{
int largest_index = k;
for(i=k+1; i<count; ++i)
{
if( num[largest_index] < num[i] )
largest_index = i;
}
int tmp = num[k];
num[k] = num[largest_index];
num[largest_index] = tmp;
++k;
}
for (i=0; i<count; ++i)
printf("%d\n", num[i]);
return 0;
}
As an alternative, tou might use qsort :
#include <stdio.h>
#include <stdlib.h>
#define N 50
int comp(const void * a, const void *b)
{
return *(int *)b - *(int*)a;
}
int main()
{
int num[N], i=0, count =0;
printf("Enter 0 to exit entering integers.\n\nEnter your integers:\n");
do
{
if( scanf("%d", &num[i]) != 1) break;
++i;
count++;
} while ( i<N && num[i-1] !=0 );
qsort(num, count, sizeof(num[0]), comp);
for (i=0; i<count; ++i)
printf("%d\n", num[i]);
return 0;
}
modified 16-Oct-17 9:37am.
|
|
|
|
|
i need to find the biggest number, but it doesn't print the biggest number.
#include <conio.h>
#include <stdio.h>
int main(){
int num[50], i=0, j, count =0;
printf("Enter 0 to exit entering integers.\n\nEnter your integers:\n");
do{
scanf("%d", &num[i]);
i++;
count++;
}while(num[i-1]!=0);
for(i=0; i<=count -1; i++){
for(j=0; j<=count-1; j++){
if(i != j)
num[i] > num[j];
else
break;
}
printf("%d is the biggest number", num[i]);
}
return 0;
}
modified 13-Oct-17 12:07pm.
|
|
|
|
|
Tarun Jha wrote: num[i] > num[j];
I suspect that you think that line is doing something that it is not.
Put some curly braces around that line then print out the values before and after it.
|
|
|
|
|
do you mean inside he inner for loop, to print value of i ?
|
|
|
|
|
Print i,j and the array values of each before and after that line.
|
|
|
|
|
Most of that code is redundant, all you need is something like:
int num = -1, largest = 0;
do{
printf("Enter an integer, 0 to exit:\n");
scanf("%d", &num);
if (num > largest)
largest = num;
}while(num != 0);
printf("%d is the biggest number", largest);
|
|
|
|
|
I know that method but i need to know what is wrong with the one i am working with.
|
|
|
|
|
Start with the hint that jschell gave, look at that line of code and see what it is doing if anything, or better yet step though each line of code with a debugger.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Tarun Jha wrote: what is wrong with the one i am working with. Your second loop makes no sense as you are using two index varaibles when you only need one, and you never compare the values to see which is largest, or keep a note of the largest value you have found so far.
|
|
|
|
|
ohh! Thank you.
but the code written below only works some time..
#include <conio.h>
#include <stdio.h>
int main(){
int num[50], i=0, j, count =0;
int k, b;
printf("Enter 0 to exit entering integers.\n\nEnter your integers:\n");
do{
scanf("%d", &num[i]);
i++;
count++;
}while(num[i-1]!=0);
for(k=0; k<=count-2; k++){
for(j=0; j<=count-2; j++){
if(k != j){
num[k] > num[j];
b = k;
continue;
}
else
break;
}
}
printf("%d is the biggest number", num[b]);
return 0;
}
modified 13-Oct-17 13:39pm.
|
|
|
|
|
Tarun Jha wrote: ...only works some time Which technically means it does not work. If your algorithm is dependent upon its input in order to produce the correct output, it is wrong, period.
You should be able to do this entire exercise using pencil and paper before ever committing anything to code. Short of that and you are just guessing (hoping) at best.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Yes, because your code is still wrong, mainly because there is no logic to it. I gave you the answer in a previous comment, which should at least give you an idea of the logic involved in such a simple task.
|
|
|
|