|
Theo Buys wrote: I must do dialog development in 1024 x 768 pixels at 96 dpi Dialogs have their own measurement system (dialog units) which is supposed to make them look the same on any screen. But, as I said above, if you magnify to 150% you need to make sure it will still fit in the space you have.
|
|
|
|
|
|
Thanks! This is the info where I was looking for!
|
|
|
|
|
We define accelerators in the resource file like this :
IMB_MYAPP ACCELERATORS
BEGIN
"0", IDM_MY_ACTION, VIRTKEY, CONTROL, NOINVERT
END
This will let me use the ctrl-0 key to do "IDM_MY_ACTION".
This only works for the left-control key; the right control-key does not work.
Is there a way to define an accelerator for the right-control key in the resource or do I have to handle that in the code ?
Thanks
I'd rather be phishing!
|
|
|
|
|
I have just tried this and it works with both left and right CTRL keys. It must be something to do with your system.
[edit]
If you look at the structure of an accelerator table (ACCEL structure (Windows)[^]) you can see that there is only a single value to represent either control key,
[/edit]
modified 5-Nov-17 9:12am.
|
|
|
|
|
Yeah, at first it did not work, but for some reason it works as expected.
I'd rather be phishing!
|
|
|
|
|
Greetings, i have a problem finding a solution for this algorithm: i have to find the maximun range in an unordered array (i cant order the array). An example will be:
+--------------------------+
| 100 | -10 | -10 | -10 | 100 | --> this sould return the range 0-4
+--------------------------+
+-----------------+
| -7 | 5 | -1 | 9 | -6 | --> this sould return the range 1-3
+-----------------+
+-----------------+
| -7 | 5 | -6 | 9 | -6 | --> this sould return the range 3-3
+-----------------+
I dont have problems doing the algorithm in O(n^2) but i need to do this algoithm in O(n), can anyone help me?
Cuadratic algorithm:
void maximunSegment(vector<int> &V, int &start, int &end){
int i = 0, j = 0, r = 0, aux = 0;
start = 0; end = 0;
while(i < V.size()){
j = i;
while(j < V.size() - 1){
aux += V[j];
if(aux >= r){
r = aux;
start = i + 1; end = j + 1;
}
++j;
}
aux = 0;
++i;
}
}
IMPORTANTE NOTE: the positions of the array are important, i mean that the content of V[i] is linked to that i (if v[3] = 89, that 89 always have to refered to v[3] even if you change the array you need to remember that this 89 was on position 3), so if you reorder the array you need to keep that reference.
Thank you so much.
|
|
|
|
|
Member 13501021 wrote: ...i have to find the maximun range When I hear the phrase "maximum range" I think of things like: 1) what's the farthest that ball can be hit, 2) what's the longest distance that bullet will travel in 50% humidity, 3) what's the farthest that car can go on a full tank. What is your definition of maximum range?
Member 13501021 wrote: +--------------------------+
| 100 | -10 | -10 | -10 | 100 | --> this sould return the range 0-4
+--------------------------+
+-----------------+
| -7 | 5 | -1 | 9 | -6 | --> this sould return the range 1-3
+-----------------+
+-----------------+
| -7 | 5 | -6 | 9 | -6 | --> this sould return the range 3-3
What's the pattern?
"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
|
|
|
|
|
Pretty sure that the "maximum range" should be the segment of the array where the sum of its values is the highest of all possible segments.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
This surely is your homework, so I won't rob you of the opportunity to find the solution yourself.
But I'll try to nudge you onto the right track:
- Take a pen and paper, write down some random value sequences as input arrays and solve them manually. Try to do this in an algorithmic way. Use some longer sequences than you showed here.
- You can't have nested loops over n for O(n), obviously. So you will have to make do with one pass over the array. But you're free to use more or other variables.
- The solution is surprisingly easy and succinct - don't think too complicated.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Calculate sum of M natural numbers starting from N, where N and M should be read from standard input (separated by space). User FOR statement.
Example
Input:
3 4
Output:
18
So my code is:
#include <stdio.h>
int main(){
int i,n,m,sum;
scanf("%d %d",&n,&m);
sum=n;
for(i=0;i<=m;i++)
sum=sum+i;
printf("%d",sum);
}
I set i=0 because I figured since the sum is supposed to start from N itself then that's the way to do it. The problem is though it doesn't work the way it should. What's wrong with my code? :sigh:
|
|
|
|
|
Member 13478986 wrote: sum=n;
for(i=0;i<=m;i++)
sum=sum+i;
1. you are trying to sum (M+1) natural numbers: starting with 0 and ending with M...
2. You are trying to sum not was required
(i.e. N + N+1 + N+2 ... + N+M)
but
(N + 0 + 1 + ... + M)
|
|
|
|
|
that helped a lot, i changed it to
sum=0;
for(i=0;i<m;i++)
sum=sum+n+i;
works as it should, thanks!
|
|
|
|
|
You need no iteration, actually.
Since (see 1 + 2 + 3 + 4 + ⋯ - Wikipedia[^])
1 + 2 + ... + n = n * (n + 1) / 2
In your case
SUM = ((N + M - 1) * (N + M) - (N - 1) * (N)) / 2
Let's try the formula with the input
N=3, M=4
SUM = ((3 + 4 -1) * (3 + 4) - (3) * (2)) / 2 = (6 * 7 - 3 * 2) / 2 = (42 - 6) / 2 = 18
|
|
|
|
|
yeah I mean it's just an arithmetic sequence so the easiest way would be to just use the formula. the thing is the task requires using the "for" loop so I had to.
|
|
|
|
|
error :
24 no operator = for thie
104 string to TCHAR warning
i have a 'player.bmp' in the same map
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
#include <tchar.h>
#include <windows.h>
bool key[ 256 ] ;
int winx , winy ;
#define FRAME_TIMER 1
class Sprite
{
public :
int x , y , w , h ;
bool visable ;
BITMAP bmp ;
Sprite(){;}
void loadbmpfromfile( HINSTANCE hinstance , TCHAR * file )
{
bmp = LoadBitmap( hinstance , _T( file ) ) ;
w = bmp.bmWidth ;
h = bmp.bmHeight ;
visable = true ;
}
void show( HDC hdc )
{
if ( visable )
{
BitBlt( hdc , x , y , w , h/2 , hdc , 0 , 0 , MERGECOPY ) ;
BitBlt( hdc , x , y , w , h/2 , hdc , 0 , h/2 , MERGEPAINT ) ;
}
}
bool hit( Sprite spr )
{
if ( x + w < spr.x ) return false ;
if ( x > spr.x + spr.w ) return false ;
if ( y + h < spr.y ) return false ;
if ( y > spr.y + spr.h ) return false ;
return true ;
}
} ;
Sprite player ;
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
_T("sprite 1"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
) ;
ShowWindow (hwnd, nCmdShow);
player.loadbmpfromfile(hThisInstance,"player.bmp") ;
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT paint ;
HDC hdc = BeginPaint( hwnd , &paint ) ;
RECT rect ;
switch (message)
{
case WM_CREATE :
player.x = 0 ;
player.y = 0 ;
SetTimer( hwnd , FRAME_TIMER , 40 , NULL ) ;
case WM_KEYDOWN :
key[ wParam ] = true ;
switch( wParam )
{
case VK_ESCAPE :
PostQuitMessage( 0 ) ;
break ;
default : ;
}
break ;
case WM_KEYUP :
key[ wParam ] = false ;
break ;
case WM_TIMER :
switch( wParam )
{
case FRAME_TIMER :
if ( key[ VK_UP ] ) player.y-- ;
if ( key[ VK_DOWN ] ) player.y++ ;
if ( key[ VK_LEFT ] ) player.x-- ;
if ( key[ VK_RIGHT ] ) player.x++ ;
if ( player.y > winy ) player.y = 0 ;
if ( player.y < 0 ) player.y = winy ;
if ( player.x > winx ) player.x = 0 ;
if ( player.x < 0 ) player.x = winx ;
InvalidateRect( hwnd , NULL , true ) ;
break ;
default : ;
}
break ;
case WM_PAINT :
GetClientRect( hwnd , &rect ) ;
winx = rect.right ;
winy = rect.bottom ;
player.show( hdc ) ;
EndPaint( hwnd , &paint ) ;
case WM_DESTROY :
PostQuitMessage( 0 ) ;
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0 ;
}
|
|
|
|
|
Please stop doing this. Do not just dump a load of code with a vague comment and expect someone to figure out what the problem is and then fix it for you. Edit your question, remove the code not relevant to the problem, and explain clearly what is going wrong, and where it happens.
|
|
|
|
|
The _T() macro is for constant strings (and characters) only:
bmp = LoadBitmap(hinstance, file);
When supporting Unicode and non-Unicode builds, all constant strings must be embedded in that macro:
player.loadbmpfromfile(hThisInstance, _T("player.bmp"));
|
|
|
|
|
Both errors look like they could be coming from the call to LoadBitmap() , but since you failed to include line numbers, it's hard to say for sure. That function returns a BOOL not a BITMAP . Also, the _T() macro is for string literals.
"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
|
|
|
|
|
a error font by the compler
can have a source elsewere so i have to post al the code
i don't know how to include the line numbers
my english in writing is not great
so i have to be short
|
|
|
|
|
ok i try it
i changed the folowing :
player.loadbmpformfil( ,_T("player.bmp)) ;
my sprite looks like this now :
class Sprite
{
public :
int x , y , w , h ;
bool visable ;
HBITMAP hbmp ;
HDC bmphdc ;
Sprite(){;}
void loadbmpfromfile( HINSTANCE hinstance , TCHAR * file )
{
hbmp = LoadBitmap( hinstance , file ) ;
w = hbmp.i ;
h = hbmp.i ;
visable = true ;
}
void show( HDC hdc )
{
if ( visable )
{
BitBlt( hdc , x , y , w , h/2 , bmphdc , 0 , 0 , MERGECOPY ) ;
BitBlt( hdc , x , y , w , h/2 , bmphdc , 0 , h/2 , MERGEPAINT ) ;
}
}
bool hit( Sprite spr )
{
if ( x + w < spr.x ) return false ;
if ( x > spr.x + spr.w ) return false ;
if ( y + h < spr.y ) return false ;
if ( y > spr.y + spr.h ) return false ;
return true ;
}
} ;
Sprite player ;
i know this is wrong . how do i do this ?
my wm_paint :
case WM_PAINT :
GetClientRect( hwnd , &rect ) ;
winx = rect.right ;
winy = rect.bottom ;
player.bmphdc = CreateCompatibleDC(hdc);
player.show( hdc ) ;
DeleteDC( player.bmphdc ) ;
EndPaint( hwnd , &paint ) ;
this can be wrong . how do i do this ?
|
|
|
|
|
I told you a week ago, you must call BeginPaint inside your WM_PAINT code. So it needs to be:
case WM_PAINT :
hdc = BeginPaint( hwnd , &paint );
EndPaint( hwnd , &paint ) ;
break;
|
|
|
|
|
ok done that
how do i proseed next ?
case WM_PAINT :
hdc = BeginPaint( hwnd , &paint ) ;
GetClientRect( hwnd , &rect ) ;
winx = rect.right ;
winy = rect.bottom ;
player.bmphdc = CreateCompatibleDC( hdc ) ;
player.show( hdc ) ;
DeleteDC( player.bmphdc ) ;
EndPaint( hwnd , &paint ) ;
break ;
case WM_DESTROY :
|
|
|
|
|
bluatigro wrote: how do i proseed next ? What do you mean? As far as I can see the above code does not do anything.
|
|
|
|
|
by me pc its giving error's
if i knew what to do i won't ask
this is new to me
what do i ad / change so it does work as expected ?
it shoot show a sprite 'player.bmp' whit cursor control
|
|
|
|
|