|
Looks like MM posted that while drunk.
|
|
|
|
|
(in order to reproduce his test)
|
|
|
|
|
I try to find out what the best strategy is to create a MFC based application that is dpi-aware. Windows is based on 96 dpi for years. Today there are pc's like the Microsoft Surface that have lot more dots per inch.
In windows you can set the screen scaling factor to 100%, 125%, 150%, etc.
If you build the application with a manifest that set DPI Awareness with High DPI Aware, then the resource templates like dialogs scale automatically. Only the custom drawings must be scaled with extra code
like:
int DpiScale(int val)
{
const HDC hDC = ::GetDC(NULL);
const UINT dpix = ::GetDeviceCaps(hDC, LOGPIXELSX);
::ReleaseDC(NULL, hDC);
return ::MulDiv(val, dpix, 96);
}
int DpiPerc()
{
return DpiScale(100);
}
DpiScale you can for coordinates or font points. DpiPerc you can use to select the a icon or picturewith the right resolution from resource.
My question is, must I develop the application for 1024 x 768?
|
|
|
|
|
Theo Buys wrote: must I develop the application for 1024 x 768? No, your application should work on any screen if it allows Window to scale it correctly. If the screen size is important then you can get the current values from GetSystemMetrics function (Windows)[^].
|
|
|
|
|
Yes I can use GetSytemMetrics for the custom drawings. But not the dialogs templates in resource which are sized by the system.
|
|
|
|
|
Dialogs are scaled by Windows to match the screen size.
|
|
|
|
|
Not true... When I created a dialog template that is at 96 dpi full screen. With a system dpi scaling of 150% ( 144 dpi) the bottom and right are not visible with the same screen size.
|
|
|
|
|
If you increase the scaling to 150%, then everything in the display will be that much larger.
|
|
|
|
|
Because the Microsoft Surface is default at 150% system scaling,
I must do dialog development in 1024 x 768 pixels at 96 dpi to match the full screen for a dpi-aware application. Right?
|
|
|
|
|
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 ;
}
|
|
|
|
|