My progress.. thnx to Cprogramming forumites
Thought i should share my progress here after all mourning and groaning.. Having starting windows programming three weeks back... This program only does user interface, next part is to do calculations. You welcome to comment or give feedback..
I have 5 files
1. Main.c
Code:
//=============================================================================
//MAIN Function - Copyright ©2008 Songezo Nkukwana
//=============================================================================
#include "RFSAntenna.h"
// Global Variables
PAINTSTRUCT pntS;
HWND rdrAntnCntrl[5];
double beamWazth=0;
int update=0,box1=0,box2=0,box3=0;
HMENU rdr_tbl[16]={
(HMENU)IDCE_SINGLELINE1,
(HMENU)IDCE_SINGLELINE2,
(HMENU)IDCE_SINGLELINE3,
(HMENU)IDCE_SINGLELINE4,
(HMENU)IDCE_SINGLELINE5,
(HMENU)IDCE_SINGLELINE6,
(HMENU)IDCE_SINGLELINE7,
(HMENU)IDCE_SINGLELINE8,
(HMENU)IDCE_SINGLELINE9,
(HMENU)IDCE_SINGLELINE10,
(HMENU)IDCE_SINGLELINE11,
(HMENU)IDCE_SINGLELINE12,
(HMENU)IDCE_SINGLELINE13,
(HMENU)IDCE_SINGLELINE14,
(HMENU)IDCE_SINGLELINE15,
(HMENU)IDCE_SINGLELINE16,
};
//WIN_MAIN's API funxion
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hprevInst,LPSTR pStr,int nCmd)
{
TCHAR *classname=_T("RFS Range");
int desktopwidth;
int desktopheight;
MSG msg;
HWND hwnd;
WNDCLASSEX wcx={0}; //used for storing information about the wnd 'class'
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.lpfnWndProc = WndProc; //wnd Procedure pointer
wcx.hInstance = hInst; //app instance
wcx.hIcon = (HICON)LoadImage(0,IDI_APPLICATION,IMAGE_ICON,0,0,LR_SHARED);
wcx.hCursor = (HCURSOR)LoadImage(0,IDC_ARROW,IMAGE_CURSOR,0,0,LR_SHARED);
wcx.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
wcx.lpszClassName = classname;
if (!RegisterClassEx(&wcx))
{
ErrMsg(_T("Failed to register wnd class"));
return -1;
}
desktopwidth=GetSystemMetrics(SM_CXSCREEN);
desktopheight=GetSystemMetrics(SM_CYSCREEN);
hwnd=CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
classname,
_T("RFS Range"),
WS_OVERLAPPEDWINDOW,
/*CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,*/
desktopwidth/4,
desktopheight/4,
desktopwidth/2,
desktopheight/2,
NULL,
NULL,
hInst,
NULL);
if (!hwnd)
{
MessageBox(0,_T("Failed to create wnd"),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION);
return -1;
}
ShowWindow(hwnd,SW_SHOWMAXIMIZED);
UpdateWindow(hwnd);
while (GetMessage(&msg,0,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)(msg.wParam);
}
1. RFSInterface.c
Code:
//=============================================================================
//FRS Range Function Definitions - Copyright ©2008 Songezo Nkukwana
//=============================================================================
#include "RFSAntenna.h"
// =============================================================================
// Globals
//=============================================================================
int ErrMsg(const TCHAR* s)
{
return MessageBox(0,s,_T("ERROR"),MB_OK|MB_ICONEXCLAMATION);
}
//=============================================================================
//handles the WM_CREATE message of the main, parent window; return -1 to fail
HWND OnCreate(const HWND hwnd,CREATESTRUCT *cs, RECT rc, HMENU EditID)
{
return CreateEdit(hwnd,cs->hInstance,0,rc,EditID,_T(""));
}
// EDIT control
HWND CreateEdit(const HWND hParent,const HINSTANCE hInst,DWORD dwStyle,
const RECT rc, HMENU id,const TCHAR* caption)
{
dwStyle|=WS_CHILD|WS_VISIBLE;
return CreateWindowEx(WS_EX_CLIENTEDGE,
_T("edit"),
caption,
dwStyle,
rc.left,
rc.top,
rc.right,
rc.bottom,
(HWND)hParent,
id,
hInst,
0);
}
//=============================================================================
// BUTTON Control
HWND CreateButton(const HWND hParent,const HINSTANCE hInst,DWORD dwStyle,
const RECT rc, HMENU id,const TCHAR* caption)
{
dwStyle|=WS_CHILD|WS_VISIBLE;
return CreateWindowEx(0,
_T("button"),
caption,
dwStyle,
rc.left,
rc.top,
rc.right,
rc.bottom,
hParent,
id,
hInst,
0);
}
// Purpose: Draws rectangle object on the parent window
void paintObject(HWND hwnd, const RECT rc, RGBColor *color, HDC hdc, int border, int brush)
{
HPEN hpen=CreatePen(PS_SOLID, 2, RGB(color[border].R, color[border].G, color[border].B));
HBRUSH hbrush=CreateSolidBrush(RGB(color[brush].R, color[brush].G, color[brush].B));
DrawARectangle(hwnd, hpen, hdc, hbrush, rc);
DeleteObject(hpen);
DeleteObject(hbrush);
}
// Draw Rectangles on Window Area
void drawArea(HWND hwnd, HDC hdc, RGBColor *colors)
{
paintObject(hwnd,initRecArea(10,10,340,230),colors, hdc, BLACK, GREY); // Left window (RADAR ANTENNA)
paintObject(hwnd,initRecArea(345,10,625,285),colors, hdc, BLACK, GREY); // Right window (RADAR TRANSMITTER/RECEIVER)
paintObject(hwnd,initRecArea(10,235,340,335),colors, hdc, BLACK, GREY); // Second left (TARGET)
paintObject(hwnd,initRecArea(10,340,340,440),colors, hdc, BLACK, GREY); // Third left (GENERAL PARAMETERS)
paintObject(hwnd,initRecArea(10,445,690,780),colors, hdc, BLACK, KHAKI); // Yellow window (RESULTS)
paintObject(hwnd,initRecArea(390,550,680,770),colors, hdc, BLACK, KHAKI); // Yellow mini window (RESULTS)
// Ranges small Rectangles
paintObject(hwnd,initRecArea(580,605,640,625),colors, hdc, RED, YELLOW);
paintObject(hwnd,initRecArea(580,635,640,655),colors, hdc, RED, YELLOW);
paintObject(hwnd,initRecArea(580,665,640,685),colors, hdc, RED, YELLOW);
paintObject(hwnd,initRecArea(580,705,640,760),colors, hdc, RED, YELLOW);
}
// Purpose: Draws a rectangle which will have text boxes for input data
void DrawARectangle(HWND hwnd, HPEN hpen, HDC hdc, HBRUSH hbrush, const RECT rc)
{
// Select the new pen and brush, and then draw.
HPEN hpenOld=(HPEN)SelectObject(hdc, hpen);
HBRUSH hbrushOld=(HBRUSH)SelectObject(hdc, hbrush);
Rectangle(hdc,rc.left,rc.top,rc.right,rc.bottom);
SelectObject(hdc, hpenOld);
SelectObject(hdc, hbrushOld);
}
// Initialize rectangle area
RECT initRecArea(int left, int top, int right, int bottom)
{
static RECT rec;
rec.left=left;
rec.top=top;
rec.right=right;
rec.bottom=bottom;
return rec;
}
// Display text on screen
void printText(HWND hWnd, TCHAR txt[], RECT rc, HDC hDC, DWORD fnWeight,
COLORREF bkgrndClr, COLORREF txtColor, BOOL italics)
{
long lfHeight=-MulDiv(12, GetDeviceCaps(hDC, LOGPIXELSY), 72);
HFONT font=CreateFont(lfHeight, 0, 0, 0, fnWeight, italics,
0, 0, 0, 0, 0, 0, 0, _T("Times New Roman"));
HGDIOBJ hDefFont=SelectObject(hDC, font);
SetBkColor(hDC, bkgrndClr);
SetTextColor(hDC, txtColor);
TextOut(hDC, rc.left, rc.top, txt, (int)_tcslen(txt));
SelectObject(hDC, hDefFont);
DeleteObject(hDefFont);
}
// ======================================================================================================
// User Interface functions
/* Labes for Radar Antenna Area */
void RadaAntennaText(HWND hwnd, TCHAR rdrAntenaLbl[5][25], TCHAR deg[], TCHAR db[],
TCHAR halfMin[], TCHAR mtrs[], HDC hdc, TXTFONT fntClr[])
{
// Display semicolons
POINT dsplPos={188, 45};
displayTxtData(hwnd, hdc, dsplPos, fntClr, " :", 75);
dsplPos.x=188;
dsplPos.y=130;
displayTxtData(hwnd, hdc, dsplPos, fntClr, " :", 190);
// Display Text (Labels)
printText(hwnd, _T("Radar Antenna"), initRecArea(15,15,0,0), hdc,
fntClr[0].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle); // Header
printText(hwnd, rdrAntenaLbl[AZIM], initRecArea(55,45,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, deg, initRecArea(265,45,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrAntenaLbl[ELEV], initRecArea(48,75,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, deg, initRecArea(265,75,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrAntenaLbl[GAIN], initRecArea(156,130,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, db, initRecArea(265,130,0,0), hdc, fntClr[1].boldStyle,
fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrAntenaLbl[RPM], initRecArea(151,160,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, halfMin, initRecArea(265,160,0,0), hdc, fntClr[1].boldStyle,
fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrAntenaLbl[HGTH], initRecArea(145,190,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, mtrs, initRecArea(265,190,0,0), hdc, fntClr[1].boldStyle,
fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
}
/* Labes for Radar Transceiver Area */
void RadarReceiverText(HWND hwnd, TCHAR rdrTrans_recv[8][20], TCHAR hz[], TCHAR mhz[], TCHAR mtrs[],
TCHAR kw[], TCHAR usec[], TCHAR db[], TCHAR wvlFig[], HDC hdc, TXTFONT fntClr[])
{
// Display semicolons
POINT dsplPos={462, 45};
displayTxtData(hwnd, hdc, dsplPos, fntClr, " :", 255);
/* Radar Transmitter/Receiver Area */
printText(hwnd, _T("Radar Transmitter/Receiver"),
initRecArea(350,15,0,0), hdc, fntClr[0].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrTrans_recv[FREQ], initRecArea(395,45,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, mhz, initRecArea(540,45,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, wvlFig, initRecArea(490,75,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrTrans_recv[WVLNTH], initRecArea(388,75,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, mtrs, initRecArea(540,75,0,0), hdc, fntClr[1].boldStyle,
fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrTrans_recv[PP], initRecArea(384,105,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, kw, initRecArea(540,105,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrTrans_recv[PW], initRecArea(386,135,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, usec, initRecArea(540,135,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrTrans_recv[PRF], initRecArea(431,165,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, hz, initRecArea(540,165,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrTrans_recv[BNDWTH], initRecArea(401,195,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, mhz, initRecArea(540,195,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrTrans_recv[NF], initRecArea(380,225,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, db, initRecArea(540,225,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrTrans_recv[LOSS], initRecArea(415,255,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, db, initRecArea(540,255,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
}
/* Labes for Target Area */
void TargetText(HWND hwnd, TCHAR targetLbl[3][30], TCHAR sqm[], TCHAR mtrs[], HDC hdc, TXTFONT fntClr[])
{
char temp[30];
// Display semicolons
POINT dsplPos={188, 270};
displayTxtData(hwnd, hdc, dsplPos, fntClr, " :", 300);
strcpy(temp,targetLbl[0]);
printText(hwnd, _T("Target"), initRecArea(15,240,0,0), hdc,
fntClr[0].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle); // Header
printText(hwnd, strcat(targetLbl[RCS], targetLbl[RCS+2]), initRecArea(25,270,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, sqm, initRecArea(265,270,0,0), hdc, fntClr[1].boldStyle,
fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, targetLbl[DP], initRecArea(87,300,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, mtrs, initRecArea(265,300,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
strcpy(targetLbl[0], temp);
}
/* Labes for General Parameters Area */
void GenParams(HWND hwnd, TCHAR genPara[2][30], TCHAR FARErng[], TCHAR DPrang[], HDC hdc, TXTFONT fntClr[])
{
// Display semicolons
POINT dsplPos={188, 375};
displayTxtData(hwnd, hdc, dsplPos, fntClr, " :", 405);
printText(hwnd, _T("General Parameters"), initRecArea(15,345,0,0), hdc,
fntClr[0].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle); // Header
printText(hwnd, genPara[RCS], initRecArea(18,375,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, FARErng, initRecArea(255,375,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, genPara[DP], initRecArea(57,405,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, DPrang, initRecArea(255,405,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
}
// Display text around radio buttons
void RadioButtonsText(HWND hwnd, HDC hdc, TCHAR polarLbl[], TXTFONT fntClr[])
{
printText(hwnd, polarLbl, initRecArea(115,100,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, _T("c"), initRecArea(222,100,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, _T("h"), initRecArea(252,100,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, _T("v"), initRecArea(282,100,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
}
// Insert Edit Controls
void EditBoxes(HWND hwnd, CREATESTRUCT *cs)
{
int next, cnt;
/* RADAR ANTENNA - Edit Boxes */
OnCreate(hwnd,cs,initRecArea(205,45,55,20),rdr_tbl[0]);
OnCreate(hwnd,cs,initRecArea(205,75,55,20),rdr_tbl[1]);
for (next=130, cnt=2;next<=190;next+=30, cnt++){
OnCreate(hwnd,cs,initRecArea(205,next,55,20),rdr_tbl[cnt]);
}
/* RADAR TRANSMITTER/RECEIVER - Edit Boxes */
OnCreate(hwnd,cs,initRecArea(480,45,55,20),rdr_tbl[cnt]);
for (next=105;next<=255;next+=30,cnt++){
OnCreate(hwnd,cs,initRecArea(480,next,55,20),rdr_tbl[cnt]);
}
/* TARGET - Edit Boxes */
OnCreate(hwnd,cs,initRecArea(205,270,55,20),rdr_tbl[cnt++]);
OnCreate(hwnd,cs,initRecArea(205,300,55,20),rdr_tbl[cnt++]);
/* GENERAL PARAMETERS - Edit Boxes */
OnCreate(hwnd,cs,initRecArea(205,375,45,20),rdr_tbl[cnt++]);
OnCreate(hwnd,cs,initRecArea(205,405,45,20),rdr_tbl[cnt++]);
}
// Results Window
void DisplayResultsBox(HWND hwnd, HDC hdc, TCHAR rdrTrans_recv[8][20], TCHAR targetLbl[3][30], TXTFONT fntClr[])
{
POINT dsplPos={280, 480};
/* Initialize headings and labels */
static TCHAR CalcParams[4][34]={_T("Antenna Gain"), _T("Polarisation Loss"),
_T("Signal To Noise Required"), _T("Intergration Improvement Factor")};
static TCHAR rdrRng[]=_T("Radar Range"), rng[]=_T("Ranges"),rdrHrzn[]=_T("Radar Horizon"),
constnt[]=_T("Constant"), db[]=_T("db"),km[]=_T("km"), prfRng[]=_T("PRF-Range"), max[25]=_T("Maximum ");
static TCHAR itlcText[6][20]={_T(" (Two Way)"), _T(" (Static Target)"), _T(" (Moving Target)"),
_T("Figure of Merit"), _T("(Free Space)"), _T("Maximum Radar Range")};
printText(hwnd, _T("Calculated Parameters"), initRecArea(15,450,0,0), hdc,
fntClr[0].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
// Display semicolons
displayTxtData(hwnd, hdc, dsplPos, fntClr, " :", 750);
dsplPos.x=340;
displayTxtData(hwnd, hdc, dsplPos, fntClr, "dB", 750);
/* Displaying Labels */
printText(hwnd, rdrTrans_recv[PP], initRecArea(202,480,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, CalcParams[AG], initRecArea(123,510,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, itlcText[TW], initRecArea(204,510,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[2].italicStyle);
printText(hwnd, CalcParams[PL], initRecArea(178,540,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, targetLbl[0], initRecArea(152,570,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrTrans_recv[1], initRecArea(208,600,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrTrans_recv[5], initRecArea(223,630,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, rdrTrans_recv[6], initRecArea(202,660,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, CalcParams[STNR], initRecArea(24,690,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, itlcText[ST], initRecArea(182,690,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[2].italicStyle);
printText(hwnd, CalcParams[STNR], initRecArea(14,720,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
printText(hwnd, itlcText[MT], initRecArea(170,720,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[2].italicStyle);
printText(hwnd, CalcParams[IIF], initRecArea(80,750,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
//Losses
printText(hwnd, rdrTrans_recv[LOSS], initRecArea(390,480,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
dsplPos.x=432;
dsplPos.y=480;
displayTxtData(hwnd, hdc, dsplPos, fntClr, " :", 480);
dsplPos.x=475;
displayTxtData(hwnd, hdc, dsplPos, fntClr, "dB", 480);
// Constant
printText(hwnd, constnt, initRecArea(535,480,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
dsplPos.x=590;
dsplPos.y=480;
displayTxtData(hwnd, hdc, dsplPos, fntClr, " :", 510);
dsplPos.x=640;
displayTxtData(hwnd, hdc, dsplPos, fntClr, "dB", 510);
// Figure of Merit
printText(hwnd, itlcText[3], initRecArea(491,510,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[2].italicStyle);
//Ranges
dsplPos.x=570;
dsplPos.y=605;
displayTxtData(hwnd, hdc, dsplPos, fntClr, " :", 665);
dsplPos.x=645;
dsplPos.y=605;
displayTxtData(hwnd, hdc, dsplPos, fntClr, "km", 665);
dsplPos.x=570;
dsplPos.y=720;
displayTxtData(hwnd, hdc, dsplPos, fntClr, " :", 720);
dsplPos.x=642;
dsplPos.y=705;
displayTxtData(hwnd, hdc, dsplPos, fntClr, " km", 705);
dsplPos.y=735;
displayTxtData(hwnd, hdc, dsplPos, fntClr, " nm", 735);
printText(hwnd, rng, initRecArea(505,565,0,0), hdc, //header
fntClr[0].boldStyle, fntClr[0].bkgrngColor, fntClr[3].txtColor, fntClr[0].italicStyle);
printText(hwnd, rdrRng, initRecArea(395,605,0,0), hdc,
fntClr[0].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[0].italicStyle);
printText(hwnd, itlcText[FS], initRecArea(488,605,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[2].italicStyle);
printText(hwnd, prfRng, initRecArea(498,635,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[0].italicStyle);
printText(hwnd, rdrHrzn, initRecArea(480,665,0,0), hdc,
fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[0].italicStyle);
printText(hwnd, strcat(max, rdrRng), initRecArea(410,720,0,0), hdc,
fntClr[0].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[2].italicStyle);
strcpy(max,"Maximum ");
}
// Display Extra labes or data
void displayTxtData(HWND hwnd, HDC hdc, POINT pos, TXTFONT fntClr[], TCHAR data[], int last)
{
int next;
for (next=pos.y;next<=last;next+=30){
printText(hwnd, data, initRecArea(pos.x,next,0,0),
hdc, fntClr[1].boldStyle, fntClr[0].bkgrngColor, fntClr[0].txtColor, fntClr[1].italicStyle);
}
}
3. RFSWinProc.c
Code:
//=============================================================================
//FRS Range Windows Procedure - Copyright ©2008 Songezo Nkukwana
//=============================================================================
#include "RFSAntenna.h"
//=============================================================================
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
// ************************************************************************************
// Local Variables
/* Init Labels */
static TCHAR deg[]=_T("degrees"), db[]=_T("dB"), halfMin[]=_T("1/minute"), mtrs[]=_T("meters"),
mhz[]=_T("MHz"), kw[]=_T("kW"), usec[]=_T("usec"), hz[]=_T("Hz"), dpRng[]=_T("0.1 - 0.95%"),
sqm[]=_T("sqm"), fareRng[]=_T("-4 or -6"), wvlnthFig[]=_T("0.032");
static TCHAR rdrAntenaLbl[5][25]={_T("Beamwidth (Azimuth)"), _T("Beamwidth (Elevation)"),
_T("Gain"), _T("RPM"), _T("Height")};
static TCHAR polarLbl[]=_T("Polarisation");
static TCHAR targetLbl[3][30]={_T("Radar Cross Section"), _T("Height of Target"), _T(" RCS")};
static TCHAR rdrTrans_recv[8][20]={_T("Frequency"), _T("Wavelenght"), _T("Peak Power"), _T("Pulse Width"),
_T("PRF"), _T("Bandwith"), _T("Noise Figure"), _T("Losses")};
static TCHAR genPara[2][30]={_T("False Alarm Rate Exponent"), _T("Detection Probability")};
/* Declare variables */
HDC hdc;
int maxChars=20, cnrtlIndx=0;
// Rectangle Colors
RGBColor colors[MAXCOLOR]= {
{0x00,0x00,0x00}, // Black
{0xFF,0xFF,0xFF}, // White
{0xFF,0x00,0x00}, // Red
{0xD3,0xD3,0xD3}, // Grey
{0xFF,0xFF,0x00}, // Yellow
{0xF0,0xE6,0x8C}, // Khaki
{0xFF,0xD7,0x00}, // Gold
{0xFF,0xF8,0xDC}, // Cornsilk
};
/* Initialize text fonts */
TXTFONT stdFont[4]= {
{RGB(0x00,0x00,0x00), RGB(0xD3,0xD3,0xD3), 700, FALSE}, // Bold Text
{RGB(0x00,0x00,0x00), RGB(0xD3,0xD3,0xD3), 0, FALSE}, // Normal Text
{RGB(0x00,0x00,0x00), RGB(0xD3,0xD3,0xD3), 0, TRUE}, // Italic Text
{RGB(0xF0,0x00,0x00), RGB(0xD3,0xD3,0xD3), 700, FALSE} // Red|Bold Text
},
rsltFont[4]={
{RGB(0x00,0x00,0x00), RGB(0xF0,0xE6,0x8C), 700, FALSE}, // Bold Text
{RGB(0x00,0x00,0x00), RGB(0xF0,0xE6,0x8C), 0, FALSE}, // Normal Text
{RGB(0x00,0x00,0x00), RGB(0xF0,0xE6,0x8C), 0, TRUE}, // Italic Text
{RGB(0xF0,0x00,0x00), RGB(0xF0,0xE6,0x8C), 700, FALSE} // Red|Bold Text
};
CREATESTRUCT *cs=(CREATESTRUCT*)(lParam);
// ************************************************************************************
// Window Messages
switch (uMsg)
{
case WM_CREATE:
// Create edit controls for user input
EditBoxes(hwnd, cs);
/* Create Radio Buttons */
CreateButton(hwnd,cs->hInstance,BS_AUTORADIOBUTTON,initRecArea(205,105,14,12),
(HMENU)IDBC_CHECKBOX_C,_T("Polar - C"));
CreateButton(hwnd,cs->hInstance,BS_AUTORADIOBUTTON,initRecArea(235,105,14,12),
(HMENU)IDBC_CHECKBOX_H,_T("Polar - H"));
CreateButton(hwnd,cs->hInstance,BS_AUTORADIOBUTTON,initRecArea(265,105,14,12),
(HMENU)IDBC_CHECKBOX_V,_T("Polar - V"));
/* Create Quit & Update Buttons */
CreateButton(hwnd,cs->hInstance,BS_DEFPUSHBUTTON,initRecArea(400,340,60,30),
(HMENU)IDBC_QUITBUTTON,_T("QUIT!"));
CreateButton(hwnd,cs->hInstance,BS_DEFPUSHBUTTON,initRecArea(500,340,80,30),
(HMENU)IDBC_UPDATEBUTTON,_T("UPDATE!"));
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd, &pntS);
/* *** User Interface *** */
drawArea(hwnd, hdc, colors);
RadioButtonsText(hwnd, hdc, polarLbl, stdFont);
TargetText(hwnd, targetLbl, sqm, mtrs, hdc, stdFont);
GenParams(hwnd, genPara, fareRng, dpRng, hdc, stdFont);
RadaAntennaText(hwnd, rdrAntenaLbl, deg, db, halfMin, mtrs, hdc, stdFont);
DisplayResultsBox(hwnd, hdc, rdrTrans_recv, targetLbl, rsltFont);
RadarReceiverText(hwnd, rdrTrans_recv, hz, mhz, mtrs, kw, usec, db, wvlnthFig, hdc, stdFont);
EndPaint(hwnd, &pntS);
return 0;
case WM_COMMAND:
// Listen to the input commands
switch( LOWORD(wParam) )
{
case IDBC_QUITBUTTON:
{
if(HIWORD(wParam) == BN_CLICKED){
PostQuitMessage(0);
}
}
case IDBC_UPDATEBUTTON:
{
if(HIWORD(wParam) == BN_CLICKED)
{
InvalidateRect (hwnd, NULL, TRUE);
UpdateWindow(hwnd);
}
}
}
return 0;
case WM_TIMER:
//SetTimer(hwnd, ID_TIMER, 500, NULL);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
//let system deal with msg
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
4. RFSAntenna.h
Code:
//=============================================================================
//FRSAntenna Header Files - Copyright ©2008 Songezo Nkukwana
//=============================================================================
#include <windows.h>
#include <tchar.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#define MAXCOLOR 8
// ======================================================
// ENUM types
//Edit control id's
enum {
IDCE_SINGLELINE=200,
IDCE_SINGLELINE1,
IDCE_SINGLELINE2,
IDCE_SINGLELINE3,
IDCE_SINGLELINE4,
IDCE_SINGLELINE5,
IDCE_SINGLELINE6,
IDCE_SINGLELINE7,
IDCE_SINGLELINE8,
IDCE_SINGLELINE9,
IDCE_SINGLELINE10,
IDCE_SINGLELINE11,
IDCE_SINGLELINE12,
IDCE_SINGLELINE13,
IDCE_SINGLELINE14,
IDCE_SINGLELINE15,
IDCE_SINGLELINE16,
IDCE_MULTILINE,
IDBC_DEFPUSHBUTTON,
IDBC_PUSHBUTTON,
IDBC_QUITBUTTON,
IDBC_UPDATEBUTTON,
IDBC_CHECKBOX_C,
IDBC_CHECKBOX_H,
IDBC_CHECKBOX_V,
IDBC_AUTORADIOBUTTON,
IDBC_GROUPBOX,
IDBC_ICON,
IDBC_BITMAP
};
// Radar Antenna indices
enum {
AZIM,
ELEV,
GAIN,
RPM,
HGTH
};
// Color indicators
enum {
BLACK,
WHITE,
RED,
GREY,
YELLOW,
KHAKI,
GOLD,
CORNSILK
};
// Italic Text
enum {
TW,
ST,
MT,
FOM,
FS,
MRR
};
// Radar Transmitter/Receiver indices
enum {
FREQ,
WVLNTH,
PP,
PW,
PRF,
BNDWTH,
NF,
LOSS
};
// Calculated Parameters
enum {
AG,
PL,
STNR,
IIF,
};
// Target indices
enum {
RCS,
HOT
};
// General Parameters indices
enum {
FARE,
DP
};
// Define structure for colors
typedef struct rgbColors {
int R,G,B;
} RGBColor;
// Font Structure
typedef struct fonts {
COLORREF txtColor;
COLORREF bkgrngColor;
int boldStyle;
BOOL italicStyle;
} TXTFONT;
//=============================================================================
// Function declarations
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int ErrMsg(const TCHAR*);
double GetValue(HWND ,int);
double Round(double,int);
BOOL SelectedButton(HWND,int);
RECT initRecArea(int,int,int,int);
void EditBoxes(HWND,CREATESTRUCT*);
void drawArea(HWND,HDC,RGBColor[]);
BOOL SetDlgItemFloat(HWND,int,float);
void RadioButtonsText(HWND,HDC,TCHAR[],TXTFONT[]);
void displayDBLbl(HWND, HDC, POINT,TXTFONT[],int);
HWND OnCreate(const HWND,CREATESTRUCT*,RECT,HMENU);
void DrawARectangle(HWND,HPEN,HDC,HBRUSH,const RECT);
void paintObject(HWND,const RECT,RGBColor*,HDC,int,int);
void displayTxtData(HWND, HDC, POINT, TXTFONT[],TCHAR[],int);
void GenParams(HWND,TCHAR[2][30],TCHAR[],TCHAR[],HDC,TXTFONT[]);
void printText(HWND,TCHAR[],RECT,HDC,DWORD,COLORREF,COLORREF,BOOL);
void TargetText(HWND ,TCHAR[3][30],TCHAR sqm[],TCHAR[],HDC,TXTFONT[]);
void DisplayResultsBox(HWND, HDC, TCHAR[8][20],TCHAR[3][30],TXTFONT[]);
HWND CreateEdit(const HWND,const HINSTANCE,DWORD,const RECT,HMENU,const TCHAR*);
HWND CreateButton(const HWND,const HINSTANCE,DWORD,const RECT,HMENU,const TCHAR*);
void RadaAntennaText(HWND,TCHAR[5][25],TCHAR[],TCHAR[],TCHAR[],TCHAR[],HDC,TXTFONT[]);
void RadarReceiverText(HWND,TCHAR[8][20],TCHAR[],TCHAR[],TCHAR[],TCHAR[],TCHAR[],TCHAR[],TCHAR[],HDC,TXTFONT[]);
// External Global variables
extern PAINTSTRUCT pntS;
extern HWND rdrAntnCntrl[5];
extern double beamWazth;
extern int update,box1,box2,box3;
extern HMENU rdr_tbl[16];
5. RFSCalculate
Code:
//=============================================================================
//Calculating Functions - Copyright ©2008 Songezo Nkukwana
//=============================================================================
// Read in text as numerical values
double GetValue(HWND hEdit,int nCtrlID)
{
float fValue=0.00;
char szText[256];
GetWindowText(hEdit, (TCHAR *)szText, nCtrlID);
sscanf_s(szText,"%f",&fValue);
return Round((double)fValue, 2);
}
// Display the value to screen
BOOL SetDlgItemFloat(HWND hWnd,int nCtrlID,float fValue)
{
HWND hControl=GetDlgItem(hWnd,nCtrlID);
char szText[256];
sprintf_s(szText, sizeof(szText), "%.2f", fValue);
return SetWindowTextA(hControl,(LPCSTR)szText);
}
// Rounds a double variable to nPlaces decimal places
double Round(double dbVal, int nPlaces)
{
const double dbShift=pow(10.0, nPlaces);
return floor(dbVal * dbShift + 0.5) / dbShift;
}
// Check if Radio button is checked
BOOL SelectedButton(HWND hwnd, int CheckID)
{
return (int)SendMessage ( GetDlgItem(hwnd,CheckID),BM_GETCHECK,0,0 );
}
This last one will grow bigger as more functions come in, expect more questions... lol