-
C GUI Problems
Hello, i made a C Program that identify the n° of bytes of a determined resource.
Here is the code:
rc.rc(Resource file)
Code:
#include "rc.h"
DD DIALOGEX 6,5,167,49
CAPTION "Testando"
{
CONTROL "Digite alguma coisa:",label,"Static",0x50000000,50,3,66,20
CONTROL "",txt,"Edit",0x500100C0,4,14,160,13,0x00000200
CONTROL "Criar",btn,"Button",0x50010001,56,29,54,13
}
data RCDATA
{
"C:\\cs.exe"
}
rc.h(Header File)
Code:
#define DD 1
#define btn 2
#define data 3
#define txt 4
#define label 5
Main File
Code:
#include<windows.h>
#include "rc.h"
LRESULT CALLBACK WinProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
DialogBox(hInstance,MAKEINTRESOURCE(DD),NULL,(DLGPROC)WinProc);
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
case WM_COMMAND:
if(wParam==btn)
{
HRSRC hRes = FindResource(0, MAKEINTRESOURCE(DD), RT_RCDATA);
HGLOBAL hMem = LoadResource(0, hRes);
void *pMem = LockResource(hMem);
DWORD size = SizeofResource(0, hRes);
SetDlgItemInt(hwnd,txt,size,false);
}
break;
}
return 0;
}
Well the problem is that the program not return the number of bytes, its return 0
Someone knows the problem?
Thanks
Bye
-
Well technically the program can only return 0, see second last line, I don't know if you mean one of the functions, provide more detail into what function that returns 0 and what it is that you intend it to do.
If you want to return the number of bytes (i am assuming the DWORD size), then try returning that. Also pMem is not used, so there is not much point in declaring it.
-
Hello Again :)
The line
is not the problem, if you change this line
Code:
SetDlgItemInt(hwnd,txt,size,false);
by this:
Code:
SetDlgItemInt(hwnd,txt,"2222",false);
So the program return the numer 2222
=/
The problem is on some of resources functions, the variable "size" are not working, and I dont know why
:)
Bye
-
You have a dialog box as a resource, wouldn't you want to just display it? This can be done in one line (avoiding all this size stuff):
Code:
DialogBox(hInstance, TEXT ("DD"), hwnd, DlgProc);
If the program is returning text of a control in a dialog box, setting it, will return whatever you set it to, are you sure you shouldn't be using GetDlgInt?