"John Carson" <jcarson_n_o_sp_am_@netspace.net.au> wrote in news:ebv0uo
$1801$1@otis.netspace.net.au:
Ah, why not. I plan to make the thing open-source later. The code DOES
need cleaning, but right now I'm just mucking around with things to
figure out certain thing in win32
//------------------------
// NASSAC.h
//------------------------
#define PROGRAM_NAME "YASSAC pre-alpha"
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <cstring>
#include <string>
using std::basic_string;
#include <commctrl.h>
#include <vector>
using std::vector;
#include "resource.h"
#define ID_EDIT_CTRL 15001
#define EDIT_ENTER_PRESSED 15002
#define BUTTON_GRAB 16001
#define BUTTON_PLAY 16002
#define ID_LISTBOX1 17001
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK LineListProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK EditSubProc(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam);
WNDPROC EditProc;
HWND winprochwnd;
HMENU mainhMenu;
HWND hwndEdit;
HWND hwndGrabButton;
HWND hwndPlayButton;
class ssString : public basic_string<TCHAR>
{
};
class NASSAC
{
public:
NASSAC();
int LineListTop;
int idFocus;
bool doNyanko;
unsigned int currentPosition; // position of the line currently being
edited
unsigned int topLine; // top of the bottom section: the part
with the listing of the line info
unsigned int bottomLine;
unsigned int wavBoxTop;
unsigned int wavBoxBotton;
unsigned int wavBoxLeft;
unsigned int wavBoxRight;
HWND mainhwnd;
HWND listBoxHwnd;
private:
void GenerateConfig();
};
class WaveWindow
{
public:
LRESULT CALLBACK WaveWindowProc(HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam);
private:
HWND myParent;
};
WaveWindow wavewindow;
NASSAC nas;
//------------------------
// NASSAC.cpp
//------------------------
#include "NASSAC.h"
#include "resource.h"
NASSAC nassac;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT (PROGRAM_NAME) ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
mainhMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1) );
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName ;
HACCEL hAccel;
hAccel = LoadAccelerators (hInstance, szAppName );
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT (PROGRAM_NAME),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
800, 570,
NULL, mainhMenu, hInstance, NULL) ;
nas.mainhwnd = hwnd;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
if ( !TranslateAccelerator (hwnd, (HACCEL) hAccel, &msg) )
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
TCHAR buffer[200];
RECT rect ;
RECT wavRect;
int cxClient, cyClient;
int ipos;
TCHAR tcbuffer [32769]; // max size of a windows text buffer
HBRUSH hBrush;
winprochwnd = hwnd;
//HWND hwndEdit;//the edit box we want to process messages for
long CALLBACK SubProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam);
switch(message)
{
case WM_CREATE:
_stprintf(buffer, TEXT("x\0"), tcbuffer );
GetClientRect (hwnd, &rect) ;
cxClient = rect.right;
cyClient = rect.bottom;
// Edit box position
if ( nassac.LineListTop == 0 )
{
nassac.LineListTop = rect.bottom / 50;
}
// Edit box in the middle
hwndEdit = CreateWindow( TEXT ("edit"), NULL, WS_CHILD | WS_VISIBLE
|
WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, 0, 200, rect.right, 24,
// single-line edit box
//WS_BORDER | ES_LEFT | ES_MULTILINE, 0, 200, rect.right, 56,
hwnd, (HMENU) ID_EDIT_CTRL, ((LPCREATESTRUCT) lParam)->
hInstance, NULL);
// Edit box overrides for things like responding to the Enter key
and any additional right mouse button clicks
EditProc = (WNDPROC)GetWindowLong(hwndEdit, GWL_WNDPROC);
SetWindowLong(hwndEdit, GWL_WNDPROC, (long)EditSubProc);
// Buttons
hwndGrabButton = CreateWindow( TEXT ("button"), TEXT("Grab
Selected"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
140, 140, 160, 53,
hwnd, (HMENU) BUTTON_GRAB,
((LPCREATESTRUCT) lParam)->hInstance, NULL);
hwndPlayButton = CreateWindow( TEXT ("button"), TEXT("Play
Selected"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
320, 140, 160, 53,
hwnd, (HMENU) BUTTON_PLAY,
((LPCREATESTRUCT) lParam)->hInstance, NULL);
// List boxes
// http://msdn.microsoft.com/library/de...l=/library/en-
us/shellcc/platform/commctls/listboxes/listboxreference/listboxmessages/l
b_settabstops.asp
// http://support.microsoft.com/default...b;en-us;816176
nas.listBoxHwnd = CreateWindow( TEXT ("listbox"), TEXT("#"),
WS_CHILD | WS_VISIBLE | LBS_USETABSTOPS | // LBS_MULTICOLUMN |
LBS_MULTIPLESEL |
LBS_NOTIFY, 0, 0, rect.right, 140,
hwnd,
(HMENU) ID_LISTBOX1, (HINSTANCE)
GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
return 0;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
// wav file window
SetRect(&wavRect, rect.left, nas.wavBoxTop, rect.right,
nas.wavBoxBotton);
hBrush = CreateSolidBrush( RGB(10, 255, 10) );
hdc = GetDC(hwnd);
FillRect(hdc, &wavRect, hBrush);
MoveToEx(hdc, wavRect.left, wavRect.top, NULL);
LineTo (hdc, wavRect.right, (wavRect.top + wavRect.bottom) / 2);
EndPaint (hwnd, &ps);
DeleteObject(hBrush);
ReleaseDC(hwnd, hdc);
return 0 ;
case WM_COMMAND:
switch( LOWORD(wParam ) )
{
case ID_ACCELERATOR_VKF1:
_stprintf(tcbuffer, TEXT("CTRL-X") );
SendMessage(hwnd, WM_SETTEXT, sizeof(tcbuffer), (LPARAM) (TCHAR
* )tcbuffer );
return 0;
case ID_FILE_EXIT:
SendMessage(hwnd, WM_CLOSE, 0, 0);
return 0;
case BUTTON_GRAB:
_stprintf(tcbuffer, TEXT("Don't grab me like that!") );
SendMessage(hwnd, WM_SETTEXT, sizeof(tcbuffer), (LPARAM) (TCHAR
* )tcbuffer );
return 0;
case BUTTON_PLAY:
_stprintf(tcbuffer, TEXT("Play sound or something...") );
SendMessage(hwnd, WM_SETTEXT, sizeof(tcbuffer), (LPARAM) (TCHAR
* )tcbuffer );
return 0;
}
break;
case EDIT_ENTER_PRESSED:
_stprintf(tcbuffer, TEXT("Enter Pressed!") );
SendMessage(hwndEdit, WM_SETTEXT, sizeof(tcbuffer), (LPARAM) (TCHAR
* )tcbuffer );
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
LRESULT CALLBACK WaveWindow::WaveWindowProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch(message)
{
case WM_CREATE:
myParent = GetParent(hwnd);
return 0;
case WM_KEYDOWN: // I want the controls to be passed to the main
window
SendMessage( myParent, message, wParam, lParam);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
//// Class stuff here
NASSAC::NASSAC()
{
LineListTop = 0;
currentPosition = 0;
topLine = 0;
bottomLine = 0;
wavBoxTop = 300;
wavBoxBotton = 566;
wavBoxLeft = 0;
wavBoxRight = 800;
doNyanko = false;
}
LRESULT CALLBACK EditSubProc(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
int iState;
bool passBack = false;
UINT msgback = message;
/*
if ( GetKeyState ( VK_CONTROL) < 0 ) // we lose CTRL-LEFT and CTRL-
RIGHT but that's a minor loss
{
SendMessage( (nas.mainhwnd), message, wParam, lParam);
}
*/
switch(message)
{
case WM_KEYUP:
switch(LOWORD(wParam))
{
case VK_RETURN:
nas.doNyanko = true;
SendMessage( (nas.mainhwnd), EDIT_ENTER_PRESSED, 0, 0);
return 0;
default:
break;
}
default:
return CallWindowProc(EditProc, hwnd, message, wParam, lParam);
}
return TRUE;
}
//------------------------
// resource.h
//------------------------
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by YASSAC.rc
//
#define IDR_MENU1 101
#define IDR_ACCELERATOR1 102
#define ID_FILE_EXIT 40001
#define ID_FILE_NEW40002 40002
#define ID_ACCELERATOR_VKF1 40003
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40005
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
/////////////////
// YASSAC.rc //
/////////////////
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////
////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////
////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////
////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////
////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////
////
//
// Menu
//
IDR_MENU1 MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "New", ID_FILE_NEW40002
MENUITEM SEPARATOR
MENUITEM "Exit", ID_FILE_EXIT
END
END
/////////////////////////////////////////////////////////////////////////
////
//
// Accelerator
//
IDR_ACCELERATOR1 ACCELERATORS
BEGIN
VK_F1, ID_ACCELERATOR_VKF1, VIRTKEY, NOINVERT
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////
////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////
////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////
////
#endif // not APSTUDIO_INVOKED