Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (NnamueN, 1 invisible), 1,489 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 1 of 2 1 2
Common Dialog Ex. w/ Win32 API menus (Lite-C pure) #155752
09/20/07 18:45
09/20/07 18:45
Joined: Mar 2007
Posts: 197
Y
yorisimo Offline OP
Member
yorisimo  Offline OP
Member
Y

Joined: Mar 2007
Posts: 197
Hope you find this useful! Now that I finally got the callbacks to work, I will use the win32 menu system instead of having to create Panels and buttons and all Plus, it's easy to make things look professional.
Code:
 
//Press the 'c' key, right click in the window, or click on file menu to bring up color selection dialog
#include <acknex.h>
#include <default.c> //optional
#include <windows.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
function SelectColor(COLOR* bgr);

//See MSDN (Visual Studio) documentation for info about the Flags and any win32 API functions)
//Make sure you use windows.h with CHOOSECOLOR declared (like in V7.06 beta)
//I couldn't get RGB(r,g,b) macros to work so I just used hex values (0x00BBGGRR) for colors
CHOOSECOLOR cc; //choosecolor struct for ChooseColor function
COLORREF customcolors[16]={0x000000fe,0x0000fe00,0x00fe0000,0x00fefe00,0x00fe00fe,0x0000fefe,0x00fefefe, 0, 0, 0, 0, 0, 0, 0, 0, 0};
COLORREF defaultcolor=0x00000000;

HMENU hMenu; //main menu
HMENU hSubMenu;//dropdown menu
HMENU hPopup; //popup menu on rightclick

POINT cursor; //point struct for cursor position

var setup_flag=ON;
var choose_flag=OFF;

function main()
{
wait(1);

COLOR usercolor;
hMenu=CreateMenu();
hSubMenu=CreateMenu();
hPopup=CreatePopupMenu();

InsertMenu(hMenu,0,MF_BYPOSITION|MF_STRING|MF_POPUP,hSubMenu,"File");
InsertMenu(hSubMenu,0,MF_BYPOSITION|MF_STRING,1,"Choose Color");
InsertMenu(hSubMenu,1,MF_BYPOSITION|MF_STRING,2,"QUIT");
InsertMenu(hPopup,0,MF_BYPOSITION|MF_STRING,3,"Choose Color");
InsertMenu(hPopup,1,MF_BYPOSITION|MF_STRING,4,"QUIT");

SetWindowLong(hWnd,GWL_WNDPROC, WndProc); //change the window procedure
//Change Window style to activate Maximize button
SetWindowLong(hWnd,GWL_STYLE, WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_SIZEBOX);
SetMenu(hWnd,hMenu); //activate the main menu
ShowWindow(hWnd,SW_SHOW);

while (1)
{
if(choose_flag){
if(SelectColor(&usercolor)) {vec_set(screen_color,usercolor);}
choose_flag=OFF;
}
wait(1);
}
}

function SelectColor(COLOR* bgr){
if(setup_flag==ON){ //initialize the struct if first time through
cc.lStructSize=sizeof(CHOOSECOLOR);
cc.hwndOwner=hWnd; //can be NULL (will not appear within engine window)
cc.hInstance=NULL;
cc.rgbResult=defaultcolor; //can be NULL (black)
cc.lpCustColors=customcolors; //may not be NULL!
cc.Flags=CC_RGBINIT;
cc.lCustData=NULL;
cc.lpfnHook=NULL;
cc.lpTemplateName=NULL;
setup_flag=OFF;
}

if(ChooseColor(&cc)){
bgr.blue=GetBValue(cc.rgbResult);
bgr.green=GetGValue(cc.rgbResult);
bgr.red=GetRValue(cc.rgbResult);
return(1);
}
return(0);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
switch(message){
case WM_RBUTTONUP:
GetCursorPos(&cursor); //or use GS cursor function
//Activate the popupmenu at the cursor location
TrackPopupMenu(hPopup,TPM_LEFTALIGN,cursor.x,cursor.y,0,hWnd,0);
break;
case WM_CHAR:
switch(wParam){
case 99: choose_flag=ON; break; //letter 'c'
}
case WM_COMMAND:
switch(wParam){
case 1: //main menu 'Coose Color'
case 3: choose_flag=ON; break;//popup menu 'Coose Color'
case 2: //main menu 'Quit'
case 4: sys_exit(NULL); //popup menu 'Quit'
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return(0);
}



Re: Common Dialog Ex. w/ Win32 API menus (Lite-C pure) [Re: yorisimo] #155753
09/21/07 04:00
09/21/07 04:00
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
Thanks again yorisimo!
gonna try it. but does it work after publishing?

Re: Common Dialog Ex. w/ Win32 API menus (Lite-C p [Re: Shadow969] #155754
09/21/07 14:29
09/21/07 14:29
Joined: Mar 2007
Posts: 197
Y
yorisimo Offline OP
Member
yorisimo  Offline OP
Member
Y

Joined: Mar 2007
Posts: 197
yes. you scared me there for a moment.

For others trying this, if you don't have access to the 7.06beta windows.h file, just add the following code at the end of your windows.h
Code:
 
//from windows.h V7.06.0 beta
typedef DWORD COLORREF;
typedef struct CHOOSECOLOR {
long lStructSize;
long hwndOwner;
long hInstance;
COLORREF rgbResult;
COLORREF *lpCustColors;
long Flags;
long lCustData;
long lpfnHook;
char* lpTemplateName;
} CHOOSECOLOR;

#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))
#define GetRValue(rgb) ((BYTE)(rgb))
#define GetGValue(rgb) ((BYTE)(((WORD)(rgb)) >> 8))
#define GetBValue(rgb) ((BYTE)((rgb)>>16))

BOOL WINAPI ChooseColor(CHOOSECOLOR* lpcc);
#define PRAGMA_API ChooseColor;comdlg32.dll!ChooseColorA



Re: Common Dialog Ex. w/ Win32 API menus (Lite-C p [Re: yorisimo] #155755
09/21/07 21:00
09/21/07 21:00
Joined: Aug 2006
Posts: 78
A
amadeu Offline
Junior Member
amadeu  Offline
Junior Member
A

Joined: Aug 2006
Posts: 78
hi

I tried to run your script but did nor work.
Appear this:
CreatePopupMenu(); wrong number/type of parameters

What is the right code?

thx

Re: Common Dialog Ex. w/ Win32 API menus (Lite-C p [Re: amadeu] #155756
09/25/07 15:43
09/25/07 15:43
Joined: Mar 2007
Posts: 197
Y
yorisimo Offline OP
Member
yorisimo  Offline OP
Member
Y

Joined: Mar 2007
Posts: 197
this works for me, I don't know why you are getting this error. You might try editing windows.h line: "long WINAPI CreatePopupMenu(long);" to "long WINAPI CreatePopupMenu(void);"
as CreatePopupMenu does not have any inputs.


Joris Lambrecht
My Contributions: Relative Rotation, Window Sizing
Re: Common Dialog Ex. w/ Win32 API menus (Lite-C p [Re: yorisimo] #155757
09/28/07 15:37
09/28/07 15:37
Joined: Mar 2007
Posts: 197
Y
yorisimo Offline OP
Member
yorisimo  Offline OP
Member
Y

Joined: Mar 2007
Posts: 197
when i updated to v7.06 beta i got this error, and my fix fixed it.

Note: you should avoid using the method I used here, and rather use ScanMessage. Changing the windows procedures prevents all the default things like keystrokes from being detected unless you code them yourself. See my post on ScanMessage in Lite-C Scripting/Win API with Lite-C pure mode

Re: Common Dialog Ex. w/ Win32 API menus (Lite-C p [Re: yorisimo] #155758
09/28/07 19:00
09/28/07 19:00
Joined: Jun 2007
Posts: 236
acknex.exe
ACKNEX007 Offline
Member
ACKNEX007  Offline
Member

Joined: Jun 2007
Posts: 236
acknex.exe
it worked after adding the lines in windows.h as 'yorisimo' said.

Re: Common Dialog Ex. w/ Win32 API menus (Lite-C p [Re: ACKNEX007] #155759
09/28/07 21:41
09/28/07 21:41
Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
TripleX Offline
Expert
TripleX  Offline
Expert

Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
fascinating.. would have been great for GameEdit.. And I've programmed all that damn [censored] with panels.. hmm

Thanks for the contrib, will maybe be a great possibility for future generators ^^

Re: Common Dialog Ex. w/ Win32 API menus (Lite-C p [Re: yorisimo] #155760
10/12/07 23:54
10/12/07 23:54
Joined: Apr 2006
Posts: 1,551
Netherlands
D3D Offline
Serious User
D3D  Offline
Serious User

Joined: Apr 2006
Posts: 1,551
Netherlands
Excellent contribution yorisimo, thanks for sharing!


smile
Re: Common Dialog Ex. w/ Win32 API menus (Lite-C p [Re: D3D] #155761
10/14/07 06:13
10/14/07 06:13
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline
User
MrCode  Offline
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
But from a programming standpoint....isn't it easier just to use Acknex buttons and panels? I mean, what with all the instances and message handling with Windows... Ugh, no wonder I don't take interest in learning the Windows API.


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1