- enhancement: use token list instead of single string to do code completion ( intial version)
- fix: language options in the project wizard don't work - fix: "ake as default language" option in the project wizard doesn't work
5
NEWS.md
|
@ -1,3 +1,8 @@
|
|||
Version 0.11.0 For Dev-C++ 7 Beta
|
||||
- enhancement: use token list instead of single string to do code completion ( intial version)
|
||||
- fix: language options in the project wizard don't work
|
||||
- fix: "ake as default language" option in the project wizard doesn't work
|
||||
|
||||
Version 0.10.4 For Dev-C++ 7 Beta
|
||||
- fix: can't correctly undo/redo indent
|
||||
- fix: can't correctly undo/redo unindent
|
||||
|
|
|
@ -4594,6 +4594,10 @@ void MainWindow::on_actionNew_Project_triggered()
|
|||
{
|
||||
NewProjectDialog dialog;
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
if (dialog.makeDefaultLanguage()) {
|
||||
pSettings->editor().setDefaultFileCpp(dialog.isCppProject());
|
||||
pSettings->editor().save();
|
||||
}
|
||||
if (dialog.useAsDefaultProjectDir()) {
|
||||
pSettings->dirs().setProjectDir(dialog.getLocation());
|
||||
pSettings->dirs().save();
|
||||
|
@ -4656,14 +4660,13 @@ void MainWindow::on_actionNew_Project_triggered()
|
|||
|
||||
// Create an empty project
|
||||
mProject = std::make_shared<Project>(s,dialog.getProjectName());
|
||||
if (!mProject->assignTemplate(dialog.getTemplate())) {
|
||||
if (!mProject->assignTemplate(dialog.getTemplate(),dialog.isCppProject())) {
|
||||
mProject = nullptr;
|
||||
QMessageBox::critical(this,
|
||||
tr("New project fail"),
|
||||
tr("Can't assign project template"),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
mProject->options().useGPP = dialog.isCppProject();
|
||||
mProject->saveAll();
|
||||
updateProjectView();
|
||||
}
|
||||
|
|
|
@ -624,14 +624,14 @@ void Project::setCompilerSet(int compilerSetIndex)
|
|||
}
|
||||
}
|
||||
|
||||
bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate)
|
||||
bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, bool useCpp)
|
||||
{
|
||||
if (!aTemplate) {
|
||||
return true;
|
||||
}
|
||||
|
||||
mOptions = aTemplate->options();
|
||||
mOptions.compilerSet = pSettings->compilerSets().defaultIndex();
|
||||
mOptions.useGPP = useCpp;
|
||||
updateCompilerSetType();
|
||||
mOptions.icon = aTemplate->icon();
|
||||
|
||||
|
@ -653,7 +653,7 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate)
|
|||
PTemplateUnit templateUnit = aTemplate->unit(i);
|
||||
QString s;
|
||||
PProjectUnit unit;
|
||||
if (aTemplate->options().useGPP) {
|
||||
if (options().useGPP) {
|
||||
s = templateUnit->CppText;
|
||||
unit = newUnit(mNode, templateUnit->CppName);
|
||||
} else {
|
||||
|
|
|
@ -164,7 +164,7 @@ public:
|
|||
void setCompilerSet(int compilerSetIndex);
|
||||
|
||||
//void showOptions();
|
||||
bool assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate);
|
||||
bool assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, bool useCpp);
|
||||
//void saveToLog();
|
||||
|
||||
std::shared_ptr<CppParser> cppParser();
|
||||
|
|
|
@ -947,14 +947,14 @@ void CodeCompletionPopup::getCompletionFor(const QStringList &expression, const
|
|||
scopeName,
|
||||
mCurrentStatement,
|
||||
parentTypeStatement);
|
||||
qDebug()<<scopeName;
|
||||
qDebug()<<memberOperator;
|
||||
qDebug()<<memberExpression;
|
||||
// qDebug()<<scopeName;
|
||||
// qDebug()<<memberOperator;
|
||||
// qDebug()<<memberExpression;
|
||||
if(!ownerStatement ) {
|
||||
qDebug()<<"not found!";
|
||||
// qDebug()<<"not found!";
|
||||
return;
|
||||
}
|
||||
qDebug()<<"found: "<<ownerStatement->fullName;
|
||||
// qDebug()<<"found: "<<ownerStatement->fullName;
|
||||
if (memberOperator == "::") {
|
||||
if (ownerStatement->kind==StatementKind::skNamespace) {
|
||||
//there might be many statements corresponding to one namespace;
|
||||
|
|
|
@ -81,9 +81,9 @@ bool NewProjectDialog::isCppProject()
|
|||
return ui->rdCppProject->isChecked();
|
||||
}
|
||||
|
||||
bool NewProjectDialog::makeProjectDefault()
|
||||
bool NewProjectDialog::makeDefaultLanguage()
|
||||
{
|
||||
return ui->chkMakeDefault->isChecked();
|
||||
return ui->chkMakeDefaultLanguage->isChecked();
|
||||
}
|
||||
|
||||
void NewProjectDialog::addTemplate(const QString &filename)
|
||||
|
@ -187,15 +187,21 @@ void NewProjectDialog::on_lstTemplates_currentItemChanged(QListWidgetItem *curre
|
|||
PProjectTemplate t = mTemplates[index];
|
||||
ui->lblDescription->setText(t->description());
|
||||
if (t->options().useGPP) {
|
||||
ui->rdCProject->setEnabled(false);
|
||||
ui->rdCppProject->setChecked(true);
|
||||
} else {
|
||||
ui->rdCProject->setChecked(true);
|
||||
ui->rdCProject->setEnabled(true);
|
||||
if (pSettings->editor().defaultFileCpp()) {
|
||||
ui->rdCppProject->setChecked(true);
|
||||
} else {
|
||||
ui->rdCProject->setChecked(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ui->lblDescription->setText("");
|
||||
ui->rdCProject->setChecked(false);
|
||||
ui->rdCppProject->setChecked(false);
|
||||
ui->chkMakeDefault->setChecked(false);
|
||||
ui->chkMakeDefaultLanguage->setChecked(false);
|
||||
}
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
|
||||
current && !ui->txtProjectName->text().isEmpty()
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
bool useAsDefaultProjectDir();
|
||||
bool isCProject();
|
||||
bool isCppProject();
|
||||
bool makeProjectDefault();
|
||||
bool makeDefaultLanguage();
|
||||
private slots:
|
||||
void updateView();
|
||||
void updateProjectLocation();
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
<number>10</number>
|
||||
</property>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="chkMakeDefault">
|
||||
<widget class="QCheckBox" name="chkMakeDefaultLanguage">
|
||||
<property name="text">
|
||||
<string>Make default language</string>
|
||||
</property>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=Windows Application
|
||||
Icon=Windows.ico
|
||||
Description=A standard Windows application
|
||||
Category=Basic
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
CppName=main.cpp
|
||||
C=winapp_c.txt
|
||||
Cpp=winapp_c.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=0
|
|
@ -0,0 +1,16 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=Console Application
|
||||
Icon=ConsoleToo.ico
|
||||
Description=A console application (MS-DOS window)
|
||||
Category=Basic
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
CppName=main.cpp
|
||||
C=consoleapp_c.txt
|
||||
Cpp=consoleapp_cpp.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=1
|
|
@ -0,0 +1,14 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=Static Library
|
||||
Icon=StaticLib.ico
|
||||
Description=A static library (.a)
|
||||
Category=Basic
|
||||
|
||||
[Unit0]
|
||||
CName=
|
||||
CppName=
|
||||
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=2
|
|
@ -0,0 +1,25 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=DLL
|
||||
Icon=DLL.ico
|
||||
Description=A Dynamic Link Library (DLL)
|
||||
Category=Basic
|
||||
|
||||
[Unit0]
|
||||
CName=dllmain.c
|
||||
CppName=dllmain.cpp
|
||||
C=DLL_c.txt
|
||||
Cpp=Dll_cpp.txt
|
||||
|
||||
[Unit1]
|
||||
CName=dll.h
|
||||
CppName=dll.h
|
||||
C=DLL_h.txt
|
||||
Cpp=Dll_hpp.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=2
|
||||
Type=3
|
||||
|
||||
Compiler=-DBUILDING_DLL=1
|
||||
CppCompiler=-DBUILDING_DLL=1
|
|
@ -0,0 +1,14 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=Empty Project
|
||||
Icon=Empty.ico
|
||||
Description=An empty project
|
||||
Category=Basic
|
||||
|
||||
[Unit0]
|
||||
CName=
|
||||
CppName=
|
||||
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=1
|
After Width: | Height: | Size: 4.2 KiB |
|
@ -0,0 +1,17 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=GLUT
|
||||
Icon=CL_GLUT.ico
|
||||
Description=A simple GLUT program
|
||||
Category=Multimedia
|
||||
[Unit0]
|
||||
CppName=main.cpp
|
||||
C=CL_GLUT_cpp.txt
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=0
|
||||
IsCpp=1
|
||||
linker=-lm -lfreeglut_static -lopengl32 -lwinmm -lgdi32_@@__@@_
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
#define FREEGLUT_STATIC
|
||||
#include <stdlib.h>
|
||||
#include <GL/glut.h>
|
||||
|
||||
void keyboard(unsigned char key, int x, int y);
|
||||
void display(void);
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
glutCreateWindow("GLUT Test");
|
||||
glutKeyboardFunc(&keyboard);
|
||||
glutDisplayFunc(&display);
|
||||
glutMainLoop();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void keyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case '\x1B':
|
||||
exit(EXIT_SUCCESS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void display()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glColor3f(1.0f, 0.0f, 0.0f);
|
||||
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex2f(-0.5f, -0.5f);
|
||||
glVertex2f( 0.5f, -0.5f);
|
||||
glVertex2f( 0.5f, 0.5f);
|
||||
glVertex2f(-0.5f, 0.5f);
|
||||
glEnd();
|
||||
|
||||
glFlush();
|
||||
}
|
After Width: | Height: | Size: 4.1 KiB |
|
@ -0,0 +1,16 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=Graphics.h
|
||||
Icon=CL_Graphics.ico
|
||||
Description=A simple program use Easy Graphics Engine
|
||||
Category=Multimedia
|
||||
[Unit0]
|
||||
CppName=main.cpp
|
||||
Cpp=CL_Graphics_cpp.txt
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=0
|
||||
IsCpp=1
|
||||
linker=-lgraphics -luuid -lmsimg32 -lgdi32 -limm32 -lole32 -loleaut32 -lwinmm -lgdiplus_@@__@@_
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
#include <graphics.h>
|
||||
#include <math.h>
|
||||
|
||||
void paintstar(double x, double y, double r, double a)
|
||||
{
|
||||
int pt[10];
|
||||
for (int n = 0; n < 5; ++n)
|
||||
{
|
||||
pt[n*2] = (int)( -cos( PI * 4 / 5 * n + a ) * r + x );
|
||||
pt[n*2+1] = (int)( sin( PI * 4 / 5 * n + a) * r + y );
|
||||
}
|
||||
fillpoly(5, pt);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
initgraph( 640, 480 );
|
||||
setcolor( RGB(0xff, 0xff, 0xff) );
|
||||
setfillcolor( RGB(0, 0, 0xff) );
|
||||
setrendermode(RENDER_MANUAL);
|
||||
|
||||
double r = 0;
|
||||
for ( ; is_run(); delay_fps(60) )
|
||||
{
|
||||
r += 0.02;
|
||||
if (r > PI * 2) r -= PI * 2;
|
||||
|
||||
cleardevice();
|
||||
paintstar(300, 200, 100, r);
|
||||
}
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 4.2 KiB |
|
@ -0,0 +1,15 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=Turtle Graphics
|
||||
Icon=CL_Turtle.ico
|
||||
Description=A simple program using Turtle Graphics (https://github.com/royqh1979/libturtle)
|
||||
Category=Multimedia
|
||||
[Unit0]
|
||||
CppName=main.cpp
|
||||
Cpp=CL_Turtle_cpp.txt
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=0
|
||||
IsCpp=1
|
||||
linker=-lturtle -lgraphics -luuid -lmsimg32 -lgdi32 -limm32 -lole32 -loleaut32 -lwinmm -lgdiplus_@@__@@_
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#include <turtle.h>
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
initWorld(800,600);
|
||||
setSpeed(1000);
|
||||
//setImmediate(1);
|
||||
|
||||
n=50;
|
||||
for (int i=0;i<n;i++) {
|
||||
for (int j=0;j<4;j++) {
|
||||
fd(90);
|
||||
lt(90);
|
||||
}
|
||||
lt(360.0/n);
|
||||
}
|
||||
pause();
|
||||
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 2.9 KiB |
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#include <iostream>
|
||||
|
||||
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 4.2 KiB |
|
@ -0,0 +1,34 @@
|
|||
/* Replace "dll.h" with the name of your header */
|
||||
#include "dll.h"
|
||||
#include <windows.h>
|
||||
|
||||
DLLIMPORT void HelloWorld()
|
||||
{
|
||||
MessageBox(0,"Hello World from DLL!\n","Hi",MB_ICONINFORMATION);
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
|
||||
{
|
||||
switch(fdwReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case DLL_THREAD_ATTACH:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case DLL_THREAD_DETACH:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return TRUE on success, FALSE on failure */
|
||||
return TRUE;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/* Replace "dll.h" with the name of your header */
|
||||
#include "dll.h"
|
||||
#include <windows.h>
|
||||
|
||||
DllClass::DllClass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DllClass::~DllClass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DllClass::HelloWorld()
|
||||
{
|
||||
MessageBox(0, "Hello World from DLL!\n","Hi",MB_ICONINFORMATION);
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
|
||||
{
|
||||
switch(fdwReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case DLL_THREAD_ATTACH:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case DLL_THREAD_DETACH:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return TRUE on success, FALSE on failure */
|
||||
return TRUE;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef _DLL_H_
|
||||
#define _DLL_H_
|
||||
|
||||
#if BUILDING_DLL
|
||||
#define DLLIMPORT __declspec(dllexport)
|
||||
#else
|
||||
#define DLLIMPORT __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
DLLIMPORT void HelloWorld();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef _DLL_H_
|
||||
#define _DLL_H_
|
||||
|
||||
#if BUILDING_DLL
|
||||
#define DLLIMPORT __declspec(dllexport)
|
||||
#else
|
||||
#define DLLIMPORT __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
class DLLIMPORT DllClass
|
||||
{
|
||||
public:
|
||||
DllClass();
|
||||
virtual ~DllClass();
|
||||
void HelloWorld();
|
||||
};
|
||||
|
||||
#endif
|
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 766 B |
|
@ -0,0 +1,29 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=File Editor
|
||||
Icon=Editor.ico
|
||||
Description=A simple Win32 file editor
|
||||
Category=Win32
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
CppName=main.cpp
|
||||
C=FileEditor_c.txt
|
||||
Cpp=FileEditor_c.txt
|
||||
|
||||
[Unit1]
|
||||
CName=main.h
|
||||
CppName=main.h
|
||||
C=FileEditor_h.txt
|
||||
Cpp=FileEditor_h.txt
|
||||
|
||||
[Unit2]
|
||||
CName=resource.rc
|
||||
CppName=resource.rc
|
||||
C=FileEditor_rc.txt
|
||||
Cpp=FileEditor_rc.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=3
|
||||
Type=0
|
||||
Icon=Editor.ico
|
|
@ -0,0 +1,172 @@
|
|||
#include <windows.h>
|
||||
#include "main.h"
|
||||
|
||||
BOOL LoadFile(HWND hEdit, LPSTR pszFileName) {
|
||||
HANDLE hFile;
|
||||
BOOL bSuccess = FALSE;
|
||||
|
||||
hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
|
||||
if(hFile != INVALID_HANDLE_VALUE) {
|
||||
DWORD dwFileSize;
|
||||
dwFileSize = GetFileSize(hFile, NULL);
|
||||
if(dwFileSize != 0xFFFFFFFF) {
|
||||
LPSTR pszFileText;
|
||||
pszFileText = (LPSTR)GlobalAlloc(GPTR, dwFileSize + 1);
|
||||
if(pszFileText != NULL) {
|
||||
DWORD dwRead;
|
||||
if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL)) {
|
||||
pszFileText[dwFileSize] = 0; // Null terminator
|
||||
if(SetWindowText(hEdit, pszFileText))
|
||||
bSuccess = TRUE; // It worked!
|
||||
}
|
||||
GlobalFree(pszFileText);
|
||||
}
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
BOOL SaveFile(HWND hEdit, LPSTR pszFileName) {
|
||||
HANDLE hFile;
|
||||
BOOL bSuccess = FALSE;
|
||||
|
||||
hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if(hFile != INVALID_HANDLE_VALUE) {
|
||||
DWORD dwTextLength;
|
||||
dwTextLength = GetWindowTextLength(hEdit);
|
||||
if(dwTextLength > 0) {
|
||||
LPSTR pszText;
|
||||
pszText = (LPSTR)GlobalAlloc(GPTR, dwTextLength + 1);
|
||||
if(pszText != NULL) {
|
||||
if(GetWindowText(hEdit, pszText, dwTextLength + 1)) {
|
||||
DWORD dwWritten;
|
||||
if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
|
||||
bSuccess = TRUE;
|
||||
}
|
||||
GlobalFree(pszText);
|
||||
}
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
BOOL DoFileOpenSave(HWND hwnd, BOOL bSave) {
|
||||
OPENFILENAME ofn;
|
||||
char szFileName[MAX_PATH];
|
||||
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
szFileName[0] = 0;
|
||||
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = hwnd;
|
||||
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0";
|
||||
ofn.lpstrFile = szFileName;
|
||||
ofn.nMaxFile = MAX_PATH;
|
||||
ofn.lpstrDefExt = "txt";
|
||||
|
||||
if(bSave) {
|
||||
ofn.Flags = OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
|
||||
if(GetSaveFileName(&ofn)) {
|
||||
if(!SaveFile(GetDlgItem(hwnd, IDC_MAIN_TEXT), szFileName)) {
|
||||
MessageBox(hwnd, "Save file failed.", "Error",MB_OK|MB_ICONEXCLAMATION);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ofn.Flags = OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
|
||||
if(GetOpenFileName(&ofn)) {
|
||||
if(!LoadFile(GetDlgItem(hwnd, IDC_MAIN_TEXT), szFileName)) {
|
||||
MessageBox(hwnd, "Load of file failed.", "Error",MB_OK|MB_ICONEXCLAMATION);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
|
||||
switch(Message) {
|
||||
case WM_CREATE:
|
||||
CreateWindow("EDIT", "",WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_WANTRETURN,CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,hwnd, (HMENU)IDC_MAIN_TEXT, GetModuleHandle(NULL), NULL);
|
||||
SendDlgItemMessage(hwnd, IDC_MAIN_TEXT, WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE,0));
|
||||
break;
|
||||
case WM_SIZE:
|
||||
if(wParam != SIZE_MINIMIZED)
|
||||
MoveWindow(GetDlgItem(hwnd, IDC_MAIN_TEXT), 0, 0, LOWORD(lParam),HIWORD(lParam), TRUE);
|
||||
break;
|
||||
case WM_SETFOCUS:
|
||||
SetFocus(GetDlgItem(hwnd, IDC_MAIN_TEXT));
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
switch(LOWORD(wParam)) {
|
||||
case CM_FILE_OPEN:
|
||||
DoFileOpenSave(hwnd, FALSE);
|
||||
break;
|
||||
case CM_FILE_SAVEAS:
|
||||
DoFileOpenSave(hwnd, TRUE);
|
||||
break;
|
||||
case CM_FILE_EXIT:
|
||||
PostMessage(hwnd, WM_CLOSE, 0, 0);
|
||||
break;
|
||||
case CM_ABOUT:
|
||||
MessageBox (NULL, "File Editor for Windows!\nCreated using the Win32 API" , "About...", 0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hwnd);
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hwnd, Message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow) {
|
||||
WNDCLASSEX wc;
|
||||
HWND hwnd;
|
||||
MSG Msg;
|
||||
|
||||
wc.cbSize = sizeof(WNDCLASSEX);
|
||||
wc.style = 0;
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = hInstance;
|
||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wc.lpszMenuName = "MAINMENU";
|
||||
wc.lpszClassName = "WindowClass";
|
||||
wc.hIconSm = LoadIcon(hInstance,"A"); /* A is name used by project icons */
|
||||
|
||||
if(!RegisterClassEx(&wc)) {
|
||||
MessageBox(0,"Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK|MB_SYSTEMMODAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","File Editor Example Program",WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
320,240,
|
||||
NULL, NULL, hInstance, NULL);
|
||||
|
||||
if(hwnd == NULL) {
|
||||
MessageBox(0, "Window Creation Failed!", "Error!",MB_ICONEXCLAMATION|MB_OK|MB_SYSTEMMODAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ShowWindow(hwnd,1);
|
||||
UpdateWindow(hwnd);
|
||||
|
||||
while(GetMessage(&Msg, NULL, 0, 0) > 0) {
|
||||
TranslateMessage(&Msg);
|
||||
DispatchMessage(&Msg);
|
||||
}
|
||||
return Msg.wParam;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#define CM_FILE_SAVEAS 9072
|
||||
#define CM_FILE_EXIT 9071
|
||||
#define CM_FILE_OPEN 9070
|
||||
#define CM_ABOUT 9069
|
||||
|
||||
#define IDC_MAIN_TEXT 1001
|
|
@ -0,0 +1,18 @@
|
|||
#include "main.h"
|
||||
|
||||
MAINMENU MENU
|
||||
{
|
||||
POPUP "&File"
|
||||
{
|
||||
MENUITEM "&Open...", CM_FILE_OPEN
|
||||
MENUITEM "Save &As...", CM_FILE_SAVEAS
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "E&xit", CM_FILE_EXIT
|
||||
}
|
||||
|
||||
POPUP "&Help"
|
||||
{
|
||||
MENUITEM "&About", CM_ABOUT
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 4.2 KiB |
|
@ -0,0 +1,32 @@
|
|||
[Template]
|
||||
ver=2
|
||||
Name=GLFW
|
||||
Description=A simple GLFW program
|
||||
Icon=GLFW.ico
|
||||
Category=Multimedia
|
||||
[Unit0]
|
||||
CppName=main.cpp
|
||||
Cpp=GLFW_main.cpp.txt
|
||||
[Unit1]
|
||||
CppName=shader.h
|
||||
Cpp=GLFW_shader.h.txt
|
||||
[Unit2]
|
||||
CppName=shader.frag
|
||||
Cpp=GLFW_shader.frag.txt
|
||||
[Unit3]
|
||||
CppName=shader.vs
|
||||
Cpp=GLFW_shader.vs.txt
|
||||
[Project]
|
||||
UnitCount=4
|
||||
Type=1
|
||||
IsCpp=1
|
||||
Compiler=
|
||||
CppCompiler=
|
||||
Linker=-lglfw3 -lglew32 -lopengl32 -lwinmm -lgdi32_@@__@@_
|
||||
CompilerSettings=0000000000110000000001000
|
||||
CompilerSet=1
|
||||
UseUTF8=0
|
||||
StaticLink=1
|
||||
AddCharset=1
|
||||
IncludeVersionInfo=0
|
||||
SupportXPThemes=0
|
|
@ -0,0 +1,111 @@
|
|||
#include <iostream>
|
||||
// GLEW
|
||||
#define GLEW_STATIC
|
||||
#include <GL/glew.h>
|
||||
// GLFW
|
||||
#include <GLFW/glfw3.h>
|
||||
// Other includes
|
||||
#include "shader.h"
|
||||
|
||||
// Function prototypes
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
|
||||
|
||||
// Window dimensions
|
||||
const GLuint WIDTH = 800, HEIGHT = 600;
|
||||
|
||||
// The MAIN function, from here we start the application and run the game loop
|
||||
int main()
|
||||
{
|
||||
// Init GLFW
|
||||
glfwInit();
|
||||
// Set all the required options for GLFW
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
|
||||
// Create a GLFWwindow object that we can use for GLFW's functions
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr);
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
// Set the required callback functions
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
// Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions
|
||||
glewExperimental = GL_TRUE;
|
||||
// Initialize GLEW to setup the OpenGL Function pointers
|
||||
glewInit();
|
||||
|
||||
// Define the viewport dimensions
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
|
||||
//读取shader文件,并编译,见shader.h代码
|
||||
Shader ourShader("shader.vs", "shader.frag");
|
||||
|
||||
|
||||
// 一维数组,每六个代表一个顶点属性,前三个代表位置属性,后三个代表颜色属性
|
||||
GLfloat vertices[] = {
|
||||
// Positions // Colors
|
||||
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // Bottom Right
|
||||
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // Bottom Left
|
||||
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // Top
|
||||
};
|
||||
GLuint VBO, VAO;//声明顶点缓冲,声明顶点数组用于管理顶点数据
|
||||
glGenVertexArrays(1, &VAO);//创建顶点数组,返回一个独一无二的整数,标识数组
|
||||
glGenBuffers(1, &VBO);//创建顶点缓冲,返回一个独一无二的整数,标识缓冲区
|
||||
|
||||
glBindVertexArray(VAO);//绑定顶点数组
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);//绑定顶点缓冲
|
||||
//指定顶点数组的数据源为vertices,第四个参数代表显卡如何管理给定的数据,GL_STATIC_DRWA代表几乎不会改变
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
// 指定顶点属性的解析方式。即,如何从顶点缓冲获取相应的顶点属性和相应的颜色属性。或者说,顶点着色器中如何知道去哪个顶点属性分量重着色呢
|
||||
//对每一个顶点而言,属性有2种,一是位置属性,而是颜色属性,因此每六个浮点数决定了一个顶点的位置和颜色
|
||||
|
||||
//顶点着色器中使用layout(location = 0)定义了position顶点属性的位置值(Location),因此第一个参数,代表属性分量的索引
|
||||
//参数二:顶点位置属性的维度,参数三:属性向量的数据类型,参数四:是否标准化;参数五,顶点位置属性的总字节长度,参数六:在缓冲数组中的偏移量,即起始位置
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);
|
||||
glEnableVertexAttribArray(0);//启用属性0,因为默认是禁用的
|
||||
|
||||
// 参数一,对应顶点着色器中的layout (location = 1) in vec3 color;参数六:说明颜色属性的偏移量在三个浮点数后,与上文vertices一致
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
|
||||
glEnableVertexAttribArray(1);//启用属性1.
|
||||
|
||||
//顶点数组对象(Vertex Array Object, VAO)的好处就是,当配置顶点属性指针时,你只需要将上面的代码调用执行一次,之后再绘制物体的时候只需要绑定相应的VAO就行了。如下文循环中的绑定再解绑
|
||||
glBindVertexArray(0); // 解绑 VAO
|
||||
// Game loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// 检查事件,调用相应的回调函数,如下文的key_callback函数
|
||||
glfwPollEvents();
|
||||
|
||||
// Render
|
||||
// Clear the colorbuffer
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);//渲染颜色到后台缓冲
|
||||
glClear(GL_COLOR_BUFFER_BIT);//清除前台缓冲
|
||||
|
||||
// Draw the triangle
|
||||
ourShader.Use();//启用着色器程序
|
||||
glBindVertexArray(VAO);//每次循环都调用,绑定函数绑定VAO
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
glBindVertexArray(0);//解绑
|
||||
|
||||
// Swap the screen buffers
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
// Properly de-allocate all resources once they've outlived their purpose
|
||||
glDeleteVertexArrays(1, &VAO);
|
||||
glDeleteBuffers(1, &VBO);
|
||||
// Terminate GLFW, clearing any resources allocated by GLFW.
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Is called whenever a key is pressed/released via GLFW
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#version 330 core
|
||||
in vec3 ourColor;
|
||||
out vec4 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
color = vec4(ourColor, 1.0f);
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
#ifndef SHADER_H
|
||||
#define SHADER_H
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
GLuint Program;
|
||||
// Constructor generates the shader on the fly
|
||||
Shader(const GLchar* vertexPath, const GLchar* fragmentPath)
|
||||
{
|
||||
// 1. Retrieve the vertex/fragment source code from filePath
|
||||
std::string vertexCode;
|
||||
std::string fragmentCode;
|
||||
std::ifstream vShaderFile;
|
||||
std::ifstream fShaderFile;
|
||||
// ensures ifstream objects can throw exceptions:
|
||||
vShaderFile.exceptions(std::ifstream::badbit);
|
||||
fShaderFile.exceptions(std::ifstream::badbit);
|
||||
try
|
||||
{
|
||||
// Open files
|
||||
vShaderFile.open(vertexPath);
|
||||
fShaderFile.open(fragmentPath);
|
||||
std::stringstream vShaderStream, fShaderStream;
|
||||
// Read file's buffer contents into streams
|
||||
vShaderStream << vShaderFile.rdbuf();
|
||||
fShaderStream << fShaderFile.rdbuf();
|
||||
// close file handlers
|
||||
vShaderFile.close();
|
||||
fShaderFile.close();
|
||||
// Convert stream into string
|
||||
vertexCode = vShaderStream.str();
|
||||
fragmentCode = fShaderStream.str();
|
||||
}
|
||||
catch (std::ifstream::failure e)
|
||||
{
|
||||
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl;
|
||||
}
|
||||
const GLchar* vShaderCode = vertexCode.c_str();
|
||||
const GLchar * fShaderCode = fragmentCode.c_str();
|
||||
// 2. Compile shaders
|
||||
GLuint vertex, fragment;
|
||||
GLint success;
|
||||
GLchar infoLog[512];
|
||||
// Vertex Shader
|
||||
vertex = glCreateShader(GL_VERTEX_SHADER);//创建顶点着色器
|
||||
glShaderSource(vertex, 1, &vShaderCode, NULL);//指定源代码
|
||||
glCompileShader(vertex);//编译着色器
|
||||
// Print compile errors if any
|
||||
glGetShaderiv(vertex, GL_COMPILE_STATUS, &success);//查看是否编译成功
|
||||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(vertex, 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
// Fragment Shader
|
||||
fragment = glCreateShader(GL_FRAGMENT_SHADER);//创建片段着色器
|
||||
glShaderSource(fragment, 1, &fShaderCode, NULL);
|
||||
glCompileShader(fragment);
|
||||
// Print compile errors if any
|
||||
glGetShaderiv(fragment, GL_COMPILE_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(fragment, 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
// Shader Program
|
||||
this->Program = glCreateProgram();//创建着色程序
|
||||
glAttachShader(this->Program, vertex);//关联顶点着色器
|
||||
glAttachShader(this->Program, fragment);//关联片段着色器
|
||||
glLinkProgram(this->Program);//链接编译器
|
||||
// Print linking errors if any
|
||||
glGetProgramiv(this->Program, GL_LINK_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetProgramInfoLog(this->Program, 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
// Delete the shaders as they're linked into our program now and no longer necessery
|
||||
glDeleteShader(vertex);
|
||||
glDeleteShader(fragment);
|
||||
|
||||
}
|
||||
// Uses the current shader
|
||||
void Use()
|
||||
{
|
||||
glUseProgram(this->Program);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 position;//in 代表输入向量, location,与下面的顶点属性描述有关。
|
||||
layout (location = 1) in vec3 color;
|
||||
|
||||
out vec3 ourColor;//out 代表输出3维向量,作为片段着色器的输入,见下文
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(position, 1.0f);
|
||||
ourColor = color;
|
||||
}
|
After Width: | Height: | Size: 5.9 KiB |
|
@ -0,0 +1,17 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=Hello World
|
||||
Icon=Communication.ico
|
||||
Description=A classic Hello World program
|
||||
Category=Console
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
CppName=main.cpp
|
||||
C=Hello_c.txt
|
||||
Cpp=Hello_cpp.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=1
|
||||
Icon=Communication.ico
|
|
@ -0,0 +1,16 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=Input Loop
|
||||
Icon=ConsoleToo.ico
|
||||
Description=A console with an input loop
|
||||
Category=Console
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
CppName=main.c
|
||||
C=HelloInput_c.txt
|
||||
Cpp=HelloInput_cpp.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=1
|
|
@ -0,0 +1,27 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void Foo() {
|
||||
printf("Hello World!\n");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
char input = 0;
|
||||
|
||||
printf("Hello! This is a console application.\n");
|
||||
printf("Press q to quit, press a to execute foo.\n");
|
||||
while(1) {
|
||||
if(scanf("%c",&input) == 1) {
|
||||
if(input == 'a') {
|
||||
Foo();
|
||||
} else if(input == 'q') {
|
||||
break;
|
||||
} else if(input != '\n') {
|
||||
printf("Unknown command '%c'! Ignoring...\n",input);
|
||||
}
|
||||
} else {
|
||||
printf("Invalid input! Ignoring...\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#include <iostream>
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
void Foo() {
|
||||
cout << "Hello World!" << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
char input = 0;
|
||||
|
||||
cout << "Hello! This is a console application." << endl;
|
||||
cout << "Press q to quit, press a to execute foo." << endl;
|
||||
while(1) {
|
||||
cin >> input;
|
||||
if(input == 'a') {
|
||||
Foo();
|
||||
} else if(input == 'q') {
|
||||
break;
|
||||
} else if(input != '\n') {
|
||||
cout << "Unknown command '" << input << "'! Ignoring...\n";
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
printf("Hello world!\n");
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
#include <iostream>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::cout << "Hello world!\n";
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=Jackpot
|
||||
Icon=Games.ico
|
||||
Description=A number guessing game
|
||||
Category=Console
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
CppName=main.cpp
|
||||
C=Jackpot_c.txt
|
||||
Cpp=Jackpot_cpp.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=1
|
||||
Icon=Games.ico
|
|
@ -0,0 +1,88 @@
|
|||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void Start();
|
||||
void GetResults();
|
||||
|
||||
int i, j, life, maxrand;
|
||||
char c;
|
||||
|
||||
void Start() {
|
||||
i = 0;
|
||||
j = 0;
|
||||
life = 0;
|
||||
maxrand = 6;
|
||||
|
||||
cout << "Select difficulty mode:\n"; // the user has to select a difficutly level
|
||||
cout << "1 : Easy (0-15)\n";
|
||||
cout << "2 : Medium (0-30)\n";
|
||||
cout << "3 : Difficult (0-50)\n";
|
||||
cout << "or type another key to quit\n";
|
||||
c = 30;
|
||||
|
||||
cin >> c; // read the user's choice
|
||||
cout << "\n";
|
||||
|
||||
switch (c) {
|
||||
case '1':
|
||||
maxrand = 15; // the random number will be between 0 and maxrand
|
||||
break;
|
||||
case '2':
|
||||
maxrand = 30;
|
||||
break;
|
||||
case '3':
|
||||
maxrand = 50;
|
||||
break;
|
||||
default:
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
|
||||
life = 5; // number of lifes of the player
|
||||
srand((unsigned)time(NULL)); // init Rand() function
|
||||
j = rand() % maxrand; // j get a random value between 0 and maxrand
|
||||
|
||||
GetResults();
|
||||
}
|
||||
|
||||
void GetResults() {
|
||||
if (life <= 0) { // if player has no more life then he loses
|
||||
cout << "You lose !\n\n";
|
||||
Start();
|
||||
}
|
||||
|
||||
cout << "Type a number: \n";
|
||||
cin >> i;
|
||||
|
||||
if((i>maxrand) || (i<0)) { // if the user number isn't correct, restart
|
||||
cout << "Error: number not between 0 and \n" << maxrand;
|
||||
GetResults();
|
||||
}
|
||||
|
||||
if(i == j) {
|
||||
cout << "YOU WIN!\n\n"; // the user found the secret number
|
||||
Start();
|
||||
} else if(i>j) {
|
||||
cout << "Too BIG\n";
|
||||
life = life - 1;
|
||||
cout << "Lives remaining: " << life << "\n\n";
|
||||
GetResults();
|
||||
} else if(i<j) {
|
||||
cout << "Too SMALL\n";
|
||||
life = life - 1;
|
||||
cout << "Lives remaining: " << life << "\n\n";
|
||||
GetResults();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cout << "** Jackpot game **\n";
|
||||
cout << "The goal of this game is to guess a number.\n";
|
||||
cout << "Jackpot will tell you if the number is too big or too\n";
|
||||
cout << "small compared to the secret number to find.\n\n";
|
||||
Start();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=MDI Editor
|
||||
Icon=Windows.ico
|
||||
Description=A Win32 MDI file editor
|
||||
Category=Win32
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
CppName=main.cpp
|
||||
C=MDIEditor_c.txt
|
||||
Cpp=MDIEditor_c.txt
|
||||
|
||||
[Unit1]
|
||||
CName=main.h
|
||||
CppName=main.h
|
||||
C=MDIEditor_h.txt
|
||||
Cpp=MDIEditor_h.txt
|
||||
|
||||
[Unit2]
|
||||
CName=resource.rc
|
||||
CppName=resource.rc
|
||||
C=MDIEditor_rc.txt
|
||||
Cpp=MDIEditor_rc.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=3
|
||||
Type=0
|
|
@ -0,0 +1,433 @@
|
|||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
|
||||
#include "main.h"
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
|
||||
LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT Message, WPARAM wParam,LPARAM lParam);
|
||||
|
||||
char g_szAppName[] = "MyMDIWindow";
|
||||
char g_szChild[] = "MyMDIChild";
|
||||
HINSTANCE g_hInst;
|
||||
HWND g_hMDIClient, g_hStatusBar, g_hToolBar;
|
||||
HWND g_hMainWindow;
|
||||
|
||||
BOOL LoadFile(HWND hEdit, LPSTR pszFileName) {
|
||||
HANDLE hFile;
|
||||
BOOL bSuccess = FALSE;
|
||||
|
||||
hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if(hFile != INVALID_HANDLE_VALUE) {
|
||||
DWORD dwFileSize;
|
||||
dwFileSize = GetFileSize(hFile, NULL);
|
||||
if(dwFileSize != 0xFFFFFFFF) {
|
||||
LPSTR pszFileText;
|
||||
pszFileText = (LPSTR)(GlobalAlloc(GPTR, dwFileSize + 1));
|
||||
if(pszFileText != NULL) {
|
||||
DWORD dwRead;
|
||||
if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL)) {
|
||||
pszFileText[dwFileSize] = 0; // Null terminator
|
||||
if(SetWindowText(hEdit, pszFileText))
|
||||
bSuccess = TRUE; // It worked!
|
||||
}
|
||||
GlobalFree(pszFileText);
|
||||
}
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
BOOL SaveFile(HWND hEdit, LPSTR pszFileName) {
|
||||
HANDLE hFile;
|
||||
BOOL bSuccess = FALSE;
|
||||
|
||||
hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, NULL,
|
||||
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if(hFile != INVALID_HANDLE_VALUE) {
|
||||
DWORD dwTextLength;
|
||||
dwTextLength = GetWindowTextLength(hEdit);
|
||||
if(dwTextLength > 0) {// No need to bother if there's no text.
|
||||
LPSTR pszText;
|
||||
pszText = (LPSTR)(GlobalAlloc(GPTR, dwTextLength + 1));
|
||||
if(pszText != NULL) {
|
||||
if(GetWindowText(hEdit, pszText, dwTextLength + 1)) {
|
||||
DWORD dwWritten;
|
||||
if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
|
||||
bSuccess = TRUE;
|
||||
}
|
||||
GlobalFree(pszText);
|
||||
}
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
BOOL GetFileName(HWND hwnd, LPSTR pszFileName, BOOL bSave) {
|
||||
OPENFILENAME ofn;
|
||||
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
pszFileName[0] = 0;
|
||||
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = hwnd;
|
||||
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0";
|
||||
ofn.lpstrFile = pszFileName;
|
||||
ofn.nMaxFile = MAX_PATH;
|
||||
ofn.lpstrDefExt = "txt";
|
||||
|
||||
if(bSave) {
|
||||
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY |
|
||||
OFN_OVERWRITEPROMPT;
|
||||
if(!GetSaveFileName(&ofn))
|
||||
return FALSE;
|
||||
} else {
|
||||
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
|
||||
if(!GetOpenFileName(&ofn))
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpszCmdParam, int nCmdShow) {
|
||||
MSG Msg;
|
||||
WNDCLASSEX WndClassEx;
|
||||
|
||||
g_hInst = hInstance;
|
||||
|
||||
WndClassEx.cbSize = sizeof(WNDCLASSEX);
|
||||
WndClassEx.style = CS_HREDRAW | CS_VREDRAW;
|
||||
WndClassEx.lpfnWndProc = WndProc;
|
||||
WndClassEx.cbClsExtra = 0;
|
||||
WndClassEx.cbWndExtra = 0;
|
||||
WndClassEx.hInstance = hInstance;
|
||||
WndClassEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
WndClassEx.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
WndClassEx.hbrBackground = (HBRUSH)(COLOR_3DSHADOW+1);
|
||||
WndClassEx.lpszMenuName = "MAIN";
|
||||
WndClassEx.lpszClassName = g_szAppName;
|
||||
WndClassEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
|
||||
if(!RegisterClassEx(&WndClassEx)) {
|
||||
MessageBox(0, "Could Not Register Window", "Oh Oh...",MB_ICONEXCLAMATION | MB_OK);
|
||||
return -1;
|
||||
}
|
||||
|
||||
WndClassEx.lpfnWndProc = MDIChildWndProc;
|
||||
WndClassEx.lpszMenuName = NULL;
|
||||
WndClassEx.lpszClassName = g_szChild;
|
||||
WndClassEx.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
|
||||
|
||||
if(!RegisterClassEx(&WndClassEx)) {
|
||||
MessageBox(0, "Could Not Register Child Window", "Oh Oh...",
|
||||
MB_ICONEXCLAMATION | MB_OK);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_hMainWindow = CreateWindowEx(WS_EX_APPWINDOW,g_szAppName,"MDI File Editor",WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
0, 0, hInstance, NULL);
|
||||
|
||||
if (g_hMainWindow == NULL){
|
||||
MessageBox(0, "No Window", "Oh Oh...", MB_ICONEXCLAMATION | MB_OK);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ShowWindow(g_hMainWindow, nCmdShow);
|
||||
UpdateWindow(g_hMainWindow);
|
||||
|
||||
while(GetMessage(&Msg, NULL, 0, 0)) {
|
||||
if (!TranslateMDISysAccel(g_hMDIClient, &Msg)) {
|
||||
TranslateMessage(&Msg);
|
||||
DispatchMessage(&Msg);
|
||||
}
|
||||
}
|
||||
return Msg.wParam;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
|
||||
switch(Message) {
|
||||
case WM_CREATE: {
|
||||
CLIENTCREATESTRUCT ccs;
|
||||
int iStatusWidths[] = {200, 300, -1};
|
||||
TBADDBITMAP tbab;
|
||||
TBBUTTON tbb[9];
|
||||
|
||||
// Find window menu where children will be listed
|
||||
ccs.hWindowMenu = GetSubMenu(GetMenu(hwnd), 2);
|
||||
ccs.idFirstChild = ID_MDI_FIRSTCHILD;
|
||||
g_hMDIClient = CreateWindowEx(WS_EX_CLIENTEDGE, "mdiclient", NULL,
|
||||
WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
hwnd, (HMENU)ID_MDI_CLIENT, g_hInst, (LPVOID)&ccs);
|
||||
ShowWindow(g_hMDIClient, SW_SHOW);
|
||||
|
||||
g_hStatusBar = CreateWindowEx(0, STATUSCLASSNAME, NULL,
|
||||
WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,
|
||||
hwnd, (HMENU)ID_STATUSBAR, g_hInst, NULL);
|
||||
SendMessage(g_hStatusBar, SB_SETPARTS, 3, (LPARAM)iStatusWidths);
|
||||
SendMessage(g_hStatusBar, SB_SETTEXT, 2, (LPARAM)"Toolbar & Statusbar Example");
|
||||
|
||||
g_hToolBar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
|
||||
WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
|
||||
hwnd, (HMENU)ID_TOOLBAR, g_hInst, NULL);
|
||||
|
||||
// Send the TB_BUTTONSTRUCTSIZE message, which is required for
|
||||
// backward compatibility.
|
||||
SendMessage(g_hToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
|
||||
|
||||
tbab.hInst = HINST_COMMCTRL;
|
||||
tbab.nID = IDB_STD_SMALL_COLOR;
|
||||
SendMessage(g_hToolBar, TB_ADDBITMAP, 0, (LPARAM)&tbab);
|
||||
|
||||
ZeroMemory(tbb, sizeof(tbb));
|
||||
|
||||
tbb[0].iBitmap = STD_FILENEW;
|
||||
tbb[0].fsState = TBSTATE_ENABLED;
|
||||
tbb[0].fsStyle = TBSTYLE_BUTTON;
|
||||
tbb[0].idCommand = CM_FILE_NEW;
|
||||
|
||||
tbb[1].iBitmap = STD_FILEOPEN;
|
||||
tbb[1].fsState = TBSTATE_ENABLED;
|
||||
tbb[1].fsStyle = TBSTYLE_BUTTON;
|
||||
tbb[1].idCommand = CM_FILE_OPEN;
|
||||
|
||||
tbb[2].iBitmap = STD_FILESAVE;
|
||||
tbb[2].fsStyle = TBSTYLE_BUTTON;
|
||||
tbb[2].idCommand = CM_FILE_SAVE;
|
||||
|
||||
tbb[3].fsStyle = TBSTYLE_SEP;
|
||||
|
||||
tbb[4].iBitmap = STD_CUT;
|
||||
tbb[4].fsStyle = TBSTYLE_BUTTON;
|
||||
tbb[4].idCommand = CM_EDIT_CUT;
|
||||
|
||||
tbb[5].iBitmap = STD_COPY;
|
||||
tbb[5].fsStyle = TBSTYLE_BUTTON;
|
||||
tbb[5].idCommand = CM_EDIT_COPY;
|
||||
|
||||
tbb[6].iBitmap = STD_PASTE;
|
||||
tbb[6].fsStyle = TBSTYLE_BUTTON;
|
||||
tbb[6].idCommand = CM_EDIT_PASTE;
|
||||
|
||||
tbb[7].fsStyle = TBSTYLE_SEP;
|
||||
|
||||
tbb[8].iBitmap = STD_UNDO;
|
||||
tbb[8].fsStyle = TBSTYLE_BUTTON;
|
||||
tbb[8].idCommand = CM_EDIT_UNDO;
|
||||
|
||||
SendMessage(g_hToolBar, TB_ADDBUTTONS, 9, (LPARAM)&tbb);
|
||||
return 0;
|
||||
}
|
||||
case WM_COMMAND: {
|
||||
switch(LOWORD(wParam)) {
|
||||
case CM_FILE_EXIT:
|
||||
PostMessage(hwnd, WM_CLOSE, 0, 0);
|
||||
break;
|
||||
case CM_FILE_NEW: {
|
||||
MDICREATESTRUCT mcs;
|
||||
HWND hChild;
|
||||
|
||||
mcs.szTitle = "[Untitled]";
|
||||
mcs.szClass = g_szChild;
|
||||
mcs.hOwner = g_hInst;
|
||||
mcs.x = mcs.cx = CW_USEDEFAULT;
|
||||
mcs.y = mcs.cy = CW_USEDEFAULT;
|
||||
mcs.style = MDIS_ALLCHILDSTYLES;
|
||||
|
||||
hChild = (HWND)SendMessage(g_hMDIClient, WM_MDICREATE,0, (LPARAM)&mcs);
|
||||
if(!hChild) {
|
||||
MessageBox(hwnd, "MDI Child creation failed.", "Oh Oh...",MB_ICONEXCLAMATION | MB_OK);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CM_FILE_OPEN: {
|
||||
MDICREATESTRUCT mcs;
|
||||
HWND hChild;
|
||||
char szFileName[MAX_PATH];
|
||||
|
||||
if(!GetFileName(hwnd, szFileName, FALSE))
|
||||
break;
|
||||
|
||||
mcs.szTitle = szFileName;
|
||||
mcs.szClass = g_szChild;
|
||||
mcs.hOwner = g_hInst;
|
||||
mcs.x = mcs.cx = CW_USEDEFAULT;
|
||||
mcs.y = mcs.cy = CW_USEDEFAULT;
|
||||
mcs.style = MDIS_ALLCHILDSTYLES;
|
||||
|
||||
hChild = (HWND)SendMessage(g_hMDIClient, WM_MDICREATE, 0, (LPARAM)&mcs);
|
||||
|
||||
if(!hChild) {
|
||||
MessageBox(hwnd, "MDI Child creation failed.", "Oh Oh...",
|
||||
MB_ICONEXCLAMATION | MB_OK);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CM_WINDOW_TILEHORZ:
|
||||
PostMessage(g_hMDIClient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
|
||||
break;
|
||||
case CM_WINDOW_TILEVERT:
|
||||
PostMessage(g_hMDIClient, WM_MDITILE, MDITILE_VERTICAL, 0);
|
||||
break;
|
||||
case CM_WINDOW_CASCADE:
|
||||
PostMessage(g_hMDIClient, WM_MDICASCADE, 0, 0);
|
||||
break;
|
||||
case CM_WINDOW_ARRANGE:
|
||||
PostMessage(g_hMDIClient, WM_MDIICONARRANGE, 0, 0);
|
||||
break;
|
||||
default: {
|
||||
if(LOWORD(wParam) >= ID_MDI_FIRSTCHILD){
|
||||
DefFrameProc(hwnd, g_hMDIClient, Message, wParam, lParam);
|
||||
} else {
|
||||
HWND hChild;
|
||||
hChild = (HWND)SendMessage(g_hMDIClient, WM_MDIGETACTIVE,0,0);
|
||||
if(hChild){
|
||||
SendMessage(hChild, WM_COMMAND, wParam, lParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_SIZE: {
|
||||
RECT rectClient, rectStatus, rectTool;
|
||||
UINT uToolHeight, uStatusHeight, uClientAlreaHeight;
|
||||
|
||||
SendMessage(g_hToolBar, TB_AUTOSIZE, 0, 0);
|
||||
SendMessage(g_hStatusBar, WM_SIZE, 0, 0);
|
||||
|
||||
GetClientRect(hwnd, &rectClient);
|
||||
GetWindowRect(g_hStatusBar, &rectStatus);
|
||||
GetWindowRect(g_hToolBar, &rectTool);
|
||||
|
||||
uToolHeight = rectTool.bottom - rectTool.top;
|
||||
uStatusHeight = rectStatus.bottom - rectStatus.top;
|
||||
uClientAlreaHeight = rectClient.bottom;
|
||||
|
||||
MoveWindow(g_hMDIClient, 0, uToolHeight, rectClient.right, uClientAlreaHeight - uStatusHeight - uToolHeight, TRUE);
|
||||
break;
|
||||
}
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hwnd);
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefFrameProc(hwnd, g_hMDIClient, Message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT Message, WPARAM wParam,LPARAM lParam) {
|
||||
switch(Message) {
|
||||
case WM_CREATE: {
|
||||
char szFileName[MAX_PATH];
|
||||
HWND hEdit;
|
||||
|
||||
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_WANTRETURN,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
hwnd, (HMENU)IDC_CHILD_EDIT, g_hInst, NULL);
|
||||
|
||||
SendMessage(hEdit, WM_SETFONT,
|
||||
(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0));
|
||||
|
||||
GetWindowText(hwnd, szFileName, MAX_PATH);
|
||||
if(*szFileName != '[') {
|
||||
if(!LoadFile(hEdit, szFileName)) {
|
||||
MessageBox(hwnd, "Couldn't Load File.", "Error.",MB_OK | MB_ICONEXCLAMATION);
|
||||
return -1; //cancel window creation
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_SIZE:
|
||||
if(wParam != SIZE_MINIMIZED)
|
||||
MoveWindow(GetDlgItem(hwnd, IDC_CHILD_EDIT), 0, 0, LOWORD(lParam),HIWORD(lParam), TRUE);
|
||||
break;
|
||||
case WM_MDIACTIVATE: {
|
||||
HMENU hMenu, hFileMenu;
|
||||
BOOL EnableFlag;
|
||||
char szFileName[MAX_PATH];
|
||||
|
||||
hMenu = GetMenu(g_hMainWindow);
|
||||
if(hwnd == (HWND)lParam){ //being activated
|
||||
EnableFlag = TRUE;
|
||||
} else{
|
||||
EnableFlag = FALSE; //being de-activated
|
||||
}
|
||||
EnableMenuItem(hMenu, 1, MF_BYPOSITION | (EnableFlag ? MF_ENABLED : MF_GRAYED));
|
||||
EnableMenuItem(hMenu, 2, MF_BYPOSITION | (EnableFlag ? MF_ENABLED : MF_GRAYED));
|
||||
|
||||
hFileMenu = GetSubMenu(hMenu, 0);
|
||||
EnableMenuItem(hFileMenu, CM_FILE_SAVE, MF_BYCOMMAND | (EnableFlag ? MF_ENABLED : MF_GRAYED));
|
||||
EnableMenuItem(hFileMenu, CM_FILE_SAVEAS, MF_BYCOMMAND | (EnableFlag ? MF_ENABLED : MF_GRAYED));
|
||||
|
||||
DrawMenuBar(g_hMainWindow);
|
||||
|
||||
SendMessage(g_hToolBar, TB_ENABLEBUTTON, CM_FILE_SAVE, MAKELONG(EnableFlag, 0));
|
||||
SendMessage(g_hToolBar, TB_ENABLEBUTTON, CM_EDIT_UNDO, MAKELONG(EnableFlag, 0));
|
||||
SendMessage(g_hToolBar, TB_ENABLEBUTTON, CM_EDIT_CUT, MAKELONG(EnableFlag, 0));
|
||||
SendMessage(g_hToolBar, TB_ENABLEBUTTON, CM_EDIT_COPY, MAKELONG(EnableFlag, 0));
|
||||
SendMessage(g_hToolBar, TB_ENABLEBUTTON, CM_EDIT_PASTE, MAKELONG(EnableFlag, 0));
|
||||
|
||||
GetWindowText(hwnd, szFileName, MAX_PATH);
|
||||
SendMessage(g_hStatusBar, SB_SETTEXT, 0, (LPARAM)(EnableFlag ? szFileName : ""));
|
||||
break;
|
||||
}
|
||||
case WM_SETFOCUS:
|
||||
SetFocus(GetDlgItem(hwnd, IDC_CHILD_EDIT));
|
||||
break;
|
||||
case WM_COMMAND: {
|
||||
switch(LOWORD(wParam)) {
|
||||
case CM_FILE_SAVE: {
|
||||
char szFileName[MAX_PATH];
|
||||
|
||||
GetWindowText(hwnd, szFileName, MAX_PATH);
|
||||
if(*szFileName != '[') {
|
||||
if(!SaveFile(GetDlgItem(hwnd, IDC_CHILD_EDIT), szFileName)) {
|
||||
MessageBox(hwnd, "Couldn't Save File.", "Error.",MB_OK | MB_ICONEXCLAMATION);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PostMessage(hwnd, WM_COMMAND,MAKEWPARAM(CM_FILE_SAVEAS, 0), 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
case CM_FILE_SAVEAS: {
|
||||
char szFileName[MAX_PATH];
|
||||
|
||||
if(GetFileName(hwnd, szFileName, TRUE)) {
|
||||
if(!SaveFile(GetDlgItem(hwnd, IDC_CHILD_EDIT), szFileName)) {
|
||||
MessageBox(hwnd, "Couldn't Save File.", "Error.",MB_OK | MB_ICONEXCLAMATION);
|
||||
return 0;
|
||||
} else {
|
||||
SetWindowText(hwnd, szFileName);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
case CM_EDIT_UNDO:
|
||||
SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, EM_UNDO, 0, 0);
|
||||
break;
|
||||
case CM_EDIT_CUT:
|
||||
SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_CUT, 0, 0);
|
||||
break;
|
||||
case CM_EDIT_COPY:
|
||||
SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_COPY, 0, 0);
|
||||
break;
|
||||
case CM_EDIT_PASTE:
|
||||
SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_PASTE, 0, 0);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return DefMDIChildProc(hwnd, Message, wParam, lParam);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
#define CM_WINDOW_TILEVERT 9080
|
||||
#define CM_WINDOW_TILEHORZ 9082
|
||||
#define CM_WINDOW_ARRANGE 9081
|
||||
#define CM_WINDOW_TILE 9080
|
||||
#define CM_WINDOW_CASCADE 9076
|
||||
#define CM_EDIT_PASTE 9079
|
||||
#define CM_EDIT_COPY 9078
|
||||
#define CM_EDIT_CUT 9077
|
||||
#define CM_EDIT_REDO 9076
|
||||
#define CM_EDIT_UNDO 9075
|
||||
#define CM_FILE_SAVEAS 9074
|
||||
#define CM_FILE_SAVE 9073
|
||||
#define CM_FILE_OPEN 9072
|
||||
#define CM_HELP_ABOUT 9072
|
||||
#define CM_FILE_EXIT 9071
|
||||
#define CM_FILE_NEW 9070
|
||||
|
||||
#define ID_STATUSBAR 4997
|
||||
#define ID_TOOLBAR 4998
|
||||
|
||||
#define ID_MDI_CLIENT 4999
|
||||
#define ID_MDI_FIRSTCHILD 50000
|
||||
|
||||
#define IDC_CHILD_EDIT 2000
|
|
@ -0,0 +1,31 @@
|
|||
#include "main.h"
|
||||
|
||||
MAIN MENU
|
||||
{
|
||||
POPUP "&File"
|
||||
{
|
||||
MENUITEM "&New", CM_FILE_NEW
|
||||
MENUITEM "&Open...", CM_FILE_OPEN
|
||||
MENUITEM "&Save", CM_FILE_SAVE, GRAYED
|
||||
MENUITEM "Save &As...", CM_FILE_SAVEAS, GRAYED
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "E&xit", CM_FILE_EXIT
|
||||
}
|
||||
|
||||
POPUP "&Edit", GRAYED
|
||||
{
|
||||
MENUITEM "&Undo\tCtrl+Z", CM_EDIT_UNDO
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Cu&t\tCtrl+X", CM_EDIT_CUT
|
||||
MENUITEM "&Copy\tCtrl+C", CM_EDIT_COPY
|
||||
MENUITEM "&Paste\tCtrl+V", CM_EDIT_PASTE
|
||||
}
|
||||
|
||||
POPUP "&Window", GRAYED
|
||||
{
|
||||
MENUITEM "&Cascade", CM_WINDOW_CASCADE
|
||||
MENUITEM "Tile &Horizontal", CM_WINDOW_TILEHORZ
|
||||
MENUITEM "Tile &Vertical", CM_WINDOW_TILEVERT
|
||||
MENUITEM "Arrange &Icons", CM_WINDOW_ARRANGE
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=OpenGL
|
||||
Icon=Pizza.ico
|
||||
Description=A basic OpenGL program
|
||||
Category=Multimedia
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
CppName=main.cpp
|
||||
C=OpenGL.txt
|
||||
Cpp=OpenGL.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=0
|
||||
Linker=-lopengl32
|
|
@ -0,0 +1,190 @@
|
|||
/**************************
|
||||
* Includes
|
||||
*
|
||||
**************************/
|
||||
|
||||
#include <windows.h>
|
||||
#include <gl/gl.h>
|
||||
|
||||
|
||||
/**************************
|
||||
* Function Declarations
|
||||
*
|
||||
**************************/
|
||||
|
||||
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
|
||||
WPARAM wParam, LPARAM lParam);
|
||||
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
|
||||
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
|
||||
|
||||
|
||||
/**************************
|
||||
* WinMain
|
||||
*
|
||||
**************************/
|
||||
|
||||
int WINAPI WinMain (HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int iCmdShow)
|
||||
{
|
||||
WNDCLASS wc;
|
||||
HWND hWnd;
|
||||
HDC hDC;
|
||||
HGLRC hRC;
|
||||
MSG msg;
|
||||
BOOL bQuit = FALSE;
|
||||
float theta = 0.0f;
|
||||
|
||||
/* register window class */
|
||||
wc.style = CS_OWNDC;
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = hInstance;
|
||||
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = "GLSample";
|
||||
RegisterClass (&wc);
|
||||
|
||||
/* create main window */
|
||||
hWnd = CreateWindow (
|
||||
"GLSample", "OpenGL Sample",
|
||||
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
|
||||
0, 0, 256, 256,
|
||||
NULL, NULL, hInstance, NULL);
|
||||
|
||||
/* enable OpenGL for the window */
|
||||
EnableOpenGL (hWnd, &hDC, &hRC);
|
||||
|
||||
/* program main loop */
|
||||
while (!bQuit)
|
||||
{
|
||||
/* check for messages */
|
||||
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
/* handle or dispatch messages */
|
||||
if (msg.message == WM_QUIT)
|
||||
{
|
||||
bQuit = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
TranslateMessage (&msg);
|
||||
DispatchMessage (&msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* OpenGL animation code goes here */
|
||||
|
||||
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear (GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glPushMatrix ();
|
||||
glRotatef (theta, 0.0f, 0.0f, 1.0f);
|
||||
glBegin (GL_TRIANGLES);
|
||||
glColor3f (1.0f, 0.0f, 0.0f); glVertex2f (0.0f, 1.0f);
|
||||
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.87f, -0.5f);
|
||||
glColor3f (0.0f, 0.0f, 1.0f); glVertex2f (-0.87f, -0.5f);
|
||||
glEnd ();
|
||||
glPopMatrix ();
|
||||
|
||||
SwapBuffers (hDC);
|
||||
|
||||
theta += 1.0f;
|
||||
Sleep (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* shutdown OpenGL */
|
||||
DisableOpenGL (hWnd, hDC, hRC);
|
||||
|
||||
/* destroy the window explicitly */
|
||||
DestroyWindow (hWnd);
|
||||
|
||||
return msg.wParam;
|
||||
}
|
||||
|
||||
|
||||
/********************
|
||||
* Window Procedure
|
||||
*
|
||||
********************/
|
||||
|
||||
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
|
||||
WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case WM_CREATE:
|
||||
return 0;
|
||||
case WM_CLOSE:
|
||||
PostQuitMessage (0);
|
||||
return 0;
|
||||
|
||||
case WM_DESTROY:
|
||||
return 0;
|
||||
|
||||
case WM_KEYDOWN:
|
||||
switch (wParam)
|
||||
{
|
||||
case VK_ESCAPE:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return DefWindowProc (hWnd, message, wParam, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*******************
|
||||
* Enable OpenGL
|
||||
*
|
||||
*******************/
|
||||
|
||||
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
|
||||
{
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
int iFormat;
|
||||
|
||||
/* get the device context (DC) */
|
||||
*hDC = GetDC (hWnd);
|
||||
|
||||
/* set the pixel format for the DC */
|
||||
ZeroMemory (&pfd, sizeof (pfd));
|
||||
pfd.nSize = sizeof (pfd);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
|
||||
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = 24;
|
||||
pfd.cDepthBits = 16;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
iFormat = ChoosePixelFormat (*hDC, &pfd);
|
||||
SetPixelFormat (*hDC, iFormat, &pfd);
|
||||
|
||||
/* create and enable the render context (RC) */
|
||||
*hRC = wglCreateContext( *hDC );
|
||||
wglMakeCurrent( *hDC, *hRC );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/******************
|
||||
* Disable OpenGL
|
||||
*
|
||||
******************/
|
||||
|
||||
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
|
||||
{
|
||||
wglMakeCurrent (NULL, NULL);
|
||||
wglDeleteContext (hRC);
|
||||
ReleaseDC (hWnd, hDC);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=OpenMP
|
||||
Icon=File Management.ico
|
||||
Description=A OpenMP multithreading example
|
||||
Category=Console
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
CppName=main.cpp
|
||||
C=OpenMP_c.txt
|
||||
Cpp=OpenMP_cpp.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=1
|
||||
Compiler=-fopenmp
|
||||
CppCompiler=-fopenmp
|
||||
Linker=-lgomp
|
|
@ -0,0 +1,17 @@
|
|||
#include <omp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
|
||||
int i;
|
||||
|
||||
#pragma omp parallel num_threads(2)
|
||||
printf("Hi, I'm thread number %d!\n",omp_get_thread_num());
|
||||
|
||||
#pragma omp parallel for num_threads(2)
|
||||
for(i = 0;i < 20;i++) {
|
||||
printf("\nThread number %d, executing iteration %d...",omp_get_thread_num(),i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#include <omp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// not using iostream here due to output ordering issues
|
||||
|
||||
// iostream tends to output each part between <<'s separately to the console,
|
||||
// which can lead to random output if multiple threads are doing the same
|
||||
// thing.
|
||||
|
||||
// printf will generally output the whole result string in one go, so results
|
||||
// of separate printf calls, even from different threads, will remain intact
|
||||
|
||||
// Another fix, other than using printf, would be to give each thread its own
|
||||
// place to store output temporarily (a stringstream), and then output the whole
|
||||
// result in one go.
|
||||
|
||||
int main() {
|
||||
|
||||
#pragma omp parallel num_threads(2)
|
||||
printf("Hi, I'm thread number %d!\n",omp_get_thread_num());
|
||||
|
||||
#pragma omp parallel for num_threads(2)
|
||||
for(int i = 0;i < 20;i++) {
|
||||
printf("\nThread number %d, executing iteration %d...",omp_get_thread_num(),i);
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 766 B |
After Width: | Height: | Size: 766 B |
|
@ -0,0 +1,28 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=Single Dialog Application
|
||||
Icon=Single Dialog Application.ico
|
||||
Description=An Appliction use a dialog as the main UI
|
||||
Category=Win32
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
C=Single_Dialog_Application_main.c.txt
|
||||
[Unit1]
|
||||
CName=resource.rc
|
||||
C=Single_Dialog_Application_resource.rc.txt
|
||||
[Unit2]
|
||||
CName=resource.h
|
||||
C=Single_Dialog_Application_resource.h.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=3
|
||||
Type=0
|
||||
IsCpp=0
|
||||
Compiler=
|
||||
CppCompiler=
|
||||
Linker=
|
||||
CompilerSettings=0000000000000000000000000
|
||||
CompilerSet=0
|
||||
IncludeVersionInfo=0
|
||||
SupportXPThemes=0
|
||||
Icon=Single Dialog Application.project.ico
|
|
@ -0,0 +1,42 @@
|
|||
#include <windows.h>
|
||||
#include "resource.h"
|
||||
|
||||
HINSTANCE hInst;
|
||||
|
||||
LRESULT MainDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
|
||||
MSG msg;
|
||||
HWND hMainDlg = NULL;
|
||||
|
||||
hInst = hInstance;
|
||||
hMainDlg = CreateDialog(hInstance, (LPCTSTR)IDD_MAIN_DIALOG, 0,(DLGPROC)MainDlgProc);
|
||||
ShowWindow(hMainDlg, nCmdShow);
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT MainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
switch (message) {
|
||||
case WM_INITDIALOG :
|
||||
return TRUE ;
|
||||
case WM_COMMAND :
|
||||
switch (LOWORD (wParam)) {
|
||||
case IDOK :
|
||||
case IDCANCEL :
|
||||
DestroyWindow(hDlg);
|
||||
return TRUE ;
|
||||
}
|
||||
break ;
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hDlg);
|
||||
return TRUE;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
return TRUE;
|
||||
};
|
||||
return FALSE;//返回FALSE给缺省对话框函数DefDlgProc(),表示没有处理本消息
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef IDC_STATIC
|
||||
#define IDC_STATIC (-1)
|
||||
#endif
|
||||
|
||||
#define IDD_MAIN_DIALOG 101
|
|
@ -0,0 +1,24 @@
|
|||
// Generated by ResEdit 1.6.5
|
||||
// Copyright (C) 2006-2015
|
||||
// http://www.resedit.net
|
||||
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
#include <richedit.h>
|
||||
#include "resource.h"
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Dialog resources
|
||||
//
|
||||
LANGUAGE 0, SUBLANG_NEUTRAL
|
||||
IDD_MAIN_DIALOG DIALOG 0, 0, 186, 95
|
||||
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
|
||||
CAPTION "Dialog"
|
||||
FONT 8, "Ms Shell Dlg"
|
||||
{
|
||||
PUSHBUTTON "Cancel", IDCANCEL, 129, 24, 50, 14, 0, WS_EX_LEFT
|
||||
DEFPUSHBUTTON "OK", IDOK, 129, 7, 50, 14, 0, WS_EX_LEFT
|
||||
}
|
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 4.2 KiB |
|
@ -0,0 +1,19 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=std::thread
|
||||
Icon=Software.ico
|
||||
Description=A C++ multithreading example
|
||||
Category=Console
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
CppName=main.cpp
|
||||
C=StdThread_c.txt
|
||||
Cpp=StdThread_cpp.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=1
|
||||
Type=1
|
||||
Compiler=
|
||||
CppCompiler=-std=gnu++11
|
||||
Linker=
|
|
@ -0,0 +1,2 @@
|
|||
// Please note that MinGW32 compilers currently do not support <thread>. Use MinGW64 builds like TDM-GCC instead.
|
||||
// C does not support this magic ;)
|
|
@ -0,0 +1,43 @@
|
|||
// Please note that MinGW32 compilers currently do not support <thread>. Use MinGW64 builds like TDM-GCC instead.
|
||||
|
||||
#include <thread>
|
||||
using std::thread;
|
||||
#include <vector>
|
||||
using std::vector;
|
||||
#include <stdio.h>
|
||||
|
||||
struct ThreadItem {
|
||||
char* result; // could've used stringstream too, but don't like their syntax
|
||||
thread worker;
|
||||
};
|
||||
|
||||
void* ThreadFunction(char** result) {
|
||||
*result = new char[256];
|
||||
snprintf(*result,256,"Hello World from thread ID %d",
|
||||
std::this_thread::get_id());
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Get the amount of "processing units"
|
||||
int n = std::thread::hardware_concurrency();
|
||||
|
||||
// Create array of threads
|
||||
vector<ThreadItem> threadlist;
|
||||
threadlist.resize(n);
|
||||
|
||||
// Spawn a thread for each core
|
||||
for(int i = 0;i < n;i++) {
|
||||
threadlist[i].worker = thread(ThreadFunction,&threadlist[i].result); // pass rand() as data argument
|
||||
}
|
||||
|
||||
// Wait for them all to finish
|
||||
for(int i = 0;i < n;i++) {
|
||||
threadlist[i].worker.join();
|
||||
}
|
||||
|
||||
// Present their calculation results
|
||||
printf("Results:\n");
|
||||
for(int i = 0;i < n;i++) {
|
||||
printf("%s\n",threadlist[i].result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
[Template]
|
||||
ver=1
|
||||
Name=Animation Example
|
||||
Icon=Windows.ico
|
||||
Description=A Win32 painting example
|
||||
Category=Win32
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
CppName=main.cpp
|
||||
C=WinAnim_c.txt
|
||||
Cpp=WinAnim_c.txt
|
||||
|
||||
[Unit1]
|
||||
CName=resource.rc
|
||||
CppName=resource.rc
|
||||
C=WinAnim_rc.txt
|
||||
Cpp=WinAnim_rc.txt
|
||||
|
||||
[Project]
|
||||
UnitCount=2
|
||||
Type=0
|
|
@ -0,0 +1,191 @@
|
|||
/*
|
||||
Name: WinAnim
|
||||
Author: Brook Miles
|
||||
Description: Making an animation in windows
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
static char g_szClassName[] = "MyWindowClass";
|
||||
static HINSTANCE g_hInst = NULL;
|
||||
|
||||
const UINT idTimer1 = 1;
|
||||
UINT nTimerDelay = 10;
|
||||
|
||||
HBITMAP hbmBall, hbmMask;
|
||||
BITMAP bm;
|
||||
|
||||
int ballX, ballY;
|
||||
int deltaX, deltaY;
|
||||
|
||||
int deltaValue = 4;
|
||||
|
||||
void EraseBall(HDC hdc)
|
||||
{
|
||||
RECT rc;
|
||||
rc.left = ballX;
|
||||
rc.top = ballY;
|
||||
rc.right = ballX + bm.bmWidth;
|
||||
rc.bottom = ballY + bm.bmHeight;
|
||||
FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
|
||||
}
|
||||
|
||||
void DrawBall(HDC hdc)
|
||||
{
|
||||
HDC hdcMemory;
|
||||
hdcMemory = CreateCompatibleDC(hdc);
|
||||
|
||||
SelectObject(hdcMemory, hbmMask);
|
||||
BitBlt(hdc, ballX, ballY, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCAND);
|
||||
|
||||
SelectObject(hdcMemory, hbmBall);
|
||||
BitBlt(hdc, ballX, ballY, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCPAINT);
|
||||
|
||||
DeleteDC(hdcMemory);
|
||||
}
|
||||
|
||||
void UpdateBall(HWND hwnd)
|
||||
{
|
||||
RECT rc;
|
||||
GetClientRect(hwnd, &rc);
|
||||
|
||||
ballX += deltaX;
|
||||
ballY += deltaY;
|
||||
|
||||
if(ballX < 0){
|
||||
ballX = 0;
|
||||
deltaX = deltaValue;
|
||||
}
|
||||
else if(ballX + bm.bmWidth > rc.right){
|
||||
ballX = rc.right - bm.bmWidth;
|
||||
deltaX = -deltaValue;
|
||||
}
|
||||
if(ballY < 0){
|
||||
ballY = 0;
|
||||
deltaY = deltaValue;
|
||||
}
|
||||
else if(ballY + bm.bmHeight > rc.bottom){
|
||||
ballY = rc.bottom - bm.bmHeight;
|
||||
deltaY = -deltaValue;
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(Message)
|
||||
{
|
||||
case WM_CREATE:
|
||||
hbmBall = LoadBitmap(g_hInst, "BALLBMP");
|
||||
hbmMask = LoadBitmap(g_hInst, "MASKBMP");
|
||||
if(!hbmBall || !hbmMask){
|
||||
MessageBox(hwnd, "Load of resources failed.", "Error",
|
||||
MB_OK | MB_ICONEXCLAMATION);
|
||||
return -1;
|
||||
}
|
||||
|
||||
GetObject(hbmBall, sizeof(bm), &bm);
|
||||
SetTimer(hwnd, idTimer1, nTimerDelay, NULL);
|
||||
|
||||
ballX = 0;
|
||||
ballY = 0;
|
||||
deltaX = deltaValue;
|
||||
deltaY = deltaValue;
|
||||
|
||||
break;
|
||||
case WM_TIMER:
|
||||
if(hbmBall && hbmMask)
|
||||
{
|
||||
HDC hdcWindow;
|
||||
hdcWindow = GetDC(hwnd);
|
||||
|
||||
EraseBall(hdcWindow);
|
||||
UpdateBall(hwnd);
|
||||
DrawBall(hdcWindow);
|
||||
|
||||
ReleaseDC(hwnd, hdcWindow);
|
||||
}
|
||||
break;
|
||||
case WM_PAINT:
|
||||
if(hbmBall && hbmMask)
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdcWindow;
|
||||
hdcWindow = BeginPaint(hwnd, &ps);
|
||||
|
||||
DrawBall(hdcWindow);
|
||||
|
||||
EndPaint(hwnd, &ps);
|
||||
}
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hwnd);
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
KillTimer(hwnd, idTimer1);
|
||||
|
||||
DeleteObject(hbmBall);
|
||||
DeleteObject(hbmMask);
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hwnd, Message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine, int nCmdShow)
|
||||
{
|
||||
WNDCLASSEX WndClass;
|
||||
HWND hwnd;
|
||||
MSG Msg;
|
||||
|
||||
g_hInst = hInstance;
|
||||
|
||||
WndClass.cbSize = sizeof(WNDCLASSEX);
|
||||
WndClass.style = 0;
|
||||
WndClass.lpfnWndProc = WndProc;
|
||||
WndClass.cbClsExtra = 0;
|
||||
WndClass.cbWndExtra = 0;
|
||||
WndClass.hInstance = g_hInst;
|
||||
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
|
||||
WndClass.lpszMenuName = NULL;
|
||||
WndClass.lpszClassName = g_szClassName;
|
||||
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
|
||||
if(!RegisterClassEx(&WndClass))
|
||||
{
|
||||
MessageBox(0, "Window Registration Failed!", "Error!",
|
||||
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
hwnd = CreateWindowEx(
|
||||
WS_EX_CLIENTEDGE,
|
||||
g_szClassName,
|
||||
"A Bitmap Program",
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, 320, 240,
|
||||
NULL, NULL, g_hInst, NULL);
|
||||
|
||||
if(hwnd == NULL)
|
||||
{
|
||||
MessageBox(0, "Window Creation Failed!", "Error!",
|
||||
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ShowWindow(hwnd, nCmdShow);
|
||||
UpdateWindow(hwnd);
|
||||
|
||||
while(GetMessage(&Msg, NULL, 0, 0))
|
||||
{
|
||||
TranslateMessage(&Msg);
|
||||
DispatchMessage(&Msg);
|
||||
}
|
||||
return Msg.wParam;
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
BALLBMP BITMAP "ball.bmp" // can be found in the Templates folder, please copy to the project folder
|
||||
MASKBMP BITMAP "ballmask.bmp" // as above
|
|
@ -0,0 +1,66 @@
|
|||
#include <windows.h>
|
||||
|
||||
/* This is where all the input to the window goes to */
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
|
||||
switch(Message) {
|
||||
|
||||
/* Upon destruction, tell the main thread to stop */
|
||||
case WM_DESTROY: {
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
|
||||
/* All other messages (a lot of them) are processed using default procedures */
|
||||
default:
|
||||
return DefWindowProc(hwnd, Message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The 'main' function of Win32 GUI programs: this is where execution starts */
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
||||
WNDCLASSEX wc; /* A properties struct of our window */
|
||||
HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
|
||||
MSG msg; /* A temporary location for all messages */
|
||||
|
||||
/* zero out the struct and set the stuff we want to modify */
|
||||
memset(&wc,0,sizeof(wc));
|
||||
wc.cbSize = sizeof(WNDCLASSEX);
|
||||
wc.lpfnWndProc = WndProc; /* This is where we will send messages to */
|
||||
wc.hInstance = hInstance;
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
|
||||
/* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wc.lpszClassName = "WindowClass";
|
||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
|
||||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */
|
||||
|
||||
if(!RegisterClassEx(&wc)) {
|
||||
MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Caption",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, /* x */
|
||||
CW_USEDEFAULT, /* y */
|
||||
640, /* width */
|
||||
480, /* height */
|
||||
NULL,NULL,hInstance,NULL);
|
||||
|
||||
if(hwnd == NULL) {
|
||||
MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
This is the heart of our program where all input is processed and
|
||||
sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
|
||||
this loop will not produce unreasonably high CPU usage
|
||||
*/
|
||||
while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
|
||||
TranslateMessage(&msg); /* Translate key codes to chars if present */
|
||||
DispatchMessage(&msg); /* Send it to WndProc */
|
||||
}
|
||||
return msg.wParam;
|
||||
}
|
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 630 B |
After Width: | Height: | Size: 190 B |